-
Notifications
You must be signed in to change notification settings - Fork 0
/
openssl.rkt
373 lines (314 loc) · 19.8 KB
/
openssl.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#lang racket/base
(require ffi/unsafe
racket/runtime-path
(for-syntax racket/base)
openssl/sha1)
(provide (struct-out BN)
(struct-out DH)
(struct-out RSA)
EVP_MAX_MD_SIZE
SHA1_DIGEST_LENGTH
SHA256_DIGEST_LENGTH
NID_sha1
BNp
BN_num_bytes)
(define-runtime-path libcrypto-so
(case (system-type)
[(windows) '(so "libeay32")]
[else '(so "libcrypto")]))
(define libcrypto
(with-handlers ([exn:fail? (lambda (exn)
(log-warning (format "warning: couldn't load OpenSSL library: ~a"
(if (exn? exn)
(exn-message exn)
exn)))
#f)])
(ffi-lib libcrypto-so '("" "0.9.8b" "0.9.8" "0.9.7"))))
(define-syntax-rule (define-crypto-func name func-signature)
(begin
(define name (and libcrypto (get-ffi-obj (quote name) libcrypto func-signature (lambda () #f))))
(provide name)))
(define-cstruct _BN ([j1 _long] [top _int] [dmax _int] [neg _int] [flags _int]))
(define-cstruct _DH ([pad _int] [version _int] [p _BN-pointer][g _BN-pointer] [length _long] [pub_key _BN-pointer] [priv_key _BN-pointer]))
(define-cstruct _RSA ([pad _long]
[version _long]
[meth _pointer]
[engine _pointer]
[n _BN-pointer]
[e _BN-pointer]
[d _BN-pointer]
[p _BN-pointer]
[q _BN-pointer]
[dmp1 _BN-pointer]
[dmq1 _BN-pointer]
[iqmp _BN-pointer]
;[ex_data _int]
[sk _pointer]
[dummy _int]
[references _int]
[flags _int]
[_method_mod_n _pointer]
[_method_mod_p _pointer]
[_method_mod_q _pointer]
[bignum_data _bytes]
[blinding _pointer]
[mt_blinding _pointer]))
(define _MD5_CTX-pointer _pointer)
(define _SHA1_CTX-pointer _pointer)
(define _SHA256_CTX-pointer _pointer)
(define _DSA-pointer _pointer)
(define _EC_KEY-pointer _pointer)
(define _BIO-pointer _pointer)
(define _BIO_METHOD-pointer _pointer)
(define _FILE-pointer _pointer)
(define _EVP_MD_CTX-pointer _pointer)
(define _EVP_MD-pointer _pointer)
(define _EVP_PKEY-pointer _pointer)
(define _ENGINE-pointer _pointer)
(define _EVP_CIPHER_CTX-pointer _pointer)
(define _EVP_CIPHER-pointer _pointer)
(define _ASN1_TYPE-pointer _pointer)
(define _HMAC_CTX-pointer _pointer)
(define-crypto-func OpenSSL_add_all_algorithms (_fun -> _void))
(define-crypto-func OpenSSL_add_all_digests (_fun -> _void))
(define EVP_MAX_MD_SIZE 64)
;(define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */
(define HMAC_MAX_MD_CBLOCK 128)
(define NID_sha1 64)
(define SHA1_DIGEST_LENGTH 20)
(define SHA256_DIGEST_LENGTH 32)
(define-crypto-func DH_new (_fun -> _DH-pointer))
(define-crypto-func DH_generate_key (_fun _DH-pointer -> _int))
(define-crypto-func DH_compute_key (_fun _bytes _BN-pointer _DH-pointer -> _int))
(define-crypto-func DH_size (_fun _DH-pointer -> _int))
(define-crypto-func DH_free (_fun _DH-pointer -> _int))
(define-crypto-func BN_new (_fun -> _BN-pointer))
(define-crypto-func BN_free (_fun _BN-pointer -> _int))
(define-crypto-func BN_bin2bn (_fun _bytes _int _BN-pointer -> _BN-pointer))
(define-crypto-func BN_hex2bn (_fun (_ptr i _BN-pointer) _bytes -> _int))
(define-crypto-func BN_dec2bn (_fun (_ptr i _BN-pointer) _bytes -> _int))
(define-crypto-func BN_num_bits (_fun _BN-pointer -> _int))
(define-crypto-func BN_bn2bin (_fun _BN-pointer _bytes -> _int))
(define-crypto-func BN_print_fp (_fun _pointer _BN-pointer -> _int))
(define-crypto-func BN_rand (_fun _BN-pointer _int _int _int -> _int))
(define-crypto-func BN_cmp (_fun _BN-pointer _BN-pointer -> _int))
(define-crypto-func BN_is_bit_set (_fun _BN-pointer _int -> _int))
(define-crypto-func BN_value_one (_fun -> _BN-pointer))
(define-crypto-func BN_sub (_fun _BN-pointer _BN-pointer _BN-pointer -> _int))
(define-crypto-func BN_clear_free (_fun _BN-pointer -> _int))
(define-crypto-func PEM_read_bio_RSAPrivateKey (_fun _BIO-pointer (_or-null _RSA-pointer) (_or-null _pointer) (_or-null _pointer) -> _RSA-pointer))
(define-crypto-func PEM_read_RSAPrivateKey (_fun _FILE-pointer _RSA-pointer _pointer _pointer -> _RSA-pointer))
(define-crypto-func PEM_read_bio_PrivateKey (_fun _BIO-pointer (_or-null _EVP_PKEY-pointer) (_or-null _pointer) (_or-null _pointer) -> _EVP_PKEY-pointer))
(define-crypto-func PEM_read_PrivateKey (_fun _FILE-pointer (_or-null _EVP_PKEY-pointer) (_or-null _pointer) (_or-null _pointer) -> _EVP_PKEY-pointer))
(define-crypto-func PEM_read_bio_RSAPublicKey (_fun _BIO-pointer (_or-null _RSA-pointer) (_or-null _pointer) (_or-null _pointer) -> (_or-null _RSA-pointer)))
(define-crypto-func PEM_read_RSAPublicKey (_fun _FILE-pointer _RSA-pointer _pointer _pointer -> _RSA-pointer))
(define-crypto-func PEM_read_bio_PublicKey (_fun _BIO-pointer (_or-null _EVP_PKEY-pointer) (_or-null _pointer) (_or-null _pointer) -> _EVP_PKEY-pointer))
(define-crypto-func PEM_read_PublicKey (_fun _FILE-pointer (_or-null _EVP_PKEY-pointer) (_or-null _pointer) (_or-null _pointer) -> _EVP_PKEY-pointer))
(define-crypto-func PEM_write_bio_RSAPublicKey (_fun _BIO-pointer _RSA-pointer -> _int))
(define-crypto-func BIO_s_file (_fun -> _BIO_METHOD-pointer))
(define-crypto-func BIO_new_file (_fun _bytes _bytes -> _BIO-pointer))
(define-crypto-func BIO_new_fp (_fun _FILE-pointer _int -> _BIO-pointer))
(define-crypto-func BIO_new_mem_buf (_fun _bytes _int -> _BIO-pointer))
(define-crypto-func BIO_free (_fun _BIO-pointer -> _void))
(define-crypto-func BIO_set_fp (_fun _BIO-pointer _FILE-pointer _int -> _void))
(define-crypto-func BIO_get_fp (_fun _BIO-pointer ( _ptr o _FILE-pointer) -> _void))
(define-crypto-func BIO_write_filename (_fun _BIO-pointer _bytes -> _int))
(define-crypto-func BIO_append_filename (_fun _BIO-pointer _bytes -> _int))
(define-crypto-func BIO_rw_filename (_fun _BIO-pointer _bytes -> _int))
(define-crypto-func MD5_Init (_fun _MD5_CTX-pointer -> _int))
(define-crypto-func MD5_Update (_fun _MD5_CTX-pointer _bytes _long -> _int))
(define-crypto-func MD5_Final (_fun _bytes _MD5_CTX-pointer -> _int))
(define-crypto-func MD5 (_fun _bytes _long (_ptr i _bytes) -> _int))
(define-crypto-func MD5_Transform (_fun _MD5_CTX-pointer _bytes -> _void))
(define-crypto-func SHA1_Init (_fun _SHA1_CTX-pointer -> _int))
(define-crypto-func SHA1_Update (_fun _SHA1_CTX-pointer _bytes _long -> _int))
(define-crypto-func SHA1_Final (_fun _bytes _SHA1_CTX-pointer -> _int))
(define-crypto-func SHA1 (_fun _bytes _long (_ptr i _bytes) -> _int))
(define-crypto-func SHA1_Transform (_fun _SHA1_CTX-pointer _bytes -> _void))
(define-crypto-func SHA256_Init (_fun _SHA256_CTX-pointer -> _int))
(define-crypto-func SHA256_Update (_fun _SHA256_CTX-pointer _bytes _long -> _int))
(define-crypto-func SHA256_Final (_fun _bytes _SHA256_CTX-pointer -> _int))
(define-crypto-func SHA256 (_fun _bytes _long (_ptr i _bytes) -> _int))
(define-crypto-func SHA256_Transform (_fun _SHA256_CTX-pointer _bytes -> _void))
(define-crypto-func RSA_new (_fun -> _RSA-pointer))
(define-crypto-func RSA_sign (_fun _int _bytes _int _bytes (_ptr io _int) _RSA-pointer -> _int))
(define-crypto-func RSA_verify (_fun _int _bytes _int _bytes _int _RSA-pointer -> _int))
(define-crypto-func RSA_size (_fun _RSA-pointer -> _int))
(define-crypto-func EVP_MD_CTX_init (_fun _EVP_MD_CTX-pointer -> _void))
(define-crypto-func EVP_MD_CTX_create (_fun -> _EVP_MD_CTX-pointer))
(define-crypto-func EVP_DigestInit_ex (_fun _EVP_MD_CTX-pointer _EVP_MD-pointer _ENGINE-pointer -> _int))
(define-crypto-func EVP_DigestUpdate (_fun _EVP_MD_CTX-pointer _bytes _long -> _int))
(define-crypto-func EVP_DigestFinal_ex (_fun _EVP_MD_CTX-pointer _bytes (_ptr io _int) -> _int))
(define-crypto-func EVP_DigestInit (_fun _EVP_MD_CTX-pointer _EVP_MD-pointer -> _int))
(define-crypto-func EVP_DigestFinal (_fun _EVP_MD_CTX-pointer _bytes (_ptr io _int) -> _int))
(define-crypto-func EVP_MD_CTX_cleanup (_fun _EVP_MD_CTX-pointer -> _int))
(define-crypto-func EVP_MD_CTX_destroy (_fun _EVP_MD_CTX-pointer -> _void))
(define-crypto-func EVP_MD_CTX_copy_ex (_fun _EVP_MD_CTX-pointer _EVP_MD_CTX-pointer -> _int))
(define-crypto-func EVP_MD_CTX_copy (_fun _EVP_MD_CTX-pointer _EVP_MD_CTX-pointer -> _int))
(define-crypto-func EVP_MD_type (_fun _EVP_MD-pointer -> _int))
(define-crypto-func EVP_MD_pkey_type (_fun _EVP_MD-pointer -> _int))
(define-crypto-func EVP_MD_size (_fun _EVP_MD-pointer -> _int))
(define-crypto-func EVP_MD_block_size (_fun _EVP_MD-pointer -> _int))
(define-crypto-func EVP_MD_CTX_md (_fun _EVP_MD_CTX-pointer -> _int))
(define-crypto-func EVP_MD_CTX_size (_fun _EVP_MD_CTX-pointer -> _int))
(define-crypto-func EVP_MD_CTX_block_size (_fun _EVP_MD_CTX-pointer -> _int))
(define-crypto-func EVP_MD_CTX_type (_fun _EVP_MD_CTX-pointer -> _int))
(define-crypto-func EVP_md_null (_fun -> _EVP_MD-pointer))
(define-crypto-func EVP_md2 (_fun -> _EVP_MD-pointer))
(define-crypto-func EVP_md5 (_fun -> _EVP_MD-pointer))
(define-crypto-func EVP_sha (_fun -> _EVP_MD-pointer))
(define-crypto-func EVP_sha1 (_fun -> _EVP_MD-pointer))
(define-crypto-func EVP_dss (_fun -> _EVP_MD-pointer))
(define-crypto-func EVP_dss1 (_fun -> _EVP_MD-pointer))
(define-crypto-func EVP_mdc2 (_fun -> _EVP_MD-pointer))
(define-crypto-func EVP_ripemd160 (_fun -> _EVP_MD-pointer))
(define-crypto-func EVP_get_digestbyname (_fun _bytes -> _EVP_MD-pointer ))
; #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
; #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
;(define-crypto-func EVP_SignInit_ex (_fun _EVP_MD_CTX-pointer _EVP_MD-pointer _ENGINE-pointer -> _int))
;(define-crypto-func EVP_SignUpdate (_fun _EVP_MD_CTX-pointer _bytes _int -> _int))
(define-crypto-func EVP_SignFinal (_fun _EVP_MD_CTX-pointer _bytes (_ptr io _int) _EVP_PKEY-pointer -> _int))
;(define-crypto-func EVP_SignInit (_fun _EVP_MD_CTX-pointer _EVP_MD-pointer -> _void))
(define-crypto-func HMAC (_fun _EVP_MD-pointer _bytes _int _bytes _int _bytes (_ptr io _int) -> _bytes))
(define-crypto-func HMAC_CTX_init (_fun _HMAC_CTX-pointer -> _void))
(define-crypto-func HMAC_Init (_fun _HMAC_CTX-pointer _bytes _int _EVP_MD-pointer -> _void))
(define-crypto-func HMAC_Init_ex (_fun _HMAC_CTX-pointer _bytes _int (_or-null _EVP_MD-pointer) (_or-null _ENGINE-pointer) -> _void))
(define-crypto-func HMAC_Update (_fun _HMAC_CTX-pointer _bytes _int -> _void))
(define-crypto-func HMAC_Final (_fun _HMAC_CTX-pointer _bytes (i : (_ptr o _int)) -> _void -> i))
(define-crypto-func HMAC_CTX_cleanup (_fun _HMAC_CTX-pointer -> _void))
(define-crypto-func HMAC_cleanup (_fun _HMAC_CTX-pointer -> _void))
(define-crypto-func EVP_PKEY_new (_fun -> _EVP_PKEY-pointer))
(define-crypto-func EVP_PKEY_free (_fun _EVP_PKEY-pointer -> _void))
(define-crypto-func EVP_PKEY_set1_RSA (_fun _EVP_PKEY-pointer _RSA-pointer -> _int))
(define-crypto-func EVP_PKEY_set1_DSA (_fun _EVP_PKEY-pointer _DSA-pointer -> _int))
(define-crypto-func EVP_PKEY_set1_DH (_fun _EVP_PKEY-pointer _DH-pointer -> _int))
(define-crypto-func EVP_PKEY_set1_EC_KEY (_fun _EVP_PKEY-pointer _EC_KEY-pointer -> _int))
(define-crypto-func EVP_PKEY_get1_RSA (_fun _EVP_PKEY-pointer -> _RSA-pointer))
(define-crypto-func EVP_PKEY_get1_DSA (_fun _EVP_PKEY-pointer -> _DSA-pointer))
(define-crypto-func EVP_PKEY_get1_DH (_fun _EVP_PKEY-pointer -> _DH-pointer))
(define-crypto-func EVP_PKEY_get1_EC_KEY (_fun _EVP_PKEY-pointer -> _EC_KEY-pointer))
(define-crypto-func EVP_PKEY_assign_RSA (_fun _EVP_PKEY-pointer _RSA-pointer -> _int))
(define-crypto-func EVP_PKEY_assign_DSA (_fun _EVP_PKEY-pointer _DSA-pointer -> _int))
(define-crypto-func EVP_PKEY_assign_DH (_fun _EVP_PKEY-pointer _DH-pointer -> _int))
(define-crypto-func EVP_PKEY_assign_EC_KEY (_fun _EVP_PKEY-pointer _EC_KEY-pointer -> _int))
(define-crypto-func EVP_PKEY_type (_fun _int -> _int))
(define-crypto-func EVP_PKEY_size (_fun _EVP_PKEY-pointer -> _int))
(define-crypto-func EVP_CIPHER_CTX_init (_fun _EVP_CIPHER_CTX-pointer -> _void))
(define-crypto-func EVP_CIPHER_CTX_cleanup (_fun _EVP_CIPHER_CTX-pointer -> _int))
(define-crypto-func EVP_CIPHER_CTX_new (_fun -> _EVP_CIPHER_CTX-pointer))
(define-crypto-func EVP_CIPHER_CTX_free (_fun _EVP_CIPHER_CTX-pointer -> _void))
(define-crypto-func EVP_CIPHER_CTX_set_padding (_fun _EVP_CIPHER_CTX-pointer _int -> _int))
(define-crypto-func EVP_CIPHER_CTX_set_key_length (_fun _EVP_CIPHER_CTX-pointer _int -> _int))
(define-crypto-func EVP_CIPHER_CTX_ctrl (_fun _EVP_CIPHER_CTX-pointer _int _int _pointer -> _int))
(define-crypto-func EVP_EncryptInit_ex (_fun _EVP_CIPHER_CTX-pointer _EVP_CIPHER-pointer (_or-null _ENGINE-pointer) (_or-null (_ptr i _bytes)) (_or-null (_ptr i _bytes)) -> _int))
(define-crypto-func EVP_EncryptUpdate (_fun _EVP_CIPHER_CTX-pointer _bytes (_ptr io _int) _bytes _int -> _int))
(define-crypto-func EVP_EncryptFinal_ex (_fun _EVP_CIPHER_CTX-pointer _bytes (_ptr io _int) -> _int))
(define-crypto-func EVP_DecryptInit_ex (_fun _EVP_CIPHER_CTX-pointer _EVP_CIPHER-pointer (_or-null _ENGINE-pointer) (_or-null (_ptr i _bytes)) (_or-null (_ptr i _bytes)) -> _int))
(define-crypto-func EVP_DecryptUpdate (_fun _EVP_CIPHER_CTX-pointer _bytes (i : (_ptr o _int)) _bytes _int -> (i2 : _int) -> (values i2 i)))
(define-crypto-func EVP_DecryptFinal_ex (_fun _EVP_CIPHER_CTX-pointer _bytes (i : (_ptr o _int)) -> (i2 : _int) -> (values i2 i)))
(define-crypto-func EVP_CipherInit_ex (_fun _EVP_CIPHER_CTX-pointer _EVP_CIPHER-pointer (_or-null _ENGINE-pointer) (_or-null (_ptr i _bytes)) (_or-null (_ptr i _bytes)) _int -> _int))
(define-crypto-func EVP_CipherUpdate (_fun _EVP_CIPHER_CTX-pointer _bytes (ol : (_ptr o _int)) _bytes _int -> (rc : _int) -> (values rc ol)))
(define-crypto-func EVP_CipherFinal_ex (_fun _EVP_CIPHER_CTX-pointer _bytes (ol : (_ptr o _int)) -> (rc : _int) -> (values rc ol)))
(define-crypto-func EVP_EncryptInit (_fun _EVP_CIPHER_CTX-pointer _EVP_CIPHER-pointer _bytes _bytes -> _int))
(define-crypto-func EVP_EncryptFinal (_fun _EVP_CIPHER_CTX-pointer _bytes (_ptr io _int) -> _int))
(define-crypto-func EVP_DecryptInit (_fun _EVP_CIPHER_CTX-pointer _EVP_CIPHER-pointer _bytes _bytes -> _int))
(define-crypto-func EVP_DecryptFinal (_fun _EVP_CIPHER_CTX-pointer _bytes (_ptr io _int) -> _int))
(define-crypto-func EVP_CipherInit (_fun _EVP_CIPHER_CTX-pointer _EVP_CIPHER-pointer _bytes _bytes _int -> _int))
(define-crypto-func EVP_CipherFinal (_fun _EVP_CIPHER_CTX-pointer _bytes (_ptr io _int) -> _int))
(define-crypto-func EVP_get_cipherbyname (_fun _bytes -> _EVP_CIPHER-pointer))
;#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
;#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
(define-crypto-func EVP_CIPHER_nid (_fun _EVP_CIPHER-pointer -> _int))
(define-crypto-func EVP_CIPHER_block_size (_fun _EVP_CIPHER-pointer -> _int))
(define-crypto-func EVP_CIPHER_key_length (_fun _EVP_CIPHER-pointer -> _int))
(define-crypto-func EVP_CIPHER_iv_length (_fun _EVP_CIPHER-pointer -> _int))
(define-crypto-func EVP_CIPHER_flags (_fun _EVP_CIPHER-pointer -> _int))
;(define-crypto-func EVP_CIPHER_mode (_fun _EVP_CIPHER-pointer -> _int)) ( e) ( ( e)->flags) & EVP_CIPH_MODE)
(define-crypto-func EVP_CIPHER_type (_fun _EVP_CIPHER-pointer -> _int))
(define-crypto-func EVP_CIPHER_CTX_cipher (_fun _EVP_CIPHER_CTX-pointer -> _EVP_CIPHER-pointer ))
(define-crypto-func EVP_CIPHER_CTX_nid (_fun _EVP_CIPHER_CTX-pointer -> _int))
(define-crypto-func EVP_CIPHER_CTX_block_size (_fun _EVP_CIPHER_CTX-pointer -> _int))
(define-crypto-func EVP_CIPHER_CTX_key_length (_fun _EVP_CIPHER_CTX-pointer -> _int))
(define-crypto-func EVP_CIPHER_CTX_iv_length (_fun _EVP_CIPHER_CTX-pointer -> _int))
(define-crypto-func EVP_CIPHER_CTX_get_app_data (_fun _EVP_CIPHER_CTX-pointer -> _pointer))
(define-crypto-func EVP_CIPHER_CTX_set_app_data (_fun _EVP_CIPHER_CTX-pointer _pointer -> _int))
(define-crypto-func EVP_CIPHER_CTX_type (_fun _EVP_CIPHER_CTX-pointer -> _int))
(define-crypto-func EVP_CIPHER_CTX_flags (_fun _EVP_CIPHER_CTX-pointer -> _int))
;(define-crypto-func EVP_CIPHER_CTX_mode (_fun _EVP_CIPHER_CTX-pointer -> _int)) ( e) ( ( e)->cipher->flags & EVP_CIPH_MODE)
(define-crypto-func EVP_CIPHER_param_to_asn1 (_fun _EVP_CIPHER_CTX-pointer _ASN1_TYPE-pointer -> _int))
(define-crypto-func EVP_CIPHER_asn1_to_param (_fun _EVP_CIPHER_CTX-pointer _ASN1_TYPE-pointer -> _int))
(define-crypto-func EVP_aes_128_cbc (_fun -> _EVP_CIPHER-pointer))
(define-syntax-rule (define-ciphers a ...)
(begin
(define-crypto-func a (_fun -> _EVP_CIPHER-pointer)) ...))
(define-ciphers
EVP_enc_null
EVP_des_cbc
EVP_des_ecb
EVP_des_cfb
EVP_des_ofb
EVP_des_ede_cbc
EVP_des_ede
EVP_des_ede_ofb
EVP_des_ede_cfb
EVP_des_ede3_cbc
EVP_des_ede3
EVP_des_ede3_ofb
EVP_des_ede3_cfb
EVP_desx_cbc
EVP_rc4
EVP_rc4_40
EVP_idea_cbc
EVP_idea_ecb
EVP_idea_cfb
EVP_idea_ofb
EVP_rc2_cbc
EVP_rc2_ecb
EVP_rc2_cfb
EVP_rc2_ofb
EVP_rc2_40_cbc
EVP_rc2_64_cbc
EVP_bf_cbc
EVP_bf_ecb
EVP_bf_cfb
EVP_bf_ofb
EVP_cast5_cbc
EVP_cast5_ecb
EVP_cast5_cfb
EVP_cast5_ofb
EVP_rc5_32_12_16_cbc
EVP_rc5_32_12_16_ecb
EVP_rc5_32_12_16_cfb
EVP_rc5_32_12_16_ofb
EVP_aes_128_ecb
;EVP_aes_128_cbc
EVP_aes_128_cfb1
EVP_aes_128_cfb8
EVP_aes_128_cfb128
EVP_aes_128_ofb
EVP_aes_192_ecb
EVP_aes_192_cbc
EVP_aes_192_cfb1
EVP_aes_192_cfb8
EVP_aes_192_cfb128
EVP_aes_192_ofb
EVP_aes_256_ecb
EVP_aes_256_cbc
EVP_aes_256_cfb1
EVP_aes_256_cfb8
EVP_aes_256_cfb128
EVP_aes_256_ofb)
(define EVP_aes_128_cfb EVP_aes_128_cfb128)
(define EVP_aes_192_cfb EVP_aes_192_cfb128)
(define EVP_aes_256_cfb EVP_aes_256_cfb128)
(define-syntax-rule (for/sum ([a b]...) body ...)
(for/fold ([sum 0]) ([a b]...)
(+ sum (begin body ...))))
(define (BNp bn)
(define bits-set (for/sum ([i (in-range (BN_num_bits bn))]) (BN_is_bit_set bn i)))
(define b (make-bytes (BN_num_bytes bn) 0))
(define bl (BN_bn2bin bn b))
(printf "~a ~a ~a ~a ~a/~a\n" (BN-top bn) (BN-dmax bn) (BN-neg bn) (BN-flags bn) bits-set (BN_num_bits bn))
(printf "~a\n" (bytes->hex-string (subbytes b 0 bl))))
(define (BN_num_bytes bn)
(ceiling (/ (+ (BN_num_bits bn) 7) 8)))