Skip to content

[crypto] Harden RSA key import CRT checks with random mask #226

Draft
mkannwischer wants to merge 2 commits intomasterfrom
mjk/rsa-check-key-hardening
Draft

[crypto] Harden RSA key import CRT checks with random mask #226
mkannwischer wants to merge 2 commits intomasterfrom
mjk/rsa-check-key-hardening

Conversation

@mkannwischer
Copy link
Copy Markdown
Contributor

As proposed in #170, this PR
multiplies a nonzero random mask into the d_p, d_q, and i_q
validity checks. Instead of computing e * d_p mod (p-1) and
comparing to 1, we now computes r * e * d_p mod (p-1) and
the C side compares against r.

This avoids the multi-limb value 1 as an intermediate or
comparison target, hardening the check against fault injection.

I have also added additional negative tests that test these failures cases for invalid d_q and i_q.

Multiply a nonzero random mask into the d_p, d_q, and i_q
validity checks. Instead of computing e * d_p mod (p-1) and
comparing to 1, we now computes r * e * d_p mod (p-1) and
the C side compares against r.

This avoids the multi-limb value 1 as an intermediate or
comparison target, hardening the check against fault injection.

Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
The existing tests only checked rejection of an invalid d_p.
Add test cases for invalid d_q and i_q as well, each constructed
by flipping an arbitrary single bit in the valid test vector.

Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
Comment on lines +225 to +227
bn.wsrr w20, URND
bn.rshi w20, w31, w20 >> 1
bn.addi w20, w20, 1
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is a 256-bit (or rather-255 bit) random mask sufficient here, or do we need a full-width masks?
If we need a full width masks, then we would need different masks mod p, mod q, and mod p-1.

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.

[crypto] Harden RSA private key import check values from OTBN

1 participant