Increased test suite ciphers buffer size (ticket #5000))

Enhancement to support ECC domain param HEX string or unsigned bin comparison (ticket #5035)
This commit is contained in:
Tesfa Mael 2019-04-15 17:54:23 -07:00
parent 378f5c0d4b
commit 393ca1b30c
3 changed files with 59 additions and 13 deletions

View File

@ -180,7 +180,7 @@ int testsuite_test(int argc, char** argv)
/* show ciphers */
{
char ciphers[1024];
char ciphers[1024*2];
XMEMSET(ciphers, 0, sizeof(ciphers));
wolfSSL_get_ciphers(ciphers, sizeof(ciphers)-1);
printf("ciphers = %s\n", ciphers);

View File

@ -3173,11 +3173,11 @@ int wc_ecc_get_curve_id_from_name(const char* curveName)
}
/* Compares a curve parameter (hex, from ecc_sets[]) to given input
* parameter (byte array) for equality.
*
* parameter for equality.
* encType is WC_TYPE_UNSIGNED_BIN or WC_TYPE_HEX_STR
* Returns MP_EQ on success, negative on error */
static int wc_ecc_cmp_param(const char* curveParam,
const byte* param, word32 paramSz)
const byte* param, word32 paramSz, int encType)
{
int err = MP_OKAY;
#ifdef WOLFSSL_SMALL_STACK
@ -3209,9 +3209,12 @@ static int wc_ecc_cmp_param(const char* curveParam,
return err;
}
if (err == MP_OKAY)
err = mp_read_unsigned_bin(a, param, paramSz);
if (err == MP_OKAY) {
if (encType == WC_TYPE_HEX_STR)
err = mp_read_radix(a, (char*) param, MP_RADIX_HEX);
else
err = mp_read_unsigned_bin(a, param, paramSz);
}
if (err == MP_OKAY)
err = mp_read_radix(b, curveParam, MP_RADIX_HEX);
@ -3270,13 +3273,17 @@ int wc_ecc_get_curve_id_from_params(int fieldSize,
for (idx = 0; ecc_sets[idx].size != 0; idx++) {
if (curveSz == ecc_sets[idx].size) {
if ((wc_ecc_cmp_param(ecc_sets[idx].prime, prime,
primeSz) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Af, Af, AfSz) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Bf, Bf, BfSz) == MP_EQ) &&
primeSz, WC_TYPE_UNSIGNED_BIN) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Af, Af, AfSz,
WC_TYPE_UNSIGNED_BIN) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Bf, Bf, BfSz,
WC_TYPE_UNSIGNED_BIN) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].order, order,
orderSz) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Gx, Gx, GxSz) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Gy, Gy, GySz) == MP_EQ) &&
orderSz, WC_TYPE_UNSIGNED_BIN) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Gx, Gx, GxSz,
WC_TYPE_UNSIGNED_BIN) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Gy, Gy, GySz,
WC_TYPE_UNSIGNED_BIN) == MP_EQ) &&
(cofactor == ecc_sets[idx].cofactor)) {
break;
}
@ -3289,6 +3296,43 @@ int wc_ecc_get_curve_id_from_params(int fieldSize,
return ecc_sets[idx].id;
}
int wc_ecc_get_curve_id_from_dp_params(const ecc_set_type* dp)
{
int idx;
if (dp == NULL)
return BAD_FUNC_ARG;
if (dp == NULL || dp->prime == NULL || dp->Af == NULL ||
dp->Bf == NULL || dp->order == NULL || dp->Gx == NULL || dp->Gy == NULL)
return BAD_FUNC_ARG;
for (idx = 0; ecc_sets[idx].size != 0; idx++) {
if (dp->size == ecc_sets[idx].size) {
if ((wc_ecc_cmp_param(ecc_sets[idx].prime, (const byte*)dp->prime,
(word32)XSTRLEN(dp->prime), WC_TYPE_HEX_STR) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Af, (const byte*)dp->Af,
(word32)XSTRLEN(dp->Af),WC_TYPE_HEX_STR) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Bf, (const byte*)dp->Bf,
(word32)XSTRLEN(dp->Bf),WC_TYPE_HEX_STR) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].order, (const byte*)dp->order,
(word32)XSTRLEN(dp->order),WC_TYPE_HEX_STR) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Gx, (const byte*)dp->Gx,
(word32)XSTRLEN(dp->Gx),WC_TYPE_HEX_STR) == MP_EQ) &&
(wc_ecc_cmp_param(ecc_sets[idx].Gy, (const byte*)dp->Gy,
(word32)XSTRLEN(dp->Gy),WC_TYPE_HEX_STR) == MP_EQ) &&
(dp->cofactor == ecc_sets[idx].cofactor)) {
break;
}
}
}
if (ecc_sets[idx].size == 0)
return ECC_CURVE_INVALID;
return ecc_sets[idx].id;
}
/* Returns the curve id that corresponds to a given OID,
* as listed in ecc_sets[] of ecc.c.
*

View File

@ -501,6 +501,8 @@ int wc_ecc_get_curve_id_from_params(int fieldSize,
const byte* prime, word32 primeSz, const byte* Af, word32 AfSz,
const byte* Bf, word32 BfSz, const byte* order, word32 orderSz,
const byte* Gx, word32 GxSz, const byte* Gy, word32 GySz, int cofactor);
WOLFSSL_API
int wc_ecc_get_curve_id_from_dp_params(const ecc_set_type* dp);
WOLFSSL_API
int wc_ecc_get_curve_id_from_oid(const byte* oid, word32 len);