Fix for wolfCrypt test custom curve test not setting wc_ecc_set_custom_curvebefore calling wc_ecc_import_x963_ex. Fix for using ECC_CACHE_CURVE option and wc_ecc_set_custom_curve. Added error checking for wc_ecc_set_custom_curve calls. Reverted ASN header change in test.c.

This commit is contained in:
David Garske
2017-07-24 21:04:18 -07:00
parent 33e214ffc1
commit 08488b52b7
3 changed files with 43 additions and 9 deletions

View File

@@ -929,6 +929,15 @@ const ecc_set_type ecc_sets[] = {
}, },
#endif /* !NO_ECC_SECP */ #endif /* !NO_ECC_SECP */
#endif /* ECC521 */ #endif /* ECC521 */
#if defined(WOLFSSL_CUSTOM_CURVES) && defined(ECC_CACHE_CURVE)
/* place holder for custom curve index for cache */
{
1, /* non-zero */
ECC_CURVE_CUSTOM,
NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, 0, 0, 0
},
#endif
{ {
0, -1, 0, -1,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -2506,7 +2515,8 @@ int wc_ecc_get_curve_idx_from_name(const char* curveName)
len = (word32)XSTRLEN(curveName); len = (word32)XSTRLEN(curveName);
for (curve_idx = 0; ecc_sets[curve_idx].size != 0; curve_idx++) { for (curve_idx = 0; ecc_sets[curve_idx].size != 0; curve_idx++) {
if (XSTRNCASECMP(ecc_sets[curve_idx].name, curveName, len) == 0) { if (ecc_sets[curve_idx].name &&
XSTRNCASECMP(ecc_sets[curve_idx].name, curveName, len) == 0) {
break; break;
} }
} }

View File

@@ -43,7 +43,11 @@
#include <wolfssl/wolfcrypt/logging.h> #include <wolfssl/wolfcrypt/logging.h>
#include <wolfssl/wolfcrypt/types.h> #include <wolfssl/wolfcrypt/types.h>
#ifdef WOLFSSL_TEST_CERT
#include <wolfssl/wolfcrypt/asn.h> #include <wolfssl/wolfcrypt/asn.h>
#else
#include <wolfssl/wolfcrypt/asn_public.h>
#endif
#include <wolfssl/wolfcrypt/md2.h> #include <wolfssl/wolfcrypt/md2.h>
#include <wolfssl/wolfcrypt/md5.h> #include <wolfssl/wolfcrypt/md5.h>
#include <wolfssl/wolfcrypt/md4.h> #include <wolfssl/wolfcrypt/md4.h>
@@ -10142,10 +10146,13 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
goto done; goto done;
#ifdef WOLFSSL_CUSTOM_CURVES #ifdef WOLFSSL_CUSTOM_CURVES
if (dp) { if (dp != NULL) {
wc_ecc_set_custom_curve(&userA, dp); ret = wc_ecc_set_custom_curve(&userA, dp);
wc_ecc_set_custom_curve(&userB, dp); if (ret != 0)
wc_ecc_set_custom_curve(&pubKey, dp); goto done;
ret = wc_ecc_set_custom_curve(&userB, dp);
if (ret != 0)
goto done;
} }
#endif #endif
@@ -10232,6 +10239,12 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
goto done; goto done;
#ifdef HAVE_ECC_KEY_IMPORT #ifdef HAVE_ECC_KEY_IMPORT
#ifdef WOLFSSL_CUSTOM_CURVES
if (dp != NULL) {
ret = wc_ecc_set_custom_curve(&pubKey, dp);
if (ret != 0) goto done;
}
#endif
ret = wc_ecc_import_x963_ex(exportBuf, x, &pubKey, curve_id); ret = wc_ecc_import_x963_ex(exportBuf, x, &pubKey, curve_id);
if (ret != 0) if (ret != 0)
goto done; goto done;
@@ -10259,10 +10272,16 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
if (ret != 0) if (ret != 0)
goto done; goto done;
wc_ecc_free(&pubKey); wc_ecc_free(&pubKey);
ret = wc_ecc_init_ex(&pubKey, HEAP_HINT, devId); ret = wc_ecc_init_ex(&pubKey, HEAP_HINT, devId);
if (ret != 0) if (ret != 0)
goto done; goto done;
#ifdef WOLFSSL_CUSTOM_CURVES
if (dp != NULL) {
ret = wc_ecc_set_custom_curve(&pubKey, dp);
if (ret != 0) goto done;
}
#endif
ret = wc_ecc_import_x963_ex(exportBuf, x, &pubKey, curve_id); ret = wc_ecc_import_x963_ex(exportBuf, x, &pubKey, curve_id);
if (ret != 0) if (ret != 0)
goto done; goto done;
@@ -10994,12 +11013,13 @@ static int ecc_test_custom_curves(WC_RNG* rng)
int ret; int ret;
/* test use of custom curve - using BRAINPOOLP256R1 for test */ /* test use of custom curve - using BRAINPOOLP256R1 for test */
const word32 ecc_oid_brainpoolp256r1_sum = 104;
const ecc_oid_t ecc_oid_brainpoolp256r1[] = { const ecc_oid_t ecc_oid_brainpoolp256r1[] = {
0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07
}; };
const ecc_set_type ecc_dp_brainpool256r1 = { const ecc_set_type ecc_dp_brainpool256r1 = {
32, /* size/bytes */ 32, /* size/bytes */
ECC_BRAINPOOLP256R1, /* ID */ ECC_CURVE_CUSTOM, /* ID */
"BRAINPOOLP256R1", /* curve name */ "BRAINPOOLP256R1", /* curve name */
"A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* prime */ "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* prime */
"7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* A */ "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* A */
@@ -11009,7 +11029,7 @@ static int ecc_test_custom_curves(WC_RNG* rng)
"547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", /* Gy */ "547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", /* Gy */
ecc_oid_brainpoolp256r1, /* oid/oidSz */ ecc_oid_brainpoolp256r1, /* oid/oidSz */
sizeof(ecc_oid_brainpoolp256r1) / sizeof(ecc_oid_t), sizeof(ecc_oid_brainpoolp256r1) / sizeof(ecc_oid_t),
ECC_BRAINPOOLP256R1_OID, /* oid sum */ ecc_oid_brainpoolp256r1_sum, /* oid sum */
1, /* cofactor */ 1, /* cofactor */
}; };

View File

@@ -158,6 +158,10 @@ typedef enum ecc_curve_id {
#ifdef HAVE_X448 #ifdef HAVE_X448
ECC_X448, ECC_X448,
#endif #endif
#ifdef WOLFSSL_CUSTOM_CURVES
ECC_CURVE_CUSTOM,
#endif
} ecc_curve_id; } ecc_curve_id;
#ifdef HAVE_OID_ENCODING #ifdef HAVE_OID_ENCODING