Skip to content

Commit 0cc45e7

Browse files
rolandshoemakercagedmantis
authored andcommitted
[release-branch.go1.22] 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 #71422 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> (cherry picked from commit 6fc23a3) Reviewed-on: https://go-review.googlesource.com/c/go/+/645535 Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Bypass: Carlos Amedee <carlos@golang.org>
1 parent c3c6a50 commit 0cc45e7

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

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

126126
#define CAR1 V6
127+
128+
#define SEL V8
129+
#define ZER V9
130+
127131
// func p256NegCond(val *p256Point, cond int)
128132
TEXT ·p256NegCond(SB), NOSPLIT, $0-16
129133
MOVD val+0(FP), P1ptr
130134
MOVD $16, R16
131135

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

136145
MOVD $p256mul<>+0x00(SB), CPOOL
137146

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

160+
VSEL T1H, Y1H, SEL, T1H
161+
VSEL T1L, Y1L, SEL, T1L
162+
151163
XXPERMDI T1H, T1H, $2, T1H
152164
XXPERMDI T1L, T1L, $2, T1L
153165

@@ -164,6 +176,8 @@ TEXT ·p256NegCond(SB), NOSPLIT, $0-16
164176
#undef PL
165177
#undef PH
166178
#undef CAR1
179+
#undef SEL
180+
#undef ZER
167181

168182
#define P3ptr R3
169183
#define P1ptr R4

0 commit comments

Comments
 (0)