libssh  0.7.2
include/libssh/libgcrypt.h
00001 /*
00002  * This file is part of the SSH Library
00003  *
00004  * Copyright (c) 2009 by Aris Adamantiadis
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #ifndef LIBGCRYPT_H_
00022 #define LIBGCRYPT_H_
00023 
00024 #include "config.h"
00025 
00026 #ifdef HAVE_LIBGCRYPT
00027 
00028 #include <gcrypt.h>
00029 typedef gcry_md_hd_t SHACTX;
00030 typedef gcry_md_hd_t SHA256CTX;
00031 typedef gcry_md_hd_t SHA384CTX;
00032 typedef gcry_md_hd_t SHA512CTX;
00033 typedef gcry_md_hd_t MD5CTX;
00034 typedef gcry_md_hd_t HMACCTX;
00035 typedef void *EVPCTX;
00036 #define SHA_DIGEST_LENGTH 20
00037 #define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
00038 #define MD5_DIGEST_LEN 16
00039 #define SHA256_DIGEST_LENGTH 32
00040 #define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
00041 #define SHA384_DIGEST_LENGTH 48
00042 #define SHA384_DIGEST_LEN SHA384_DIGEST_LENGTH
00043 #define SHA512_DIGEST_LENGTH 64
00044 #define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
00045 
00046 #ifndef EVP_MAX_MD_SIZE
00047 #define EVP_MAX_MD_SIZE 64
00048 #endif
00049 
00050 #define EVP_DIGEST_LEN EVP_MAX_MD_SIZE
00051 
00052 typedef gcry_mpi_t bignum;
00053 
00054 /* missing gcrypt functions */
00055 int my_gcry_dec2bn(bignum *bn, const char *data);
00056 char *my_gcry_bn2dec(bignum bn);
00057 
00058 #define bignum_new() gcry_mpi_new(0)
00059 #define bignum_free(num) gcry_mpi_release(num)
00060 #define bignum_set_word(bn,n) gcry_mpi_set_ui(bn,n)
00061 #define bignum_bin2bn(bn,datalen,data) gcry_mpi_scan(data,GCRYMPI_FMT_USG,bn,datalen,NULL)
00062 #define bignum_bn2dec(num) my_gcry_bn2dec(num)
00063 #define bignum_dec2bn(num, data) my_gcry_dec2bn(data, num)
00064 #define bignum_bn2hex(num,data) gcry_mpi_aprint(GCRYMPI_FMT_HEX,data,NULL,num)
00065 #define bignum_hex2bn(num,datalen,data) gcry_mpi_scan(num,GCRYMPI_FMT_HEX,data,datalen,NULL)
00066 #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)
00067 #define bignum_mod_exp(dest,generator,exp,modulo) gcry_mpi_powm(dest,generator,exp,modulo)
00068 #define bignum_num_bits(num) gcry_mpi_get_nbits(num)
00069 #define bignum_num_bytes(num) ((gcry_mpi_get_nbits(num)+7)/8)
00070 #define bignum_is_bit_set(num,bit) gcry_mpi_test_bit(num,bit)
00071 #define bignum_bn2bin(num,datalen,data) gcry_mpi_print(GCRYMPI_FMT_USG,data,datalen,NULL,num)
00072 #define bignum_cmp(num1,num2) gcry_mpi_cmp(num1,num2)
00073 
00074 #endif /* HAVE_LIBGCRYPT */
00075 
00076 struct ssh_cipher_struct *ssh_get_ciphertab(void);
00077 
00078 #endif /* LIBGCRYPT_H_ */