Commit bcf68dd
committed
aes_gcm/x86_64: Tweak
Instead of starting with the body of the original
`gcm_ghash_vpclmulqdq_avx2` and removing the multi-block support, start with
`gcm_gmult_vpclmulqdq_avx2` and add the XOR of `aad`.
The instruction scheduling seems a bit better. Also, this computes
`bswap(Xi ^ aad)` instead of `bswap(Xi) ^ bswap(aad)`, saving one pshufb.
Rename the function to `gcm_ghash_vpclmulqdq_avx2_16` to better reflect its
constraint on `aad_len_16`.
This is the diff between this function and BoringSSL's
`gcm_gmult_vpclmulqdq_avx2`, as of
14d05a3.
```diff
--- a/crypto/fipsmodule/aes/asm/aes-gcm-avx2-x86_64.pl
+++ b/crypto/fipsmodule/aes/asm/aes-gcm-avx2-x86_64.pl
@@ -436,10 +436,17 @@ sub _ghash_4x {
return $code;
}
-# void gcm_gmult_vpclmulqdq_avx2(uint8_t Xi[16], const u128 Htable[16]);
-$code .= _begin_func "gcm_gmult_vpclmulqdq_avx2", 1;
+# void gcm_ghash_vpclmulqdq_avx2_16(uint8_t Xi[16], const u128 Htable[16],
+# const uint8_t aad[16], size_t aad_len_16);
+#
+# Using the key |Htable|, update the GHASH accumulator |Xi| with the data given
+# by |aad| and |aad_len_16|. |aad_len_16| must be exactly 16.
+#
+# This has the same signature `gcm_ghash_vpclmulqdq_avx2` but uses the
+# implementation from `gcm_gmult_vpclmulqdq_avx2`, with the XOR of `aad` added.
+$code .= _begin_func "gcm_ghash_vpclmulqdq_avx2_16", 1;
{
- my ( $GHASH_ACC_PTR, $HTABLE ) = @argregs[ 0 .. 1 ];
+ my ( $GHASH_ACC_PTR, $HTABLE, $AAD, $AAD_LEN_16 ) = @argregs[ 0 .. 3 ];
my ( $GHASH_ACC, $BSWAP_MASK, $H_POW1, $GFPOLY, $T0, $T1, $T2 ) =
map( "%xmm$_", ( 0 .. 6 ) );
@@ -448,6 +455,10 @@ $code .= _begin_func "gcm_gmult_vpclmulqdq_avx2", 1;
.seh_endprologue
vmovdqu ($GHASH_ACC_PTR), $GHASH_ACC
+
+ # XOR the AAD into the accumulator.
+ vpxor ($AAD), $GHASH_ACC, $GHASH_ACC
+
vmovdqu .Lbswap_mask(%rip), $BSWAP_MASK
vmovdqu $OFFSETOFEND_H_POWERS-16($HTABLE), $H_POW1
vmovdqu .Lgfpoly(%rip), $GFPOLY
@@ -463,108 +474,6 @@ ___
}
$code .= _end_func;
```
See the full diff:
```
git difftool 14d05a3 \
crypto/fipsmodule/aes/asm/aes-gcm-avx2-x86_64.pl
```gcm_ghash_vpclmulqdq_avx2_16.1 parent ec4f5be commit bcf68dd
File tree
3 files changed
+24
-42
lines changed- crypto/fipsmodule/aes/asm
- src/aead/gcm
3 files changed
+24
-42
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
949 | 949 | | |
950 | 950 | | |
951 | 951 | | |
952 | | - | |
| 952 | + | |
953 | 953 | | |
954 | 954 | | |
955 | 955 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
436 | 436 | | |
437 | 437 | | |
438 | 438 | | |
439 | | - | |
440 | | - | |
| 439 | + | |
| 440 | + | |
441 | 441 | | |
442 | 442 | | |
443 | | - | |
444 | | - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
445 | 448 | | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
460 | 452 | | |
461 | 453 | | |
462 | | - | |
| 454 | + | |
463 | 455 | | |
464 | 456 | | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
| 457 | + | |
470 | 458 | | |
471 | | - | |
472 | | - | |
473 | | - | |
| 459 | + | |
| 460 | + | |
474 | 461 | | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
475 | 466 | | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
| 467 | + | |
484 | 468 | | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
| 469 | + | |
| 470 | + | |
489 | 471 | | |
490 | | - | |
| 472 | + | |
491 | 473 | | |
492 | 474 | | |
493 | 475 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
0 commit comments