15 Commits
Author SHA1 Message Date
Eric Biggers 14d05a3b27 Remove the avx10_256 entry from BORINGSSL_function_hit
Assign aes_gcm_enc_update_vaes_avx2 to the index that was originally
used for aes_gcm_enc_update_vaes_avx10_256.

Change-Id: I9d6b2cf245c8ca59da76e5239f31134ad7c6bb73
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/77849
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2025-03-19 15:26:23 -07:00
Eric Biggers c7bec85f2b Rename avx10 and avx10_512 to avx512
Intel has made a late change to the AVX10 specification that removes
support for maximum vector lengths other than 512 bits.  Therefore,
there won't be any such thing as AVX10/256.  AVX10 will just be what was
originally planned to be called AVX10/512, effectively just
consolidating the AVX512 CPUID feature bits.

In light of this development and the fact that the 256-bit support in
aes-gcm-avx10-x86_64.pl didn't end up being used, the early adoption of
the "avx10", "avx10_256", and "avx10_512" names no longer makes sense.
So let's just use "avx512" instead.

Rename file names and function names accordingly, and update some
comments.  No functional changes.

Change-Id: I2d59912b72d5ca0679b0ea54ae770a672ca36dea
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/77847
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-03-19 15:20:44 -07:00
David Benjamin 33d1049b1f Switch the license to Apache 2.0, matching OpenSSL upstream
We use the standard Apache 2.0 file header, described in "APPENDIX: How
to apply the Apache License to your work."

This was primarily automated by running:

  git ls-tree -r --name-only HEAD | xargs go run ./util/relicense.go

See go/boringssl-relicensing-triage for the results of triaging the
output of the tool.

As part of this, switch from taking fiat-crypto under MIT license to
Apache 2.0. (It is licensed under MIT OR Apache-2.0 OR BSD-1-Clause.)

The copyright_summary tool can also be used to confirm we didn't
accidentally drop any copyright lines:

  # Run before the CL
  git grep -l Copyright | xargs go run ./util/copyright_summary.go  -out /tmp/old.json
  # Run after the CL
  git grep -l Copyright | xargs go run ./util/copyright_summary.go  -compare /tmp/old.json

Bug: 364634028
Change-Id: I17c50e761e9d077a1f92e25969e50ed35e320c59
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75852
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-02-03 15:05:16 -08:00
Eric Biggers 0fd879120d Disable the "AVX10/256" AES-GCM functions for now
Since there is now a VAES+AVX2 implementation of AES-GCM, and the future
of AVX10/256 is uncertain, disable the AES-GCM functions that use
AVX10/256 (equivalently AVX512 with a maximum vector length of 256
bits).  This leaves VAES+AVX2 as the sole 256-bit support for now.

For now this just affects Intel Ice Lake and Tiger Lake (which actually
support AVX512, but where downclocking issues make 256-bit arguably
preferable to 512-bit), where a slight performance loss is seen on long
messages.  The following tables compare AES-256-GCM throughput in MB/s
on Ice Lake server for various message lengths:

Encryption:

            | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    --------+-------+-------+-------+-------+-------+-------+
    Before  |  7533 |  6990 |  6220 |  5096 |  4200 |  2702 |
    After   |  7403 |  6879 |  6236 |  4980 |  4040 |  2868 |

            |   300 |   200 |    64 |    63 |    16 |
    --------+-------+-------+-------+-------+-------+
    Before  |  2086 |  1555 |  1031 |   657 |   433 |
    After   |  2069 |  1635 |  1045 |   667 |   430 |

Decryption:

            | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    --------+-------+-------+-------+-------+-------+-------+
    Before  |  7703 |  7140 |  6524 |  5283 |  4244 |  2990 |
    After   |  7572 |  7056 |  6494 |  5155 |  4224 |  3073 |

            |   300 |   200 |    64 |    63 |    16 |
    --------+-------+-------+-------+-------+-------+
    Before  |  2276 |  1733 |  1070 |   680 |   447 |
    After   |  2249 |  1743 |  1100 |   692 |   447 |

This change should be reconsidered if AVX10/256 sees widespread support,
as we shouldn't carry forward a restriction to AVX2 unnecessarily.

This change also replaces gcm_init_vpclmulqdq_avx10 with
gcm_init_vpclmulqdq_avx10_512, now instantiated using 512-bit vectors.
Otherwise it would be the only avx10 function left using 256-bit.

Change-Id: I7fd21568482118a2ce7a382e9042b187cd2739f7
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74369
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-01-06 14:17:42 -08:00
Eric Biggers 3b6e1be439 Add VAES + AVX2 optimized AES-GCM
Add a VAES-optimized AES-GCM implementation that is optimized for AMD
Zen 3 processors, using AVX2 instead of AVX512 / AVX10.  With AVX2 only
16 vector registers are available and some instructions are missing,
which is inconvenient and makes the code not easily sharable with the
AVX512 / AVX10 version.  However, using VAES still gives a significant
performance improvement, about 80-85% on long messages as shown by the
following tables which show the change in AES-256-GCM throughput in MB/s
on a Zen 3 "Milan" processor for various message lengths in bytes.

Encryption:

            | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    --------+-------+-------+-------+-------+-------+-------+
    Before  |  3955 |  3749 |  3597 |  3054 |  2411 |  2038 |
    After   |  7128 |  6631 |  5975 |  4788 |  3807 |  2676 |

            |   300 |   200 |    64 |    63 |    16 |
    --------+-------+-------+-------+-------+-------+
    Before  |  1757 |  1405 |   856 |   602 |   356 |
    After   |  1885 |  1430 |   940 |   593 |   381 |

Decryption:

            | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    --------+-------+-------+-------+-------+-------+-------+
    Before  |  3962 |  3774 |  3593 |  2978 |  2510 |  1998 |
    After   |  7378 |  6836 |  6282 |  4826 |  3868 |  2753 |

            |   300 |   200 |    64 |    63 |    16 |
    --------+-------+-------+-------+-------+-------+
    Before  |  1742 |  1428 |   856 |   535 |   383 |
    After   |  1940 |  1534 |   940 |   573 |   383 |

Change-Id: I583dd6b48b81ab3c6df51bfe8729366cad500537
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74368
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-01-06 14:14:57 -08:00
David Benjamin 6f4159567d Start maintaining an AUTHORS file
Following the guidance in
https://opensource.google/documentation/reference/releasing/authors,
start maintaining an AUTHORS file.

Update all existing Google copyright lines to 'The BoringSSL Authors'
per the document. This CL also changes the styling to match the new
guidance: removed the '(c)' and the comma.

All other existing copyright lines are left unmodified. Going forward,
our preference will be that new contributions to BoringSSL use 'The
BoringSSL Authors', optionally adding to the AUTHORS file if the
contributor desires.

To avoid being presumptuous, this CL does *not* proactively list every
past contributor in the BoringSSL half of the AUTHORS file. Past
contributors are welcome to send us a patch to be added, or request that
we add you. (Listed or not, the commit log continues to be a more
accurate record, and any existing non-Google copyright lines were left
unmodified.)

The OpenSSL half of the AUTHORS file is seeded with the contents of the
current OpenSSL AUTHORS file, as of writing. The current contents in the
latest revision of the 1.1.1 branch
(b372b1f76450acdfed1e2301a39810146e28b02c) and master
(d992e8729ee38b082482dc010e090bb20d1c7bd5) are identical, just formatted
in text vs Markdown.

Note when reviewing: CONTRIBUTING.md and AUTHORS contain non-mechanical
changes.

Bug: 364634028
Change-Id: I319d0ee63ec021ad85e248e8e3304b9cf9566681
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74149
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2024-12-11 13:52:41 -08:00
Eric Biggers 57f525e425 Add VAES and VPCLMULQDQ accelerated AES-GCM
Add an AES-GCM implementation for x86_64 that uses VAES, VPCLMULQDQ, and
either AVX10 or a compatible AVX512 feature set.  The assembly code is
based on the code I wrote for the Linux kernel
(https://git.kernel.org/linus/b06affb1cb580e13).  Some substantial
changes were needed for BoringSSL integration; see the file comment.

The following tables compare the performance of AES-256-GCM before and
after this patch, and also versus the alternative patch from Cloudflare
(https://boringssl-review.googlesource.com/c/boringssl/+/65987/3).  All
tables show throughput in MB/s, for implementation name vs. message
length in bytes.  All benchmarks were done using EVP_AEAD_CTX_seal() and
EVP_AEAD_CTX_open() with an associated data length of 16 bytes.

AMD Zen 5, Granite Ridge (encryption):

               | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    -----------+-------+-------+-------+-------+-------+-------+
    This patch | 26358 | 21295 | 17402 | 10672 |  7798 |  4840 |
    Cloudflare | 22363 | 18330 | 17008 | 10979 |  7070 |  5870 |
    Existing   |  7194 |  6743 |  6465 |  5404 |  4075 |  3563 |

               |   300 |   200 |    64 |    63 |    16 |
    -----------+-------+-------+-------+-------+-------+
    This patch |  3248 |  2557 |  1359 |   937 |   537 |
    Cloudflare |  3624 |  2770 |  1293 |  1028 |   517 |
    Existing   |  2938 |  2271 |  1266 |   959 |   528 |

AMD Zen 5, Granite Ridge (decryption):

               | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    -----------+-------+-------+-------+-------+-------+-------+
    This patch | 27214 | 22298 | 18824 | 11401 |  8496 |  5399 |
    Cloudflare | 22629 | 19257 | 17792 | 11575 |  7807 |  6031 |
    Existing   |  7122 |  6805 |  6228 |  4922 |  4604 |  3565 |

               |   300 |   200 |    64 |    63 |    16 |
    -----------+-------+-------+-------+-------+-------+
    This patch |  3637 |  2497 |  1483 |   952 |   589 |
    Cloudflare |  3714 |  2847 |  1437 |  1030 |   567 |
    Existing   |  3012 |  2354 |  1514 |   880 |   632 |

AMD Zen 4, Genoa (encryption):

               | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    -----------+-------+-------+-------+-------+-------+-------+
    This patch | 10093 |  8907 |  7614 |  5399 |  4247 |  2719 |
    Cloudflare |  9174 |  8073 |  7521 |  5414 |  3786 |  3111 |
    Existing   |  4239 |  3964 |  3800 |  3186 |  2398 |  2069 |

               |   300 |   200 |    64 |    63 |    16 |
    -----------+-------+-------+-------+-------+-------+
    This patch |  1940 |  1553 |   851 |   581 |   343 |
    Cloudflare |  2023 |  1619 |   775 |   619 |   311 |
    Existing   |  1735 |  1334 |   775 |   573 |   317 |

AMD Zen 4, Genoa (decryption):

               | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    -----------+-------+-------+-------+-------+-------+-------+
    This patch | 10108 |  8922 |  7879 |  5526 |  4250 |  2872 |
    Cloudflare |  9441 |  8347 |  7723 |  5366 |  3902 |  3067 |
    Existing   |  4249 |  3999 |  3810 |  3101 |  2535 |  2026 |

               |   300 |   200 |    64 |    63 |    16 |
    -----------+-------+-------+-------+-------+-------+
    This patch |  2031 |  1536 |   868 |   568 |   346 |
    Cloudflare |  1933 |  1579 |   765 |   569 |   300 |
    Existing   |  1723 |  1381 |   806 |   516 |   345 |

Intel Emerald Rapids (encryption):

               | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    -----------+-------+-------+-------+-------+-------+-------+
    This patch | 13974 | 11827 | 10166 |  6601 |  4904 |  3334 |
    Cloudflare | 12735 | 10752 |  9966 |  6709 |  4524 |  3647 |
    Existing   |  5237 |  4831 |  4639 |  3747 |  2816 |  2409 |

               |   300 |   200 |    64 |    63 |    16 |
    -----------+-------+-------+-------+-------+-------+
    This patch |  2251 |  1763 |   915 |   649 |   363 |
    Cloudflare |  2329 |  1850 |   855 |   676 |   342 |
    Existing   |  1971 |  1502 |   808 |   626 |   359 |

Intel Emerald Rapids (decryption):

               | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    -----------+-------+-------+-------+-------+-------+-------+
    This patch | 14239 | 12180 | 10370 |  6692 |  5305 |  3344 |
    Cloudflare | 13348 | 11485 | 10460 |  6736 |  5229 |  3641 |
    Existing   |  5306 |  4958 |  4702 |  3767 |  3071 |  2432 |

               |   300 |   200 |    64 |    63 |    16 |
    -----------+-------+-------+-------+-------+-------+
    This patch |  2197 |  2077 |  1040 |   628 |   390 |
    Cloudflare |  2186 |  1911 |   938 |   615 |   370 |
    Existing   |  2024 |  1727 |   999 |   599 |   421 |

Intel Sapphire Rapids (encryption):

               | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    -----------+-------+-------+-------+-------+-------+-------+
    This patch | 12726 | 10618 |  9248 |  6012 |  4466 |  2986 |
    Cloudflare | 11059 |  9794 |  9071 |  6052 |  4089 |  3306 |
    Existing   |  4761 |  4397 |  4222 |  3408 |  2560 |  2188 |

               |   300 |   200 |    64 |    63 |    16 |
    -----------+-------+-------+-------+-------+-------+
    This patch |  2051 |  1612 |   838 |   579 |   351 |
    Cloudflare |  2110 |  1686 |   775 |   622 |   311 |
    Existing   |  1792 |  1369 |   733 |   567 |   324 |

Intel Sapphire Rapids (decryption):

               | 16384 |  4096 |  4095 |  1420 |   512 |   500 |
    -----------+-------+-------+-------+-------+-------+-------+
    This patch | 12951 | 11100 |  9447 |  6067 |  4862 |  3030 |
    Cloudflare | 12165 | 10421 |  9506 |  6126 |  4767 |  3321 |
    Existing   |  4807 |  4507 |  4275 |  3400 |  2791 |  2216 |

               |   300 |   200 |    64 |    63 |    16 |
    -----------+-------+-------+-------+-------+-------+
    This patch |  2003 |  1894 |   950 |   572 |   357 |
    Cloudflare |  1999 |  1741 |   857 |   559 |   328 |
    Existing   |  1831 |  1571 |   838 |   539 |   382 |

Change-Id: I5b0833d2ffe8fd273cb38a26cd104c52c3532ceb
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/70187
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2024-12-09 23:32:46 +00:00
David Benjamin 4d955d20d2 Check static CPU capabilities on x86.
On Arm, our CRYPTO_is_*_capable functions check the corresponding
preprocessor symbol. This allows us to automatically drop dynamic checks
and fallback code when some capability is always avilable.

This CL does the same on x86, as well as consolidates our
OPENSSL_ia32cap_P checks in one place. Since this abstraction is
incompatible with some optimizations we do around OPENSSL_ia32cap_get()
in the FIPS module, I've marked the symbol __attribute__((const)), which
is enough to make GCC and Clang do the optimizations for us. (We already
do the same to DEFINE_BSS_GET.)

Most x86 platforms support a much wider range of capabilities, so this
is usually a no-op. But, notably, all x86_64 Mac hardware has SSSE3
available, so this allows us to statically drop an AES implementation.
(On macOS with -Wl,-dead_strip, this seems to trim 35080 bytes from the
bssl binary.) Configs like -march=native can also drop a bunch of code.

Update-Note: This CL may break build environments that incorrectly mark
some instruction as statically available. This is unlikely to happen
with vector instructions like AVX, where the compiler could freely emit
them anyway. However, instructions like AES-NI might be set incorrectly.

Change-Id: I44fd715c9887d3fda7cb4519c03bee4d4f2c7ea6
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/51548
Reviewed-by: Adam Langley <agl@google.com>
2022-02-23 19:17:28 +00:00
David Benjamin 661266ea06 Move CPU detection symbols to crypto/internal.h.
These symbols were not marked OPENSSL_EXPORT, so they weren't really
usable externally anyway. They're also very sensitive to various build
configuration toggles, which don't always get reflected into projects
that include our headers. Move them to crypto/internal.h.

Change-Id: I79a1fcf0b24e398d75a9cc6473bae28ec85cb835
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/50846
Reviewed-by: Adam Langley <agl@google.com>
2022-01-07 18:33:50 +00:00
Adam Langley 577eadc424 Fix test build with recent Clang.
Some configurations of Clang hate not using a reference in a C++
range-for loop.

Change-Id: I90abf99625df4bbb67e835411bd85d995252beae
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/40471
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2020-04-01 14:49:21 +00:00
David Benjamin 0de64a749b Make the dispatch tests opt-in.
The assembly dispatch tests currently assume NDEBUG is consistently
defined between C/C++ and assembly. While this is usually the case for
UNIX, CMake does not pass NDEBUG to NASM. This is giving gRPC some
difficulties in updating BoringSSL, so switch it to an opt-in
-DBORINGSSL_DISPATCH_TEST flag instead.

Update-Note: If you were copying NDEBUG over to assembly files, that's
no longer required (though it's harmless to leave it in). If you want to
run ImplDispatchTest.*, build both C/C++ and assembly with
-DBORINGSSL_DISPATCH_TEST in your debug builds. (Don't enable it in
release builds. It causes assembly to scribble in some globals.)

Change-Id: I9ab3371dc0f0a40b27b44ef93835e007a6346900
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37764
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-09-27 19:02:43 +00:00
David Benjamin f4d8b96920 Use ScopedEVP_AEAD_CTX in ImplDispatchTest.AEAD_AES_GCM.
EVP_AEAD_CTX_cleanup is often a no-op now that the data is embedded, but
best to be tidy.

Change-Id: I1ba56e5e36d6e69ae1ba07e40c4a7bda7329fa79
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37430
Reviewed-by: Adam Langley <agl@google.com>
2019-09-13 17:48:50 +00:00
David Benjamin df11bed9ee Update ImplDispatchTest for bsaes-x86_64 removal.
I always forget to update this.

Bug: 256
Change-Id: I85fea8fa48da8d4ed6a1e1f001f5e1a74f1b706d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/35384
Reviewed-by: Adam Langley <agl@google.com>
2019-03-23 15:15:48 +00:00
David Benjamin 65dc321492 Enable vpaes for AES_* functions.
This makes the AES_* functions meet our constant-time goals for
platforms where we have vpaes available. In particular, QUIC packet
number encryption needs single-block operations and those should have
vpaes available.

As a bonus, when vpaes is statically available, the aes_nohw_* functions
should be dropped by the linker. (Notably, NEON is guaranteed on
aarch64. Although vpaes-armv8.pl itself may take some more exploration.
https://crbug.com/boringssl/246#c4)

Bug: 263
Change-Id: Ie1c4727a166ec101a8453761757c87dadc188769
Reviewed-on: https://boringssl-review.googlesource.com/c/34875
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-02-22 23:09:19 +00:00
Adam Langley c1615719ce Add test of assembly code dispatch.
The first attempt involved using Linux's support for hardware
breakpoints to detect when assembly code was run. However, this doesn't
work with SDE, which is a problem.

This version has the assembly code update a global flags variable when
it's run, but only in non-FIPS and non-debug builds.

Update-Note: Assembly files now pay attention to the NDEBUG preprocessor
symbol. Ensure the build passes the symbol in. (If release builds fail
to link due to missing BORINGSSL_function_hit, this is the cause.)

Change-Id: I6b7ced442b7a77d0b4ae148b00c351f68af89a6e
Reviewed-on: https://boringssl-review.googlesource.com/c/33384
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-01-22 20:22:53 +00:00