Skip to content

Commit e502cc8

Browse files
Andy Polyakovmattcaswell
Andy Polyakov
authored andcommitted
bn/asm/rsaz-avx2.pl: fix digit correction bug in rsaz_1024_mul_avx2.
Credit to OSS-Fuzz for finding this. CVE-2017-3738 Reviewed-by: Rich Salz <rsalz@openssl.org>
1 parent 6fca9fe commit e502cc8

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Diff for: crypto/bn/asm/rsaz-avx2.pl

+7-8
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
vmovdqu 32*8-128($ap), $ACC8
247247
248248
lea 192(%rsp), $tp0 # 64+128=192
249-
vpbroadcastq .Land_mask(%rip), $AND_MASK
249+
vmovdqu .Land_mask(%rip), $AND_MASK
250250
jmp .LOOP_GRANDE_SQR_1024
251251
252252
.align 32
@@ -1077,10 +1077,10 @@
10771077
vpmuludq 32*6-128($np),$Yi,$TEMP1
10781078
vpaddq $TEMP1,$ACC6,$ACC6
10791079
vpmuludq 32*7-128($np),$Yi,$TEMP2
1080-
vpblendd \$3, $ZERO, $ACC9, $ACC9 # correct $ACC3
1080+
vpblendd \$3, $ZERO, $ACC9, $TEMP1 # correct $ACC3
10811081
vpaddq $TEMP2,$ACC7,$ACC7
10821082
vpmuludq 32*8-128($np),$Yi,$TEMP0
1083-
vpaddq $ACC9, $ACC3, $ACC3 # correct $ACC3
1083+
vpaddq $TEMP1, $ACC3, $ACC3 # correct $ACC3
10841084
vpaddq $TEMP0,$ACC8,$ACC8
10851085
10861086
mov %rbx, %rax
@@ -1093,7 +1093,9 @@
10931093
vmovdqu -8+32*2-128($ap),$TEMP2
10941094
10951095
mov $r1, %rax
1096+
vpblendd \$0xfc, $ZERO, $ACC9, $ACC9 # correct $ACC3
10961097
imull $n0, %eax
1098+
vpaddq $ACC9,$ACC4,$ACC4 # correct $ACC3
10971099
and \$0x1fffffff, %eax
10981100
10991101
imulq 16-128($ap),%rbx
@@ -1329,15 +1331,12 @@
13291331
# But as we underutilize resources, it's possible to correct in
13301332
# each iteration with marginal performance loss. But then, as
13311333
# we do it in each iteration, we can correct less digits, and
1332-
# avoid performance penalties completely. Also note that we
1333-
# correct only three digits out of four. This works because
1334-
# most significant digit is subjected to less additions.
1334+
# avoid performance penalties completely.
13351335

13361336
$TEMP0 = $ACC9;
13371337
$TEMP3 = $Bi;
13381338
$TEMP4 = $Yi;
13391339
$code.=<<___;
1340-
vpermq \$0, $AND_MASK, $AND_MASK
13411340
vpaddq (%rsp), $TEMP1, $ACC0
13421341
13431342
vpsrlq \$29, $ACC0, $TEMP1
@@ -1770,7 +1769,7 @@
17701769
17711770
.align 64
17721771
.Land_mask:
1773-
.quad 0x1fffffff,0x1fffffff,0x1fffffff,-1
1772+
.quad 0x1fffffff,0x1fffffff,0x1fffffff,0x1fffffff
17741773
.Lscatter_permd:
17751774
.long 0,2,4,6,7,7,7,7
17761775
.Lgather_permd:

0 commit comments

Comments
 (0)