Skip to content

Commit

Permalink
[crypto] Check for zero in P256 modular inverse.
Browse files Browse the repository at this point in the history
A zero input (such as a point-at-infinity in the conversion to affine
coordinates) can cause the GCD algorithm to not terminate.

Signed-off-by: Jade Philipoom <[email protected]>
  • Loading branch information
jadephilipoom authored and moidx committed Mar 1, 2024
1 parent da87fc1 commit 9aa8309
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sw/otbn/crypto/p256_verify.s
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ p256_verify:
* show a data dependent timing and execution profile. Only use in situations
* where a full white-box environment is acceptable.
*
* The `a` parameter must be nonzero. If it is zero, the code will jump to
* `p256_invalid_input`.
*
* Flags: Flags have no meaning beyond the scope of this subroutine.
*
* @param[in] w0: a, operand
Expand All @@ -289,6 +292,11 @@ p256_verify:
* clobbered flag groups: FG0
*/
mod_inv_var:
/* Check if the input is zero. */
bn.cmp w0, w31
csrrs x2, FG0, x0
andi x2, x2, 8
bne x2, x0, p256_invalid_input

/* w2 = r = 0 */
bn.mov w2, w31
Expand Down

0 comments on commit 9aa8309

Please sign in to comment.