Skip to content

Commit f55039b

Browse files
committed
add tomcrypt_private.h
1 parent 5d8f35e commit f55039b

File tree

7 files changed

+336
-312
lines changed

7 files changed

+336
-312
lines changed

src/headers/tomcrypt_hash.h

-40
Original file line numberDiff line numberDiff line change
@@ -507,46 +507,6 @@ int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outle
507507
int hash_file(int hash, const char *fname, unsigned char *out, unsigned long *outlen);
508508
#endif
509509

510-
/* a simple macro for making hash "process" functions */
511-
#define HASH_PROCESS(func_name, compress_name, state_var, block_size) \
512-
int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) \
513-
{ \
514-
unsigned long n; \
515-
int err; \
516-
LTC_ARGCHK(md != NULL); \
517-
LTC_ARGCHK(in != NULL); \
518-
if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \
519-
return CRYPT_INVALID_ARG; \
520-
} \
521-
if ((md-> state_var .length + inlen) < md-> state_var .length) { \
522-
return CRYPT_HASH_OVERFLOW; \
523-
} \
524-
while (inlen > 0) { \
525-
if (md-> state_var .curlen == 0 && inlen >= block_size) { \
526-
if ((err = compress_name (md, in)) != CRYPT_OK) { \
527-
return err; \
528-
} \
529-
md-> state_var .length += block_size * 8; \
530-
in += block_size; \
531-
inlen -= block_size; \
532-
} else { \
533-
n = MIN(inlen, (block_size - md-> state_var .curlen)); \
534-
XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \
535-
md-> state_var .curlen += n; \
536-
in += n; \
537-
inlen -= n; \
538-
if (md-> state_var .curlen == block_size) { \
539-
if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) { \
540-
return err; \
541-
} \
542-
md-> state_var .length += 8*block_size; \
543-
md-> state_var .curlen = 0; \
544-
} \
545-
} \
546-
} \
547-
return CRYPT_OK; \
548-
}
549-
550510
/* ref: $Format:%D$ */
551511
/* git commit: $Format:%H$ */
552512
/* commit time: $Format:%ai$ */

src/headers/tomcrypt_mac.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ int blake2bmac_file(const char *fname, const unsigned char *key, unsigned long k
146146
int blake2bmac_test(void);
147147
#endif /* LTC_BLAKE2BMAC */
148148

149+
149150
#ifdef LTC_PELICAN
150151

151152
typedef struct pelican_state
@@ -391,12 +392,6 @@ int ocb3_decrypt_verify_memory(int cipher,
391392

392393
int ocb3_test(void);
393394

394-
#ifdef LTC_SOURCE
395-
/* internal helper functions */
396-
int ocb3_int_ntz(unsigned long x);
397-
void ocb3_int_xor_blocks(unsigned char *out, const unsigned char *block_a, const unsigned char *block_b, unsigned long block_len);
398-
#endif /* LTC_SOURCE */
399-
400395
#endif /* LTC_OCB3_MODE */
401396

402397
#ifdef LTC_CCM_MODE

src/headers/tomcrypt_math.h

-71
Original file line numberDiff line numberDiff line change
@@ -524,77 +524,6 @@ extern const ltc_math_descriptor tfm_desc;
524524
extern const ltc_math_descriptor gmp_desc;
525525
#endif
526526

527-
#if !defined(DESC_DEF_ONLY) && defined(LTC_SOURCE)
528-
529-
#define MP_DIGIT_BIT ltc_mp.bits_per_digit
530-
531-
/* some handy macros */
532-
#define mp_init(a) ltc_mp.init(a)
533-
#define mp_init_multi ltc_init_multi
534-
#define mp_clear(a) ltc_mp.deinit(a)
535-
#define mp_clear_multi ltc_deinit_multi
536-
#define mp_cleanup_multi ltc_cleanup_multi
537-
#define mp_init_copy(a, b) ltc_mp.init_copy(a, b)
538-
539-
#define mp_neg(a, b) ltc_mp.neg(a, b)
540-
#define mp_copy(a, b) ltc_mp.copy(a, b)
541-
542-
#define mp_set(a, b) ltc_mp.set_int(a, b)
543-
#define mp_set_int(a, b) ltc_mp.set_int(a, b)
544-
#define mp_get_int(a) ltc_mp.get_int(a)
545-
#define mp_get_digit(a, n) ltc_mp.get_digit(a, n)
546-
#define mp_get_digit_count(a) ltc_mp.get_digit_count(a)
547-
#define mp_cmp(a, b) ltc_mp.compare(a, b)
548-
#define mp_cmp_d(a, b) ltc_mp.compare_d(a, b)
549-
#define mp_count_bits(a) ltc_mp.count_bits(a)
550-
#define mp_cnt_lsb(a) ltc_mp.count_lsb_bits(a)
551-
#define mp_2expt(a, b) ltc_mp.twoexpt(a, b)
552-
553-
#define mp_read_radix(a, b, c) ltc_mp.read_radix(a, b, c)
554-
#define mp_toradix(a, b, c) ltc_mp.write_radix(a, b, c)
555-
#define mp_unsigned_bin_size(a) ltc_mp.unsigned_size(a)
556-
#define mp_to_unsigned_bin(a, b) ltc_mp.unsigned_write(a, b)
557-
#define mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c)
558-
559-
#define mp_add(a, b, c) ltc_mp.add(a, b, c)
560-
#define mp_add_d(a, b, c) ltc_mp.addi(a, b, c)
561-
#define mp_sub(a, b, c) ltc_mp.sub(a, b, c)
562-
#define mp_sub_d(a, b, c) ltc_mp.subi(a, b, c)
563-
#define mp_mul(a, b, c) ltc_mp.mul(a, b, c)
564-
#define mp_mul_d(a, b, c) ltc_mp.muli(a, b, c)
565-
#define mp_sqr(a, b) ltc_mp.sqr(a, b)
566-
#define mp_sqrtmod_prime(a, b, c) ltc_mp.sqrtmod_prime(a, b, c)
567-
#define mp_div(a, b, c, d) ltc_mp.mpdiv(a, b, c, d)
568-
#define mp_div_2(a, b) ltc_mp.div_2(a, b)
569-
#define mp_mod(a, b, c) ltc_mp.mpdiv(a, b, NULL, c)
570-
#define mp_mod_d(a, b, c) ltc_mp.modi(a, b, c)
571-
#define mp_gcd(a, b, c) ltc_mp.gcd(a, b, c)
572-
#define mp_lcm(a, b, c) ltc_mp.lcm(a, b, c)
573-
574-
#define mp_addmod(a, b, c, d) ltc_mp.addmod(a, b, c, d)
575-
#define mp_submod(a, b, c, d) ltc_mp.submod(a, b, c, d)
576-
#define mp_mulmod(a, b, c, d) ltc_mp.mulmod(a, b, c, d)
577-
#define mp_sqrmod(a, b, c) ltc_mp.sqrmod(a, b, c)
578-
#define mp_invmod(a, b, c) ltc_mp.invmod(a, b, c)
579-
580-
#define mp_montgomery_setup(a, b) ltc_mp.montgomery_setup(a, b)
581-
#define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b)
582-
#define mp_montgomery_reduce(a, b, c) ltc_mp.montgomery_reduce(a, b, c)
583-
#define mp_montgomery_free(a) ltc_mp.montgomery_deinit(a)
584-
585-
#define mp_exptmod(a,b,c,d) ltc_mp.exptmod(a,b,c,d)
586-
#define mp_prime_is_prime(a, b, c) ltc_mp.isprime(a, b, c)
587-
588-
#define mp_iszero(a) (mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO)
589-
#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)
590-
#define mp_exch(a, b) do { void *ABC__tmp = a; a = b; b = ABC__tmp; } while(0)
591-
592-
#define mp_tohex(a, b) mp_toradix(a, b, 16)
593-
594-
#define mp_rand(a, b) ltc_mp.rand(a, b)
595-
596-
#endif
597-
598527
/* ref: $Format:%D$ */
599528
/* git commit: $Format:%H$ */
600529
/* commit time: $Format:%ai$ */

src/headers/tomcrypt_misc.h

-8
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ int hkdf(int hash_idx,
8585
/* ---- MEM routines ---- */
8686
int mem_neq(const void *a, const void *b, size_t len);
8787
void zeromem(volatile void *dst, size_t len);
88-
#ifdef LTC_SOURCE
89-
void copy_or_zeromem(const unsigned char* src, unsigned char* dest, unsigned long len, int coz);
90-
#endif
9188
void burn_stack(unsigned long len);
9289

9390
const char *error_to_string(int err);
@@ -155,11 +152,6 @@ enum padding_type {
155152

156153
int padding_pad(unsigned char *data, unsigned long length, unsigned long* padded_length, unsigned long mode);
157154
int padding_depad(const unsigned char *data, unsigned long *length, unsigned long mode);
158-
159-
#ifdef LTC_SOURCE
160-
/* internal helper functions */
161-
#define LTC_PAD_MASK (0xF000U)
162-
#endif
163155
#endif /* LTC_PADDING */
164156

165157
int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which);

src/headers/tomcrypt_pk.h

+1-162
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,6 @@ enum public_key_type {
2525

2626
int rand_prime(void *N, long len, prng_state *prng, int wprng);
2727

28-
#ifdef LTC_SOURCE
29-
/* internal helper functions */
30-
int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng);
31-
int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng);
32-
33-
enum public_key_algorithms {
34-
PKA_RSA,
35-
PKA_DSA
36-
};
37-
38-
typedef struct Oid {
39-
unsigned long OID[16];
40-
/** Number of OID digits in use */
41-
unsigned long OIDlen;
42-
} oid_st;
43-
44-
int pk_get_oid(int pk, oid_st *st);
45-
int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen);
46-
int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen);
47-
#endif /* LTC_SOURCE */
48-
4928
/* ---- RSA ---- */
5029
#ifdef LTC_MRSA
5130

@@ -233,19 +212,6 @@ int dh_shared_secret(const dh_key *private_key, const dh_key *public_key,
233212
void dh_free(dh_key *key);
234213

235214
int dh_export_key(void *out, unsigned long *outlen, int type, const dh_key *key);
236-
237-
#ifdef LTC_SOURCE
238-
typedef struct {
239-
int size;
240-
const char *name, *base, *prime;
241-
} ltc_dh_set_type;
242-
243-
extern const ltc_dh_set_type ltc_dh_sets[];
244-
245-
/* internal helper functions */
246-
int dh_check_pubkey(const dh_key *key);
247-
#endif
248-
249215
#endif /* LTC_MDH */
250216

251217

@@ -387,76 +353,6 @@ int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
387353
const unsigned char *hash, unsigned long hashlen,
388354
int *stat, const ecc_key *key);
389355

390-
391-
#ifdef LTC_SOURCE
392-
/* INTERNAL ONLY - it should be later moved to src/headers/tomcrypt_internal.h */
393-
394-
int ecc_set_dp_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key);
395-
int ecc_copy_dp(const ecc_key *srckey, ecc_key *key);
396-
int ecc_set_dp_by_size(int size, ecc_key *key);
397-
398-
/* low level functions */
399-
ecc_point *ltc_ecc_new_point(void);
400-
void ltc_ecc_del_point(ecc_point *p);
401-
int ltc_ecc_set_point_xyz(ltc_mp_digit x, ltc_mp_digit y, ltc_mp_digit z, ecc_point *p);
402-
int ltc_ecc_copy_point(const ecc_point *src, ecc_point *dst);
403-
int ltc_ecc_is_point(const ltc_ecc_dp *dp, void *x, void *y);
404-
int ltc_ecc_is_point_at_infinity(const ecc_point *P, void *modulus, int *retval);
405-
int ltc_ecc_import_point(const unsigned char *in, unsigned long inlen, void *prime, void *a, void *b, void *x, void *y);
406-
int ltc_ecc_export_point(unsigned char *out, unsigned long *outlen, void *x, void *y, unsigned long size, int compressed);
407-
int ltc_ecc_verify_key(const ecc_key *key);
408-
409-
/* point ops (mp == montgomery digit) */
410-
#if !defined(LTC_MECC_ACCEL) || defined(LTM_DESC) || defined(GMP_DESC)
411-
/* R = 2P */
412-
int ltc_ecc_projective_dbl_point(const ecc_point *P, ecc_point *R, void *ma, void *modulus, void *mp);
413-
414-
/* R = P + Q */
415-
int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_point *R, void *ma, void *modulus, void *mp);
416-
#endif
417-
418-
#if defined(LTC_MECC_FP)
419-
/* optimized point multiplication using fixed point cache (HAC algorithm 14.117) */
420-
int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *a, void *modulus, int map);
421-
422-
/* functions for saving/loading/freeing/adding to fixed point cache */
423-
int ltc_ecc_fp_save_state(unsigned char **out, unsigned long *outlen);
424-
int ltc_ecc_fp_restore_state(unsigned char *in, unsigned long inlen);
425-
void ltc_ecc_fp_free(void);
426-
int ltc_ecc_fp_add_point(ecc_point *g, void *modulus, int lock);
427-
428-
/* lock/unlock all points currently in fixed point cache */
429-
void ltc_ecc_fp_tablelock(int lock);
430-
#endif
431-
432-
/* R = kG */
433-
int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *modulus, int map);
434-
435-
#ifdef LTC_ECC_SHAMIR
436-
/* kA*A + kB*B = C */
437-
int ltc_ecc_mul2add(const ecc_point *A, void *kA,
438-
const ecc_point *B, void *kB,
439-
ecc_point *C,
440-
void *ma,
441-
void *modulus);
442-
443-
#ifdef LTC_MECC_FP
444-
/* Shamir's trick with optimized point multiplication using fixed point cache */
445-
int ltc_ecc_fp_mul2add(const ecc_point *A, void *kA,
446-
const ecc_point *B, void *kB,
447-
ecc_point *C,
448-
void *ma,
449-
void *modulus);
450-
#endif
451-
452-
#endif
453-
454-
455-
/* map P to affine from projective */
456-
int ltc_ecc_map(ecc_point *P, void *modulus, void *mp);
457-
458-
#endif /* LTC_SOURCE */
459-
460356
#endif
461357

462358
#ifdef LTC_MDSA
@@ -533,16 +429,10 @@ int dsa_decrypt_key(const unsigned char *in, unsigned long inlen,
533429
int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key);
534430
int dsa_export(unsigned char *out, unsigned long *outlen, int type, const dsa_key *key);
535431
int dsa_verify_key(const dsa_key *key, int *stat);
536-
#ifdef LTC_SOURCE
537-
/* internal helper functions */
538-
int dsa_int_validate_xy(const dsa_key *key, int *stat);
539-
int dsa_int_validate_pqg(const dsa_key *key, int *stat);
540-
int dsa_int_validate_primes(const dsa_key *key, int *stat);
541-
#endif
542432
int dsa_shared_secret(void *private_key, void *base,
543433
const dsa_key *public_key,
544434
unsigned char *out, unsigned long *outlen);
545-
#endif
435+
#endif /* LTC_MDSA */
546436

547437
#ifdef LTC_DER
548438
/* DER handling */
@@ -705,30 +595,6 @@ int der_length_custom_type(const ltc_asn1_list *root,
705595
unsigned long *outlen,
706596
unsigned long *payloadlen);
707597

708-
#ifdef LTC_SOURCE
709-
/* internal helper functions */
710-
int der_decode_custom_type_ex(const unsigned char *in, unsigned long inlen,
711-
ltc_asn1_list *root,
712-
ltc_asn1_list *list, unsigned long outlen, unsigned int flags);
713-
714-
int der_encode_asn1_identifier(const ltc_asn1_list *id, unsigned char *out, unsigned long *outlen);
715-
int der_decode_asn1_identifier(const unsigned char *in, unsigned long *inlen, ltc_asn1_list *id);
716-
int der_length_asn1_identifier(const ltc_asn1_list *id, unsigned long *idlen);
717-
718-
int der_encode_asn1_length(unsigned long len, unsigned char* out, unsigned long* outlen);
719-
int der_decode_asn1_length(const unsigned char* len, unsigned long* lenlen, unsigned long* outlen);
720-
int der_length_asn1_length(unsigned long len, unsigned long *outlen);
721-
722-
int der_length_sequence_ex(const ltc_asn1_list *list, unsigned long inlen,
723-
unsigned long *outlen, unsigned long *payloadlen);
724-
725-
extern const ltc_asn1_type der_asn1_tag_to_type_map[];
726-
extern const unsigned long der_asn1_tag_to_type_map_sz;
727-
728-
extern const int der_asn1_type_to_identifier_map[];
729-
extern const unsigned long der_asn1_type_to_identifier_map_sz;
730-
#endif /* LTC_SOURCE */
731-
732598
/* SET */
733599
#define der_decode_set(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, LTC_DER_SEQ_SET)
734600
#define der_length_set der_length_sequence
@@ -741,10 +607,6 @@ int der_encode_setof(const ltc_asn1_list *list, unsigned long inlen,
741607
/* VA list handy helpers with triplets of <type, size, data> */
742608
int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...);
743609
int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...);
744-
#ifdef LTC_SOURCE
745-
/* internal helper functions */
746-
int der_decode_sequence_multi_ex(const unsigned char *in, unsigned long inlen, unsigned int flags, ...);
747-
#endif /* LTC_SOURCE */
748610

749611
/* FLEXI DECODER handle unknown list decoder */
750612
int der_decode_sequence_flexi(const unsigned char *in, unsigned long *inlen, ltc_asn1_list **out);
@@ -809,13 +671,6 @@ int der_decode_teletex_string(const unsigned char *in, unsigned long inlen,
809671
unsigned char *out, unsigned long *outlen);
810672
int der_length_teletex_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen);
811673

812-
#ifdef LTC_SOURCE
813-
/* internal helper functions */
814-
int der_teletex_char_encode(int c);
815-
int der_teletex_value_decode(int v);
816-
#endif /* LTC_SOURCE */
817-
818-
819674
/* PRINTABLE STRING */
820675
int der_encode_printable_string(const unsigned char *in, unsigned long inlen,
821676
unsigned char *out, unsigned long *outlen);
@@ -846,10 +701,6 @@ int der_encode_utf8_string(const wchar_t *in, unsigned long inlen,
846701
int der_decode_utf8_string(const unsigned char *in, unsigned long inlen,
847702
wchar_t *out, unsigned long *outlen);
848703
unsigned long der_utf8_charsize(const wchar_t c);
849-
#ifdef LTC_SOURCE
850-
/* internal helper functions */
851-
int der_utf8_valid_char(const wchar_t c);
852-
#endif /* LTC_SOURCE */
853704
int der_length_utf8_string(const wchar_t *in, unsigned long noctets, unsigned long *outlen);
854705

855706

@@ -900,18 +751,6 @@ int der_decode_generalizedtime(const unsigned char *in, unsigned long *inlen,
900751

901752
int der_length_generalizedtime(const ltc_generalizedtime *gtime, unsigned long *outlen);
902753

903-
#ifdef LTC_SOURCE
904-
/* internal helper functions */
905-
/* SUBJECT PUBLIC KEY INFO */
906-
int x509_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen,
907-
unsigned int algorithm, const void* public_key, unsigned long public_key_len,
908-
ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len);
909-
910-
int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long inlen,
911-
unsigned int algorithm, void* public_key, unsigned long* public_key_len,
912-
ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long *parameters_len);
913-
#endif /* LTC_SOURCE */
914-
915754
#endif
916755

917756
/* ref: $Format:%D$ */

0 commit comments

Comments
 (0)