Skip to content

Commit 6fc23a3

Browse files
crypto/internal/fips140/nistec: make p256NegCond constant time on ppc64le
Remove the branching instruction from p256NegCond which made it variable time. The technique used matches that used in p256MovCond. Fixes #71383 Fixes CVE-2025-22866 Change-Id: Ibc2a46814d856cbbdaf6cc0c5a415ed5d42ca793 Reviewed-on: https://go-review.googlesource.com/c/go/+/643735 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Paul Murphy <murp@ibm.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 70b603f commit 6fc23a3

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

‎src/crypto/internal/fips140/nistec/p256_asm_ppc64le.s

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,23 @@ GLOBL p256mul<>(SB), 8, $160
126126
#define PH V31
127127

128128
#define CAR1 V6
129+
130+
#define SEL V8
131+
#define ZER V9
132+
129133
// func p256NegCond(val *p256Point, cond int)
130134
TEXT ·p256NegCond(SB), NOSPLIT, $0-16
131135
MOVD val+0(FP), P1ptr
132136
MOVD $16, R16
133137

134-
MOVD cond+8(FP), R6
135-
CMP $0, R6
136-
BC 12, 2, LR // just return if cond == 0
138+
// Copy cond into SEL (cond is R1 + 8 (cond offset) + 32)
139+
MOVD $40, R17
140+
LXVDSX (R1)(R17), SEL
141+
// Zeroize ZER
142+
VSPLTISB $0, ZER
143+
// SEL controls whether to return the original value (Y1H/Y1L)
144+
// or the negated value (T1H/T1L).
145+
VCMPEQUD SEL, ZER, SEL
137146

138147
MOVD $p256mul<>+0x00(SB), CPOOL
139148

@@ -150,6 +159,9 @@ TEXT ·p256NegCond(SB), NOSPLIT, $0-16
150159
VSUBUQM PL, Y1L, T1L // subtract part2 giving result
151160
VSUBEUQM PH, Y1H, CAR1, T1H // subtract part1 using carry from part2
152161

162+
VSEL T1H, Y1H, SEL, T1H
163+
VSEL T1L, Y1L, SEL, T1L
164+
153165
XXPERMDI T1H, T1H, $2, T1H
154166
XXPERMDI T1L, T1L, $2, T1L
155167

@@ -166,6 +178,8 @@ TEXT ·p256NegCond(SB), NOSPLIT, $0-16
166178
#undef PL
167179
#undef PH
168180
#undef CAR1
181+
#undef SEL
182+
#undef ZER
169183

170184
#define P3ptr R3
171185
#define P1ptr R4

0 commit comments

Comments
 (0)