Skip to content

Commit

Permalink
allow compilation of ECC w/o DER
Browse files Browse the repository at this point in the history
via e.g.

```
make -j9 EXTRALIBS="../libtommath/libtommath.a " \
	CFLAGS="-DLTC_NOTHING -DLTC_MINIMAL -DLTC_MECC -DUSE_LTM \
	-DLTM_DESC -I../libtommath"
```
  • Loading branch information
sjaeckel authored and karel-m committed Apr 11, 2021
1 parent 9d74895 commit d96dd76
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src/headers/tomcrypt_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,11 @@
#define LTC_PKCS_8
#endif

#ifdef LTC_PKCS_8
#if defined(LTC_PKCS_8) && defined(LTC_DER)
#define LTC_PADDING
#define LTC_PBES
#else
#undef LTC_PKCS_8
#endif

#if defined(LTC_CLEAN_STACK)
Expand Down Expand Up @@ -622,7 +624,7 @@
#error ASN.1 DER requires MPI functionality
#endif

#if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC)) && !defined(LTC_DER)
#if (defined(LTC_MDSA) || defined(LTC_MRSA)) && !defined(LTC_DER)
#error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled
#endif

Expand Down
12 changes: 12 additions & 0 deletions src/headers/tomcrypt_pk.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,22 +267,27 @@ int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key);
int ecc_make_key_ex(prng_state *prng, int wprng, ecc_key *key, const ltc_ecc_curve *cu);
void ecc_free(ecc_key *key);

#if defined(LTC_DER)
int ecc_export(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_curve *cu);
#endif

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

#if defined(LTC_DER)
int ecc_export_openssl(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
int ecc_import_openssl(const unsigned char *in, unsigned long inlen, ecc_key *key);
int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen, const void *pwd, unsigned long pwdlen, ecc_key *key);
int ecc_import_x509(const unsigned char *in, unsigned long inlen, ecc_key *key);
#endif

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

#if defined(LTC_DER)
int ecc_encrypt_key(const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen,
prng_state *prng, int wprng, int hash,
Expand All @@ -295,6 +300,7 @@ int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
int ecc_sign_hash(const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen,
prng_state *prng, int wprng, const ecc_key *key);
#endif

int ecc_sign_hash_rfc7518(const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen,
Expand All @@ -305,25 +311,31 @@ int ecc_sign_hash_rfc7518_ex(const unsigned char *in, unsigned long inlen,
prng_state *prng, int wprng,
int *recid, const ecc_key *key);

#if defined(LTC_SSH)
int ecc_sign_hash_rfc5656(const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen,
prng_state *prng, int wprng, const ecc_key *key);
#endif

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

#if defined(LTC_DER)
int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
const unsigned char *hash, unsigned long hashlen,
int *stat, const ecc_key *key);
#endif

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

#if defined(LTC_SSH)
int ecc_verify_hash_rfc5656(const unsigned char *sig, unsigned long siglen,
const unsigned char *hash, unsigned long hashlen,
int *stat, const ecc_key *key);
#endif

int ecc_verify_hash_eth27(const unsigned char *sig, unsigned long siglen,
const unsigned char *hash, unsigned long hashlen,
Expand Down
7 changes: 6 additions & 1 deletion src/headers/tomcrypt_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef int (*fn_kdf_t)(const unsigned char *password, unsigned long password_le
int iteration_count, int hash_idx,
unsigned char *out, unsigned long *outlen);

#if defined(LTC_PBES)
typedef struct {
/* KDF */
fn_kdf_t kdf;
Expand All @@ -61,6 +62,7 @@ typedef struct
/* only used for RC2 */
unsigned long key_bits;
} pbes_arg;
#endif

/*
* Internal functions
Expand Down Expand Up @@ -204,10 +206,12 @@ void ocb3_int_xor_blocks(unsigned char *out, const unsigned char *block_a, const

void copy_or_zeromem(const unsigned char* src, unsigned char* dest, unsigned long len, int coz);

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

int pbes1_extract(const ltc_asn1_list *s, pbes_arg *res);
int pbes2_extract(const ltc_asn1_list *s, pbes_arg *res);
#endif


/* tomcrypt_pk.h */
Expand All @@ -219,6 +223,8 @@ int pk_get_oid(enum ltc_oid_id id, const char **st);
int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen);
int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen);

int pk_oid_cmp_with_ulong(const char *o1, const unsigned long *o2, unsigned long o2size);

/* ---- DH Routines ---- */
#ifdef LTC_MRSA
int rsa_init(rsa_key *key);
Expand Down Expand Up @@ -394,7 +400,6 @@ int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long i
unsigned int algorithm, void* public_key, unsigned long* public_key_len,
ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long *parameters_len);

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

#endif /* LTC_DER */
Expand Down
4 changes: 2 additions & 2 deletions src/pk/asn1/oid/pk_oid_cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"

#ifdef LTC_DER

/*
Compare an OID string to an array of `unsigned long`.
@return CRYPT_OK if equal
Expand All @@ -28,6 +26,8 @@ int pk_oid_cmp_with_ulong(const char *o1, const unsigned long *o2, unsigned long
return CRYPT_OK;
}

#ifdef LTC_DER

/*
Compare an OID string to an OID element decoded from ASN.1.
@return CRYPT_OK if equal
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_decrypt_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ECC Crypto, Tom St Denis
*/

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

/**
Decrypt an ECC encrypted key
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_encrypt_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ECC Crypto, Tom St Denis
*/

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

/**
Encrypt a symmetric key with ECC
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_export.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ECC Crypto, Tom St Denis
*/

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

/**
Export an ECC key as a binary packet
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_export_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "tomcrypt_private.h"

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

/**
Export an ECC key as a binary packet
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ECC Crypto, Tom St Denis
*/

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

/**
Import an ECC key from a binary packet
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_import_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "tomcrypt_private.h"

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

static int s_ecc_import_private_with_oid(const unsigned char *in, unsigned long inlen, ecc_key *key)
{
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_import_pkcs8.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "tomcrypt_private.h"

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

typedef struct {
ltc_asn1_type t;
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_import_x509.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

static int s_ecc_import_x509_with_oid(const unsigned char *in, unsigned long inlen, ecc_key *key)
{
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_recover_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "tomcrypt_private.h"

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

#ifdef LTC_ECC_SHAMIR

Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_sign_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "tomcrypt_private.h"

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

/**
Sign a message digest (ANSI X9.62 format)
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_verify_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "tomcrypt_private.h"

#ifdef LTC_MECC
#if defined(LTC_MECC) && defined(LTC_DER)

/**
@file ecc_verify_hash.c
Expand Down

0 comments on commit d96dd76

Please sign in to comment.