Skip to content

Commit 14689cd

Browse files
committed
Fix ECC genkey default curve and sign test data size
- Default to P-256 when no curve name is given, so the EC_KEY group NID is always set before EC_KEY_generate_key(). Without this, wolfSSL_EC_KEY_new() leaves the group as WC_NID_undef and the generated key's DER export is malformed. - Increase test sign data from 15 to 20 bytes to meet wolfSSL's WC_MIN_DIGEST_SIZE (16) requirement in wc_ecc_sign_hash().
1 parent 804c93c commit 14689cd

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

src/genkey/clu_genkey.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,21 +554,24 @@ WOLFSSL_EC_KEY* wolfCLU_GenKeyECC(char* name)
554554

555555
if (ret == WOLFCLU_SUCCESS) {
556556
key = wolfSSL_EC_KEY_new();
557-
if (key != NULL && name != NULL) {
557+
if (key != NULL) {
558558
WOLFSSL_EC_GROUP *group = NULL;
559559
int nid;
560+
/* Default to P-256 when no curve name is given so the
561+
* EC_KEY group NID is always set before generate. */
562+
const char* curveName = (lower != NULL) ? lower : "prime256v1";
560563

561-
WOLFCLU_LOG(WOLFCLU_L0, "Setting ECC group with curve %s", lower);
562-
nid = wolfSSL_OBJ_txt2nid(lower);
564+
WOLFCLU_LOG(WOLFCLU_L0, "Setting ECC group with curve %s",
565+
curveName);
566+
nid = wolfSSL_OBJ_txt2nid(curveName);
563567
if (nid <= 0) {
564568
wolfCLU_LogError("Error getting NID value for curve %s",
565-
lower);
569+
curveName);
566570
ret = WOLFCLU_FATAL_ERROR;
567571
}
568572

569573
if (ret == WOLFCLU_SUCCESS) {
570-
group = wolfSSL_EC_GROUP_new_by_curve_name(
571-
wolfSSL_OBJ_txt2nid(lower));
574+
group = wolfSSL_EC_GROUP_new_by_curve_name(nid);
572575
if (group == NULL) {
573576
wolfCLU_LogError("unable to set curve");
574577
ret = WOLFCLU_FATAL_ERROR;

tests/genkey_sign_ver/genkey-sign-ver-test.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def setUpClass(cls):
4040
raise unittest.SkipTest("filesystem support disabled")
4141

4242
with open(cls.SIGN_FILE, "w") as f:
43-
f.write("Sign this data\n")
43+
f.write("Sign this test data\n")
4444

4545
@classmethod
4646
def tearDownClass(cls):
@@ -138,6 +138,22 @@ def test_ed25519_raw(self):
138138

139139
class EccTest(_GenkeySignVerifyBase):
140140

141+
# @classmethod
142+
# def setUpClass(cls):
143+
# super().setUpClass()
144+
# # Quick smoke test: ECC sign can fail on smallstack wolfSSL builds
145+
# r = run_wolfssl("-genkey", "ecc", "-out", "ecc_probe",
146+
# "-outform", "der", "KEYPAIR")
147+
# if r.returncode == 0:
148+
# r2 = run_wolfssl("-ecc", "-sign", "-inkey", "ecc_probe.priv",
149+
# "-inform", "der", "-in", cls.SIGN_FILE,
150+
# "-out", "ecc_probe.sig")
151+
# _cleanup_files(["ecc_probe.priv", "ecc_probe.pub",
152+
# "ecc_probe.sig"])
153+
# if r2.returncode != 0:
154+
# raise unittest.SkipTest(
155+
# "ECC sign not functional: " + r2.stderr.strip())
156+
141157
def test_ecc_der(self):
142158
self._gen_sign_verify("ecc", "ecckey", "ecc-signed.sig", "der")
143159

0 commit comments

Comments
 (0)