kex.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Dropbear - a SSH2 server
  3. *
  4. * Copyright (c) 2002,2003 Matt Johnston
  5. * All rights reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE. */
  24. #ifndef DROPBEAR_KEX_H_
  25. #define DROPBEAR_KEX_H_
  26. #include "includes.h"
  27. #include "algo.h"
  28. #include "signkey.h"
  29. void send_msg_kexinit(void);
  30. void recv_msg_kexinit(void);
  31. void send_msg_newkeys(void);
  32. void recv_msg_newkeys(void);
  33. void kexfirstinitialise(void);
  34. struct kex_dh_param *gen_kexdh_param(void);
  35. void free_kexdh_param(struct kex_dh_param *param);
  36. void kexdh_comb_key(struct kex_dh_param *param, mp_int *dh_pub_them,
  37. sign_key *hostkey);
  38. #ifdef DROPBEAR_ECDH
  39. struct kex_ecdh_param *gen_kexecdh_param(void);
  40. void free_kexecdh_param(struct kex_ecdh_param *param);
  41. void kexecdh_comb_key(struct kex_ecdh_param *param, buffer *pub_them,
  42. sign_key *hostkey);
  43. #endif
  44. #ifdef DROPBEAR_CURVE25519
  45. struct kex_curve25519_param *gen_kexcurve25519_param(void);
  46. void free_kexcurve25519_param(struct kex_curve25519_param *param);
  47. void kexcurve25519_comb_key(struct kex_curve25519_param *param, buffer *pub_them,
  48. sign_key *hostkey);
  49. #endif
  50. #ifndef DISABLE_ZLIB
  51. int is_compress_trans(void);
  52. int is_compress_recv(void);
  53. #endif
  54. void recv_msg_kexdh_init(void); /* server */
  55. void send_msg_kexdh_init(void); /* client */
  56. void recv_msg_kexdh_reply(void); /* client */
  57. struct KEXState {
  58. unsigned sentkexinit : 1; /*set when we've sent/recv kexinit packet */
  59. unsigned recvkexinit : 1;
  60. unsigned them_firstfollows : 1; /* true when first_kex_packet_follows is set */
  61. unsigned sentnewkeys : 1; /* set once we've send MSG_NEWKEYS (will be cleared once we have also received */
  62. unsigned recvnewkeys : 1; /* set once we've received MSG_NEWKEYS (cleared once we have also sent */
  63. unsigned donefirstkex : 1; /* Set to 1 after the first kex has completed,
  64. ie the transport layer has been set up */
  65. unsigned our_first_follows_matches : 1;
  66. time_t lastkextime; /* time of the last kex */
  67. unsigned int datatrans; /* data transmitted since last kex */
  68. unsigned int datarecv; /* data received since last kex */
  69. };
  70. struct kex_dh_param {
  71. mp_int pub; /* e */
  72. mp_int priv; /* x */
  73. };
  74. #ifdef DROPBEAR_ECDH
  75. struct kex_ecdh_param {
  76. ecc_key key;
  77. };
  78. #endif
  79. #ifdef DROPBEAR_CURVE25519
  80. #define CURVE25519_LEN 32
  81. struct kex_curve25519_param {
  82. unsigned char priv[CURVE25519_LEN];
  83. unsigned char pub[CURVE25519_LEN];
  84. };
  85. /* No header file for curve25519_donna */
  86. int curve25519_donna(unsigned char *out, const unsigned char *secret, const unsigned char *other);
  87. #endif
  88. #define MAX_KEXHASHBUF 2000
  89. #endif /* DROPBEAR_KEX_H_ */