Skip to content

Fix Signature.suf_cma and report NULL from OQS_KEM_new/OQS_SIG_new - #166

Open
dstebila wants to merge 1 commit into
mainfrom
fix-constructor-followups
Open

dstebila wants to merge 1 commit into
mainfrom
fix-constructor-followups

Conversation

@dstebila

@dstebila dstebila commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #165. Stacked on #165: until that merges, this diff also shows its commit. I'll rebase onto main once #165 is in.

Changes

  • Signature.suf_cma was always False. Signature.__init__ copied euf_cma and the other fields from the native OQS_SIG struct but never copied suf_cma, so Signature.suf_cma and details["is_suf_cma"] read the wrapper's own zero-initialised ctypes field. For example, ML-DSA reported False.
  • NULL from OQS_KEM_new / OQS_SIG_new now raises RuntimeError. Previously the first .contents access raised ValueError: NULL pointer access, which callers could mistake for the ValueError raised for a wrong-length key. The new message names the algorithm and matches what StatefulSignature.__init__ already does.
  • secret_key type annotation narrowed to Optional[bytes] on both constructors. It advertised int, but an int always raised TypeError in the length check.

Tests

  • test_sig.test_suf_cma_matches_native: for every enabled signature, suf_cma and details["is_suf_cma"] match the native struct.
  • test_kem / test_sig test_new_returning_null_raises_runtime_error: patches OQS_*_new to return NULL and expects a RuntimeError naming the algorithm.

Tested locally on macOS (Python 3.12) against liboqs 0.17.0-rc1, built with the same options as the automatic install:

🤖 Generated with Claude Code

@dstebila
dstebila force-pushed the fix-constructor-followups branch 2 times, most recently from 938902b to 1dedfc9 Compare December 5, 2026 16:32
- Signature.__init__ never copied suf_cma from the native struct, so
  Signature.suf_cma and details["is_suf_cma"] were always False.
- KeyEncapsulation and Signature now raise RuntimeError naming the
  algorithm when OQS_KEM_new/OQS_SIG_new returns NULL, matching
  StatefulSignature, instead of a ValueError from the NULL dereference
  that callers could mistake for an invalid key length.
- Narrow the secret_key annotation on both constructors to
  Optional[bytes]; an int was advertised but always raised TypeError.

Follow-up to #165.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Douglas Stebila <dstebila@uwaterloo.ca>
@dstebila
dstebila force-pushed the fix-constructor-followups branch from 1dedfc9 to 2969455 Compare December 5, 2026 17:02

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant