We now build libssh2 in Xcode and it's a much better UB/10.4 citizen
[printdrop.git] / Vendor / libssh2 / Headers / openssl.h
1 /* Copyright (C) 2006, 2007 The Written Word, Inc. All rights reserved.
2 * Author: Simon Josefsson
3 *
4 * Redistribution and use in source and binary forms,
5 * with or without modification, are permitted provided
6 * that the following conditions are met:
7 *
8 * Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the
10 * following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 *
17 * Neither the name of the copyright holder nor the names
18 * of any other contributors may be used to endorse or
19 * promote products derived from this software without
20 * specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
34 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 */
37
38 #include <openssl/opensslconf.h>
39 #include <openssl/sha.h>
40 #ifndef OPENSSL_NO_MD5
41 #include <openssl/md5.h>
42 #endif
43 #include <openssl/evp.h>
44 #include <openssl/hmac.h>
45 #include <openssl/bn.h>
46 #include <openssl/pem.h>
47 #include <openssl/rand.h>
48
49 #ifdef OPENSSL_NO_RSA
50 # define LIBSSH2_RSA 0
51 #else
52 # define LIBSSH2_RSA 1
53 #endif
54
55 #ifdef OPENSSL_NO_DSA
56 # define LIBSSH2_DSA 0
57 #else
58 # define LIBSSH2_DSA 1
59 #endif
60
61 #ifdef OPENSSL_NO_MD5
62 # define LIBSSH2_MD5 0
63 #else
64 # define LIBSSH2_MD5 1
65 #endif
66
67 #ifdef OPENSSL_NO_RIPEMD
68 # define LIBSSH2_HMAC_RIPEMD 0
69 #else
70 # define LIBSSH2_HMAC_RIPEMD 1
71 #endif
72
73 #if OPENSSL_VERSION_NUMBER >= 0x00907000L && !defined(OPENSSL_NO_AES)
74 # define LIBSSH2_AES 1
75 #else
76 # define LIBSSH2_AES 0
77 #endif
78
79 #ifdef OPENSSL_NO_BLOWFISH
80 # define LIBSSH2_BLOWFISH 0
81 #else
82 # define LIBSSH2_BLOWFISH 1
83 #endif
84
85 #ifdef OPENSSL_NO_RC4
86 # define LIBSSH2_RC4 0
87 #else
88 # define LIBSSH2_RC4 1
89 #endif
90
91 #ifdef OPENSSL_NO_CAST
92 # define LIBSSH2_CAST 0
93 #else
94 # define LIBSSH2_CAST 1
95 #endif
96
97 #ifdef OPENSSL_NO_DES
98 # define LIBSSH2_3DES 0
99 #else
100 # define LIBSSH2_3DES 1
101 #endif
102
103 #define libssh2_random(buf, len) \
104 RAND_bytes ((buf), (len))
105
106 #define libssh2_sha1_ctx SHA_CTX
107 #define libssh2_sha1_init(ctx) SHA1_Init(ctx)
108 #define libssh2_sha1_update(ctx, data, len) SHA1_Update(&(ctx), data, len)
109 #define libssh2_sha1_final(ctx, out) SHA1_Final(out, &(ctx))
110 #define libssh2_sha1(message, len, out) SHA1(message, len, out)
111
112 #define libssh2_md5_ctx MD5_CTX
113 #define libssh2_md5_init(ctx) MD5_Init(ctx)
114 #define libssh2_md5_update(ctx, data, len) MD5_Update(&(ctx), data, len)
115 #define libssh2_md5_final(ctx, out) MD5_Final(out, &(ctx))
116 #define libssh2_md5(message, len, out) MD5(message, len, out)
117
118 #define libssh2_hmac_ctx HMAC_CTX
119 #define libssh2_hmac_sha1_init(ctx, key, keylen) \
120 HMAC_Init(ctx, key, keylen, EVP_sha1())
121 #define libssh2_hmac_md5_init(ctx, key, keylen) \
122 HMAC_Init(ctx, key, keylen, EVP_md5())
123 #define libssh2_hmac_ripemd160_init(ctx, key, keylen) \
124 HMAC_Init(ctx, key, keylen, EVP_ripemd160())
125 #define libssh2_hmac_update(ctx, data, datalen) \
126 HMAC_Update(&(ctx), data, datalen)
127 #define libssh2_hmac_final(ctx, data) HMAC_Final(&(ctx), data, NULL)
128 #define libssh2_hmac_cleanup(ctx) HMAC_cleanup(ctx)
129
130 #define libssh2_crypto_init()
131
132 #define libssh2_rsa_ctx RSA
133
134 int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa,
135 const unsigned char *edata,
136 unsigned long elen,
137 const unsigned char *ndata,
138 unsigned long nlen,
139 const unsigned char *ddata,
140 unsigned long dlen,
141 const unsigned char *pdata,
142 unsigned long plen,
143 const unsigned char *qdata,
144 unsigned long qlen,
145 const unsigned char *e1data,
146 unsigned long e1len,
147 const unsigned char *e2data,
148 unsigned long e2len,
149 const unsigned char *coeffdata, unsigned long coefflen);
150 int _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
151 LIBSSH2_SESSION * session,
152 FILE * fp, unsigned const char *passphrase);
153 int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa,
154 const unsigned char *sig,
155 unsigned long sig_len,
156 const unsigned char *m, unsigned long m_len);
157 int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
158 libssh2_rsa_ctx * rsactx,
159 const unsigned char *hash,
160 unsigned long hash_len,
161 unsigned char **signature,
162 unsigned long *signature_len);
163
164 #define _libssh2_rsa_free(rsactx) RSA_free(rsactx)
165
166 #define libssh2_dsa_ctx DSA
167
168 int _libssh2_dsa_new(libssh2_dsa_ctx ** dsa,
169 const unsigned char *pdata,
170 unsigned long plen,
171 const unsigned char *qdata,
172 unsigned long qlen,
173 const unsigned char *gdata,
174 unsigned long glen,
175 const unsigned char *ydata,
176 unsigned long ylen,
177 const unsigned char *x, unsigned long x_len);
178 int _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
179 LIBSSH2_SESSION * session,
180 FILE * fp, unsigned const char *passphrase);
181 int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx,
182 const unsigned char *sig,
183 const unsigned char *m, unsigned long m_len);
184 int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
185 const unsigned char *hash,
186 unsigned long hash_len, unsigned char *sig);
187
188 #define _libssh2_dsa_free(dsactx) DSA_free(dsactx)
189
190 #define _libssh2_cipher_type(name) const EVP_CIPHER *(*name)(void)
191 #define _libssh2_cipher_ctx EVP_CIPHER_CTX
192
193 #define _libssh2_cipher_aes256 EVP_aes_256_cbc
194 #define _libssh2_cipher_aes192 EVP_aes_192_cbc
195 #define _libssh2_cipher_aes128 EVP_aes_128_cbc
196 #define _libssh2_cipher_blowfish EVP_bf_cbc
197 #define _libssh2_cipher_arcfour EVP_rc4
198 #define _libssh2_cipher_cast5 EVP_cast5_cbc
199 #define _libssh2_cipher_3des EVP_des_ede3_cbc
200
201 int _libssh2_cipher_init(_libssh2_cipher_ctx * h,
202 _libssh2_cipher_type(algo),
203 unsigned char *iv,
204 unsigned char *secret, int encrypt);
205
206 int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
207 _libssh2_cipher_type(algo),
208 int encrypt, unsigned char *block);
209
210 #define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_cleanup(ctx)
211
212 #define _libssh2_bn BIGNUM
213 #define _libssh2_bn_ctx BN_CTX
214 #define _libssh2_bn_ctx_new() BN_CTX_new()
215 #define _libssh2_bn_ctx_free(bnctx) BN_CTX_free(bnctx)
216 #define _libssh2_bn_init() BN_new()
217 #define _libssh2_bn_rand(bn, bits, top, bottom) BN_rand(bn, bits, top, bottom)
218 #define _libssh2_bn_mod_exp(r, a, p, m, ctx) BN_mod_exp(r, a, p, m, ctx)
219 #define _libssh2_bn_set_word(bn, val) BN_set_word(bn, val)
220 #define _libssh2_bn_from_bin(bn, len, val) BN_bin2bn(val, len, bn)
221 #define _libssh2_bn_to_bin(bn, val) BN_bn2bin(bn, val)
222 #define _libssh2_bn_bytes(bn) BN_num_bytes(bn)
223 #define _libssh2_bn_bits(bn) BN_num_bits(bn)
224 #define _libssh2_bn_free(bn) BN_clear_free(bn)