~ubuntu-branches/ubuntu/trusty/libssh/trusty

« back to all changes in this revision

Viewing changes to include/libssh/wrapper.h

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2009-12-12 14:29:12 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20091212142912-ha5g2iibt6nfnjq8
Tags: 0.4.0-1
* New upstream release.
  - Bump soname
  - Adjust .symbols file
* Readd static library in -dev package
* Let dh_lintian install override file
* debian/README.Debian: Update file
* debian/rules: Add list-missing rule

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the SSH Library
 
3
 *
 
4
 * Copyright (c) 2009 by Aris Adamantiadis
 
5
 *
 
6
 * The SSH Library is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU Lesser General Public License as published by
 
8
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 
9
 * option) any later version.
 
10
 *
 
11
 * The SSH Library is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
13
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
14
 * License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public License
 
17
 * along with the SSH Library; see the file COPYING.  If not, write to
 
18
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
19
 * MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#ifndef WRAPPER_H_
 
23
#define WRAPPER_H_
 
24
 
 
25
#include "config.h"
 
26
 
 
27
#ifdef MD5_DIGEST_LEN
 
28
    #undef MD5_DIGEST_LEN
 
29
#endif
 
30
/* wrapper things */
 
31
#ifdef HAVE_LIBGCRYPT
 
32
#include <gcrypt.h>
 
33
typedef gcry_md_hd_t SHACTX;
 
34
typedef gcry_md_hd_t MD5CTX;
 
35
typedef gcry_md_hd_t HMACCTX;
 
36
#define SHA_DIGEST_LEN 20
 
37
#define MD5_DIGEST_LEN 16
 
38
#define EVP_MAX_MD_SIZE 36
 
39
 
 
40
typedef gcry_mpi_t bignum;
 
41
 
 
42
#define bignum_new() gcry_mpi_new(0)
 
43
#define bignum_free(num) gcry_mpi_release(num)
 
44
#define bignum_set_word(bn,n) gcry_mpi_set_ui(bn,n)
 
45
#define bignum_bin2bn(bn,datalen,data) gcry_mpi_scan(data,GCRYMPI_FMT_USG,bn,datalen,NULL)
 
46
#define bignum_bn2dec(num) my_gcry_bn2dec(num)
 
47
#define bignum_dec2bn(num, data) my_gcry_dec2bn(data, num)
 
48
#define bignum_bn2hex(num,data) gcry_mpi_aprint(GCRYMPI_FMT_HEX,data,NULL,num)
 
49
#define bignum_hex2bn(num,datalen,data) gcry_mpi_scan(num,GCRYMPI_FMT_HEX,data,datalen,NULL)
 
50
#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)
 
51
#define bignum_mod_exp(dest,generator,exp,modulo) gcry_mpi_powm(dest,generator,exp,modulo)
 
52
#define bignum_num_bits(num) gcry_mpi_get_nbits(num)
 
53
#define bignum_num_bytes(num) ((gcry_mpi_get_nbits(num)+7)/8)
 
54
#define bignum_is_bit_set(num,bit) gcry_mpi_test_bit(num,bit)
 
55
#define bignum_bn2bin(num,datalen,data) gcry_mpi_print(GCRYMPI_FMT_USG,data,datalen,NULL,num)
 
56
#define bignum_cmp(num1,num2) gcry_mpi_cmp(num1,num2)
 
57
 
 
58
#elif defined HAVE_LIBCRYPTO
 
59
 
 
60
#include <openssl/dsa.h>
 
61
#include <openssl/rsa.h>
 
62
#include <openssl/sha.h>
 
63
#include <openssl/md5.h>
 
64
#include <openssl/hmac.h>
 
65
typedef SHA_CTX* SHACTX;
 
66
typedef MD5_CTX*  MD5CTX;
 
67
typedef HMAC_CTX* HMACCTX;
 
68
 
 
69
#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
 
70
#define MD5_DIGEST_LEN MD5_DIGEST_LENGTH
 
71
 
 
72
#include <openssl/bn.h>
 
73
typedef BIGNUM*  bignum;
 
74
typedef BN_CTX* bignum_CTX;
 
75
 
 
76
#define bignum_new() BN_new()
 
77
#define bignum_free(num) BN_clear_free(num)
 
78
#define bignum_set_word(bn,n) BN_set_word(bn,n)
 
79
#define bignum_bin2bn(bn,datalen,data) BN_bin2bn(bn,datalen,data)
 
80
#define bignum_bn2dec(num) BN_bn2dec(num)
 
81
#define bignum_dec2bn(bn,data) BN_dec2bn(data,bn)
 
82
#define bignum_bn2hex(num) BN_bn2hex(num)
 
83
#define bignum_rand(rnd, bits, top, bottom) BN_rand(rnd,bits,top,bottom)
 
84
#define bignum_ctx_new() BN_CTX_new()
 
85
#define bignum_ctx_free(num) BN_CTX_free(num)
 
86
#define bignum_mod_exp(dest,generator,exp,modulo,ctx) BN_mod_exp(dest,generator,exp,modulo,ctx)
 
87
#define bignum_num_bytes(num) BN_num_bytes(num)
 
88
#define bignum_num_bits(num) BN_num_bits(num)
 
89
#define bignum_is_bit_set(num,bit) BN_is_bit_set(num,bit)
 
90
#define bignum_bn2bin(num,ptr) BN_bn2bin(num,ptr)
 
91
#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
 
92
 
 
93
#endif /* OPENSSL_CRYPTO */
 
94
 
 
95
MD5CTX md5_init(void);
 
96
void md5_update(MD5CTX c, const void *data, unsigned long len);
 
97
void md5_final(unsigned char *md,MD5CTX c);
 
98
SHACTX sha1_init(void);
 
99
void sha1_update(SHACTX c, const void *data, unsigned long len);
 
100
void sha1_final(unsigned char *md,SHACTX c);
 
101
void sha1(unsigned char *digest,int len,unsigned char *hash);
 
102
#define HMAC_SHA1 1
 
103
#define HMAC_MD5 2
 
104
HMACCTX hmac_init(const void *key,int len,int type);
 
105
void hmac_update(HMACCTX c, const void *data, unsigned long len);
 
106
void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
 
107
 
 
108
int crypt_set_algorithms(ssh_session );
 
109
int crypt_set_algorithms_server(ssh_session session);
 
110
struct ssh_crypto_struct *crypto_new(void);
 
111
void crypto_free(struct ssh_crypto_struct *crypto);
 
112
 
 
113
 
 
114
#endif /* WRAPPER_H_ */