forked from wolfSSL/wolfssl
Fix for wolfCrypt test custom curve test not setting wc_ecc_set_custom_curve
before 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:
@@ -929,6 +929,15 @@ const ecc_set_type ecc_sets[] = {
|
||||
},
|
||||
#endif /* !NO_ECC_SECP */
|
||||
#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,
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,11 @@
|
||||
#include <wolfssl/wolfcrypt/logging.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
|
||||
#ifdef WOLFSSL_TEST_CERT
|
||||
#include <wolfssl/wolfcrypt/asn.h>
|
||||
#else
|
||||
#include <wolfssl/wolfcrypt/asn_public.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/md2.h>
|
||||
#include <wolfssl/wolfcrypt/md5.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;
|
||||
|
||||
#ifdef WOLFSSL_CUSTOM_CURVES
|
||||
if (dp) {
|
||||
wc_ecc_set_custom_curve(&userA, dp);
|
||||
wc_ecc_set_custom_curve(&userB, dp);
|
||||
wc_ecc_set_custom_curve(&pubKey, dp);
|
||||
if (dp != NULL) {
|
||||
ret = wc_ecc_set_custom_curve(&userA, dp);
|
||||
if (ret != 0)
|
||||
goto done;
|
||||
ret = wc_ecc_set_custom_curve(&userB, dp);
|
||||
if (ret != 0)
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -10232,6 +10239,12 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
|
||||
goto done;
|
||||
|
||||
#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);
|
||||
if (ret != 0)
|
||||
goto done;
|
||||
@@ -10259,10 +10272,16 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
|
||||
if (ret != 0)
|
||||
goto done;
|
||||
wc_ecc_free(&pubKey);
|
||||
|
||||
ret = wc_ecc_init_ex(&pubKey, HEAP_HINT, devId);
|
||||
if (ret != 0)
|
||||
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);
|
||||
if (ret != 0)
|
||||
goto done;
|
||||
@@ -10994,12 +11013,13 @@ static int ecc_test_custom_curves(WC_RNG* rng)
|
||||
int ret;
|
||||
|
||||
/* test use of custom curve - using BRAINPOOLP256R1 for test */
|
||||
const word32 ecc_oid_brainpoolp256r1_sum = 104;
|
||||
const ecc_oid_t ecc_oid_brainpoolp256r1[] = {
|
||||
0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07
|
||||
};
|
||||
const ecc_set_type ecc_dp_brainpool256r1 = {
|
||||
32, /* size/bytes */
|
||||
ECC_BRAINPOOLP256R1, /* ID */
|
||||
ECC_CURVE_CUSTOM, /* ID */
|
||||
"BRAINPOOLP256R1", /* curve name */
|
||||
"A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* prime */
|
||||
"7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* A */
|
||||
@@ -11009,7 +11029,7 @@ static int ecc_test_custom_curves(WC_RNG* rng)
|
||||
"547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", /* Gy */
|
||||
ecc_oid_brainpoolp256r1, /* oid/oidSz */
|
||||
sizeof(ecc_oid_brainpoolp256r1) / sizeof(ecc_oid_t),
|
||||
ECC_BRAINPOOLP256R1_OID, /* oid sum */
|
||||
ecc_oid_brainpoolp256r1_sum, /* oid sum */
|
||||
1, /* cofactor */
|
||||
};
|
||||
|
||||
|
@@ -158,6 +158,10 @@ typedef enum ecc_curve_id {
|
||||
#ifdef HAVE_X448
|
||||
ECC_X448,
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_CUSTOM_CURVES
|
||||
ECC_CURVE_CUSTOM,
|
||||
#endif
|
||||
} ecc_curve_id;
|
||||
|
||||
#ifdef HAVE_OID_ENCODING
|
||||
|
Reference in New Issue
Block a user