libssh  0.7.3
libgcrypt.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 LIBGCRYPT_H_
22 #define LIBGCRYPT_H_
23 
24 #include "config.h"
25 
26 #ifdef HAVE_LIBGCRYPT
27 
28 #include <gcrypt.h>
29 typedef gcry_md_hd_t SHACTX;
30 typedef gcry_md_hd_t SHA256CTX;
31 typedef gcry_md_hd_t SHA384CTX;
32 typedef gcry_md_hd_t SHA512CTX;
33 typedef gcry_md_hd_t MD5CTX;
34 typedef gcry_md_hd_t HMACCTX;
35 typedef void *EVPCTX;
36 #define SHA_DIGEST_LENGTH 20
37 #define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
38 #define MD5_DIGEST_LEN 16
39 #define SHA256_DIGEST_LENGTH 32
40 #define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
41 #define SHA384_DIGEST_LENGTH 48
42 #define SHA384_DIGEST_LEN SHA384_DIGEST_LENGTH
43 #define SHA512_DIGEST_LENGTH 64
44 #define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
45 
46 #ifndef EVP_MAX_MD_SIZE
47 #define EVP_MAX_MD_SIZE 64
48 #endif
49 
50 #define EVP_DIGEST_LEN EVP_MAX_MD_SIZE
51 
52 typedef gcry_mpi_t bignum;
53 
54 /* missing gcrypt functions */
55 int my_gcry_dec2bn(bignum *bn, const char *data);
56 char *my_gcry_bn2dec(bignum bn);
57 
58 #define bignum_new() gcry_mpi_new(0)
59 #define bignum_free(num) gcry_mpi_release(num)
60 #define bignum_set_word(bn,n) gcry_mpi_set_ui(bn,n)
61 #define bignum_bin2bn(bn,datalen,data) gcry_mpi_scan(data,GCRYMPI_FMT_USG,bn,datalen,NULL)
62 #define bignum_bn2dec(num) my_gcry_bn2dec(num)
63 #define bignum_dec2bn(num, data) my_gcry_dec2bn(data, num)
64 #define bignum_bn2hex(num,data) gcry_mpi_aprint(GCRYMPI_FMT_HEX,data,NULL,num)
65 #define bignum_hex2bn(num,datalen,data) gcry_mpi_scan(num,GCRYMPI_FMT_HEX,data,datalen,NULL)
66 #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)
67 #define bignum_mod_exp(dest,generator,exp,modulo) gcry_mpi_powm(dest,generator,exp,modulo)
68 #define bignum_num_bits(num) gcry_mpi_get_nbits(num)
69 #define bignum_num_bytes(num) ((gcry_mpi_get_nbits(num)+7)/8)
70 #define bignum_is_bit_set(num,bit) gcry_mpi_test_bit(num,bit)
71 #define bignum_bn2bin(num,datalen,data) gcry_mpi_print(GCRYMPI_FMT_USG,data,datalen,NULL,num)
72 #define bignum_cmp(num1,num2) gcry_mpi_cmp(num1,num2)
73 
74 #endif /* HAVE_LIBGCRYPT */
75 
76 struct ssh_cipher_struct *ssh_get_ciphertab(void);
77 
78 #endif /* LIBGCRYPT_H_ */