Skip to content

Commit f651bd9

Browse files
daxtensherbertx
authored andcommitted
crypto: vmx - Document CTR mode counter width quirks
The CTR code comes from OpenSSL, where it does a 32-bit counter. The kernel has a 128-bit counter. This difference has lead to issues. Document it. Signed-off-by: Daniel Axtens <dja@axtens.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 334d37c commit f651bd9

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

drivers/crypto/vmx/aesp8-ppc.pl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,24 @@ ()
12861286

12871287
#########################################################################
12881288
{{{ # CTR procedure[s] #
1289+
1290+
####################### WARNING: Here be dragons! #######################
1291+
#
1292+
# This code is written as 'ctr32', based on a 32-bit counter used
1293+
# upstream. The kernel does *not* use a 32-bit counter. The kernel uses
1294+
# a 128-bit counter.
1295+
#
1296+
# This leads to subtle changes from the upstream code: the counter
1297+
# is incremented with vaddu_q_m rather than vaddu_w_m. This occurs in
1298+
# both the bulk (8 blocks at a time) path, and in the individual block
1299+
# path. Be aware of this when doing updates.
1300+
#
1301+
# See:
1302+
# 1d4aa0b4c181 ("crypto: vmx - Fixing AES-CTR counter bug")
1303+
# 009b30ac7444 ("crypto: vmx - CTR: always increment IV as quadword")
1304+
# https://github.com/openssl/openssl/pull/8942
1305+
#
1306+
#########################################################################
12891307
my ($inp,$out,$len,$key,$ivp,$x10,$rounds,$idx)=map("r$_",(3..10));
12901308
my ($rndkey0,$rndkey1,$inout,$tmp)= map("v$_",(0..3));
12911309
my ($ivec,$inptail,$inpperm,$outhead,$outperm,$outmask,$keyperm,$one)=
@@ -1357,7 +1375,7 @@ ()
13571375
addi $idx,$idx,16
13581376
bdnz Loop_ctr32_enc
13591377
1360-
vadduqm $ivec,$ivec,$one
1378+
vadduqm $ivec,$ivec,$one # Kernel change for 128-bit
13611379
vmr $dat,$inptail
13621380
lvx $inptail,0,$inp
13631381
addi $inp,$inp,16
@@ -1501,7 +1519,7 @@ ()
15011519
$SHL $len,$len,4
15021520
15031521
vadduqm $out1,$ivec,$one # counter values ...
1504-
vadduqm $out2,$ivec,$two
1522+
vadduqm $out2,$ivec,$two # (do all ctr adds as 128-bit)
15051523
vxor $out0,$ivec,$rndkey0 # ... xored with rndkey[0]
15061524
le?li $idx,8
15071525
vadduqm $out3,$out1,$two

0 commit comments

Comments
 (0)