.. | .. |
---|
50 | 50 | # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL |
---|
51 | 51 | # project. The module is, however, dual licensed under OpenSSL and |
---|
52 | 52 | # CRYPTOGAMS licenses depending on where you obtain it. For further |
---|
53 | | -# details see http://www.openssl.org/~appro/cryptogams/. |
---|
| 53 | +# details see https://www.openssl.org/~appro/cryptogams/. |
---|
54 | 54 | # ==================================================================== |
---|
55 | 55 | # |
---|
56 | 56 | # This module implements support for AES instructions as per PowerISA |
---|
.. | .. |
---|
1286 | 1286 | |
---|
1287 | 1287 | ######################################################################### |
---|
1288 | 1288 | {{{ # 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 | +######################################################################### |
---|
1289 | 1307 | my ($inp,$out,$len,$key,$ivp,$x10,$rounds,$idx)=map("r$_",(3..10)); |
---|
1290 | 1308 | my ($rndkey0,$rndkey1,$inout,$tmp)= map("v$_",(0..3)); |
---|
1291 | 1309 | my ($ivec,$inptail,$inpperm,$outhead,$outperm,$outmask,$keyperm,$one)= |
---|
.. | .. |
---|
1357 | 1375 | addi $idx,$idx,16 |
---|
1358 | 1376 | bdnz Loop_ctr32_enc |
---|
1359 | 1377 | |
---|
1360 | | - vadduqm $ivec,$ivec,$one |
---|
| 1378 | + vadduqm $ivec,$ivec,$one # Kernel change for 128-bit |
---|
1361 | 1379 | vmr $dat,$inptail |
---|
1362 | 1380 | lvx $inptail,0,$inp |
---|
1363 | 1381 | addi $inp,$inp,16 |
---|
.. | .. |
---|
1501 | 1519 | $SHL $len,$len,4 |
---|
1502 | 1520 | |
---|
1503 | 1521 | vadduqm $out1,$ivec,$one # counter values ... |
---|
1504 | | - vadduqm $out2,$ivec,$two |
---|
| 1522 | + vadduqm $out2,$ivec,$two # (do all ctr adds as 128-bit) |
---|
1505 | 1523 | vxor $out0,$ivec,$rndkey0 # ... xored with rndkey[0] |
---|
1506 | 1524 | le?li $idx,8 |
---|
1507 | 1525 | vadduqm $out3,$out1,$two |
---|