ltc sync
Karel Miko
6 years ago
26 | 26 | |
27 | 27 | /* version */ |
28 | 28 | #define CRYPT 0x0118 |
29 | #define SCRYPT "1.18.0-rc2" | |
29 | #define SCRYPT "1.18.0-rc3" | |
30 | 30 | |
31 | 31 | /* max size of either a cipher/hash block or symmetric key [largest of the two] */ |
32 | 32 | #define MAXBLOCKSIZE 128 |
19 | 19 | #define NORETURN |
20 | 20 | #endif |
21 | 21 | |
22 | void crypt_argchk(char *v, char *s, int d) NORETURN; | |
22 | void crypt_argchk(const char *v, const char *s, int d) NORETURN; | |
23 | 23 | #define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0) |
24 | 24 | #define LTC_ARGCHKVD(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0) |
25 | 25 |
348 | 348 | /** cipher descriptor table, last entry has "name == NULL" to mark the end of table */ |
349 | 349 | extern struct ltc_cipher_descriptor { |
350 | 350 | /** name of cipher */ |
351 | char *name; | |
351 | const char *name; | |
352 | 352 | /** internal ID */ |
353 | 353 | unsigned char ID; |
354 | 354 | /** min keysize (octets) */ |
498 | 498 | /** Accelerated GCM packet (one shot) |
499 | 499 | @param key The secret key |
500 | 500 | @param keylen The length of the secret key |
501 | @param IV The initial vector | |
502 | @param IVlen The length of the initial vector | |
501 | @param IV The initialization vector | |
502 | @param IVlen The length of the initialization vector | |
503 | 503 | @param adata The additional authentication data (header) |
504 | 504 | @param adatalen The length of the adata |
505 | 505 | @param pt The plaintext |
527 | 527 | #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_MKAT) |
528 | 528 | /* Include the MPI functionality? (required by the PK algorithms) */ |
529 | 529 | #define LTC_MPI |
530 | ||
531 | #ifndef LTC_PK_MAX_RETRIES | |
532 | /* iterations limit for retry-loops */ | |
533 | #define LTC_PK_MAX_RETRIES 20 | |
534 | #endif | |
530 | 535 | #endif |
531 | 536 | |
532 | 537 | #ifdef LTC_MRSA |
203 | 203 | /** hash descriptor */ |
204 | 204 | extern struct ltc_hash_descriptor { |
205 | 205 | /** name of hash */ |
206 | char *name; | |
206 | const char *name; | |
207 | 207 | /** internal ID */ |
208 | 208 | unsigned char ID; |
209 | 209 | /** Size of digest in octets */ |
34 | 34 | /** math descriptor */ |
35 | 35 | typedef struct { |
36 | 36 | /** Name of the math provider */ |
37 | char *name; | |
37 | const char *name; | |
38 | 38 | |
39 | 39 | /** Bits per digit, amount of bits must fit in an unsigned long */ |
40 | 40 | int bits_per_digit; |
18 | 18 | /* Indicates standard output formats that can be read e.g. by OpenSSL or GnuTLS */ |
19 | 19 | #define PK_STD 0x1000 |
20 | 20 | |
21 | /* iterations limit for retry-loops */ | |
22 | #define PK_MAX_RETRIES 20 | |
23 | ||
24 | 21 | int rand_prime(void *N, long len, prng_state *prng, int wprng); |
25 | 22 | |
23 | #ifdef LTC_SOURCE | |
24 | /* internal helper functions */ | |
26 | 25 | int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng); |
27 | 26 | int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng); |
28 | 27 | |
40 | 39 | } oid_st; |
41 | 40 | |
42 | 41 | int pk_get_oid(int pk, oid_st *st); |
42 | #endif /* LTC_SOURCE */ | |
43 | 43 | |
44 | 44 | /* ---- RSA ---- */ |
45 | 45 | #ifdef LTC_MRSA |
199 | 199 | #ifdef LTC_MDH |
200 | 200 | |
201 | 201 | typedef struct { |
202 | int size; | |
203 | char *name, *base, *prime; | |
204 | } ltc_dh_set_type; | |
205 | ||
206 | extern const ltc_dh_set_type ltc_dh_sets[]; | |
207 | ||
208 | typedef struct { | |
209 | 202 | int type; |
210 | 203 | void *x; |
211 | 204 | void *y; |
235 | 228 | int dh_export_key(void *out, unsigned long *outlen, int type, dh_key *key); |
236 | 229 | |
237 | 230 | #ifdef LTC_SOURCE |
231 | typedef struct { | |
232 | int size; | |
233 | const char *name, *base, *prime; | |
234 | } ltc_dh_set_type; | |
235 | ||
236 | extern const ltc_dh_set_type ltc_dh_sets[]; | |
237 | ||
238 | 238 | /* internal helper functions */ |
239 | 239 | int dh_check_pubkey(dh_key *key); |
240 | 240 | #endif |
257 | 257 | int size; |
258 | 258 | |
259 | 259 | /** name of curve */ |
260 | char *name; | |
260 | const char *name; | |
261 | 261 | |
262 | 262 | /** The prime that defines the field the curve is in (encoded in hex) */ |
263 | char *prime; | |
263 | const char *prime; | |
264 | 264 | |
265 | 265 | /** The fields A param (hex) */ |
266 | char *A; | |
266 | const char *A; | |
267 | 267 | |
268 | 268 | /** The fields B param (hex) */ |
269 | char *B; | |
269 | const char *B; | |
270 | 270 | |
271 | 271 | /** The order of the curve (hex) */ |
272 | char *order; | |
272 | const char *order; | |
273 | 273 | |
274 | 274 | /** The x co-ordinate of the base point on the curve (hex) */ |
275 | char *Gx; | |
275 | const char *Gx; | |
276 | 276 | |
277 | 277 | /** The y co-ordinate of the base point on the curve (hex) */ |
278 | char *Gy; | |
278 | const char *Gy; | |
279 | 279 | |
280 | 280 | /** The co-factor */ |
281 | 281 | unsigned long cofactor; |
79 | 79 | /* ===> PKCS #5 -- Password Based Cryptography <=== */ |
80 | 80 | #ifdef LTC_PKCS_5 |
81 | 81 | |
82 | /* Algorithm #1 (old) */ | |
82 | /* Algorithm #1 (PBKDF1) */ | |
83 | 83 | int pkcs_5_alg1(const unsigned char *password, unsigned long password_len, |
84 | 84 | const unsigned char *salt, |
85 | 85 | int iteration_count, int hash_idx, |
86 | 86 | unsigned char *out, unsigned long *outlen); |
87 | 87 | |
88 | /* Algorithm #1 - OpenSSL-compatible variant for arbitrarily-long keys. | |
88 | /* Algorithm #1 (PBKDF1) - OpenSSL-compatible variant for arbitrarily-long keys. | |
89 | 89 | Compatible with EVP_BytesToKey() */ |
90 | 90 | int pkcs_5_alg1_openssl(const unsigned char *password, |
91 | 91 | unsigned long password_len, |
93 | 93 | int iteration_count, int hash_idx, |
94 | 94 | unsigned char *out, unsigned long *outlen); |
95 | 95 | |
96 | /* Algorithm #2 (new) */ | |
96 | /* Algorithm #2 (PBKDF2) */ | |
97 | 97 | int pkcs_5_alg2(const unsigned char *password, unsigned long password_len, |
98 | 98 | const unsigned char *salt, unsigned long salt_len, |
99 | 99 | int iteration_count, int hash_idx, |
80 | 80 | /** PRNG descriptor */ |
81 | 81 | extern struct ltc_prng_descriptor { |
82 | 82 | /** Name of the PRNG */ |
83 | char *name; | |
83 | const char *name; | |
84 | 84 | /** size in bytes of exported state */ |
85 | 85 | int export_size; |
86 | 86 | /** Start a PRNG state |
45 | 45 | { |
46 | 46 | unsigned char *buf; |
47 | 47 | unsigned long keysize; |
48 | int err, max_iterations = PK_MAX_RETRIES; | |
48 | int err, max_iterations = LTC_PK_MAX_RETRIES; | |
49 | 49 | |
50 | 50 | LTC_ARGCHK(key != NULL); |
51 | 51 | LTC_ARGCHK(ltc_mp.name != NULL); |
22 | 22 | @param hash The hash that was signed |
23 | 23 | @param hashlen The length of the hash that was signed |
24 | 24 | @param stat [out] The result of the signature verification, 1==valid, 0==invalid |
25 | @param key The corresponding public DH key | |
25 | @param key The corresponding public DSA key | |
26 | 26 | @return CRYPT_OK if successful (even if the signature is invalid) |
27 | 27 | */ |
28 | 28 | int dsa_verify_hash_raw( void *r, void *s, |
88 | 88 | @param hash The hash that was signed |
89 | 89 | @param hashlen The length of the hash that was signed |
90 | 90 | @param stat [out] The result of the signature verification, 1==valid, 0==invalid |
91 | @param key The corresponding public DH key | |
91 | @param key The corresponding public DSA key | |
92 | 92 | @return CRYPT_OK if successful (even if the signature is invalid) |
93 | 93 | */ |
94 | 94 | int dsa_verify_hash(const unsigned char *sig, unsigned long siglen, |