From 1831193c208cc75045d9c6d485b27fc40f5a0b7b Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 3 Apr 2020 10:55:31 -0700 Subject: [PATCH] * Fixes for building ECC without ASN. * Fix to expose `wc_ecc_import_private_key_ex` and its ability to import a private key even when `NO_ASN` is defined. * Remove execute bit on CSharp files. --- wolfcrypt/src/ecc.c | 8 ++++++-- wolfcrypt/src/signature.c | 12 ++++++------ wolfcrypt/test/test.c | 4 +++- .../wolfSSL-TLS-Client/Properties/Settings.settings | 0 .../CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs | 0 .../wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj | 0 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config | 0 .../Properties/Settings.settings | 0 .../wolfSSL-TLS-ServerThreaded.cs | 0 .../wolfSSL-TLS-ServerThreaded.csproj | 0 wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs | 0 11 files changed, 15 insertions(+), 9 deletions(-) mode change 100755 => 100644 wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.settings mode change 100755 => 100644 wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs mode change 100755 => 100644 wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj mode change 100755 => 100644 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config mode change 100755 => 100644 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.settings mode change 100755 => 100644 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.cs mode change 100755 => 100644 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.csproj mode change 100755 => 100644 wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index dcc2d0e75..7fd33ca03 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -7319,7 +7319,6 @@ int wc_ecc_export_private_raw(ecc_key* key, byte* qx, word32* qxLen, #endif /* HAVE_ECC_KEY_EXPORT */ -#ifndef NO_ASN #ifdef HAVE_ECC_KEY_IMPORT /* import private key, public part optional if (pub) passed as NULL */ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz, @@ -7327,7 +7326,6 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz, int curve_id) { int ret; - word32 idx = 0; #if defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_ATECC508A) const CRYS_ECPKI_Domain_t* pDomain; CRYS_ECPKI_BUILD_TempData_t tempBuff; @@ -7337,10 +7335,15 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz, /* public optional, NULL if only importing private */ if (pub != NULL) { + #ifndef NO_ASN + word32 idx = 0; ret = wc_ecc_import_x963_ex(pub, pubSz, key, curve_id); if (ret < 0) ret = wc_EccPublicKeyDecode(pub, &idx, key, pubSz); key->type = ECC_PRIVATEKEY; + #else + ret = NOT_COMPILED_IN; + #endif } else { /* make sure required variables are reset */ @@ -7422,6 +7425,7 @@ int wc_ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub, } #endif /* HAVE_ECC_KEY_IMPORT */ +#ifndef NO_ASN /** Convert ECC R,S to signature r R component of signature diff --git a/wolfcrypt/src/signature.c b/wolfcrypt/src/signature.c index fcf4a28db..5d503338a 100644 --- a/wolfcrypt/src/signature.c +++ b/wolfcrypt/src/signature.c @@ -252,7 +252,7 @@ int wc_SignatureVerify( { int ret; word32 hash_len, hash_enc_len; -#ifdef WOLFSSL_SMALL_STACK +#if defined(WOLFSSL_SMALL_STACK) || defined(NO_ASN) byte *hash_data; #else byte hash_data[MAX_DER_DIGEST_SZ]; @@ -286,7 +286,7 @@ int wc_SignatureVerify( } #endif -#ifdef WOLFSSL_SMALL_STACK +#if defined(WOLFSSL_SMALL_STACK) || defined(NO_ASN) /* Allocate temporary buffer for hash data */ hash_data = (byte*)XMALLOC(hash_enc_len, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (hash_data == NULL) { @@ -328,7 +328,7 @@ int wc_SignatureVerify( } } -#ifdef WOLFSSL_SMALL_STACK +#if defined(WOLFSSL_SMALL_STACK) || defined(NO_ASN) XFREE(hash_data, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -462,7 +462,7 @@ int wc_SignatureGenerate_ex( { int ret; word32 hash_len, hash_enc_len; -#ifdef WOLFSSL_SMALL_STACK +#if defined(WOLFSSL_SMALL_STACK) || defined(NO_ASN) byte *hash_data; #else byte hash_data[MAX_DER_DIGEST_SZ]; @@ -496,7 +496,7 @@ int wc_SignatureGenerate_ex( } #endif -#ifdef WOLFSSL_SMALL_STACK +#if defined(WOLFSSL_SMALL_STACK) || defined(NO_ASN) /* Allocate temporary buffer for hash data */ hash_data = (byte*)XMALLOC(hash_enc_len, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (hash_data == NULL) { @@ -549,7 +549,7 @@ int wc_SignatureGenerate_ex( } #endif /* WOLFSSL_CRYPTOCELL */ -#ifdef WOLFSSL_SMALL_STACK +#if defined(WOLFSSL_SMALL_STACK) || defined(NO_ASN) XFREE(hash_data, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index cfdd79cbb..5db93d873 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -10293,12 +10293,14 @@ byte GetEntropy(ENTROPY_CMD cmd, byte* out) static const char* dsaKey = CERT_ROOT "dsa2048.der"; #endif #endif /* !USE_CERT_BUFFER_* */ -#if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ASN) +#if !defined(USE_CERT_BUFFERS_256) #ifdef HAVE_ECC /* cert files to be used in rsa cert gen test, check if RSA enabled */ #ifdef HAVE_ECC_KEY_IMPORT static const char* eccKeyDerFile = CERT_ROOT "ecc-key.der"; #endif +#endif +#if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ASN) #ifdef WOLFSSL_CERT_GEN #ifndef NO_RSA /* eccKeyPubFile is used in a test that requires RSA. */ diff --git a/wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.settings b/wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.settings old mode 100755 new mode 100644 diff --git a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs old mode 100755 new mode 100644 diff --git a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj old mode 100755 new mode 100644 diff --git a/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config old mode 100755 new mode 100644 diff --git a/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.settings b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.settings old mode 100755 new mode 100644 diff --git a/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.cs b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.cs old mode 100755 new mode 100644 diff --git a/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.csproj b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.csproj old mode 100755 new mode 100644 diff --git a/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs b/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs old mode 100755 new mode 100644