@@ -12027,6 +12027,11 @@ enum {
1202712027
1202812028/* Number of items in ASN.1 template for header before ECC key in cert. */
1202912029#define eccCertKeyASN_Length (sizeof(eccCertKeyASN) / sizeof(ASNItem))
12030+
12031+ #ifdef WOLFSSL_CUSTOM_CURVES
12032+ static int EccSpecifiedECDomainDecode(const byte* input, word32 inSz,
12033+ ecc_key* key, void* heap, int* curveSz);
12034+ #endif /* WOLFSSL_CUSTOM_CURVES */
1203012035#endif /* WOLFSSL_ASN_TEMPLATE */
1203112036
1203212037/* Store public ECC key in certificate object.
@@ -12140,7 +12145,18 @@ static int StoreEccKey(DecodedCert* cert, const byte* source, word32* srcIdx,
1214012145 /* Store curve OID. */
1214112146 cert->pkCurveOID = dataASN[ECCCERTKEYASN_IDX_OID].data.oid.sum;
1214212147 }
12143- /* Ignore explicit parameters. */
12148+ else {
12149+ #ifdef WOLFSSL_CUSTOM_CURVES
12150+ /* Parse explicit parameters. */
12151+ ret = EccSpecifiedECDomainDecode(
12152+ dataASN[ECCCERTKEYASN_IDX_PARAMS].data.ref.data,
12153+ dataASN[ECCCERTKEYASN_IDX_PARAMS].data.ref.length, NULL,
12154+ NULL, &cert->pkCurveSize);
12155+ #else
12156+ /* Explicit parameters not supported in build configuration. */
12157+ ret = ASN_PARSE_E;
12158+ #endif
12159+ }
1214412160
1214512161 #ifdef WOLFSSL_MAXQ10XX_TLS
1214612162 cert->publicKeyIndex =
@@ -12149,10 +12165,13 @@ static int StoreEccKey(DecodedCert* cert, const byte* source, word32* srcIdx,
1214912165 #endif
1215012166
1215112167 #ifdef HAVE_OCSP
12152- /* Calculate the hash of the subject public key for OCSP. */
12153- ret = CalcHashId_ex(dataASN[ECCCERTKEYASN_IDX_SUBJPUBKEY].data.ref.data,
12154- dataASN[ECCCERTKEYASN_IDX_SUBJPUBKEY].data.ref.length,
12155- cert->subjectKeyHash, HashIdAlg(cert->signatureOID));
12168+ if (ret == 0) {
12169+ /* Calculate the hash of the subject public key for OCSP. */
12170+ ret = CalcHashId_ex(
12171+ dataASN[ECCCERTKEYASN_IDX_SUBJPUBKEY].data.ref.data,
12172+ dataASN[ECCCERTKEYASN_IDX_SUBJPUBKEY].data.ref.length,
12173+ cert->subjectKeyHash, HashIdAlg(cert->signatureOID));
12174+ }
1215612175 }
1215712176 if (ret == 0) {
1215812177 #endif
@@ -32271,7 +32290,7 @@ static const char ecSetCustomName[] = "Custom";
3227132290
3227232291/* Explicit EC parameter values. */
3227332292static int EccSpecifiedECDomainDecode(const byte* input, word32 inSz,
32274- ecc_key* key)
32293+ ecc_key* key, void* heap, int* curveSz )
3227532294{
3227632295 DECL_ASNGETDATA(dataASN, eccSpecifiedASN_Length);
3227732296 int ret = 0;
@@ -32283,8 +32302,8 @@ static int EccSpecifiedECDomainDecode(const byte* input, word32 inSz,
3228332302 word32 baseLen;
3228432303
3228532304 /* Allocate a new parameter set. */
32286- curve = (ecc_set_type*)XMALLOC(sizeof(*curve), key-> heap,
32287- DYNAMIC_TYPE_ECC_BUFFER);
32305+ curve = (ecc_set_type*)XMALLOC(sizeof(*curve), heap,
32306+ DYNAMIC_TYPE_ECC_BUFFER);
3228832307 if (curve == NULL) {
3228932308 ret = MEMORY_E;
3229032309 }
@@ -32293,7 +32312,7 @@ static int EccSpecifiedECDomainDecode(const byte* input, word32 inSz,
3229332312 XMEMSET(curve, 0, sizeof(*curve));
3229432313 }
3229532314
32296- CALLOC_ASNGETDATA(dataASN, eccSpecifiedASN_Length, ret, key-> heap);
32315+ CALLOC_ASNGETDATA(dataASN, eccSpecifiedASN_Length, ret, heap);
3229732316
3229832317 if (ret == 0) {
3229932318 /* Set name to be: "Custom" */
@@ -32356,42 +32375,42 @@ static int EccSpecifiedECDomainDecode(const byte* input, word32 inSz,
3235632375 if (ret == 0) {
3235732376 /* Base X-ordinate */
3235832377 ret = DataToHexStringAlloc(base + 1, (word32)curve->size,
32359- (char**)&curve->Gx, key-> heap,
32378+ (char**)&curve->Gx, heap,
3236032379 DYNAMIC_TYPE_ECC_BUFFER);
3236132380 }
3236232381 if (ret == 0) {
3236332382 /* Base Y-ordinate */
3236432383 ret = DataToHexStringAlloc(base + 1 + curve->size, (word32)curve->size,
32365- (char**)&curve->Gy, key-> heap,
32384+ (char**)&curve->Gy, heap,
3236632385 DYNAMIC_TYPE_ECC_BUFFER);
3236732386 }
3236832387 if (ret == 0) {
3236932388 /* Prime */
3237032389 ret = DataToHexStringAlloc(
3237132390 dataASN[ECCSPECIFIEDASN_IDX_PRIME_P].data.ref.data,
3237232391 dataASN[ECCSPECIFIEDASN_IDX_PRIME_P].data.ref.length,
32373- (char**)&curve->prime, key-> heap, DYNAMIC_TYPE_ECC_BUFFER);
32392+ (char**)&curve->prime, heap, DYNAMIC_TYPE_ECC_BUFFER);
3237432393 }
3237532394 if (ret == 0) {
3237632395 /* Parameter A */
3237732396 ret = DataToHexStringAlloc(
3237832397 dataASN[ECCSPECIFIEDASN_IDX_PARAM_A].data.ref.data,
3237932398 dataASN[ECCSPECIFIEDASN_IDX_PARAM_A].data.ref.length,
32380- (char**)&curve->Af, key-> heap, DYNAMIC_TYPE_ECC_BUFFER);
32399+ (char**)&curve->Af, heap, DYNAMIC_TYPE_ECC_BUFFER);
3238132400 }
3238232401 if (ret == 0) {
3238332402 /* Parameter B */
3238432403 ret = DataToHexStringAlloc(
3238532404 dataASN[ECCSPECIFIEDASN_IDX_PARAM_B].data.ref.data,
3238632405 dataASN[ECCSPECIFIEDASN_IDX_PARAM_B].data.ref.length,
32387- (char**)&curve->Bf, key-> heap, DYNAMIC_TYPE_ECC_BUFFER);
32406+ (char**)&curve->Bf, heap, DYNAMIC_TYPE_ECC_BUFFER);
3238832407 }
3238932408 if (ret == 0) {
3239032409 /* Order of curve */
3239132410 ret = DataToHexStringAlloc(
3239232411 dataASN[ECCSPECIFIEDASN_IDX_ORDER].data.ref.data,
3239332412 dataASN[ECCSPECIFIEDASN_IDX_ORDER].data.ref.length,
32394- (char**)&curve->order, key-> heap, DYNAMIC_TYPE_ECC_BUFFER);
32413+ (char**)&curve->order, heap, DYNAMIC_TYPE_ECC_BUFFER);
3239532414 }
3239632415 #else
3239732416 if (ret == 0) {
@@ -32418,26 +32437,31 @@ static int EccSpecifiedECDomainDecode(const byte* input, word32 inSz,
3241832437 }
3241932438 #endif /* WOLFSSL_ECC_CURVE_STATIC */
3242032439
32421- /* Store parameter set in key. */
32422- if ((ret == 0) && (wc_ecc_set_custom_curve(key, curve) < 0)) {
32423- ret = ASN_PARSE_E;
32440+ if (key) {
32441+ /* Store parameter set in key. */
32442+ if ((ret == 0) && (wc_ecc_set_custom_curve(key, curve) < 0)) {
32443+ ret = ASN_PARSE_E;
32444+ }
32445+ if (ret == 0) {
32446+ /* The parameter set was allocated.. */
32447+ key->deallocSet = 1;
32448+ }
3242432449 }
32425- if (ret == 0) {
32426- /* The parameter set was allocated.. */
32427- key->deallocSet = 1 ;
32450+
32451+ if (curveSz) {
32452+ *curveSz = curve->size ;
3242832453 }
3242932454
3243032455 if ((ret != 0) && (curve != NULL)) {
3243132456 /* Failed to set parameters so free parameter set. */
32432- wc_ecc_free_curve(curve, key-> heap);
32457+ wc_ecc_free_curve(curve, heap);
3243332458 }
3243432459
32435- FREE_ASNGETDATA(dataASN, key-> heap);
32460+ FREE_ASNGETDATA(dataASN, heap);
3243632461 return ret;
3243732462}
3243832463#endif /* WOLFSSL_CUSTOM_CURVES */
3243932464#endif /* WOLFSSL_ASN_TEMPLATE */
32440-
3244132465#ifdef HAVE_ECC
3244232466
3244332467#ifdef WOLFSSL_ASN_TEMPLATE
@@ -32665,7 +32689,8 @@ int wc_EccPrivateKeyDecode(const byte* input, word32* inOutIdx, ecc_key* key,
3266532689 /* Parse explicit parameters. */
3266632690 ret = EccSpecifiedECDomainDecode(
3266732691 dataASN[ECCKEYASN_IDX_CURVEPARAMS].data.ref.data,
32668- dataASN[ECCKEYASN_IDX_CURVEPARAMS].data.ref.length, key);
32692+ dataASN[ECCKEYASN_IDX_CURVEPARAMS].data.ref.length, key,
32693+ key->heap, NULL);
3266932694 #else
3267032695 /* Explicit parameters not supported in build configuration. */
3267132696 ret = ASN_PARSE_E;
@@ -33100,7 +33125,8 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
3310033125 #ifdef WOLFSSL_CUSTOM_CURVES
3310133126 /* Parse explicit parameters. */
3310233127 ret = EccSpecifiedECDomainDecode(dataASN[specIdx].data.ref.data,
33103- dataASN[specIdx].data.ref.length, key);
33128+ dataASN[specIdx].data.ref.length, key,
33129+ key->heap, NULL);
3310433130 #else
3310533131 /* Explicit parameters not supported in build configuration. */
3310633132 ret = ASN_PARSE_E;
0 commit comments