libssh  0.8.0
libcrypto.h
1 /*
2  * This file is part of the SSH Library
3  *
4  * Copyright (c) 2009 by Aris Adamantiadis
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef LIBCRYPTO_H_
22 #define LIBCRYPTO_H_
23 
24 #include "config.h"
25 
26 #ifdef HAVE_LIBCRYPTO
27 
28 #include <openssl/dsa.h>
29 #include <openssl/rsa.h>
30 #include <openssl/sha.h>
31 #include <openssl/md5.h>
32 #include <openssl/hmac.h>
33 #include <openssl/evp.h>
34 
35 typedef EVP_MD_CTX* SHACTX;
36 typedef EVP_MD_CTX* SHA256CTX;
37 typedef EVP_MD_CTX* SHA384CTX;
38 typedef EVP_MD_CTX* SHA512CTX;
39 typedef EVP_MD_CTX* MD5CTX;
40 typedef HMAC_CTX* HMACCTX;
41 #ifdef HAVE_ECC
42 typedef EVP_MD_CTX *EVPCTX;
43 #else
44 typedef void *EVPCTX;
45 #endif
46 
47 #define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
48 #define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
49 #define SHA384_DIGEST_LEN SHA384_DIGEST_LENGTH
50 #define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
51 #ifdef MD5_DIGEST_LEN
52  #undef MD5_DIGEST_LEN
53 #endif
54 #define MD5_DIGEST_LEN MD5_DIGEST_LENGTH
55 
56 #ifdef HAVE_OPENSSL_ECC
57 #define EVP_DIGEST_LEN EVP_MAX_MD_SIZE
58 #endif
59 
60 #include <openssl/bn.h>
61 #include <openssl/opensslv.h>
62 #define OPENSSL_0_9_7b 0x0090702fL
63 #if (OPENSSL_VERSION_NUMBER <= OPENSSL_0_9_7b)
64 #define BROKEN_AES_CTR
65 #endif
66 typedef BIGNUM* bignum;
67 typedef BN_CTX* bignum_CTX;
68 
69 #define bignum_new() BN_new()
70 #define bignum_free(num) BN_clear_free(num)
71 #define bignum_set_word(bn,n) BN_set_word(bn,n)
72 #define bignum_bin2bn(bn,datalen,data) BN_bin2bn(bn,datalen,data)
73 #define bignum_bn2dec(num) BN_bn2dec(num)
74 #define bignum_dec2bn(bn,data) BN_dec2bn(data,bn)
75 #define bignum_bn2hex(num) BN_bn2hex(num)
76 #define bignum_rand(rnd, bits, top, bottom) BN_rand(rnd,bits,top,bottom)
77 #define bignum_ctx_new() BN_CTX_new()
78 #define bignum_ctx_free(num) BN_CTX_free(num)
79 #define bignum_mod_exp(dest,generator,exp,modulo,ctx) BN_mod_exp(dest,generator,exp,modulo,ctx)
80 #define bignum_num_bytes(num) BN_num_bytes(num)
81 #define bignum_num_bits(num) BN_num_bits(num)
82 #define bignum_is_bit_set(num,bit) BN_is_bit_set(num,bit)
83 #define bignum_bn2bin(num,ptr) BN_bn2bin(num,ptr)
84 #define bignum_cmp(num1,num2) BN_cmp(num1,num2)
85 
86 SHA256CTX sha256_init(void);
87 void sha256_update(SHA256CTX c, const void *data, unsigned long len);
88 void sha256_final(unsigned char *md, SHA256CTX c);
89 
90 SHA384CTX sha384_init(void);
91 void sha384_update(SHA384CTX c, const void *data, unsigned long len);
92 void sha384_final(unsigned char *md, SHA384CTX c);
93 
94 SHA512CTX sha512_init(void);
95 void sha512_update(SHA512CTX c, const void *data, unsigned long len);
96 void sha512_final(unsigned char *md, SHA512CTX c);
97 
98 struct ssh_cipher_struct *ssh_get_ciphertab(void);
99 
100 #endif /* HAVE_LIBCRYPTO */
101 
102 #endif /* LIBCRYPTO_H_ */