33 #include "libssh/wrapper.h"
42 #ifdef HAVE_OPENSSL_ECDH_H
43 #include <openssl/ecdh.h>
45 #include "libssh/ecdh.h"
46 #include "libssh/kex.h"
47 #include "libssh/curve25519.h"
49 #define DIGEST_MAX_LEN 64
51 enum ssh_key_exchange_e {
53 SSH_KEX_DH_GROUP1_SHA1=1,
55 SSH_KEX_DH_GROUP14_SHA1,
57 SSH_KEX_ECDH_SHA2_NISTP256,
59 SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG
62 struct ssh_crypto_struct {
66 ssh_string ecdh_client_pubkey;
67 ssh_string ecdh_server_pubkey;
69 #ifdef HAVE_CURVE25519
70 ssh_curve25519_privkey curve25519_privkey;
71 ssh_curve25519_pubkey curve25519_client_pubkey;
72 ssh_curve25519_pubkey curve25519_server_pubkey;
74 ssh_string dh_server_signature;
76 unsigned char *session_id;
77 unsigned char *secret_hash;
78 unsigned char *encryptIV;
79 unsigned char *decryptIV;
80 unsigned char *decryptkey;
81 unsigned char *encryptkey;
82 unsigned char *encryptMAC;
83 unsigned char *decryptMAC;
84 unsigned char hmacbuf[DIGEST_MAX_LEN];
85 struct ssh_cipher_struct *in_cipher, *out_cipher;
86 enum ssh_hmac_e in_hmac, out_hmac;
88 ssh_string server_pubkey;
89 const char *server_pubkey_type;
92 int delayed_compress_in;
93 int delayed_compress_out;
94 void *compress_out_ctx;
95 void *compress_in_ctx;
97 struct ssh_kex_struct server_kex;
98 struct ssh_kex_struct client_kex;
99 char *kex_methods[SSH_KEX_METHODS];
100 enum ssh_key_exchange_e kex_type;
101 enum ssh_mac_e mac_type;
104 struct ssh_cipher_struct {
106 unsigned int blocksize;
108 #ifdef HAVE_LIBGCRYPT
109 gcry_cipher_hd_t *key;
110 #elif defined HAVE_LIBCRYPTO
114 unsigned int keysize;
116 int (*set_encrypt_key)(
struct ssh_cipher_struct *cipher,
void *key,
void *IV);
117 int (*set_decrypt_key)(
struct ssh_cipher_struct *cipher,
void *key,
void *IV);
118 void (*encrypt)(
struct ssh_cipher_struct *cipher,
void *in,
void *out,
120 void (*decrypt)(
struct ssh_cipher_struct *cipher,
void *in,
void *out,