Commit Graph

57 Commits (3c911eeb2995fb0837f852714c935a926d5e3c19)

Author SHA1 Message Date
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
sebastian-carpenter 9172130c8e fixed 'small' ecc signatures so they do not have trailing 0x00 padding bytes 2026-03-06 14:26:44 -07:00
lealem47 427a1a33ce
Merge pull request #78 from mjdemilliano/move-rsa-only-cdefs
Move some cdef declarations for RSA to separate section
2025-12-11 11:06:25 -07:00
Martijn de Milliano f9f73550bd Make wc_PemToDer|wc_DerToPemEx depend only on ASN not KEYGEN
These functions are actually not tied to the KEYGEN feature.
2025-12-08 23:07:12 +01:00
Martijn de Milliano 4f37e78d2b Include wc_GetPkcs8TraditionalOffset also when RSA feature is selected
It's part of the ASN feature but since it's also used by the RSA
binding this function must also be part of the library when only
the RSA feature is selected.
2025-12-08 22:30:48 +01:00
Martijn de Milliano 6b241ca696 Move some cdef declarations for RSA to separate section
The definitions for the following functions are not always available
when wolfSSL is configured to only contain a minimum of functionality:
- wc_GetPkcs8TraditionalOffset (only with ASN, which is required for
      RSA)
- wc_PemToDer (only when KEYGEN is enabled)
- wc_DerToPemEx (only when KEYGEN is enabled)

This change allows for building the Python wrapper when ASN and RSA
are both disabled.
2025-11-24 12:32:59 +01:00
Martijn de Milliano e62464362b build_ffi.py: Fix header parsing of feature detection logic
`defines` was a string instead of a list of strings. This made it
impossible to build a wrapper with a configuration in which AES-CBC
is disabled, because `'#define NO_AES' in defines` matched also
when the header contains `#define NO_AES_CBC`. With `defines` being
a list the code actually does what you think it does.
2025-11-24 12:02:33 +01:00
lealem47 e9ebda0619
Merge pull request #73 from mjdemilliano/hdkf
Add HKDF support
2025-11-19 13:37:49 -07:00
Martijn de Milliano 523b36bf97 Add support for multiple associated data blocks 2025-11-12 14:39:48 +01:00
Martijn de Milliano 56e7814c6e Add AES-SIV support (single block only) 2025-11-12 14:39:05 +01:00
Martijn de Milliano d7041ea176 Add HKDF support 2025-11-12 11:37:18 +01:00
Lealem Amedie 5c7e1ee15f Detect availability of ML-KEM for USE_LOCAL_WOLFSSL 2025-11-06 13:28:21 -07:00
Lealem Amedie c6dd1eaf21 Prepare for v5.8.2 release 2025-07-24 12:31:54 -06:00
Koji Takeda 24993ad370 Use HAVE_DILITHIUM flag to judge ML-DSA enablement 2025-03-07 08:03:32 +09:00
Koji Takeda c59e5910d1 Fix details by hand 2025-03-03 16:14:07 +09:00
Devin AI b501989317 Support ML-DSA
Co-Authored-By: Koji Takeda <takeda@wolfssl.com>
2025-03-03 16:11:37 +09:00