algo.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_ALGO_H_
  25. #define DROPBEAR_ALGO_H_
  26. #include "includes.h"
  27. #include "buffer.h"
  28. #define DROPBEAR_MODE_UNUSED 0
  29. #define DROPBEAR_MODE_CBC 1
  30. #define DROPBEAR_MODE_CTR 2
  31. struct Algo_Type {
  32. const char *name; /* identifying name */
  33. char val; /* a value for this cipher, or -1 for invalid */
  34. const void *data; /* algorithm specific data */
  35. char usable; /* whether we can use this algorithm */
  36. const void *mode; /* the mode, currently only used for ciphers,
  37. points to a 'struct dropbear_cipher_mode' */
  38. };
  39. typedef struct Algo_Type algo_type;
  40. /* lists mapping ssh types of algorithms to internal values */
  41. extern algo_type sshkex[];
  42. extern algo_type sigalgs[];
  43. extern algo_type sshciphers[];
  44. extern algo_type sshhashes[];
  45. extern algo_type ssh_compress[];
  46. extern algo_type ssh_delaycompress[];
  47. extern algo_type ssh_nocompress[];
  48. extern const struct dropbear_cipher dropbear_nocipher;
  49. extern const struct dropbear_cipher_mode dropbear_mode_none;
  50. extern const struct dropbear_hash dropbear_nohash;
  51. struct dropbear_cipher {
  52. const struct ltc_cipher_descriptor *cipherdesc;
  53. const unsigned long keysize;
  54. const unsigned char blocksize;
  55. };
  56. struct dropbear_cipher_mode {
  57. int (*start)(int cipher, const unsigned char *IV,
  58. const unsigned char *key,
  59. int keylen, int num_rounds, void *cipher_state);
  60. int (*encrypt)(const unsigned char *pt, unsigned char *ct,
  61. unsigned long len, void *cipher_state);
  62. int (*decrypt)(const unsigned char *ct, unsigned char *pt,
  63. unsigned long len, void *cipher_state);
  64. int (*aead_crypt)(unsigned int seq,
  65. const unsigned char *in, unsigned char *out,
  66. unsigned long len, unsigned long taglen,
  67. void *cipher_state, int direction);
  68. int (*aead_getlength)(unsigned int seq,
  69. const unsigned char *in, unsigned int *outlen,
  70. unsigned long len, void *cipher_state);
  71. const struct dropbear_hash *aead_mac;
  72. };
  73. struct dropbear_hash {
  74. const struct ltc_hash_descriptor *hash_desc;
  75. const unsigned long keysize;
  76. /* hashsize may be truncated from the size returned by hash_desc,
  77. eg sha1-96 */
  78. const unsigned char hashsize;
  79. };
  80. enum dropbear_kex_mode {
  81. #if DROPBEAR_NORMAL_DH
  82. DROPBEAR_KEX_NORMAL_DH,
  83. #endif
  84. #if DROPBEAR_ECDH
  85. DROPBEAR_KEX_ECDH,
  86. #endif
  87. #if DROPBEAR_CURVE25519
  88. DROPBEAR_KEX_CURVE25519,
  89. #endif
  90. };
  91. struct dropbear_kex {
  92. enum dropbear_kex_mode mode;
  93. /* "normal" DH KEX */
  94. const unsigned char *dh_p_bytes;
  95. const int dh_p_len;
  96. /* elliptic curve DH KEX */
  97. #if DROPBEAR_ECDH
  98. const struct dropbear_ecc_curve *ecc_curve;
  99. #else
  100. const void* dummy;
  101. #endif
  102. /* both */
  103. const struct ltc_hash_descriptor *hash_desc;
  104. };
  105. /* Includes all algorithms is useall is set */
  106. void buf_put_algolist_all(buffer * buf, const algo_type localalgos[], int useall);
  107. /* Includes "usable" algorithms */
  108. void buf_put_algolist(buffer * buf, const algo_type localalgos[]);
  109. #define KEXGUESS2_ALGO_NAME "kexguess2@matt.ucc.asn.au"
  110. int buf_has_algo(buffer *buf, const char *algo);
  111. algo_type * first_usable_algo(algo_type algos[]);
  112. algo_type * buf_match_algo(buffer* buf, algo_type localalgos[],
  113. int kexguess2, int *goodguess);
  114. #if DROPBEAR_USER_ALGO_LIST
  115. int check_user_algos(const char* user_algo_list, algo_type * algos,
  116. const char *algo_desc);
  117. char * algolist_string(const algo_type algos[]);
  118. #endif
  119. enum {
  120. DROPBEAR_COMP_NONE,
  121. DROPBEAR_COMP_ZLIB,
  122. DROPBEAR_COMP_ZLIB_DELAY,
  123. };
  124. #endif /* DROPBEAR_ALGO_H_ */