Skip to content

Commit a114bca

Browse files
Add missing definition ML_DSA_KEYGEN_SEED_LENGTH.
1 parent ec8ce54 commit a114bca

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

scripts/build_ffi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,7 @@ def build_ffi(local_wolfssl, features):
13061306

13071307
if features["ML_DSA"]:
13081308
cdef += """
1309+
static const int DILITHIUM_SEED_SZ;
13091310
static const int WC_ML_DSA_44;
13101311
static const int WC_ML_DSA_65;
13111312
static const int WC_ML_DSA_87;

tests/test_mldsa.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,14 @@ def test_sign_with_seed_and_context(mldsa_type, rng):
203203
with pytest.raises(ValueError):
204204
_ = mldsa_priv.sign_with_seed(message, signature_seed[:-1], ctx=bytes(1000))
205205

206+
def test_make_key_from_seed(mldsa_type):
207+
seed = bytes(MlDsaPrivate.ML_DSA_KEYGEN_SEED_LENGTH)
208+
assert MlDsaPrivate.make_key_from_seed(mldsa_type, seed)
209+
210+
@pytest.mark.parametrize(
211+
"seed_length", [MlDsaPrivate.ML_DSA_KEYGEN_SEED_LENGTH - 1, MlDsaPrivate.ML_DSA_KEYGEN_SEED_LENGTH + 1]
212+
)
213+
def test_make_key_from_seed_bad_length(mldsa_type, seed_length):
214+
seed = bytes(seed_length)
215+
with pytest.raises(ValueError):
216+
MlDsaPrivate.make_key_from_seed(mldsa_type, seed)

wolfcrypt/ciphers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,7 @@ class MlDsaType(IntEnum):
21392139

21402140
class _MlDsaBase:
21412141
INVALID_DEVID = _lib.INVALID_DEVID
2142+
ML_DSA_KEYGEN_SEED_LENGTH = _lib.DILITHIUM_SEED_SZ
21422143

21432144
def __init__(self, mldsa_type):
21442145
self._init_done = False
@@ -2300,9 +2301,9 @@ def make_key_from_seed(cls, mldsa_type, seed):
23002301
raise TypeError(
23012302
"seed must support the buffer protocol, such as `bytes` or `bytearray`"
23022303
) from exception
2303-
if len(seed_view) != ML_DSA_KEYGEN_SEED_LENGTH:
2304+
if len(seed_view) != cls.ML_DSA_KEYGEN_SEED_LENGTH:
23042305
raise ValueError(
2305-
f"Seed for generating ML-DSA key must be {ML_DSA_KEYGEN_SEED_LENGTH} bytes"
2306+
f"Seed for generating ML-DSA key must be {cls.ML_DSA_KEYGEN_SEED_LENGTH} bytes"
23062307
)
23072308

23082309
ret = _lib.wc_dilithium_make_key_from_seed(mldsa_priv.native_object,

0 commit comments

Comments
 (0)