Skip to content

Fix StatefulSignature.export_secret_key TypeErrors on Windows#141

Merged
dstebila merged 1 commit into
mainfrom
fix-136-stfl-export-secret-key
May 14, 2026
Merged

Fix StatefulSignature.export_secret_key TypeErrors on Windows#141
dstebila merged 1 commit into
mainfrom
fix-136-stfl-export-secret-key

Conversation

@dstebila
Copy link
Copy Markdown
Member

Two failures reported in #136, both in export_secret_key:

  1. On Python 3.14 32-bit: ct.util.find_library("c") returns None on Windows, so CDLL(None) raises TypeError. Even on Unix where it worked, liboqs's malloc and libc's free can come from different CRT heaps on Windows. Use liboqs's own OQS_MEM_secure_free instead — ABI-compatible by construction, and also zeroizes the secret-key bytes before freeing.

  2. On Python 3.14 64-bit: OQS_SIG_STFL_SECRET_KEY_serialize fails with "OverflowError: int too long to convert" on argument 3 (the secret-key handle). Cause: restype c_void_p auto-unwraps the returned pointer to a Python int, and on Windows Python 3.14 the int -> c_void_p arg conversion path chokes on high-bit-set addresses. Use a c_void_p subclass as the restype so ctypes keeps the pointer as an object; subsequent calls take the same-type fast path and skip int conversion entirely.

Closes #136.

Two failures reported in #136, both in export_secret_key:

1. On Python 3.14 32-bit: ct.util.find_library("c") returns None on
   Windows, so CDLL(None) raises TypeError. Even on Unix where it
   worked, liboqs's malloc and libc's free can come from different
   CRT heaps on Windows. Use liboqs's own OQS_MEM_secure_free
   instead — ABI-compatible by construction, and also zeroizes the
   secret-key bytes before freeing.

2. On Python 3.14 64-bit: OQS_SIG_STFL_SECRET_KEY_serialize fails
   with "OverflowError: int too long to convert" on argument 3 (the
   secret-key handle). Cause: restype c_void_p auto-unwraps the
   returned pointer to a Python int, and on Windows Python 3.14 the
   int -> c_void_p arg conversion path chokes on high-bit-set
   addresses. Use a c_void_p subclass as the restype so ctypes keeps
   the pointer as an object; subsequent calls take the same-type
   fast path and skip int conversion entirely.

Closes #136.

Signed-off-by: Douglas Stebila <dstebila@uwaterloo.ca>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dstebila dstebila self-assigned this May 14, 2026
@dstebila dstebila added the bug Something isn't working label May 14, 2026
@dstebila dstebila added this to the 0.16.0 milestone May 14, 2026
@dstebila dstebila merged commit f956587 into main May 14, 2026
8 checks passed
@dstebila dstebila deleted the fix-136-stfl-export-secret-key branch May 14, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

export_secret_key from StatefulSignature: TypeError: LoadLibrary() argument 1 must be str, not None

1 participant