4343 * sensitive ; since aborting the program will be quicker than completing it,
4444 * the flag's value is likely clearly visible to an attacker through timing.
4545 *
46- * @param [ in ] w31: all - zero
47- * @param [ in ] FG0.Z: boolean indicating fault condition
46+ * @param [ in ] FG0.Z: boolean indicating fault condition when 1
4847 *
49- * clobbered registers: x2
48+ * clobbered registers: x2 , w31
5049 * clobbered flag groups: none
5150 * /
52- trigger_fault_if_fg0_z :
51+ trigger_fault_if_fg0_not_z :
5352 / * Read the FG0.Z flag (position 3 ).
5453 x2 <= FG0.Z * /
5554 csrrw x2 , FG0 , x0
5655 andi x2 , x2 , 8
57- srli x2 , x2 , 3
56+ addi x2 , x2 , 31
5857
59- / * Subtract FG0.Z from 0 .
60- x2 <= 0 - x2 = FG0.Z ? 2 ^ 32 - 1 : 0 * /
61- sub x2 , x0 , x2
62-
63- / * The `bn.lid` instruction causes an `BAD_DATA_ADDR` error if the
64- memory address is out of bounds. Therefore , if FG0.Z is 1 , this
65- instruction causes an error , but if FG0.Z is 0 it simply loads the word at
66- address 0 into w31. * /
67- li x3 , 31
68- bn.lid x3 , 0 (x2)
58+ / * The `bn.lid` instruction causes an `ILLEGAL_INSN` error if the index of the
59+ bignum register (stored in x2 in this case) is invalid. Therefore , if FG0.Z
60+ is 1 , this instruction causes an error , but if FG0.Z is 0 it simply loads
61+ the word at address 0 into w31. * /
62+ bn.lid x2 , 0 (x0)
6963
7064 / * If we get here , the flag must have been 0 . Restore w31 to zero and return.
7165 w31 <= 0 * /
72- bn. xor w31 , w31 , w31
66+ bn. xor w31 , w31 , w31
7367
7468 ret
7569
@@ -84,29 +78,28 @@ trigger_fault_if_fg0_z:
8478 * sensitive ; since aborting the program will be quicker than completing it,
8579 * the flag's value is likely clearly visible to an attacker through timing.
8680 *
87- * @param [ in ] w31: all - zero
88- * @param [ in ] FG0.Z: boolean indicating fault condition
81+ * @param [ in ] FG0.Z: boolean indicating fault condition when 0
8982 *
90- * clobbered registers: x2
83+ * clobbered registers: x2 , w31
9184 * clobbered flag groups: none
9285 * /
93- trigger_fault_if_fg0_not_z :
86+ trigger_fault_if_fg0_z :
9487 / * Read the FG0.Z flag (position 3 ).
9588 x2 <= FG0.Z * /
9689 csrrw x2 , FG0 , x0
9790 andi x2 , x2 , 8
98- slli x2 , x2 , 3
91+ xori x2 , x2 , 8
92+ addi x2 , x2 , 31
9993
100- / * The `bn.lid` instruction causes an `BAD_DATA_ADDR` error if the
101- memory address is out of bounds. Therefore , if FG0.Z is 1 , this
102- instruction causes an error , but if FG0.Z is 0 it simply loads the word at
103- address 0 into w31. * /
104- li x3 , 31
105- bn.lid x3 , 0 (x2)
94+ / * The `bn.lid` instruction causes an `ILLEGAL_INSN` error if the index of the
95+ bignum register (stored in x2 in this case) is invalid. Therefore , if FG0.Z
96+ is 0 , this instruction causes an error , but if FG0.Z is 1 it simply loads
97+ the word at address 0 into w31. * /
98+ bn.lid x2 , 0 (x0)
10699
107100 / * If we get here , the flag must have been 1 . Restore w31 to zero and return.
108101 w31 <= 0 * /
109- bn. xor w31 , w31 , w31
102+ bn. xor w31 , w31 , w31
110103
111104 ret
112105
@@ -1358,7 +1351,7 @@ scalar_mult_int:
13581351 bn.rshi w2 , w2 , w20 >> 65
13591352
13601353 / * double - and - add loop with decreasing index * /
1361- loopi 321 , 64
1354+ loopi 321 , 63
13621355
13631356 / * double point Q
13641357 Q = (w8 , w9 , w10) <= 2 * (w8 , w9 , w10) = 2 * Q * /
@@ -1517,7 +1510,7 @@ scalar_mult_int:
15171510
15181511 FG0.Z <= if (w10 == 0 ) then 1 else 0 * /
15191512 bn. cmp w10 , w31
1520- jal x0 , trigger_fault_if_fg0_z
1513+ jal x0 , trigger_fault_if_fg0_not_z
15211514
15221515
15231516/ **
@@ -1608,7 +1601,7 @@ p256_base_mult:
16081601 The check fails if both sides are not equal.
16091602 FG0.Z <= (y^ 2 ) mod p == (x^ 2 + ax + b) mod p * /
16101603 bn. cmp w18 , w19
1611- jal x1 , trigger_fault_if_fg0_not_z
1604+ jal x1 , trigger_fault_if_fg0_z
16121605
16131606 ret
16141607
0 commit comments