00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _CRYPTO_H_
00026 #define _CRYPTO_H_
00027
00028 #include "config.h"
00029
00030 #ifdef HAVE_LIBGCRYPT
00031 #include <gcrypt.h>
00032 #endif
00033 #include "libssh/wrapper.h"
00034
00035 #ifdef cbc_encrypt
00036 #undef cbc_encrypt
00037 #endif
00038 #ifdef cbc_decrypt
00039 #undef cbc_decrypt
00040 #endif
00041
00042 #ifdef HAVE_OPENSSL_ECDH_H
00043 #include <openssl/ecdh.h>
00044 #endif
00045 #include "libssh/ecdh.h"
00046 #include "libssh/kex.h"
00047 #include "libssh/curve25519.h"
00048
00049 enum ssh_key_exchange_e {
00050
00051 SSH_KEX_DH_GROUP1_SHA1=1,
00052
00053 SSH_KEX_DH_GROUP14_SHA1,
00054
00055 SSH_KEX_ECDH_SHA2_NISTP256,
00056
00057 SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG
00058 };
00059
00060 struct ssh_crypto_struct {
00061 bignum e,f,x,k,y;
00062 #ifdef HAVE_ECDH
00063 EC_KEY *ecdh_privkey;
00064 ssh_string ecdh_client_pubkey;
00065 ssh_string ecdh_server_pubkey;
00066 #endif
00067 #ifdef HAVE_CURVE25519
00068 ssh_curve25519_privkey curve25519_privkey;
00069 ssh_curve25519_pubkey curve25519_client_pubkey;
00070 ssh_curve25519_pubkey curve25519_server_pubkey;
00071 #endif
00072 ssh_string dh_server_signature;
00073 size_t digest_len;
00074 unsigned char *session_id;
00075 unsigned char *secret_hash;
00076 unsigned char *encryptIV;
00077 unsigned char *decryptIV;
00078 unsigned char *decryptkey;
00079 unsigned char *encryptkey;
00080 unsigned char *encryptMAC;
00081 unsigned char *decryptMAC;
00082 unsigned char hmacbuf[EVP_MAX_MD_SIZE];
00083 struct ssh_cipher_struct *in_cipher, *out_cipher;
00084 ssh_string server_pubkey;
00085 const char *server_pubkey_type;
00086 int do_compress_out;
00087 int do_compress_in;
00088 int delayed_compress_in;
00089 int delayed_compress_out;
00090 void *compress_out_ctx;
00091 void *compress_in_ctx;
00092
00093 struct ssh_kex_struct server_kex;
00094 struct ssh_kex_struct client_kex;
00095 char *kex_methods[SSH_KEX_METHODS];
00096 enum ssh_key_exchange_e kex_type;
00097 enum ssh_mac_e mac_type;
00098 };
00099
00100 struct ssh_cipher_struct {
00101 const char *name;
00102 unsigned int blocksize;
00103 unsigned int keylen;
00104 #ifdef HAVE_LIBGCRYPT
00105 gcry_cipher_hd_t *key;
00106 #elif defined HAVE_LIBCRYPTO
00107 void *key;
00108 void *IV;
00109 #endif
00110 unsigned int keysize;
00111
00112 int (*set_encrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
00113 int (*set_decrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
00114 void (*cbc_encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
00115 unsigned long len);
00116 void (*cbc_decrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
00117 unsigned long len);
00118 };
00119
00120
00121 #endif