Commit Graph

72 Commits (master)

Author SHA1 Message Date
Juliusz Sosinowicz 8bb46362b7 Use byte ctxLen in wc_dilithium_verify_ctx_msg cdef (F-4014)
The CFFI cdef declared wc_dilithium_verify_ctx_msg with word32 ctxLen while the
sign variants use byte ctxLen. wolfSSL's real API (wc_MlDsaKey_VerifyCtx in
wolfcrypt/wc_mldsa.h, which the wc_dilithium_verify_ctx_msg macro forwards to)
takes byte ctxLen, matching FIPS 204's 255-byte context cap. The mismatched
cdef made CFFI marshal a 4-byte word32 into a 1-byte slot, silently truncating
any ctxLen > 255 to its low byte.

Declare ctxLen as byte to match the sign cdef and the underlying API.
2026-07-16 08:48:55 +00:00
sebastian-carpenter a59a4f8b96 update license to GPLv3 2026-07-09 18:24:23 +02:00
David Garske 905682a036
Merge pull request #130 from mjdemilliano/add-hashdrbg-reseed
Random: add DRBG reseed support
2026-07-08 12:28:45 -07:00
Martijn de Milliano c1be234aa6 Process review comments:
- Update lib.pyi
- Remove obsolete comment from test_reseed_multiple
- Update HASHDRBG detection logic to match random.h
2026-07-07 19:14:59 +02:00
David Garske c69d2f1eea
Merge pull request #134 from mjdemilliano/prepare-v5.9.2
Prepare for v5.9.2 release
2026-07-02 16:42:48 -07:00
Martijn de Milliano fbe650ac8e Fix typo in comment 2026-07-01 08:13:51 +02:00
Martijn de Milliano c0803d0c66 Update ML-KEM and ML-DSA feature selection + detection 2026-06-30 18:53:45 +02:00
Martijn de Milliano 319c9200ff Prepare for v5.9.2 release 2026-06-30 16:33:18 +02:00
Martijn de Milliano afcebbf946 Rename flag to ML_DSA_NO_CTX_ENABLED 2026-06-29 18:41:17 +02:00
Martijn de Milliano 408ac74e9a Move MIN_AUTH_TAG_SZ next to AES-GCM-stream
This place is more logical
2026-06-29 18:41:01 +02:00
Robert de Vries 9e84d054d1 Fix some function definitions to match const-ness as defined in headers. 2026-06-27 22:09:34 +02:00
Martijn de Milliano e6f4632030 Random: add DRBG reseed support 2026-06-26 14:26:46 +02:00
Martijn de Milliano f8e56cd063 ML-DSA: fix ML_DSA_NO_CTX detection and add to default features
Also detect WOLFSSL_DILITHIUM_FIPS204_DRAFT as implying no-ctx support,
mirroring the logic in dilithium.h. Add ML_DSA_NO_CTX to the default
features dict for consistency with peer flags.
2026-06-26 00:35:32 +02:00
Martijn de Milliano fc5ea53605 Update AESGCM test
Read minimum supported tag size from settings and make the
test less ambiguous.
2026-06-26 00:31:05 +02:00
Martijn de Milliano 52886c4034 ML-DSA: Deal with signing without context not always supported
In the newer wolfSSL signing and verifying without context is
not available unless it is explicitly enabled.

This change modifies the Python binding and test suite to
accommodate this.
2026-06-04 18:03:35 +02:00
Robert de Vries 92ca0e57af Remove redundant open modes.
Redundant `open` mode arguments are unnecessary and should be removed to
avoid confusion.
2026-05-18 20:30:39 +02:00
Andrew Hutchings ef4195f99a Address Fenrir findings
F-3340: AesGcmStream.final decrypt path passed len(authTag) straight to
wc_AesGcmDecryptFinal, letting a caller truncate the verification window
(forgery probability ~2^-32 instead of 2^-128 for a 4-byte tag against a
16-byte configuration). Reject len(authTag) != self._tag_bytes and pass
self._tag_bytes to wolfSSL, mirroring ChaCha20Poly1305.decrypt. Added
test_decrypt_rejects_wrong_tag_length. Also fixed test_encrypt_short_tag
which was relying on the bug (decrypt side defaulted to tag_bytes=16
against a 12-byte tag).

F-3089: Declare label as const byte* in the wc_RsaPublicEncrypt_ex and
wc_RsaPrivateDecrypt_ex cdefs so CFFI can accept Python bytes without
exposing a writable pointer into immutable memory. wolfSSL does not
modify label.

F-3090: Declare nonce as const byte* in the wc_InitRngNonce and
wc_InitRngNonce_ex cdefs for the same reason.

F-1983, F-1984: Add minimum + upper bounds to requirements/{prod,test,
docs}.txt so a hijacked release of cffi, tox, pytest, types-cffi,
Sphinx, or sphinx_rtd_theme does not get pulled silently on the next
pip install. setup.txt resolves transitively via prod.txt.
2026-05-12 13:15:35 +01:00
Andrew Hutchings 57cca0e90d Validate raw element lengths in EccPublic/EccPrivate.decode_key_raw
wc_ecc_import_unsigned takes no length parameters for qx/qy/d: it
reads exactly curve_size bytes from each pointer based on curve_id,
via mp_read_unsigned_bin in wc_ecc_import_raw_private. The Python
decode_key_raw wrappers handed the user-supplied buffers straight
through without any length check, so a shorter buffer caused the C
library to read past the end of the Python buffer (OOB read of
adjacent memory, potentially leaking it into the imported key or
segfaulting). A longer buffer silently dropped the extra bytes.

Add wc_ecc_get_curve_size_from_id to the CFFI cdef, then in both
decode_key_raw methods t2b the inputs, look up the expected curve
size, and raise ValueError if any of qx/qy/d does not match. Reject
unknown curve_id values with a clear message rather than falling
through to wolfSSL with a bogus size.

Add test_ecc_decode_key_raw_rejects_wrong_length covering short qx,
long qy, short d, unknown curve_id, and the happy path on both
EccPublic and EccPrivate.

F-3088
2026-05-11 12:33:41 +01:00
Andrew Hutchings cd9cdeba5f Fix wc_ecc_import_unsigned cdef to match wolfSSL header
scripts/build_ffi.py declared qx, qy, and d as `byte*` while the
wolfSSL header (ecc.h) declares all three as `const byte*`. wolfSSL is
const-correct here and does not mutate the inputs, so there is no
observable bug today, but the non-const cdef let CFFI hand a writable
pointer into Python bytes storage on EccPublic.decode_key_raw and
EccPrivate.decode_key_raw calls. Update the cdef to match the header.

F-3087
2026-05-11 12:29:15 +01:00
Andrew Hutchings 000472761c Fix Ed448 ctx cdef to match wolfSSL header signature
scripts/build_ffi.py declared wc_ed448_sign_msg and wc_ed448_verify_msg
with two cdef discrepancies vs the wolfSSL header (ed448.h):

  - ctx was typed `byte*` instead of `const byte*`. CFFI was therefore
    happy to forward a writable pointer into Python bytes storage.
    The wolfSSL functions are const-correct and do not mutate ctx, so
    this had no runtime impact, but it widened the surface CFFI was
    willing to permit.

  - ctx_len was typed `word32` instead of `byte`. RFC 8032 caps Ed448
    context at 255 bytes, and wolfSSL's prototype reflects that with a
    1-byte parameter. The mismatch happens to work on x86_64 SysV
    because the low byte is what the callee reads, but it is still a
    real ABI discrepancy and would not be guaranteed on other
    platforms or calling conventions.

Update the cdef to const byte* / byte to match the header on both
functions. Add a guard in Ed448Public.verify and Ed448Private.sign so
callers passing a ctx longer than 255 bytes get a clear ValueError
rather than relying on CFFI's narrowing behavior.

ML-DSA's wc_dilithium_sign_ctx_msg / wc_dilithium_verify_ctx_msg cdefs
were also reviewed and already match the wolfSSL header.

F-3086
2026-05-11 12:27:23 +01:00
Andrew Hutchings 09770093bd Fix const on `wc_RsaPSS_Verify` 2026-05-11 12:12:36 +01:00
David Garske 23e9a7c52b
Merge pull request #117 from roberthdevries/simplify-feature-enable-variable-string
Simplify generating feature enabled variables using an f-string.
2026-05-05 11:20:13 -07:00
David Garske d34abdb012
Merge pull request #116 from roberthdevries/fix-bare-except-build-ffi
Use specific exception instead of bare except in build_ffi.py
2026-05-05 11:19:57 -07:00
David Garske 87fbbe5b9f
Merge pull request #111 from roberthdevries/use-modern-f-strings
Use modern f-strings replacing str.format().
2026-05-05 11:16:40 -07:00
Robert de Vries 1723007785 Simplify generating feature enabled variables using an f-string. 2026-04-27 17:14:52 +02:00
Robert de Vries 0f61f5f771 Use specific exception instead of bare except in build_ffi.py
A bare except catches BaseException which includes KeyboardInterrupt,
SystemExit, Exception, and others.
Catching BaseException can make it hard to interrupt the program (e.g., with
Ctrl-C) and can disguise other problems.
2026-04-27 16:54:52 +02:00
Robert de Vries a60f8223fe Use modern f-strings replacing str.format().
f-strings have been introduced in Python 3.6.
2026-04-24 22:14:25 +02:00
Robert de Vries a114bca77b Add missing definition ML_DSA_KEYGEN_SEED_LENGTH. 2026-04-17 23:19:13 +02:00
Robert de Vries 6e248338b9 Remove duplicate definitions of ERROR_STRINGS/ERROR_STRINGS_ENABLED. 2026-04-17 20:43:08 +02:00
David Garske 2dd22e3500
Merge pull request #103 from roberthdevries/add-support-for-wcGetErrorString
Add support for wcGetErrorString() including error codes.
2026-04-17 09:37:15 -07:00
Jeremiah Mackey 664e887f09 Fix hash copy semantics and add tests 2026-04-16 14:34:26 +00:00
Jeremiah Mackey 88bd75957d Add tests and fix build issues 2026-04-16 14:34:26 +00:00
Jeremiah Mackey cbdc388cc4 Fix low severity static analysis issues 2026-04-16 14:34:26 +00:00
Jeremiah Mackey c65ceaabd0 Fix resource leaks 2026-04-16 14:33:55 +00:00
David Garske 1ec10b3c0d
Merge pull request #102 from roberthdevries/fix-various-minor-issues-caught-by-ruff
Fix various minor issues caught by `ruff check` in default mode.
2026-04-15 15:00:53 -07:00
David Garske 0297859652
Merge pull request #90 from mjdemilliano/ml-dsa-sign-with-context
ML-DSA: Add optional context to signing and verification
2026-04-15 14:59:20 -07:00
Daniele Lacamera 90f21e1d13
Merge branch 'master' into ml-dsa-generate-from-seed 2026-04-15 06:56:56 +02:00
Daniele Lacamera 9ebe2fe266
Merge branch 'master' into ml-dsa-sign-with-context 2026-04-15 06:51:11 +02:00
Martijn de Milliano e36859cb9c ML-DSA: Support deterministic signing 2026-04-15 06:48:36 +02:00
Robert de Vries 4813648e74 Add support for wcGetErrorString() including error codes.
It was already used, but not compiled in.
A unit test is added.

As wcGetErrorString() always returns a string the error handling
in class _Hmac  has been removed.
2026-04-12 22:10:36 +02:00
Robert de Vries da0eb45df7 Fix various minor issues caught by `ruff check` in default mode.
Fixing these minor issues helps in adding more checks to fix-up
the code without being bothered by these issues.

Two minor issues are fixed:
- Mark unused variables with a leading underscore
- Use idiomatic boolean expressions
2026-04-11 18:38:09 +02:00
David Garske 6fbdf3d6d7
Merge pull request #99 from roberthdevries/fix-missing-format-argument
Fix missing format argument in exception message.
2026-04-10 10:06:24 -07:00
Robert de Vries 9fe81ec773 Fix missing format argument in exception message. 2026-04-09 20:26:42 +02:00
Robert de Vries 2f630a4353 Clean up import statements.
* Remove unused imports.
* Move import statements together at the top of the file.
2026-04-09 20:02:01 +02:00
Robert de Vries 01fcd2af6c Add support for nonce in random number generation. 2026-04-05 23:10:29 +02:00
Martijn de Milliano 1c034b20d8 ML-DSA: Support (re-)generating MlDsaPrivate from seed
As specified in FIPS 204, implementations can store the seed from
which the key can be deterministically generated.
2026-03-24 22:08:57 +01:00
Martijn de Milliano 9a10f58601 ML-DSA: Add optional context to signing and verification 2026-03-24 21:32:17 +01:00
JeremiahM37 3ca2548ec5 Move wc_RsaSSL_Sign/Verify declarations out of RSA_PSS block 2026-03-18 18:27:11 +00:00
JeremiahM37 48fe5aefe0 Fix re.search on list instead of string in FIPS version detection 2026-03-18 18:27:11 +00:00
JeremiahM37 6892321faf Fix CHACHA20_POLY1305 feature check ignoring HAVE_CHACHA 2026-03-18 18:27:11 +00:00