Skip to content

Commit 6d41f4b

Browse files
h-filalivogelpi
authored andcommitted
[sw,cryptolib] p384 move flag clear in keygen
To follow the OTBN styleguide I added an instruction to clear the flags after a subtraction. The flags however are still needed in the subsequent instructions for the bn.sel. I moved the clear sub instruction down to clear all 4 flags. Signed-off-by: Hakim Filali <[email protected]>
1 parent b776b4f commit 6d41f4b

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

sw/device/lib/crypto/impl/ecc/p384.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ enum {
9393
* The expected instruction counts for constant time functions.
9494
*/
9595
kModeKeygenInsCnt = 1899012,
96-
kModeKeygenSideloadInsCnt = 1898906,
96+
kModeKeygenSideloadInsCnt = 1898905,
9797
kModeEcdhInsCnt = 1910611,
98-
kModeEcdhSideloadInsCnt = 1910760,
98+
kModeEcdhSideloadInsCnt = 1910759,
9999
kModeEcdsaSignInsCnt = 1546541,
100-
kModeEcdsaSignSideloadInsCnt = 1546690,
100+
kModeEcdsaSignSideloadInsCnt = 1546689,
101101
};
102102

103103
static status_t p384_masked_scalar_write(p384_masked_scalar_t *src,

sw/otbn/crypto/p384_keygen_from_seed.s

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ p384_key_from_seed:
9898
bn.sub w24, w10, w16
9999
bn.subb w25, w11, w17
100100

101-
/* Clear flags. */
102-
bn.sub w31, w31, w31
103-
104101
/* Compute d1. Because 2^384 < 2 * n, a conditional subtraction is
105102
sufficient to reduce. Similarly to the carry bit, the conditional bit here
106103
is not very sensitive because the shares are large relative to n.
@@ -111,8 +108,9 @@ p384_key_from_seed:
111108
/* Clear w25 before over writing it with a different share. */
112109
bn.xor w25, w25, w25
113110

114-
/* Dummy instruction to avoid consecutive share access. */
115-
bn.xor w31, w31, w31
111+
/* Dummy instruction to avoid consecutive share access.
112+
Clear all flags. */
113+
bn.sub w31, w31, w31
116114

117115
/* Isolate the carry bit and shift it back into position.
118116
w25 <= x0[384] << 128 */

0 commit comments

Comments
 (0)