Skip to content

Commit 467abc2

Browse files
committed
allow compilation of ECC w/o DER
via e.g. ``` make -j9 EXTRALIBS="../libtommath/libtommath.a " \ CFLAGS="-DLTC_NOTHING -DLTC_MINIMAL -DLTC_MECC -DUSE_LTM \ -DLTM_DESC -I../libtommath" ```
1 parent 72da1e7 commit 467abc2

15 files changed

+39
-16
lines changed

src/headers/tomcrypt_custom.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,11 @@
622622
#define LTC_PKCS_8
623623
#endif
624624

625-
#ifdef LTC_PKCS_8
625+
#if defined(LTC_PKCS_8) && defined(LTC_DER)
626626
#define LTC_PADDING
627627
#define LTC_PBES
628+
#else
629+
#undef LTC_PKCS_8
628630
#endif
629631

630632
#if defined(LTC_CLEAN_STACK)
@@ -664,7 +666,7 @@
664666
#error ASN.1 DER requires MPI functionality
665667
#endif
666668

667-
#if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC)) && !defined(LTC_DER)
669+
#if (defined(LTC_MDSA) || defined(LTC_MRSA)) && !defined(LTC_DER)
668670
#error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled
669671
#endif
670672

src/headers/tomcrypt_pk.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,27 @@ int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key);
312312
int ecc_make_key_ex(prng_state *prng, int wprng, ecc_key *key, const ltc_ecc_curve *cu);
313313
void ecc_free(ecc_key *key);
314314

315+
#if defined(LTC_DER)
315316
int ecc_export(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
316317
int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
317318
int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_curve *cu);
319+
#endif
318320

319321
int ecc_ansi_x963_export(const ecc_key *key, unsigned char *out, unsigned long *outlen);
320322
int ecc_ansi_x963_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
321323
int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_curve *cu);
322324

325+
#if defined(LTC_DER)
323326
int ecc_export_openssl(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
324327
int ecc_import_openssl(const unsigned char *in, unsigned long inlen, ecc_key *key);
325328
int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen, const password_ctx *pw_ctx, ecc_key *key);
326329
int ecc_import_x509(const unsigned char *in, unsigned long inlen, ecc_key *key);
330+
#endif
327331

328332
int ecc_shared_secret(const ecc_key *private_key, const ecc_key *public_key,
329333
unsigned char *out, unsigned long *outlen);
330334

335+
#if defined(LTC_DER)
331336
int ecc_encrypt_key(const unsigned char *in, unsigned long inlen,
332337
unsigned char *out, unsigned long *outlen,
333338
prng_state *prng, int wprng, int hash,
@@ -340,6 +345,7 @@ int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
340345
int ecc_sign_hash(const unsigned char *in, unsigned long inlen,
341346
unsigned char *out, unsigned long *outlen,
342347
prng_state *prng, int wprng, const ecc_key *key);
348+
#endif
343349

344350
int ecc_sign_hash_rfc7518(const unsigned char *in, unsigned long inlen,
345351
unsigned char *out, unsigned long *outlen,
@@ -350,25 +356,31 @@ int ecc_sign_hash_rfc7518_ex(const unsigned char *in, unsigned long inlen,
350356
prng_state *prng, int wprng,
351357
int *recid, const ecc_key *key);
352358

359+
#if defined(LTC_SSH)
353360
int ecc_sign_hash_rfc5656(const unsigned char *in, unsigned long inlen,
354361
unsigned char *out, unsigned long *outlen,
355362
prng_state *prng, int wprng, const ecc_key *key);
363+
#endif
356364

357365
int ecc_sign_hash_eth27(const unsigned char *in, unsigned long inlen,
358366
unsigned char *out, unsigned long *outlen,
359367
prng_state *prng, int wprng, const ecc_key *key);
360368

369+
#if defined(LTC_DER)
361370
int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
362371
const unsigned char *hash, unsigned long hashlen,
363372
int *stat, const ecc_key *key);
373+
#endif
364374

365375
int ecc_verify_hash_rfc7518(const unsigned char *sig, unsigned long siglen,
366376
const unsigned char *hash, unsigned long hashlen,
367377
int *stat, const ecc_key *key);
368378

379+
#if defined(LTC_SSH)
369380
int ecc_verify_hash_rfc5656(const unsigned char *sig, unsigned long siglen,
370381
const unsigned char *hash, unsigned long hashlen,
371382
int *stat, const ecc_key *key);
383+
#endif
372384

373385
int ecc_verify_hash_eth27(const unsigned char *sig, unsigned long siglen,
374386
const unsigned char *hash, unsigned long hashlen,

src/headers/tomcrypt_private.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ typedef int (*fn_kdf_t)(const struct password *pwd,
8484
int iteration_count, int hash_idx,
8585
unsigned char *out, unsigned long *outlen);
8686

87+
#if defined(LTC_PBES)
8788
typedef struct {
8889
/* KDF */
8990
fn_kdf_t kdf;
@@ -107,6 +108,7 @@ typedef struct
107108
/* only used for RC2 */
108109
unsigned long key_bits;
109110
} pbes_arg;
111+
#endif
110112

111113
typedef struct {
112114
const pbes_properties *data;
@@ -362,10 +364,12 @@ struct get_char {
362364
void copy_or_zeromem(const unsigned char* src, unsigned char* dest, unsigned long len, int coz);
363365
void password_free(struct password *pw, const struct password_ctx *ctx);
364366

367+
#if defined(LTC_PBES)
365368
int pbes_decrypt(const pbes_arg *arg, unsigned char *dec_data, unsigned long *dec_size);
366369

367370
int pbes1_extract(const ltc_asn1_list *s, pbes_arg *res);
368371
int pbes2_extract(const ltc_asn1_list *s, pbes_arg *res);
372+
#endif
369373

370374
int pem_decrypt(unsigned char *data, unsigned long *datalen,
371375
unsigned char *key, unsigned long keylen,
@@ -387,10 +391,14 @@ int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng);
387391
int pk_get_oid(enum ltc_oid_id id, const char **st);
388392
int pk_get_pka_id(enum ltc_oid_id id, enum ltc_pka_id *pka);
389393
int pk_get_oid_id(enum ltc_pka_id pka, enum ltc_oid_id *oid);
394+
#ifdef LTC_DER
390395
int pk_get_oid_from_asn1(const ltc_asn1_list *oid, enum ltc_oid_id *id);
396+
#endif
391397
int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen);
392398
int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen);
393399

400+
int pk_oid_cmp_with_ulong(const char *o1, const unsigned long *o2, unsigned long o2size);
401+
394402
/* ---- DH Routines ---- */
395403
#ifdef LTC_MRSA
396404
int rsa_init(rsa_key *key);
@@ -416,7 +424,9 @@ int ecc_set_curve_from_mpis(void *a, void *b, void *prime, void *order, void *gx
416424
int ecc_copy_curve(const ecc_key *srckey, ecc_key *key);
417425
int ecc_set_curve_by_size(int size, ecc_key *key);
418426
int ecc_import_subject_public_key_info(const unsigned char *in, unsigned long inlen, ecc_key *key);
427+
#ifdef LTC_DER
419428
int ecc_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, ecc_key *key);
429+
#endif
420430
int ecc_import_with_curve(const unsigned char *in, unsigned long inlen, int type, ecc_key *key);
421431
int ecc_import_with_oid(const unsigned char *in, unsigned long inlen, unsigned long *oid, unsigned long oid_len, int type, ecc_key *key);
422432

@@ -612,7 +622,6 @@ int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long i
612622
enum ltc_oid_id algorithm, void *public_key, unsigned long *public_key_len,
613623
ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long *parameters_len);
614624

615-
int pk_oid_cmp_with_ulong(const char *o1, const unsigned long *o2, unsigned long o2size);
616625
int pk_oid_cmp_with_asn1(const char *o1, const ltc_asn1_list *o2);
617626

618627
#endif /* LTC_DER */

src/pk/asn1/oid/pk_oid_cmp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/* SPDX-License-Identifier: Unlicense */
33
#include "tomcrypt_private.h"
44

5-
#ifdef LTC_DER
6-
75
/*
86
Compare an OID string to an array of `unsigned long`.
97
@return CRYPT_OK if equal
@@ -28,6 +26,8 @@ int pk_oid_cmp_with_ulong(const char *o1, const unsigned long *o2, unsigned long
2826
return CRYPT_OK;
2927
}
3028

29+
#ifdef LTC_DER
30+
3131
/*
3232
Compare an OID string to an OID element decoded from ASN.1.
3333
@return CRYPT_OK if equal

src/pk/ecc/ecc_decrypt_key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ECC Crypto, Tom St Denis
99
*/
1010

11-
#ifdef LTC_MECC
11+
#if defined(LTC_MECC) && defined(LTC_DER)
1212

1313
/**
1414
Decrypt an ECC encrypted key

src/pk/ecc/ecc_encrypt_key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ECC Crypto, Tom St Denis
99
*/
1010

11-
#ifdef LTC_MECC
11+
#if defined(LTC_MECC) && defined(LTC_DER)
1212

1313
/**
1414
Encrypt a symmetric key with ECC

src/pk/ecc/ecc_export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ECC Crypto, Tom St Denis
99
*/
1010

11-
#ifdef LTC_MECC
11+
#if defined(LTC_MECC) && defined(LTC_DER)
1212

1313
/**
1414
Export an ECC key as a binary packet

src/pk/ecc/ecc_export_openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "tomcrypt_private.h"
55

6-
#ifdef LTC_MECC
6+
#if defined(LTC_MECC) && defined(LTC_DER)
77

88
/**
99
Export an ECC key as a binary packet

src/pk/ecc/ecc_import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ECC Crypto, Tom St Denis
99
*/
1010

11-
#ifdef LTC_MECC
11+
#if defined(LTC_MECC) && defined(LTC_DER)
1212

1313
/**
1414
Import an ECC key from a binary packet

src/pk/ecc/ecc_import_openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "tomcrypt_private.h"
55

6-
#ifdef LTC_MECC
6+
#if defined(LTC_MECC) && defined(LTC_DER)
77

88
static int s_ecc_import_private_with_oid(const unsigned char *in, unsigned long inlen, ecc_key *key)
99
{

src/pk/ecc/ecc_import_pkcs8.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "tomcrypt_private.h"
55

6-
#ifdef LTC_MECC
6+
#if defined(LTC_MECC) && defined(LTC_DER)
77

88
int ecc_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, ecc_key *key)
99
{

src/pk/ecc/ecc_import_x509.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* SPDX-License-Identifier: Unlicense */
33
#include "tomcrypt_private.h"
44

5-
#ifdef LTC_MECC
5+
#if defined(LTC_MECC) && defined(LTC_DER)
66

77
static int s_ecc_import_x509_with_oid(const unsigned char *in, unsigned long inlen, ecc_key *key)
88
{

src/pk/ecc/ecc_recover_key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "tomcrypt_private.h"
55

6-
#ifdef LTC_MECC
6+
#if defined(LTC_MECC) && defined(LTC_DER)
77

88
#ifdef LTC_ECC_SHAMIR
99

src/pk/ecc/ecc_sign_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "tomcrypt_private.h"
55

6-
#ifdef LTC_MECC
6+
#if defined(LTC_MECC) && defined(LTC_DER)
77

88
/**
99
Sign a message digest (ANSI X9.62 format)

src/pk/ecc/ecc_verify_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "tomcrypt_private.h"
55

6-
#ifdef LTC_MECC
6+
#if defined(LTC_MECC) && defined(LTC_DER)
77

88
/**
99
@file ecc_verify_hash.c

0 commit comments

Comments
 (0)