Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audit: rsapss - add missing check #331

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions circuits/circuits/utils/crypto/signature/rsapss/rsapss3.circom
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ template VerifyRsaPss3Sig(CHUNK_SIZE, CHUNK_NUMBER, SALT_LEN, HASH_TYPE, KEY_LEN
db[i] <== xor.out[i];
}
}

//Step -10 of https://datatracker.ietf.org/doc/html/rfc8017#section-9.1.2
component db2Num[DB_MASK_LEN];
for (var i = 0; i < DB_MASK_LEN; i++) {
db2Num[i] = Bits2Num(8);
for (var j = 0; j < 8; j++) {
db2Num[i].in[7 - j] <== db[i*8 + j];
}
}
// Check leading zeros
for (var i = 0; i < DB_MASK_LEN - SALT_LEN - 1; i++) {
db2Num[i].out === 0;
}
// Check 0x01 byte
db2Num[DB_MASK_LEN - SALT_LEN - 1].out === 1;

//inserting salt
for (var i = 0; i < SALT_LEN_BITS; i++) {
Expand Down
15 changes: 15 additions & 0 deletions circuits/circuits/utils/crypto/signature/rsapss/rsapss65537.circom
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ template VerifyRsaPss65537Sig(CHUNK_SIZE, CHUNK_NUMBER, SALT_LEN, HASH_TYPE, KEY
db[i] <== xor.out[i];
}
}

//Step -10 of https://datatracker.ietf.org/doc/html/rfc8017#section-9.1.2
component db2Num[DB_MASK_LEN];
for (var i = 0; i < DB_MASK_LEN; i++) {
db2Num[i] = Bits2Num(8);
for (var j = 0; j < 8; j++) {
db2Num[i].in[7 - j] <== db[i*8 + j];
}
}
// Check leading zeros
for (var i = 0; i < DB_MASK_LEN - SALT_LEN - 1; i++) {
db2Num[i].out === 0;
}
// Check 0x01 byte
db2Num[DB_MASK_LEN - SALT_LEN - 1].out === 1;

//inserting salt
for (var i = 0; i < SALT_LEN_BITS; i++) {
Expand Down