Skip to content

Conversation

nasahlpa
Copy link
Member

Compute the GHASH state twice and compare it. When a mismatch due to a FI attack is detected, trap. The redundant check is only conducted for key.security_level > kOtcryptoKeySecurityLevelLow.

@nasahlpa nasahlpa added the CherryPick:earlgrey_1.0.0 This PR should be cherry-picked to earlgrey_1.0.0 label Oct 15, 2025
Copy link
Contributor

@johannheyszl johannheyszl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nasahlpa I think this is very useful.

The hardening has low code size. There is a stack size consumption penalty but I think avoiding this would add significant code size. the hardening is optional at runtime through setting the key level also.

Compute the GHASH state twice and compare it. When a mismatch due to
a FI attack is detected, trap. The redundant check is only conducted
for key.security_level > kOtcryptoKeySecurityLevelLow.

Signed-off-by: Pascal Nasahl <[email protected]>
@nasahlpa nasahlpa force-pushed the aes_gcm_fi_hardening branch from cd8dd8d to 906a284 Compare October 15, 2025 18:01
// Compare the GHASH state. Do this only at a single share to avoid
// introducing SCA leakage.
HARDENED_CHECK_EQ(
memcmp(&ctx->state0.data, ctx_redundant.state0.data, kGhashBlockNumBytes),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is memcmp constant time? If it is not, then it might still introduce some DFA possibility

Copy link
Contributor

@johannheyszl johannheyszl Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be constant time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check, we are sure not to use hardened_memeq instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memcmp not constant time IIUC, hardened_memeq cannot be used due to non-word alignment of struct

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the offline discussion. We should switch here to the new constant time memeq function introduced in this PR #28501.

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

Labels

CherryPick:earlgrey_1.0.0 This PR should be cherry-picked to earlgrey_1.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants