Mercurial > dropbear
comparison libtomcrypt/src/headers/tomcrypt_pk.h @ 1439:8d24733026c5 coverity
merge
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 24 Jun 2017 23:33:16 +0800 |
parents | f849a5ca2efc |
children | 6dba84798cd5 |
comparison
equal
deleted
inserted
replaced
1400:238a439670f5 | 1439:8d24733026c5 |
---|---|
6 }; | 6 }; |
7 | 7 |
8 int rand_prime(void *N, long len, prng_state *prng, int wprng); | 8 int rand_prime(void *N, long len, prng_state *prng, int wprng); |
9 | 9 |
10 /* ---- RSA ---- */ | 10 /* ---- RSA ---- */ |
11 #ifdef MRSA | 11 #ifdef LTC_MRSA |
12 | 12 |
13 /* Min and Max RSA key sizes (in bits) */ | 13 /* Min and Max RSA key sizes (in bits) */ |
14 #define MIN_RSA_SIZE 1024 | 14 #define MIN_RSA_SIZE 1024 |
15 #define MAX_RSA_SIZE 4096 | 15 #define MAX_RSA_SIZE 4096 |
16 | 16 |
17 /** RSA PKCS style key */ | 17 /** RSA LTC_PKCS style key */ |
18 typedef struct Rsa_key { | 18 typedef struct Rsa_key { |
19 /** Type of key, PK_PRIVATE or PK_PUBLIC */ | 19 /** Type of key, PK_PRIVATE or PK_PUBLIC */ |
20 int type; | 20 int type; |
21 /** The public exponent */ | 21 /** The public exponent */ |
22 void *e; | 22 void *e; |
42 unsigned char *out, unsigned long *outlen, int which, | 42 unsigned char *out, unsigned long *outlen, int which, |
43 rsa_key *key); | 43 rsa_key *key); |
44 | 44 |
45 void rsa_free(rsa_key *key); | 45 void rsa_free(rsa_key *key); |
46 | 46 |
47 /* These use PKCS #1 v2.0 padding */ | 47 /* These use LTC_PKCS #1 v2.0 padding */ |
48 #define rsa_encrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _prng, _prng_idx, _hash_idx, _key) \ | 48 #define rsa_encrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _prng, _prng_idx, _hash_idx, _key) \ |
49 rsa_encrypt_key_ex(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _prng, _prng_idx, _hash_idx, LTC_PKCS_1_OAEP, _key) | 49 rsa_encrypt_key_ex(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _prng, _prng_idx, _hash_idx, LTC_LTC_PKCS_1_OAEP, _key) |
50 | 50 |
51 #define rsa_decrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash_idx, _stat, _key) \ | 51 #define rsa_decrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash_idx, _stat, _key) \ |
52 rsa_decrypt_key_ex(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash_idx, LTC_PKCS_1_OAEP, _stat, _key) | 52 rsa_decrypt_key_ex(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash_idx, LTC_LTC_PKCS_1_OAEP, _stat, _key) |
53 | 53 |
54 #define rsa_sign_hash(_in, _inlen, _out, _outlen, _prng, _prng_idx, _hash_idx, _saltlen, _key) \ | 54 #define rsa_sign_hash(_in, _inlen, _out, _outlen, _prng, _prng_idx, _hash_idx, _saltlen, _key) \ |
55 rsa_sign_hash_ex(_in, _inlen, _out, _outlen, LTC_PKCS_1_PSS, _prng, _prng_idx, _hash_idx, _saltlen, _key) | 55 rsa_sign_hash_ex(_in, _inlen, _out, _outlen, LTC_LTC_PKCS_1_PSS, _prng, _prng_idx, _hash_idx, _saltlen, _key) |
56 | 56 |
57 #define rsa_verify_hash(_sig, _siglen, _hash, _hashlen, _hash_idx, _saltlen, _stat, _key) \ | 57 #define rsa_verify_hash(_sig, _siglen, _hash, _hashlen, _hash_idx, _saltlen, _stat, _key) \ |
58 rsa_verify_hash_ex(_sig, _siglen, _hash, _hashlen, LTC_PKCS_1_PSS, _hash_idx, _saltlen, _stat, _key) | 58 rsa_verify_hash_ex(_sig, _siglen, _hash, _hashlen, LTC_LTC_PKCS_1_PSS, _hash_idx, _saltlen, _stat, _key) |
59 | 59 |
60 /* These can be switched between PKCS #1 v2.x and PKCS #1 v1.5 paddings */ | 60 /* These can be switched between LTC_PKCS #1 v2.x and LTC_PKCS #1 v1.5 paddings */ |
61 int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen, | 61 int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen, |
62 unsigned char *out, unsigned long *outlen, | 62 unsigned char *out, unsigned long *outlen, |
63 const unsigned char *lparam, unsigned long lparamlen, | 63 const unsigned char *lparam, unsigned long lparamlen, |
64 prng_state *prng, int prng_idx, int hash_idx, int padding, rsa_key *key); | 64 prng_state *prng, int prng_idx, int hash_idx, int padding, rsa_key *key); |
65 | 65 |
80 const unsigned char *hash, unsigned long hashlen, | 80 const unsigned char *hash, unsigned long hashlen, |
81 int padding, | 81 int padding, |
82 int hash_idx, unsigned long saltlen, | 82 int hash_idx, unsigned long saltlen, |
83 int *stat, rsa_key *key); | 83 int *stat, rsa_key *key); |
84 | 84 |
85 /* PKCS #1 import/export */ | 85 /* LTC_PKCS #1 import/export */ |
86 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key); | 86 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key); |
87 int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key); | 87 int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key); |
88 | 88 |
89 #endif | 89 #endif |
90 | 90 |
93 | 93 |
94 /* Min and Max KAT key sizes (in bits) */ | 94 /* Min and Max KAT key sizes (in bits) */ |
95 #define MIN_KAT_SIZE 1024 | 95 #define MIN_KAT_SIZE 1024 |
96 #define MAX_KAT_SIZE 4096 | 96 #define MAX_KAT_SIZE 4096 |
97 | 97 |
98 /** Katja PKCS style key */ | 98 /** Katja LTC_PKCS style key */ |
99 typedef struct KAT_key { | 99 typedef struct KAT_key { |
100 /** Type of key, PK_PRIVATE or PK_PUBLIC */ | 100 /** Type of key, PK_PRIVATE or PK_PUBLIC */ |
101 int type; | 101 int type; |
102 /** The private exponent */ | 102 /** The private exponent */ |
103 void *d; | 103 void *d; |
123 unsigned char *out, unsigned long *outlen, int which, | 123 unsigned char *out, unsigned long *outlen, int which, |
124 katja_key *key); | 124 katja_key *key); |
125 | 125 |
126 void katja_free(katja_key *key); | 126 void katja_free(katja_key *key); |
127 | 127 |
128 /* These use PKCS #1 v2.0 padding */ | 128 /* These use LTC_PKCS #1 v2.0 padding */ |
129 int katja_encrypt_key(const unsigned char *in, unsigned long inlen, | 129 int katja_encrypt_key(const unsigned char *in, unsigned long inlen, |
130 unsigned char *out, unsigned long *outlen, | 130 unsigned char *out, unsigned long *outlen, |
131 const unsigned char *lparam, unsigned long lparamlen, | 131 const unsigned char *lparam, unsigned long lparamlen, |
132 prng_state *prng, int prng_idx, int hash_idx, katja_key *key); | 132 prng_state *prng, int prng_idx, int hash_idx, katja_key *key); |
133 | 133 |
135 unsigned char *out, unsigned long *outlen, | 135 unsigned char *out, unsigned long *outlen, |
136 const unsigned char *lparam, unsigned long lparamlen, | 136 const unsigned char *lparam, unsigned long lparamlen, |
137 int hash_idx, int *stat, | 137 int hash_idx, int *stat, |
138 katja_key *key); | 138 katja_key *key); |
139 | 139 |
140 /* PKCS #1 import/export */ | 140 /* LTC_PKCS #1 import/export */ |
141 int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key); | 141 int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key); |
142 int katja_import(const unsigned char *in, unsigned long inlen, katja_key *key); | 142 int katja_import(const unsigned char *in, unsigned long inlen, katja_key *key); |
143 | 143 |
144 #endif | 144 #endif |
145 | 145 |
146 /* ---- ECC Routines ---- */ | 146 /* ---- ECC Routines ---- */ |
147 #ifdef MECC | 147 #ifdef LTC_MECC |
148 | 148 |
149 /* size of our temp buffers for exported keys */ | 149 /* size of our temp buffers for exported keys */ |
150 #define ECC_BUF_SIZE 256 | 150 #define ECC_BUF_SIZE 256 |
151 | 151 |
152 /* max private key size */ | 152 /* max private key size */ |
249 ecc_point *ltc_ecc_new_point(void); | 249 ecc_point *ltc_ecc_new_point(void); |
250 void ltc_ecc_del_point(ecc_point *p); | 250 void ltc_ecc_del_point(ecc_point *p); |
251 int ltc_ecc_is_valid_idx(int n); | 251 int ltc_ecc_is_valid_idx(int n); |
252 | 252 |
253 /* point ops (mp == montgomery digit) */ | 253 /* point ops (mp == montgomery digit) */ |
254 #if !defined(MECC_ACCEL) || defined(LTM_DESC) || defined(GMP_DESC) | 254 #if !defined(LTC_MECC_ACCEL) || defined(LTM_LTC_DESC) || defined(GMP_LTC_DESC) |
255 /* R = 2P */ | 255 /* R = 2P */ |
256 int ltc_ecc_projective_dbl_point(ecc_point *P, ecc_point *R, void *modulus, void *mp); | 256 int ltc_ecc_projective_dbl_point(ecc_point *P, ecc_point *R, void *modulus, void *mp); |
257 | 257 |
258 /* R = P + Q */ | 258 /* R = P + Q */ |
259 int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp); | 259 int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp); |
260 #endif | 260 #endif |
261 | 261 |
262 #if defined(MECC_FP) | 262 #if defined(LTC_MECC_FP) |
263 /* optimized point multiplication using fixed point cache (HAC algorithm 14.117) */ | |
263 int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map); | 264 int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map); |
265 | |
266 /* functions for saving/loading/freeing/adding to fixed point cache */ | |
264 int ltc_ecc_fp_save_state(unsigned char **out, unsigned long *outlen); | 267 int ltc_ecc_fp_save_state(unsigned char **out, unsigned long *outlen); |
265 int ltc_ecc_fp_restore_state(unsigned char *in, unsigned long inlen); | 268 int ltc_ecc_fp_restore_state(unsigned char *in, unsigned long inlen); |
266 void ltc_ecc_fp_free(void); | 269 void ltc_ecc_fp_free(void); |
270 int ltc_ecc_fp_add_point(ecc_point *g, void *modulus, int lock); | |
271 | |
272 /* lock/unlock all points currently in fixed point cache */ | |
273 void ltc_ecc_fp_tablelock(int lock); | |
267 #endif | 274 #endif |
268 | 275 |
269 /* R = kG */ | 276 /* R = kG */ |
270 int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map); | 277 int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map); |
271 | 278 |
274 int ltc_ecc_mul2add(ecc_point *A, void *kA, | 281 int ltc_ecc_mul2add(ecc_point *A, void *kA, |
275 ecc_point *B, void *kB, | 282 ecc_point *B, void *kB, |
276 ecc_point *C, | 283 ecc_point *C, |
277 void *modulus); | 284 void *modulus); |
278 | 285 |
279 #ifdef MECC_FP | 286 #ifdef LTC_MECC_FP |
287 /* Shamir's trick with optimized point multiplication using fixed point cache */ | |
280 int ltc_ecc_fp_mul2add(ecc_point *A, void *kA, | 288 int ltc_ecc_fp_mul2add(ecc_point *A, void *kA, |
281 ecc_point *B, void *kB, | 289 ecc_point *B, void *kB, |
282 ecc_point *C, void *modulus); | 290 ecc_point *C, void *modulus); |
283 #endif | 291 #endif |
284 | 292 |
288 /* map P to affine from projective */ | 296 /* map P to affine from projective */ |
289 int ltc_ecc_map(ecc_point *P, void *modulus, void *mp); | 297 int ltc_ecc_map(ecc_point *P, void *modulus, void *mp); |
290 | 298 |
291 #endif | 299 #endif |
292 | 300 |
293 #ifdef MDSA | 301 #ifdef LTC_MDSA |
294 | 302 |
295 /* Max diff between group and modulus size in bytes */ | 303 /* Max diff between group and modulus size in bytes */ |
296 #define MDSA_DELTA 512 | 304 #define LTC_MDSA_DELTA 512 |
297 | 305 |
298 /* Max DSA group size in bytes (default allows 4k-bit groups) */ | 306 /* Max DSA group size in bytes (default allows 4k-bit groups) */ |
299 #define MDSA_MAX_GROUP 512 | 307 #define LTC_MDSA_MAX_GROUP 512 |
300 | 308 |
301 /** DSA key structure */ | 309 /** DSA key structure */ |
302 typedef struct { | 310 typedef struct { |
303 /** The key type, PK_PRIVATE or PK_PUBLIC */ | 311 /** The key type, PK_PRIVATE or PK_PUBLIC */ |
304 int type; | 312 int type; |
494 | 502 |
495 int der_printable_char_encode(int c); | 503 int der_printable_char_encode(int c); |
496 int der_printable_value_decode(int v); | 504 int der_printable_value_decode(int v); |
497 | 505 |
498 /* UTF-8 */ | 506 /* UTF-8 */ |
499 #if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED)) && !defined(LTC_NO_WCHAR) | 507 #if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED) || defined (__WCHAR_TYPE__)) && !defined(LTC_NO_WCHAR) |
500 #include <wchar.h> | 508 #include <wchar.h> |
501 #else | 509 #else |
502 typedef ulong32 wchar_t; | 510 typedef ulong32 wchar_t; |
503 #endif | 511 #endif |
504 | 512 |
537 int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen); | 545 int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen); |
538 | 546 |
539 | 547 |
540 #endif | 548 #endif |
541 | 549 |
542 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_pk.h,v $ */ | 550 /* $Source$ */ |
543 /* $Revision: 1.77 $ */ | 551 /* $Revision$ */ |
544 /* $Date: 2006/12/03 00:39:56 $ */ | 552 /* $Date$ */ |