diff options
Diffstat (limited to 'utils/tomcrypt/src/headers/tomcrypt_private.h')
-rw-r--r-- | utils/tomcrypt/src/headers/tomcrypt_private.h | 447 |
1 files changed, 447 insertions, 0 deletions
diff --git a/utils/tomcrypt/src/headers/tomcrypt_private.h b/utils/tomcrypt/src/headers/tomcrypt_private.h new file mode 100644 index 0000000000..e5e716584c --- /dev/null +++ b/utils/tomcrypt/src/headers/tomcrypt_private.h | |||
@@ -0,0 +1,447 @@ | |||
1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis */ | ||
2 | /* SPDX-License-Identifier: Unlicense */ | ||
3 | |||
4 | #include "tomcrypt.h" | ||
5 | |||
6 | /* | ||
7 | * Internal Macros | ||
8 | */ | ||
9 | |||
10 | #define LTC_PAD_MASK (0xF000U) | ||
11 | |||
12 | /* | ||
13 | * Internal Enums | ||
14 | */ | ||
15 | |||
16 | enum ltc_oid_id { | ||
17 | PKA_RSA, | ||
18 | PKA_DSA, | ||
19 | PKA_EC, | ||
20 | PKA_EC_PRIMEF, | ||
21 | PKA_X25519, | ||
22 | PKA_ED25519, | ||
23 | }; | ||
24 | |||
25 | /* | ||
26 | * Internal Types | ||
27 | */ | ||
28 | |||
29 | typedef struct { | ||
30 | int size; | ||
31 | const char *name, *base, *prime; | ||
32 | } ltc_dh_set_type; | ||
33 | |||
34 | |||
35 | typedef int (*fn_kdf_t)(const unsigned char *password, unsigned long password_len, | ||
36 | const unsigned char *salt, unsigned long salt_len, | ||
37 | int iteration_count, int hash_idx, | ||
38 | unsigned char *out, unsigned long *outlen); | ||
39 | |||
40 | typedef struct { | ||
41 | /* KDF */ | ||
42 | fn_kdf_t kdf; | ||
43 | /* Hash or HMAC */ | ||
44 | const char* h; | ||
45 | /* cipher */ | ||
46 | const char* c; | ||
47 | unsigned long keylen; | ||
48 | /* not used for pbkdf2 */ | ||
49 | unsigned long blocklen; | ||
50 | } pbes_properties; | ||
51 | |||
52 | typedef struct | ||
53 | { | ||
54 | pbes_properties type; | ||
55 | const void *pwd; | ||
56 | unsigned long pwdlen; | ||
57 | ltc_asn1_list *enc_data; | ||
58 | ltc_asn1_list *salt; | ||
59 | ltc_asn1_list *iv; | ||
60 | unsigned long iterations; | ||
61 | /* only used for RC2 */ | ||
62 | unsigned long key_bits; | ||
63 | } pbes_arg; | ||
64 | |||
65 | /* | ||
66 | * Internal functions | ||
67 | */ | ||
68 | |||
69 | |||
70 | /* tomcrypt_cipher.h */ | ||
71 | |||
72 | void blowfish_enc(ulong32 *data, unsigned long blocks, const symmetric_key *skey); | ||
73 | int blowfish_expand(const unsigned char *key, int keylen, | ||
74 | const unsigned char *data, int datalen, | ||
75 | symmetric_key *skey); | ||
76 | int blowfish_setup_with_data(const unsigned char *key, int keylen, | ||
77 | const unsigned char *data, int datalen, | ||
78 | symmetric_key *skey); | ||
79 | |||
80 | /* tomcrypt_hash.h */ | ||
81 | |||
82 | /* a simple macro for making hash "process" functions */ | ||
83 | #define HASH_PROCESS(func_name, compress_name, state_var, block_size) \ | ||
84 | int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) \ | ||
85 | { \ | ||
86 | unsigned long n; \ | ||
87 | int err; \ | ||
88 | LTC_ARGCHK(md != NULL); \ | ||
89 | LTC_ARGCHK(in != NULL); \ | ||
90 | if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \ | ||
91 | return CRYPT_INVALID_ARG; \ | ||
92 | } \ | ||
93 | if ((md-> state_var .length + inlen) < md-> state_var .length) { \ | ||
94 | return CRYPT_HASH_OVERFLOW; \ | ||
95 | } \ | ||
96 | while (inlen > 0) { \ | ||
97 | if (md-> state_var .curlen == 0 && inlen >= block_size) { \ | ||
98 | if ((err = compress_name (md, in)) != CRYPT_OK) { \ | ||
99 | return err; \ | ||
100 | } \ | ||
101 | md-> state_var .length += block_size * 8; \ | ||
102 | in += block_size; \ | ||
103 | inlen -= block_size; \ | ||
104 | } else { \ | ||
105 | n = MIN(inlen, (block_size - md-> state_var .curlen)); \ | ||
106 | XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \ | ||
107 | md-> state_var .curlen += n; \ | ||
108 | in += n; \ | ||
109 | inlen -= n; \ | ||
110 | if (md-> state_var .curlen == block_size) { \ | ||
111 | if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) { \ | ||
112 | return err; \ | ||
113 | } \ | ||
114 | md-> state_var .length += 8*block_size; \ | ||
115 | md-> state_var .curlen = 0; \ | ||
116 | } \ | ||
117 | } \ | ||
118 | } \ | ||
119 | return CRYPT_OK; \ | ||
120 | } | ||
121 | |||
122 | |||
123 | /* tomcrypt_mac.h */ | ||
124 | |||
125 | int ocb3_int_ntz(unsigned long x); | ||
126 | void ocb3_int_xor_blocks(unsigned char *out, const unsigned char *block_a, const unsigned char *block_b, unsigned long block_len); | ||
127 | |||
128 | |||
129 | /* tomcrypt_math.h */ | ||
130 | |||
131 | #if !defined(DESC_DEF_ONLY) | ||
132 | |||
133 | #define MP_DIGIT_BIT ltc_mp.bits_per_digit | ||
134 | |||
135 | /* some handy macros */ | ||
136 | #define mp_init(a) ltc_mp.init(a) | ||
137 | #define mp_init_multi ltc_init_multi | ||
138 | #define mp_clear(a) ltc_mp.deinit(a) | ||
139 | #define mp_clear_multi ltc_deinit_multi | ||
140 | #define mp_cleanup_multi ltc_cleanup_multi | ||
141 | #define mp_init_copy(a, b) ltc_mp.init_copy(a, b) | ||
142 | |||
143 | #define mp_neg(a, b) ltc_mp.neg(a, b) | ||
144 | #define mp_copy(a, b) ltc_mp.copy(a, b) | ||
145 | |||
146 | #define mp_set(a, b) ltc_mp.set_int(a, b) | ||
147 | #define mp_set_int(a, b) ltc_mp.set_int(a, b) | ||
148 | #define mp_get_int(a) ltc_mp.get_int(a) | ||
149 | #define mp_get_digit(a, n) ltc_mp.get_digit(a, n) | ||
150 | #define mp_get_digit_count(a) ltc_mp.get_digit_count(a) | ||
151 | #define mp_cmp(a, b) ltc_mp.compare(a, b) | ||
152 | #define mp_cmp_d(a, b) ltc_mp.compare_d(a, b) | ||
153 | #define mp_count_bits(a) ltc_mp.count_bits(a) | ||
154 | #define mp_cnt_lsb(a) ltc_mp.count_lsb_bits(a) | ||
155 | #define mp_2expt(a, b) ltc_mp.twoexpt(a, b) | ||
156 | |||
157 | #define mp_read_radix(a, b, c) ltc_mp.read_radix(a, b, c) | ||
158 | #define mp_toradix(a, b, c) ltc_mp.write_radix(a, b, c) | ||
159 | #define mp_unsigned_bin_size(a) ltc_mp.unsigned_size(a) | ||
160 | #define mp_to_unsigned_bin(a, b) ltc_mp.unsigned_write(a, b) | ||
161 | #define mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c) | ||
162 | |||
163 | #define mp_add(a, b, c) ltc_mp.add(a, b, c) | ||
164 | #define mp_add_d(a, b, c) ltc_mp.addi(a, b, c) | ||
165 | #define mp_sub(a, b, c) ltc_mp.sub(a, b, c) | ||
166 | #define mp_sub_d(a, b, c) ltc_mp.subi(a, b, c) | ||
167 | #define mp_mul(a, b, c) ltc_mp.mul(a, b, c) | ||
168 | #define mp_mul_d(a, b, c) ltc_mp.muli(a, b, c) | ||
169 | #define mp_sqr(a, b) ltc_mp.sqr(a, b) | ||
170 | #define mp_sqrtmod_prime(a, b, c) ltc_mp.sqrtmod_prime(a, b, c) | ||
171 | #define mp_div(a, b, c, d) ltc_mp.mpdiv(a, b, c, d) | ||
172 | #define mp_div_2(a, b) ltc_mp.div_2(a, b) | ||
173 | #define mp_mod(a, b, c) ltc_mp.mpdiv(a, b, NULL, c) | ||
174 | #define mp_mod_d(a, b, c) ltc_mp.modi(a, b, c) | ||
175 | #define mp_gcd(a, b, c) ltc_mp.gcd(a, b, c) | ||
176 | #define mp_lcm(a, b, c) ltc_mp.lcm(a, b, c) | ||
177 | |||
178 | #define mp_addmod(a, b, c, d) ltc_mp.addmod(a, b, c, d) | ||
179 | #define mp_submod(a, b, c, d) ltc_mp.submod(a, b, c, d) | ||
180 | #define mp_mulmod(a, b, c, d) ltc_mp.mulmod(a, b, c, d) | ||
181 | #define mp_sqrmod(a, b, c) ltc_mp.sqrmod(a, b, c) | ||
182 | #define mp_invmod(a, b, c) ltc_mp.invmod(a, b, c) | ||
183 | |||
184 | #define mp_montgomery_setup(a, b) ltc_mp.montgomery_setup(a, b) | ||
185 | #define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b) | ||
186 | #define mp_montgomery_reduce(a, b, c) ltc_mp.montgomery_reduce(a, b, c) | ||
187 | #define mp_montgomery_free(a) ltc_mp.montgomery_deinit(a) | ||
188 | |||
189 | #define mp_exptmod(a,b,c,d) ltc_mp.exptmod(a,b,c,d) | ||
190 | #define mp_prime_is_prime(a, b, c) ltc_mp.isprime(a, b, c) | ||
191 | |||
192 | #define mp_iszero(a) (mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO) | ||
193 | #define mp_isodd(a) (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO) | ||
194 | #define mp_exch(a, b) do { void *ABC__tmp = a; a = b; b = ABC__tmp; } while(0) | ||
195 | |||
196 | #define mp_tohex(a, b) mp_toradix(a, b, 16) | ||
197 | |||
198 | #define mp_rand(a, b) ltc_mp.rand(a, b) | ||
199 | |||
200 | #endif | ||
201 | |||
202 | |||
203 | /* tomcrypt_misc.h */ | ||
204 | |||
205 | void copy_or_zeromem(const unsigned char* src, unsigned char* dest, unsigned long len, int coz); | ||
206 | |||
207 | int pbes_decrypt(const pbes_arg *arg, unsigned char *dec_data, unsigned long *dec_size); | ||
208 | |||
209 | int pbes1_extract(const ltc_asn1_list *s, pbes_arg *res); | ||
210 | int pbes2_extract(const ltc_asn1_list *s, pbes_arg *res); | ||
211 | |||
212 | |||
213 | /* tomcrypt_pk.h */ | ||
214 | |||
215 | int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng); | ||
216 | int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng); | ||
217 | |||
218 | int pk_get_oid(enum ltc_oid_id id, const char **st); | ||
219 | int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen); | ||
220 | int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen); | ||
221 | |||
222 | /* ---- DH Routines ---- */ | ||
223 | #ifdef LTC_MRSA | ||
224 | int rsa_init(rsa_key *key); | ||
225 | void rsa_shrink_key(rsa_key *key); | ||
226 | #endif /* LTC_MRSA */ | ||
227 | |||
228 | /* ---- DH Routines ---- */ | ||
229 | #ifdef LTC_MDH | ||
230 | extern const ltc_dh_set_type ltc_dh_sets[]; | ||
231 | |||
232 | int dh_check_pubkey(const dh_key *key); | ||
233 | #endif /* LTC_MDH */ | ||
234 | |||
235 | /* ---- ECC Routines ---- */ | ||
236 | #ifdef LTC_MECC | ||
237 | int ecc_set_curve_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key); | ||
238 | int ecc_copy_curve(const ecc_key *srckey, ecc_key *key); | ||
239 | int ecc_set_curve_by_size(int size, ecc_key *key); | ||
240 | int ecc_import_subject_public_key_info(const unsigned char *in, unsigned long inlen, ecc_key *key); | ||
241 | |||
242 | #ifdef LTC_SSH | ||
243 | int ecc_ssh_ecdsa_encode_name(char *buffer, unsigned long *buflen, const ecc_key *key); | ||
244 | #endif | ||
245 | |||
246 | /* low level functions */ | ||
247 | ecc_point *ltc_ecc_new_point(void); | ||
248 | void ltc_ecc_del_point(ecc_point *p); | ||
249 | int ltc_ecc_set_point_xyz(ltc_mp_digit x, ltc_mp_digit y, ltc_mp_digit z, ecc_point *p); | ||
250 | int ltc_ecc_copy_point(const ecc_point *src, ecc_point *dst); | ||
251 | int ltc_ecc_is_point(const ltc_ecc_dp *dp, void *x, void *y); | ||
252 | int ltc_ecc_is_point_at_infinity(const ecc_point *P, void *modulus, int *retval); | ||
253 | int ltc_ecc_import_point(const unsigned char *in, unsigned long inlen, void *prime, void *a, void *b, void *x, void *y); | ||
254 | int ltc_ecc_export_point(unsigned char *out, unsigned long *outlen, void *x, void *y, unsigned long size, int compressed); | ||
255 | int ltc_ecc_verify_key(const ecc_key *key); | ||
256 | |||
257 | /* point ops (mp == montgomery digit) */ | ||
258 | #if !defined(LTC_MECC_ACCEL) || defined(LTM_DESC) || defined(GMP_DESC) | ||
259 | /* R = 2P */ | ||
260 | int ltc_ecc_projective_dbl_point(const ecc_point *P, ecc_point *R, void *ma, void *modulus, void *mp); | ||
261 | |||
262 | /* R = P + Q */ | ||
263 | int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_point *R, void *ma, void *modulus, void *mp); | ||
264 | #endif | ||
265 | |||
266 | #if defined(LTC_MECC_FP) | ||
267 | /* optimized point multiplication using fixed point cache (HAC algorithm 14.117) */ | ||
268 | int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *a, void *modulus, int map); | ||
269 | |||
270 | /* functions for saving/loading/freeing/adding to fixed point cache */ | ||
271 | int ltc_ecc_fp_save_state(unsigned char **out, unsigned long *outlen); | ||
272 | int ltc_ecc_fp_restore_state(unsigned char *in, unsigned long inlen); | ||
273 | void ltc_ecc_fp_free(void); | ||
274 | int ltc_ecc_fp_add_point(ecc_point *g, void *modulus, int lock); | ||
275 | |||
276 | /* lock/unlock all points currently in fixed point cache */ | ||
277 | void ltc_ecc_fp_tablelock(int lock); | ||
278 | #endif | ||
279 | |||
280 | /* R = kG */ | ||
281 | int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *modulus, int map); | ||
282 | |||
283 | #ifdef LTC_ECC_SHAMIR | ||
284 | /* kA*A + kB*B = C */ | ||
285 | int ltc_ecc_mul2add(const ecc_point *A, void *kA, | ||
286 | const ecc_point *B, void *kB, | ||
287 | ecc_point *C, | ||
288 | void *ma, | ||
289 | void *modulus); | ||
290 | |||
291 | #ifdef LTC_MECC_FP | ||
292 | /* Shamir's trick with optimized point multiplication using fixed point cache */ | ||
293 | int ltc_ecc_fp_mul2add(const ecc_point *A, void *kA, | ||
294 | const ecc_point *B, void *kB, | ||
295 | ecc_point *C, | ||
296 | void *ma, | ||
297 | void *modulus); | ||
298 | #endif | ||
299 | |||
300 | #endif | ||
301 | |||
302 | |||
303 | /* map P to affine from projective */ | ||
304 | int ltc_ecc_map(ecc_point *P, void *modulus, void *mp); | ||
305 | #endif /* LTC_MECC */ | ||
306 | |||
307 | #ifdef LTC_MDSA | ||
308 | int dsa_int_validate_xy(const dsa_key *key, int *stat); | ||
309 | int dsa_int_validate_pqg(const dsa_key *key, int *stat); | ||
310 | int dsa_int_validate_primes(const dsa_key *key, int *stat); | ||
311 | #endif /* LTC_MDSA */ | ||
312 | |||
313 | |||
314 | #ifdef LTC_CURVE25519 | ||
315 | |||
316 | int tweetnacl_crypto_sign( | ||
317 | unsigned char *sm,unsigned long long *smlen, | ||
318 | const unsigned char *m,unsigned long long mlen, | ||
319 | const unsigned char *sk, const unsigned char *pk); | ||
320 | int tweetnacl_crypto_sign_open( | ||
321 | int *stat, | ||
322 | unsigned char *m,unsigned long long *mlen, | ||
323 | const unsigned char *sm,unsigned long long smlen, | ||
324 | const unsigned char *pk); | ||
325 | int tweetnacl_crypto_sign_keypair(prng_state *prng, int wprng, unsigned char *pk,unsigned char *sk); | ||
326 | int tweetnacl_crypto_sk_to_pk(unsigned char *pk, const unsigned char *sk); | ||
327 | int tweetnacl_crypto_scalarmult(unsigned char *q, const unsigned char *n, const unsigned char *p); | ||
328 | int tweetnacl_crypto_scalarmult_base(unsigned char *q,const unsigned char *n); | ||
329 | |||
330 | typedef int (*sk_to_pk)(unsigned char *pk ,const unsigned char *sk); | ||
331 | int ec25519_import_pkcs8(const unsigned char *in, unsigned long inlen, | ||
332 | const void *pwd, unsigned long pwdlen, | ||
333 | enum ltc_oid_id id, sk_to_pk fp, | ||
334 | curve25519_key *key); | ||
335 | int ec25519_export( unsigned char *out, unsigned long *outlen, | ||
336 | int which, | ||
337 | const curve25519_key *key); | ||
338 | #endif /* LTC_CURVE25519 */ | ||
339 | |||
340 | #ifdef LTC_DER | ||
341 | |||
342 | #define LTC_ASN1_IS_TYPE(e, t) (((e) != NULL) && ((e)->type == (t))) | ||
343 | |||
344 | /* DER handling */ | ||
345 | int der_decode_custom_type_ex(const unsigned char *in, unsigned long inlen, | ||
346 | ltc_asn1_list *root, | ||
347 | ltc_asn1_list *list, unsigned long outlen, unsigned int flags); | ||
348 | |||
349 | int der_encode_asn1_identifier(const ltc_asn1_list *id, unsigned char *out, unsigned long *outlen); | ||
350 | int der_decode_asn1_identifier(const unsigned char *in, unsigned long *inlen, ltc_asn1_list *id); | ||
351 | int der_length_asn1_identifier(const ltc_asn1_list *id, unsigned long *idlen); | ||
352 | |||
353 | int der_encode_asn1_length(unsigned long len, unsigned char* out, unsigned long* outlen); | ||
354 | int der_decode_asn1_length(const unsigned char *in, unsigned long *inlen, unsigned long *outlen); | ||
355 | int der_length_asn1_length(unsigned long len, unsigned long *outlen); | ||
356 | |||
357 | int der_length_sequence_ex(const ltc_asn1_list *list, unsigned long inlen, | ||
358 | unsigned long *outlen, unsigned long *payloadlen); | ||
359 | |||
360 | extern const ltc_asn1_type der_asn1_tag_to_type_map[]; | ||
361 | extern const unsigned long der_asn1_tag_to_type_map_sz; | ||
362 | |||
363 | extern const int der_asn1_type_to_identifier_map[]; | ||
364 | extern const unsigned long der_asn1_type_to_identifier_map_sz; | ||
365 | |||
366 | int der_decode_sequence_multi_ex(const unsigned char *in, unsigned long inlen, unsigned int flags, ...); | ||
367 | |||
368 | int der_teletex_char_encode(int c); | ||
369 | int der_teletex_value_decode(int v); | ||
370 | |||
371 | int der_utf8_valid_char(const wchar_t c); | ||
372 | |||
373 | typedef int (*public_key_decode_cb)(const unsigned char *in, unsigned long inlen, void *ctx); | ||
374 | |||
375 | int x509_decode_public_key_from_certificate(const unsigned char *in, unsigned long inlen, | ||
376 | enum ltc_oid_id algorithm, ltc_asn1_type param_type, | ||
377 | ltc_asn1_list* parameters, unsigned long *parameters_len, | ||
378 | public_key_decode_cb callback, void *ctx); | ||
379 | |||
380 | /* SUBJECT PUBLIC KEY INFO */ | ||
381 | int x509_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen, | ||
382 | unsigned int algorithm, const void* public_key, unsigned long public_key_len, | ||
383 | ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len); | ||
384 | |||
385 | int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long inlen, | ||
386 | unsigned int algorithm, void* public_key, unsigned long* public_key_len, | ||
387 | ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long *parameters_len); | ||
388 | |||
389 | int pk_oid_cmp_with_ulong(const char *o1, const unsigned long *o2, unsigned long o2size); | ||
390 | int pk_oid_cmp_with_asn1(const char *o1, const ltc_asn1_list *o2); | ||
391 | |||
392 | #endif /* LTC_DER */ | ||
393 | |||
394 | /* tomcrypt_pkcs.h */ | ||
395 | |||
396 | #ifdef LTC_PKCS_8 | ||
397 | |||
398 | int pkcs8_decode_flexi(const unsigned char *in, unsigned long inlen, | ||
399 | const void *pwd, unsigned long pwdlen, | ||
400 | ltc_asn1_list **decoded_list); | ||
401 | |||
402 | #endif /* LTC_PKCS_8 */ | ||
403 | |||
404 | |||
405 | #ifdef LTC_PKCS_12 | ||
406 | |||
407 | int pkcs12_utf8_to_utf16(const unsigned char *in, unsigned long inlen, | ||
408 | unsigned char *out, unsigned long *outlen); | ||
409 | |||
410 | int pkcs12_kdf( int hash_id, | ||
411 | const unsigned char *pw, unsigned long pwlen, | ||
412 | const unsigned char *salt, unsigned long saltlen, | ||
413 | unsigned int iterations, unsigned char purpose, | ||
414 | unsigned char *out, unsigned long outlen); | ||
415 | |||
416 | #endif /* LTC_PKCS_12 */ | ||
417 | |||
418 | /* tomcrypt_prng.h */ | ||
419 | |||
420 | #define LTC_PRNG_EXPORT(which) \ | ||
421 | int which ## _export(unsigned char *out, unsigned long *outlen, prng_state *prng) \ | ||
422 | { \ | ||
423 | unsigned long len = which ## _desc.export_size; \ | ||
424 | \ | ||
425 | LTC_ARGCHK(prng != NULL); \ | ||
426 | LTC_ARGCHK(out != NULL); \ | ||
427 | LTC_ARGCHK(outlen != NULL); \ | ||
428 | \ | ||
429 | if (*outlen < len) { \ | ||
430 | *outlen = len; \ | ||
431 | return CRYPT_BUFFER_OVERFLOW; \ | ||
432 | } \ | ||
433 | \ | ||
434 | if (which ## _read(out, len, prng) != len) { \ | ||
435 | return CRYPT_ERROR_READPRNG; \ | ||
436 | } \ | ||
437 | \ | ||
438 | *outlen = len; \ | ||
439 | return CRYPT_OK; \ | ||
440 | } | ||
441 | |||
442 | /* extract a byte portably */ | ||
443 | #ifdef _MSC_VER | ||
444 | #define LTC_BYTE(x, n) ((unsigned char)((x) >> (8 * (n)))) | ||
445 | #else | ||
446 | #define LTC_BYTE(x, n) (((x) >> (8 * (n))) & 255) | ||
447 | #endif | ||