Repository navigation
Conversation
… a known-answer test (#1052) Root cause: i31_from_monty (lib/std/crypto/bigint.w) declared `var one: [u32; 80]` and `var d: [u32; 80]` and i31_montmul wrote d[0..mlen] with mlen = (bitlen + 30) / 31: 100 words for RSA-3072, 133 for RSA-4096, which rsa_pkcs1_sha256_verify admits (n_len up to 512 bytes). Any modulus above 2449 bits wrote past both arrays. The new known-answer test, before the fix: "panic: index out of bounds" in rsa_pkcs1_sha256_verify, with a caller frame already overwritten. I31_MAX_WORDS (140: the header and 133 limbs, with room) sizes every fixed i31 temp, in bigint.w and rsa.w alike. Test: test/behavior/behav_1052_rsa4096_kat.w calls std.crypto.rsa.rsa4096_pkcs1_sha256_kat(): an openssl-generated RSA-4096 PKCS#1 v1.5 SHA-256 signature of "abc" must verify, and the same signature with one bit flipped must not (the self-check shape of std.crypto.gcm.aes128_gcm_kat). RSA verification had no test before.
ehartford
marked this pull request as ready for review
October 25, 2026 23:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause: i31_from_monty (lib/std/crypto/bigint.w) declared
var one: [u32; 80]andvar d: [u32; 80]and i31_montmul wrote d[0..mlen]with mlen = (bitlen + 30) / 31: 100 words for RSA-3072, 133 for RSA-4096,
which rsa_pkcs1_sha256_verify admits (n_len up to 512 bytes). Any modulus
above 2449 bits wrote past both arrays. The new known-answer test, before
the fix: "panic: index out of bounds" in rsa_pkcs1_sha256_verify, with a
caller frame already overwritten.
I31_MAX_WORDS (140: the header and 133 limbs, with room) sizes every fixed
i31 temp, in bigint.w and rsa.w alike.
Test: test/behavior/behav_1052_rsa4096_kat.w calls
std.crypto.rsa.rsa4096_pkcs1_sha256_kat(): an openssl-generated RSA-4096
PKCS#1 v1.5 SHA-256 signature of "abc" must verify, and the same signature
with one bit flipped must not (the self-check shape of
std.crypto.gcm.aes128_gcm_kat). RSA verification had no test before.
Closes #1052