Skip to content

Harden length validation for compressed det1024 signatures#16

Open
nullun wants to merge 3 commits into
algorand:mainfrom
nullun:chore/deterministic-length-validation
Open

Harden length validation for compressed det1024 signatures#16
nullun wants to merge 3 commits into
algorand:mainfrom
nullun:chore/deterministic-length-validation

Conversation

@nullun

@nullun nullun commented Jun 17, 2026

Copy link
Copy Markdown

Summary

Tightens length/bounds handling on the compressed det1024 signature paths so malformed or oversized inputs are rejected cleanly.

Changes

  • convert_compressed_to_ct: reject inputs shorter than the 2-byte header + salt-version prefix, and reject trailing bytes after the decoded signature, matching the exact-consumption check falcon_verify already applies.
  • verify_compressed: perform the max-size check as sig_len - 1 > MAXSIZE - 40 before computing salted_sig_len, avoiding a potential size_t overflow in sig_len + 40 - 1 for very large sig_len.
  • CompressedSignature.ConvertToCT (Go): guard against signatures shorter than 2 bytes before taking &(*sig)[0], preventing a panic on empty input (mirrors the existing guard in Verify).
  • Tests: add TestFalconMalformedSignatures, exercising different malformed signatures against both Verify and ConvertToCT.
  • Make sigs_ct static in test_deterministic.c to silence a macOS linker alignment warning.

Testing

  • go test ./... — pass
  • make tests/test_deterministic && ./tests/test_deterministic — all KATs pass, clean build

nullun added 2 commits June 17, 2026 09:17
Add a couple of small length checks when working with compressed
det1024 signatures, and tidy up the ordering of the bounds check in
falcon_det1024_verify_compressed. Mirrors the existing checks on both
the C and Go sides.

falcon_det1024_convert_compressed_to_ct only checked that comp_decode
succeeded, not that it consumed the entire signature, so a valid
compressed signature with arbitrary trailing bytes would still convert
to a valid CT signature. Enforce exact consumption, matching the check
falcon_verify applies to compressed signatures.

Add tests covering the rejection paths for signatures too short to
contain a header and salt version, and for signatures with trailing
bytes, in both Verify and ConvertToCT.
The ~769 KiB sigs_ct array was a non-static tentative definition, so
clang emitted it as a common symbol and ld64 requested 32 KiB alignment
for it, exceeding the 16 KiB segment maximum on arm64 macOS:

  ld: warning: reducing alignment of section __DATA,__common from
  0x8000 to 0x4000 because it exceeds segment maximum alignment

The array is only used in this file, so make it static, which places it
in __bss with ordinary alignment and avoids the warning.
@nullun nullun requested review from cce and jannotti June 17, 2026 08:32
Comment thread deterministic.c
Comment thread deterministic.c Outdated
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.

2 participants