00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WRAPPER_H_
00023 #define WRAPPER_H_
00024
00025 #include "config.h"
00026
00027 #ifdef MD5_DIGEST_LEN
00028 #undef MD5_DIGEST_LEN
00029 #endif
00030
00031 #ifdef HAVE_LIBGCRYPT
00032 #include <gcrypt.h>
00033 typedef gcry_md_hd_t SHACTX;
00034 typedef gcry_md_hd_t MD5CTX;
00035 typedef gcry_md_hd_t HMACCTX;
00036 #define SHA_DIGEST_LEN 20
00037 #define MD5_DIGEST_LEN 16
00038 #define EVP_MAX_MD_SIZE 36
00039
00040 typedef gcry_mpi_t bignum;
00041
00042 #define bignum_new() gcry_mpi_new(0)
00043 #define bignum_free(num) gcry_mpi_release(num)
00044 #define bignum_set_word(bn,n) gcry_mpi_set_ui(bn,n)
00045 #define bignum_bin2bn(bn,datalen,data) gcry_mpi_scan(data,GCRYMPI_FMT_USG,bn,datalen,NULL)
00046 #define bignum_bn2dec(num) my_gcry_bn2dec(num)
00047 #define bignum_dec2bn(num, data) my_gcry_dec2bn(data, num)
00048 #define bignum_bn2hex(num,data) gcry_mpi_aprint(GCRYMPI_FMT_HEX,data,NULL,num)
00049 #define bignum_hex2bn(num,datalen,data) gcry_mpi_scan(num,GCRYMPI_FMT_HEX,data,datalen,NULL)
00050 #define bignum_rand(num,bits) gcry_mpi_randomize(num,bits,GCRY_STRONG_RANDOM),gcry_mpi_set_bit(num,bits-1),gcry_mpi_set_bit(num,0)
00051 #define bignum_mod_exp(dest,generator,exp,modulo) gcry_mpi_powm(dest,generator,exp,modulo)
00052 #define bignum_num_bits(num) gcry_mpi_get_nbits(num)
00053 #define bignum_num_bytes(num) ((gcry_mpi_get_nbits(num)+7)/8)
00054 #define bignum_is_bit_set(num,bit) gcry_mpi_test_bit(num,bit)
00055 #define bignum_bn2bin(num,datalen,data) gcry_mpi_print(GCRYMPI_FMT_USG,data,datalen,NULL,num)
00056 #define bignum_cmp(num1,num2) gcry_mpi_cmp(num1,num2)
00057
00058 #elif defined HAVE_LIBCRYPTO
00059
00060 #include <openssl/dsa.h>
00061 #include <openssl/rsa.h>
00062 #include <openssl/sha.h>
00063 #include <openssl/md5.h>
00064 #include <openssl/hmac.h>
00065 typedef SHA_CTX* SHACTX;
00066 typedef MD5_CTX* MD5CTX;
00067 typedef HMAC_CTX* HMACCTX;
00068
00069 #define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
00070 #define MD5_DIGEST_LEN MD5_DIGEST_LENGTH
00071
00072 #include <openssl/bn.h>
00073 typedef BIGNUM* bignum;
00074 typedef BN_CTX* bignum_CTX;
00075
00076 #define bignum_new() BN_new()
00077 #define bignum_free(num) BN_clear_free(num)
00078 #define bignum_set_word(bn,n) BN_set_word(bn,n)
00079 #define bignum_bin2bn(bn,datalen,data) BN_bin2bn(bn,datalen,data)
00080 #define bignum_bn2dec(num) BN_bn2dec(num)
00081 #define bignum_dec2bn(bn,data) BN_dec2bn(data,bn)
00082 #define bignum_bn2hex(num) BN_bn2hex(num)
00083 #define bignum_rand(rnd, bits, top, bottom) BN_rand(rnd,bits,top,bottom)
00084 #define bignum_ctx_new() BN_CTX_new()
00085 #define bignum_ctx_free(num) BN_CTX_free(num)
00086 #define bignum_mod_exp(dest,generator,exp,modulo,ctx) BN_mod_exp(dest,generator,exp,modulo,ctx)
00087 #define bignum_num_bytes(num) BN_num_bytes(num)
00088 #define bignum_num_bits(num) BN_num_bits(num)
00089 #define bignum_is_bit_set(num,bit) BN_is_bit_set(num,bit)
00090 #define bignum_bn2bin(num,ptr) BN_bn2bin(num,ptr)
00091 #define bignum_cmp(num1,num2) BN_cmp(num1,num2)
00092
00093 #endif
00094
00095 MD5CTX md5_init(void);
00096 void md5_update(MD5CTX c, const void *data, unsigned long len);
00097 void md5_final(unsigned char *md,MD5CTX c);
00098 SHACTX sha1_init(void);
00099 void sha1_update(SHACTX c, const void *data, unsigned long len);
00100 void sha1_final(unsigned char *md,SHACTX c);
00101 void sha1(unsigned char *digest,int len,unsigned char *hash);
00102 #define HMAC_SHA1 1
00103 #define HMAC_MD5 2
00104 HMACCTX hmac_init(const void *key,int len,int type);
00105 void hmac_update(HMACCTX c, const void *data, unsigned long len);
00106 void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
00107
00108 int crypt_set_algorithms(ssh_session );
00109 int crypt_set_algorithms_server(ssh_session session);
00110 struct ssh_crypto_struct *crypto_new(void);
00111 void crypto_free(struct ssh_crypto_struct *crypto);
00112
00113
00114 #endif