Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/build_ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,7 @@ def build_ffi(local_wolfssl, features):

if features["ML_DSA"]:
cdef += """
static const int DILITHIUM_SEED_SZ;
static const int WC_ML_DSA_44;
static const int WC_ML_DSA_65;
static const int WC_ML_DSA_87;
Expand Down
11 changes: 11 additions & 0 deletions tests/test_mldsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,14 @@ def test_sign_with_seed_and_context(mldsa_type, rng):
with pytest.raises(ValueError):
_ = mldsa_priv.sign_with_seed(message, signature_seed[:-1], ctx=bytes(1000))

def test_make_key_from_seed(mldsa_type):
seed = bytes(MlDsaPrivate.ML_DSA_KEYGEN_SEED_LENGTH)
assert MlDsaPrivate.make_key_from_seed(mldsa_type, seed)

@pytest.mark.parametrize(
"seed_length", [MlDsaPrivate.ML_DSA_KEYGEN_SEED_LENGTH - 1, MlDsaPrivate.ML_DSA_KEYGEN_SEED_LENGTH + 1]
)
def test_make_key_from_seed_bad_length(mldsa_type, seed_length):
seed = bytes(seed_length)
with pytest.raises(ValueError):
MlDsaPrivate.make_key_from_seed(mldsa_type, seed)
5 changes: 3 additions & 2 deletions wolfcrypt/ciphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,7 @@ class MlDsaType(IntEnum):

class _MlDsaBase:
INVALID_DEVID = _lib.INVALID_DEVID
ML_DSA_KEYGEN_SEED_LENGTH = _lib.DILITHIUM_SEED_SZ

def __init__(self, mldsa_type):
self._init_done = False
Expand Down Expand Up @@ -2300,9 +2301,9 @@ def make_key_from_seed(cls, mldsa_type, seed):
raise TypeError(
"seed must support the buffer protocol, such as `bytes` or `bytearray`"
) from exception
if len(seed_view) != ML_DSA_KEYGEN_SEED_LENGTH:
if len(seed_view) != cls.ML_DSA_KEYGEN_SEED_LENGTH:
raise ValueError(
f"Seed for generating ML-DSA key must be {ML_DSA_KEYGEN_SEED_LENGTH} bytes"
f"Seed for generating ML-DSA key must be {cls.ML_DSA_KEYGEN_SEED_LENGTH} bytes"
)

ret = _lib.wc_dilithium_make_key_from_seed(mldsa_priv.native_object,
Expand Down
Loading