Merge pull request #1340 from dgarske/ecc_pub_import_wcurve

Adds curve information to public key import for `wc_EccPublicKeyDecode`
This commit is contained in:
toddouska
2018-02-02 10:52:06 -08:00
committed by GitHub
2 changed files with 25 additions and 22 deletions

View File

@@ -10548,9 +10548,8 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
{
int length;
int ret;
#ifdef ECC_CHECK_PUBLIC_KEY_OID
int curve_id = ECC_CURVE_DEF;
word32 oidSum;
#endif
if (input == NULL || inOutIdx == NULL || key == NULL || inSz == 0)
return BAD_FUNC_ARG;
@@ -10566,17 +10565,14 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
return ret;
/* ecc params information */
#ifdef ECC_CHECK_PUBLIC_KEY_OID
ret = GetObjectId(input, inOutIdx, &oidSum, oidIgnoreType, inSz);
if (ret != 0)
return ret;
if (CheckCurve(oidSum) < 0)
/* get curve id */
curve_id = wc_ecc_get_oid(oidSum, NULL, 0);
if (curve_id < 0)
return ECC_CURVE_OID_E;
#else
ret = SkipObjectId(input, inOutIdx, inSz);
if (ret != 0)
return ret;
#endif
/* key header */
ret = CheckBitString(input, inOutIdx, NULL, inSz, 1, NULL);
@@ -10584,8 +10580,10 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
return ret;
/* This is the raw point data compressed or uncompressed. */
if (wc_ecc_import_x963(input + *inOutIdx, inSz - *inOutIdx, key) != 0)
if (wc_ecc_import_x963_ex(input + *inOutIdx, inSz - *inOutIdx, key,
curve_id) != 0) {
return ASN_ECC_KEY_E;
}
return 0;
}
@@ -10860,9 +10858,6 @@ int wc_Ed25519PublicKeyDecode(const byte* input, word32* inOutIdx,
{
int length;
int ret;
#ifdef ECC_CHECK_PUBLIC_KEY_OID
word32 oidSum;
#endif
if (input == NULL || inOutIdx == NULL || key == NULL || inSz == 0)
return BAD_FUNC_ARG;

View File

@@ -13810,7 +13810,11 @@ static int ecc_decode_test(void)
word32 inSz;
word32 inOutIdx;
ecc_key key;
const byte good[] = { 0x30, 0x0d, 0x30, 0x0b, 0x06, 0x00, 0x06, 0x01, 0x01,
/* SECP256R1 OID: 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 */
const byte good[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
const byte badNoObjId[] = { 0x30, 0x08, 0x30, 0x06, 0x03, 0x04,
0x00, 0x04, 0x01, 0x01 };
@@ -13820,14 +13824,18 @@ static int ecc_decode_test(void)
0x06, 0x00, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
const byte badObj2d1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x00,
0x06, 0x07, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
const byte badNotBitStr[] = { 0x30, 0x0d, 0x30, 0x0b, 0x06, 0x00,
0x06, 0x01, 0x01, 0x04, 0x04, 0x00, 0x04, 0x01, 0x01 };
const byte badBitStrLen[] = { 0x30, 0x0d, 0x30, 0x0b, 0x06, 0x00,
0x06, 0x01, 0x01, 0x03, 0x05, 0x00, 0x04, 0x01, 0x01 };
const byte badNoBitStrZero[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x00,
0x06, 0x01, 0x01, 0x03, 0x03, 0x04, 0x01, 0x01 };
const byte badPoint[] = { 0x30, 0x0b, 0x30, 0x09, 0x06, 0x00, 0x06, 0x01,
0x01, 0x03, 0x03, 0x00, 0x04, 0x01 };
const byte badNotBitStr[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
0x04, 0x04, 0x00, 0x04, 0x01, 0x01 };
const byte badBitStrLen[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
0x03, 0x05, 0x00, 0x04, 0x01, 0x01 };
const byte badNoBitStrZero[] = { 0x30, 0x13, 0x30, 0x0a, 0x06, 0x00,
0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
0x03, 0x03, 0x04, 0x01, 0x01 };
const byte badPoint[] = { 0x30, 0x12, 0x30, 0x09, 0x06, 0x00,
0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
0x03, 0x03, 0x00, 0x04, 0x01 };
XMEMSET(&key, 0, sizeof(key));
wc_ecc_init(&key);