Skip to content

Commit 9fdd663

Browse files
committed
Fix custom curve passthrough for import callbacks
1 parent 19ef100 commit 9fdd663

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10694,6 +10694,18 @@ int wc_ecc_import_x963_ex2(const byte* in, word32 inLen, ecc_key* key,
1069410694
return err;
1069510695
}
1069610696

10697+
#ifdef WOLFSSL_CUSTOM_CURVES
10698+
/* Copy custom curve params so recursive import uses correct curve */
10699+
if (key->dp != NULL) {
10700+
err = wc_ecc_set_custom_curve(tmpKey, key->dp);
10701+
if (err != 0) {
10702+
wc_ecc_free(tmpKey);
10703+
WC_FREE_VAR(tmpKey, key->heap);
10704+
return err;
10705+
}
10706+
}
10707+
#endif
10708+
1069710709
/* Recursive call imports X9.63 public key into temp via software */
1069810710
err = wc_ecc_import_x963_ex2(in, inLen, tmpKey, curve_id, untrusted);
1069910711
if (err == MP_OKAY) {
@@ -11214,6 +11226,18 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
1121411226
return tmpErr;
1121511227
}
1121611228

11229+
#ifdef WOLFSSL_CUSTOM_CURVES
11230+
/* Copy custom curve params so recursive import uses correct curve */
11231+
if (key->dp != NULL) {
11232+
tmpErr = wc_ecc_set_custom_curve(tmpKey, key->dp);
11233+
if (tmpErr != 0) {
11234+
wc_ecc_free(tmpKey);
11235+
WC_FREE_VAR(tmpKey, key->heap);
11236+
return tmpErr;
11237+
}
11238+
}
11239+
#endif
11240+
1121711241
/* Recursive call imports key material into temp via software
1121811242
* (no callback recursion since tmpKey has INVALID_DEVID) */
1121911243
tmpErr = wc_ecc_import_private_key_ex(priv, privSz, pub, pubSz,
@@ -11598,6 +11622,18 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
1159811622
return err;
1159911623
}
1160011624

11625+
#ifdef WOLFSSL_CUSTOM_CURVES
11626+
/* Copy custom curve params so recursive import uses correct curve */
11627+
if (key->dp != NULL) {
11628+
err = wc_ecc_set_custom_curve(tmpKey, key->dp);
11629+
if (err != 0) {
11630+
wc_ecc_free(tmpKey);
11631+
WC_FREE_VAR(tmpKey, key->heap);
11632+
return err;
11633+
}
11634+
}
11635+
#endif
11636+
1160111637
/* Recursive call imports key material into temp via software */
1160211638
err = wc_ecc_import_raw_private(tmpKey, qx, qy, d, curve_id, encType);
1160311639
if (err == MP_OKAY) {

0 commit comments

Comments
 (0)