kex.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. void finish_kexhashbuf(void);
  35. #if DROPBEAR_NORMAL_DH
  36. struct kex_dh_param *gen_kexdh_param(void);
  37. void free_kexdh_param(struct kex_dh_param *param);
  38. void kexdh_comb_key(struct kex_dh_param *param, mp_int *dh_pub_them,
  39. sign_key *hostkey);
  40. #endif
  41. #if DROPBEAR_ECDH
  42. struct kex_ecdh_param *gen_kexecdh_param(void);
  43. void free_kexecdh_param(struct kex_ecdh_param *param);
  44. void kexecdh_comb_key(struct kex_ecdh_param *param, buffer *pub_them,
  45. sign_key *hostkey);
  46. #endif
  47. #if DROPBEAR_CURVE25519
  48. struct kex_curve25519_param *gen_kexcurve25519_param(void);
  49. void free_kexcurve25519_param(struct kex_curve25519_param *param);
  50. void kexcurve25519_comb_key(const struct kex_curve25519_param *param, const buffer *pub_them,
  51. sign_key *hostkey);
  52. #endif
  53. #ifndef DISABLE_ZLIB
  54. int is_compress_trans(void);
  55. int is_compress_recv(void);
  56. #endif
  57. void recv_msg_kexdh_init(void); /* server */
  58. void send_msg_kexdh_init(void); /* client */
  59. void recv_msg_kexdh_reply(void); /* client */
  60. void recv_msg_ext_info(void);
  61. struct KEXState {
  62. unsigned sentkexinit : 1; /*set when we've sent/recv kexinit packet */
  63. unsigned recvkexinit : 1;
  64. unsigned them_firstfollows : 1; /* true when first_kex_packet_follows is set */
  65. unsigned sentnewkeys : 1; /* set once we've send MSG_NEWKEYS (will be cleared once we have also received */
  66. unsigned recvnewkeys : 1; /* set once we've received MSG_NEWKEYS (cleared once we have also sent */
  67. unsigned int donefirstkex; /* Set to 1 after the first kex has completed,
  68. ie the transport layer has been set up */
  69. unsigned int donesecondkex; /* Set to 1 after the second kex has completed */
  70. unsigned our_first_follows_matches : 1;
  71. time_t lastkextime; /* time of the last kex */
  72. unsigned int datatrans; /* data transmitted since last kex */
  73. unsigned int datarecv; /* data received since last kex */
  74. };
  75. #if DROPBEAR_NORMAL_DH
  76. struct kex_dh_param {
  77. mp_int pub; /* e */
  78. mp_int priv; /* x */
  79. };
  80. #endif
  81. #if DROPBEAR_ECDH
  82. struct kex_ecdh_param {
  83. ecc_key key;
  84. };
  85. #endif
  86. #if DROPBEAR_CURVE25519
  87. #define CURVE25519_LEN 32
  88. struct kex_curve25519_param {
  89. unsigned char priv[CURVE25519_LEN];
  90. unsigned char pub[CURVE25519_LEN];
  91. };
  92. #endif
  93. #endif /* DROPBEAR_KEX_H_ */