From 22f49d8597aea06e706d3af1db326635cce3c82f Mon Sep 17 00:00:00 2001 From: David Garske Date: Mon, 13 Jan 2020 11:09:25 -0800 Subject: [PATCH] Fixes for building with ECC sign/verify only. --- tests/api.c | 2 +- wolfcrypt/src/asn.c | 36 +++++++++++++++++------------------- wolfcrypt/test/test.c | 13 ++++++++++++- wolfssl/openssl/evp.h | 2 ++ 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/tests/api.c b/tests/api.c index 1d24b0114..9521e8e34 100644 --- a/tests/api.c +++ b/tests/api.c @@ -218,9 +218,9 @@ #include #endif +#include #ifndef NO_RSA #include - #include #define FOURK_BUF 4096 #define GEN_BUF 294 diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 44887763f..dd3ea64b2 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -6672,6 +6672,23 @@ WOLFSSL_LOCAL word32 SetLength(word32 length, byte* output) return i; } +WOLFSSL_LOCAL int SetMyVersion(word32 version, byte* output, int header) +{ + int i = 0; + + if (output == NULL) + return BAD_FUNC_ARG; + + if (header) { + output[i++] = ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED; + output[i++] = 3; + } + output[i++] = ASN_INTEGER; + output[i++] = 0x01; + output[i++] = (byte)version; + + return i; +} WOLFSSL_LOCAL word32 SetSequence(word32 len, byte* output) { @@ -9521,25 +9538,6 @@ void FreeTrustedPeerTable(TrustedPeerCert** table, int rows, void* heap) } #endif /* WOLFSSL_TRUST_PEER_CERT */ -WOLFSSL_LOCAL int SetMyVersion(word32 version, byte* output, int header) -{ - int i = 0; - - if (output == NULL) - return BAD_FUNC_ARG; - - if (header) { - output[i++] = ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED; - output[i++] = 3; - } - output[i++] = ASN_INTEGER; - output[i++] = 0x01; - output[i++] = (byte)version; - - return i; -} - - WOLFSSL_LOCAL int SetSerialNumber(const byte* sn, word32 snSz, byte* output, word32 outputSz, int maxSnSz) { diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 5be2108e2..697e0df74 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -17363,12 +17363,17 @@ done: static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, int curve_id, const ecc_set_type* dp) { +#if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH) DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT); DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT); +#endif #ifdef HAVE_ECC_KEY_EXPORT byte exportBuf[MAX_ECC_BYTES * 2 + 32]; #endif - word32 x, y; + word32 x; +#if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH) + word32 y; +#endif #ifdef HAVE_ECC_SIGN DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT); DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT); @@ -17687,7 +17692,9 @@ done: wc_ecc_free(&userA); FREE_VAR(sharedA, HEAP_HINT); +#if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH) FREE_VAR(sharedB, HEAP_HINT); +#endif #ifdef HAVE_ECC_SIGN FREE_VAR(sig, HEAP_HINT); FREE_VAR(digest, HEAP_HINT); @@ -18165,6 +18172,7 @@ done: } #endif +#ifdef HAVE_ECC_DHE static int ecc_ssh_test(ecc_key* key) { int ret; @@ -18199,6 +18207,7 @@ static int ecc_ssh_test(ecc_key* key) TEST_SLEEP(); return 0; } +#endif /* HAVE_ECC_DHE */ #endif static int ecc_def_curve_test(WC_RNG *rng) @@ -18246,9 +18255,11 @@ static int ecc_def_curve_test(WC_RNG *rng) if (ret < 0) goto done; #endif +#ifdef HAVE_ECC_DHE ret = ecc_ssh_test(&key); if (ret < 0) goto done; +#endif #endif /* WOLFSSL_ATECC508A */ done: wc_ecc_free(&key); diff --git a/wolfssl/openssl/evp.h b/wolfssl/openssl/evp.h index fbca9a130..5388d3deb 100644 --- a/wolfssl/openssl/evp.h +++ b/wolfssl/openssl/evp.h @@ -141,7 +141,9 @@ typedef struct WOLFSSL_EVP_CIPHER_CTX WOLFSSL_EVP_CIPHER_CTX; typedef struct WOLFSSL_EVP_MD_CTX { union { WOLFSSL_Hasher digest; + #ifndef NO_HMAC Hmac hmac; + #endif } hash; unsigned char macType; WOLFSSL_EVP_PKEY_CTX *pctx;