-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[crypto] Check for multiples of 7, 11, and 31 in RSA keygen.
All of these small primes have the nice property that 2^32 mod p = 4. Signed-off-by: Jade Philipoom <[email protected]>
- Loading branch information
1 parent
1ba1b59
commit 4599b4d
Showing
12 changed files
with
596 additions
and
161 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
2 changes: 2 additions & 0 deletions
2
sw/otbn/crypto/tests/relprime_small_primes_multiple_of_11_test.exp
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Expect 0 (check failed). | ||
w22 = 0 |
68 changes: 68 additions & 0 deletions
68
sw/otbn/crypto/tests/relprime_small_primes_multiple_of_11_test.s
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* Copyright lowRISC contributors (OpenTitan project). */ | ||
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
/** | ||
* Standalone test to check an RSA keygen subroutine. | ||
* | ||
* The `relprime_small_primes` subroutine checks if a candidate prime is a | ||
* multiple of a small prime. This test ensures that the check detects a | ||
* multiple of 11. | ||
*/ | ||
|
||
.section .text.start | ||
|
||
main: | ||
/* Init all-zero register. */ | ||
bn.xor w31, w31, w31 | ||
|
||
/* Load the number of limbs for this test. */ | ||
li x30, 4 | ||
|
||
/* w22 <= 0 if dmem[simple_positive_input] is NOT relatively prime to F4 */ | ||
la x16, input | ||
jal x1, relprime_small_primes | ||
|
||
ecall | ||
|
||
.data | ||
|
||
/** | ||
* A 1024-bit value that is a multiple of 11 and NOT 3, 5, 7, 17, or 31. | ||
* | ||
* Full value for reference = | ||
*/ | ||
.balign 32 | ||
input: | ||
.word 0x0a9a411f | ||
.word 0xca52e7f3 | ||
.word 0x2c301918 | ||
.word 0x948c97b0 | ||
.word 0x171f68fc | ||
.word 0xe36be04a | ||
.word 0x0a7ffbaa | ||
.word 0xf9cf072d | ||
.word 0x51b76bd5 | ||
.word 0x19d0fec0 | ||
.word 0x0771be64 | ||
.word 0x49c95131 | ||
.word 0x1ed7cd7a | ||
.word 0xda4a6077 | ||
.word 0x11fa0022 | ||
.word 0x66e409f1 | ||
.word 0x95548bfd | ||
.word 0x7938113a | ||
.word 0x9296d0f5 | ||
.word 0x1352294c | ||
.word 0x33eaf657 | ||
.word 0x6c47a7dc | ||
.word 0xf57e2b6b | ||
.word 0xd1194a3e | ||
.word 0x84402e7e | ||
.word 0x87641b66 | ||
.word 0x2c3c225e | ||
.word 0x5e27e299 | ||
.word 0x5ee52414 | ||
.word 0xab6816c2 | ||
.word 0x0ea3266c | ||
.word 0x5f4b97ff |
This file contains 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
2 changes: 2 additions & 0 deletions
2
sw/otbn/crypto/tests/relprime_small_primes_multiple_of_31_test.exp
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Expect 0 (check failed). | ||
w22 = 0 |
69 changes: 69 additions & 0 deletions
69
sw/otbn/crypto/tests/relprime_small_primes_multiple_of_31_test.s
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* Copyright lowRISC contributors (OpenTitan project). */ | ||
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
/** | ||
* Standalone test to check an RSA keygen subroutine. | ||
* | ||
* The `relprime_small_primes` subroutine checks if a candidate prime is a | ||
* multiple of a small prime. This test ensures that the check detects a | ||
* multiple of 31. | ||
*/ | ||
|
||
.section .text.start | ||
|
||
main: | ||
/* Init all-zero register. */ | ||
bn.xor w31, w31, w31 | ||
|
||
/* Load the number of limbs for this test. */ | ||
li x30, 4 | ||
|
||
/* w22 <= 0 if dmem[simple_positive_input] is NOT relatively prime to F4 */ | ||
la x16, input | ||
jal x1, relprime_small_primes | ||
|
||
ecall | ||
|
||
.data | ||
|
||
/** | ||
* A 1024-bit value that is a multiple of 31 and NOT 3, 5, 7, 11, or 17. | ||
* | ||
* Full value for reference = | ||
* 0xc6b202813cf17e3c55fefc6282020980fa205b3ccfb384f597e2c0749b1d5213c2ebbf45d5f239e911062650cd43d3c008183c6c2cf217ac48af2bcfeac39a280afd60eea8508324e97f40fa78d5d70a5b5fcb80c1e260feaa1f02f54c072a915d48a0d13a162f1e22f40b26c1eb29d4e7a44c48956c2daa5edfd222e7cf7221 | ||
*/ | ||
.balign 32 | ||
input: | ||
.word 0xe7cf7221 | ||
.word 0x5edfd222 | ||
.word 0x956c2daa | ||
.word 0xe7a44c48 | ||
.word 0xc1eb29d4 | ||
.word 0x22f40b26 | ||
.word 0x3a162f1e | ||
.word 0x5d48a0d1 | ||
.word 0x4c072a91 | ||
.word 0xaa1f02f5 | ||
.word 0xc1e260fe | ||
.word 0x5b5fcb80 | ||
.word 0x78d5d70a | ||
.word 0xe97f40fa | ||
.word 0xa8508324 | ||
.word 0x0afd60ee | ||
.word 0xeac39a28 | ||
.word 0x48af2bcf | ||
.word 0x2cf217ac | ||
.word 0x08183c6c | ||
.word 0xcd43d3c0 | ||
.word 0x11062650 | ||
.word 0xd5f239e9 | ||
.word 0xc2ebbf45 | ||
.word 0x9b1d5213 | ||
.word 0x97e2c074 | ||
.word 0xcfb384f5 | ||
.word 0xfa205b3c | ||
.word 0x82020980 | ||
.word 0x55fefc62 | ||
.word 0x3cf17e3c | ||
.word 0xc6b20281 |
This file contains 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
Oops, something went wrong.