14 #define MIN_RSA_SIZE 1024
15 #define MAX_RSA_SIZE 4096
18 typedef struct Rsa_key {
41 int rsa_exptmod(
const unsigned char *in,
unsigned long inlen,
42 unsigned char *out,
unsigned long *outlen,
int which,
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_LTC_PKCS_1_OAEP, _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_LTC_PKCS_1_OAEP, _stat, _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_LTC_PKCS_1_PSS, _prng, _prng_idx, _hash_idx, _saltlen, _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_LTC_PKCS_1_PSS, _hash_idx, _saltlen, _stat, _key)
61 int rsa_encrypt_key_ex(
const unsigned char *in,
unsigned long inlen,
62 unsigned char *out,
unsigned long *outlen,
63 const unsigned char *lparam,
unsigned long lparamlen,
66 int rsa_decrypt_key_ex(
const unsigned char *in,
unsigned long inlen,
67 unsigned char *out,
unsigned long *outlen,
68 const unsigned char *lparam,
unsigned long lparamlen,
69 int hash_idx,
int padding,
72 int rsa_sign_hash_ex(
const unsigned char *in,
unsigned long inlen,
73 unsigned char *out,
unsigned long *outlen,
76 int hash_idx,
unsigned long saltlen,
79 int rsa_verify_hash_ex(
const unsigned char *sig,
unsigned long siglen,
80 const unsigned char *
hash,
unsigned long hashlen,
82 int hash_idx,
unsigned long saltlen,
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);
90 int rsa_verify_simple(
const unsigned char *sig,
unsigned long siglen,
91 const unsigned char *
hash,
unsigned long hashlen,
101 #define MIN_KAT_SIZE 1024
102 #define MAX_KAT_SIZE 4096
105 typedef struct KAT_key {
126 int katja_make_key(
prng_state *prng,
int wprng,
int size, katja_key *key);
128 int katja_exptmod(
const unsigned char *in,
unsigned long inlen,
129 unsigned char *out,
unsigned long *outlen,
int which,
132 void katja_free(katja_key *key);
135 int katja_encrypt_key(
const unsigned char *in,
unsigned long inlen,
136 unsigned char *out,
unsigned long *outlen,
137 const unsigned char *lparam,
unsigned long lparamlen,
138 prng_state *prng,
int prng_idx,
int hash_idx, katja_key *key);
140 int katja_decrypt_key(
const unsigned char *in,
unsigned long inlen,
141 unsigned char *out,
unsigned long *outlen,
142 const unsigned char *lparam,
unsigned long lparamlen,
143 int hash_idx,
int *stat,
147 int katja_export(
unsigned char *out,
unsigned long *outlen,
int type, katja_key *key);
148 int katja_import(
const unsigned char *in,
unsigned long inlen, katja_key *key);
156 #define ECC_BUF_SIZE 256
159 #define ECC_MAXSIZE 66
206 const ltc_ecc_set_type *dp;
216 extern const ltc_ecc_set_type ltc_ecc_sets[];
219 void ecc_sizes(
int *low,
int *high);
220 int ecc_get_size(ecc_key *key);
222 int ecc_make_key(
prng_state *prng,
int wprng,
int keysize, ecc_key *key);
223 int ecc_make_key_ex(
prng_state *prng,
int wprng, ecc_key *key,
const ltc_ecc_set_type *dp);
224 void ecc_free(ecc_key *key);
226 int ecc_export(
unsigned char *out,
unsigned long *outlen,
int type, ecc_key *key);
227 int ecc_import(
const unsigned char *in,
unsigned long inlen, ecc_key *key);
228 int ecc_import_ex(
const unsigned char *in,
unsigned long inlen, ecc_key *key,
const ltc_ecc_set_type *dp);
230 int ecc_ansi_x963_export(ecc_key *key,
unsigned char *out,
unsigned long *outlen);
231 int ecc_ansi_x963_import(
const unsigned char *in,
unsigned long inlen, ecc_key *key);
232 int ecc_ansi_x963_import_ex(
const unsigned char *in,
unsigned long inlen, ecc_key *key, ltc_ecc_set_type *dp);
234 int ecc_shared_secret(ecc_key *private_key, ecc_key *public_key,
235 unsigned char *out,
unsigned long *outlen);
237 int ecc_encrypt_key(
const unsigned char *in,
unsigned long inlen,
238 unsigned char *out,
unsigned long *outlen,
242 int ecc_decrypt_key(
const unsigned char *in,
unsigned long inlen,
243 unsigned char *out,
unsigned long *outlen,
246 int ecc_sign_hash(
const unsigned char *in,
unsigned long inlen,
247 unsigned char *out,
unsigned long *outlen,
250 int ecc_verify_hash(
const unsigned char *sig,
unsigned long siglen,
251 const unsigned char *
hash,
unsigned long hashlen,
252 int *stat, ecc_key *key);
257 int ltc_ecc_is_valid_idx(
int n);
260 #if !defined(LTC_MECC_ACCEL) || defined(LTM_LTC_DESC) || defined(GMP_LTC_DESC)
268 #if defined(LTC_MECC_FP)
273 int ltc_ecc_fp_save_state(
unsigned char **out,
unsigned long *outlen);
274 int ltc_ecc_fp_restore_state(
unsigned char *in,
unsigned long inlen);
275 void ltc_ecc_fp_free(
void);
276 int ltc_ecc_fp_add_point(
ecc_point *g,
void *modulus,
int lock);
279 void ltc_ecc_fp_tablelock(
int lock);
285 #ifdef LTC_ECC_SHAMIR
287 int ltc_ecc_mul2add(
ecc_point *A,
void *kA,
294 int ltc_ecc_fp_mul2add(
ecc_point *A,
void *kA,
303 int ltc_ecc_map(
ecc_point *
P,
void *modulus,
void *mp);
310 #define LTC_MDSA_DELTA 512
313 #define LTC_MDSA_MAX_GROUP 512
339 int dsa_make_key(
prng_state *prng,
int wprng,
int group_size,
int modulus_size, dsa_key *key);
340 void dsa_free(dsa_key *key);
342 int dsa_sign_hash_raw(
const unsigned char *in,
unsigned long inlen,
346 int dsa_sign_hash(
const unsigned char *in,
unsigned long inlen,
347 unsigned char *out,
unsigned long *outlen,
350 int dsa_verify_hash_raw(
void *r,
void *s,
351 const unsigned char *
hash,
unsigned long hashlen,
352 int *stat, dsa_key *key);
354 int dsa_verify_hash(
const unsigned char *sig,
unsigned long siglen,
355 const unsigned char *
hash,
unsigned long hashlen,
356 int *stat, dsa_key *key);
358 int dsa_encrypt_key(
const unsigned char *in,
unsigned long inlen,
359 unsigned char *out,
unsigned long *outlen,
363 int dsa_decrypt_key(
const unsigned char *in,
unsigned long inlen,
364 unsigned char *out,
unsigned long *outlen,
367 int dsa_import(
const unsigned char *in,
unsigned long inlen, dsa_key *key);
368 int dsa_export(
unsigned char *out,
unsigned long *outlen,
int type, dsa_key *key);
369 int dsa_verify_key(dsa_key *key,
int *stat);
371 int dsa_shared_secret(
void *private_key,
void *base,
373 unsigned char *out,
unsigned long *outlen);
383 LTC_ASN1_SHORT_INTEGER,
385 LTC_ASN1_OCTET_STRING,
387 LTC_ASN1_OBJECT_IDENTIFIER,
389 LTC_ASN1_PRINTABLE_STRING,
390 LTC_ASN1_UTF8_STRING,
399 typedef struct ltc_asn1_list_ {
409 struct ltc_asn1_list_ *
prev, *
next, *child, *parent;
412 #define LTC_SET_ASN1(list, index, Type, Data, Size) \
414 int LTC_MACRO_temp = (index); \
415 ltc_asn1_list *LTC_MACRO_list = (list); \
416 LTC_MACRO_list[LTC_MACRO_temp].type = (Type); \
417 LTC_MACRO_list[LTC_MACRO_temp].data = (void*)(Data); \
418 LTC_MACRO_list[LTC_MACRO_temp].size = (Size); \
419 LTC_MACRO_list[LTC_MACRO_temp].used = 0; \
423 int der_encode_sequence_ex(ltc_asn1_list *list,
unsigned long inlen,
424 unsigned char *out,
unsigned long *outlen,
int type_of);
426 #define der_encode_sequence(list, inlen, out, outlen) der_encode_sequence_ex(list, inlen, out, outlen, LTC_ASN1_SEQUENCE)
428 int der_decode_sequence_ex(
const unsigned char *in,
unsigned long inlen,
429 ltc_asn1_list *list,
unsigned long outlen,
int ordered);
431 #define der_decode_sequence(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, 1)
433 int der_length_sequence(ltc_asn1_list *list,
unsigned long inlen,
434 unsigned long *outlen);
437 #define der_decode_set(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, 0)
438 #define der_length_set der_length_sequence
439 int der_encode_set(ltc_asn1_list *list,
unsigned long inlen,
440 unsigned char *out,
unsigned long *outlen);
442 int der_encode_setof(ltc_asn1_list *list,
unsigned long inlen,
443 unsigned char *out,
unsigned long *outlen);
446 int der_encode_sequence_multi(
unsigned char *out,
unsigned long *outlen, ...);
447 int der_decode_sequence_multi(
const unsigned char *in,
unsigned long inlen, ...);
450 int der_decode_sequence_flexi(
const unsigned char *in,
unsigned long *inlen, ltc_asn1_list **out);
451 void der_free_sequence_flexi(ltc_asn1_list *list);
452 void der_sequence_free(ltc_asn1_list *in);
455 int der_length_boolean(
unsigned long *outlen);
456 int der_encode_boolean(
int in,
457 unsigned char *out,
unsigned long *outlen);
458 int der_decode_boolean(
const unsigned char *in,
unsigned long inlen,
461 int der_encode_integer(
void *num,
unsigned char *out,
unsigned long *outlen);
462 int der_decode_integer(
const unsigned char *in,
unsigned long inlen,
void *num);
463 int der_length_integer(
void *num,
unsigned long *len);
466 int der_decode_short_integer(
const unsigned char *in,
unsigned long inlen,
unsigned long *num);
467 int der_encode_short_integer(
unsigned long num,
unsigned char *out,
unsigned long *outlen);
468 int der_length_short_integer(
unsigned long num,
unsigned long *outlen);
471 int der_encode_bit_string(
const unsigned char *in,
unsigned long inlen,
472 unsigned char *out,
unsigned long *outlen);
473 int der_decode_bit_string(
const unsigned char *in,
unsigned long inlen,
474 unsigned char *out,
unsigned long *outlen);
475 int der_length_bit_string(
unsigned long nbits,
unsigned long *outlen);
478 int der_encode_octet_string(
const unsigned char *in,
unsigned long inlen,
479 unsigned char *out,
unsigned long *outlen);
480 int der_decode_octet_string(
const unsigned char *in,
unsigned long inlen,
481 unsigned char *out,
unsigned long *outlen);
482 int der_length_octet_string(
unsigned long noctets,
unsigned long *outlen);
485 int der_encode_object_identifier(
unsigned long *words,
unsigned long nwords,
486 unsigned char *out,
unsigned long *outlen);
487 int der_decode_object_identifier(
const unsigned char *in,
unsigned long inlen,
488 unsigned long *words,
unsigned long *outlen);
489 int der_length_object_identifier(
unsigned long *words,
unsigned long nwords,
unsigned long *outlen);
490 unsigned long der_object_identifier_bits(
unsigned long x);
493 int der_encode_ia5_string(
const unsigned char *in,
unsigned long inlen,
494 unsigned char *out,
unsigned long *outlen);
495 int der_decode_ia5_string(
const unsigned char *in,
unsigned long inlen,
496 unsigned char *out,
unsigned long *outlen);
497 int der_length_ia5_string(
const unsigned char *octets,
unsigned long noctets,
unsigned long *outlen);
499 int der_ia5_char_encode(
int c);
500 int der_ia5_value_decode(
int v);
503 int der_encode_printable_string(
const unsigned char *in,
unsigned long inlen,
504 unsigned char *out,
unsigned long *outlen);
505 int der_decode_printable_string(
const unsigned char *in,
unsigned long inlen,
506 unsigned char *out,
unsigned long *outlen);
507 int der_length_printable_string(
const unsigned char *octets,
unsigned long noctets,
unsigned long *outlen);
509 int der_printable_char_encode(
int c);
510 int der_printable_value_decode(
int v);
513 #if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED) || defined (__WCHAR_TYPE__)) && !defined(LTC_NO_WCHAR)
519 int der_encode_utf8_string(
const wchar_t *in,
unsigned long inlen,
520 unsigned char *out,
unsigned long *outlen);
522 int der_decode_utf8_string(
const unsigned char *in,
unsigned long inlen,
523 wchar_t *out,
unsigned long *outlen);
524 unsigned long der_utf8_charsize(
const wchar_t c);
525 int der_length_utf8_string(
const wchar_t *in,
unsigned long noctets,
unsigned long *outlen);
529 int der_decode_choice(
const unsigned char *in,
unsigned long *inlen,
530 ltc_asn1_list *list,
unsigned long outlen);
545 int der_encode_utctime(ltc_utctime *utctime,
546 unsigned char *out,
unsigned long *outlen);
548 int der_decode_utctime(
const unsigned char *in,
unsigned long *inlen,
551 int der_length_utctime(ltc_utctime *utctime,
unsigned long *outlen);
Definition: tomcrypt_pk.h:5
#define hash
Definition: private_namespace.h:186
int rand_prime(void *N, long len, prng_state *prng, int wprng)
void rsa_key
Definition: tomcrypt_math.h:15
int next(int i, int n)
Definition: RecastContour.cpp:469
unsigned long ulong32
Definition: tomcrypt_macros.h:16
Definition: tomcrypt_pk.h:4
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
int prev(int i, int n)
Definition: RecastContour.cpp:468
G3D::int16 x
Definition: Vector2int16.h:37
void ecc_point
Definition: tomcrypt_math.h:11
uint8 const P[]
Definition: AuthenticationPackets.cpp:225
Definition: tomcrypt_prng.h:50
uint8 const Q[]
Definition: AuthenticationPackets.cpp:237