-
Notifications
You must be signed in to change notification settings - Fork 1k
AES-GCM-SIV: Add implementation in C and assembly #10807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SparkiDev
wants to merge
1
commit into
wolfSSL:master
Choose a base branch
from
SparkiDev:aes_gcm_siv_asm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| name: AES-GCM-SIV (RFC 8452) tests | ||
|
|
||
| # START OF COMMON SECTION | ||
| on: | ||
| push: | ||
| branches: [ 'release/**' ] | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, ready_for_review] | ||
| branches: [ '*' ] | ||
| # Weekday-morning cron (10:00 UTC) seeds the master-scoped ccache that PR runs | ||
| # restore (cross job only); re-runs --build-only on the default branch. | ||
| schedule: | ||
| - cron: '40 10 * * 1-5' | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| # END OF COMMON SECTION | ||
|
|
||
| jobs: | ||
| # Native x86_64 'make check'. These are --enable-cryptonly (WOLFCRYPT_ONLY) | ||
| # builds, so check runs testwolfcrypt - which includes aesgcm_siv_test (the | ||
| # RFC 8452 KATs) - but not the TLS-only tests/unit.test (the tests/api group, | ||
| # test_wc_AesGcmSivEncryptDecrypt, needs a non-cryptonly build). One runner | ||
| # per config: | ||
| # - siv-c-only : no asm, software word64-table POLYVAL + C CTR. | ||
| # - siv-word32 : GCM_WORD32 forces the word32-table software POLYVAL multiply. | ||
| # - siv-small : GCM_SMALL forces the table-free software POLYVAL multiply. | ||
| # - siv-intelasm : PCLMUL/AVX/VAES/AVX512 POLYVAL + pipelined CTR, whichever | ||
| # the runner CPU selects at runtime. | ||
| # - siv-all : SIV alongside --enable-all to catch integration regressions. | ||
| # - siv-smallstack : SIV's key schedules / derived keys live on the stack. | ||
| make_check: | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| config: | ||
| - '--enable-cryptonly --enable-aesgcm-siv' | ||
| - '--enable-cryptonly --enable-aesgcm-siv CPPFLAGS=-DGCM_WORD32' | ||
| - '--enable-cryptonly --enable-aesgcm-siv CPPFLAGS=-DGCM_SMALL' | ||
| - '--enable-cryptonly --enable-intelasm --enable-sp-asm --enable-aesgcm-siv' | ||
| - '--enable-cryptonly --enable-all-crypto --enable-intelasm --enable-sp-asm --enable-aesgcm-siv' | ||
| - '--enable-cryptonly --enable-aesgcm-siv --enable-smallstack' | ||
| name: make check (${{ matrix.config }}) | ||
| if: ${{ (github.repository_owner == 'wolfssl') && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) }} | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 12 | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| name: Checkout wolfSSL | ||
|
|
||
| - name: Build and test AES-GCM-SIV | ||
| run: | | ||
| ./autogen.sh | ||
| ./configure ${{ matrix.config }} | ||
| make -j 4 | ||
| make check | ||
|
|
||
| - name: Print errors | ||
| if: ${{ failure() }} | ||
| run: | | ||
| for file in scripts/*.log test-suite.log | ||
| do | ||
| if [ -f "$file" ]; then | ||
|
SparkiDev marked this conversation as resolved.
|
||
| echo "${file}:" | ||
| cat "$file" | ||
| echo "========================================================================" | ||
| fi | ||
| done | ||
|
|
||
| # Cross-compiled AES-GCM-SIV asm paths, built out-of-tree in parallel and run | ||
| # under qemu-user (binfmt). Covers: | ||
| # - arm64-pmull : AArch64 PMULL POLYVAL (gcm_siv_arm64_crypto). | ||
| # - arm64-no-hw-crypto : AArch64 NEON 8-bit-pmul + table POLYVAL | ||
| # (gcm_siv_arm64_neon / _base) via WOLFSSL_ARMASM_NO_HW_CRYPTO. | ||
| # - armhf-crypto : ARMv8-A 32-bit vmull.p64 POLYVAL (gcm_siv_arm32_crypto); | ||
| # QEMU_CPU=max enables the crypto extensions. | ||
| # - armhf-base : AArch32 software-table POLYVAL/CTR (gcm_siv_arm32_base) | ||
| # via NO_HW_CRYPTO, run under the default (non-crypto) CPU. | ||
| # Known gaps (a defect here would not be caught): the AArch64 base variant | ||
| # (AES_GCMSIV_polyval_base) is compiled in every aarch64 armasm build but only | ||
| # selected at runtime with NEON+HW-crypto both disabled, a config unsupported | ||
| # upstream on aarch64 (no base SHA/ChaCha armasm); and Thumb-2 (gcm_siv_thumb2, | ||
| # armv7-m) which qemu-user cannot run. Both are noted for release notes. | ||
| cross_check: | ||
| name: Cross-arch test | ||
| if: ${{ (github.repository_owner == 'wolfssl') && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) }} | ||
| runs-on: ubuntu-22.04 | ||
| timeout-minutes: 25 | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| name: Checkout wolfSSL | ||
|
|
||
| - name: Install dependencies | ||
| uses: ./.github/actions/install-apt-deps | ||
| with: | ||
| packages: autoconf automake libtool build-essential crossbuild-essential-arm64 crossbuild-essential-armhf qemu-user | ||
| ghcr-debs-tag: ubuntu-22.04-minimal | ||
|
|
||
| - name: Set up ccache | ||
| uses: ./.github/actions/ccache-setup | ||
| with: | ||
| workflow-id: aesgcm-siv | ||
| read-only: ${{ github.event_name == 'pull_request' }} | ||
| max-size: 300M | ||
|
|
||
| - name: Build all configs (parallel, out-of-tree) | ||
| run: | | ||
| cat > "$RUNNER_TEMP/aesgcm-siv-configs.json" <<'EOF' | ||
| [ | ||
| {"name": "arm64-pmull", "minutes": 6, | ||
| "cc": "ccache aarch64-linux-gnu-gcc", | ||
| "configure": ["--host=aarch64-linux-gnu", "--enable-cryptonly", | ||
| "--enable-all-crypto", "--disable-examples", "--enable-armasm", | ||
| "--enable-aesgcm-siv", "CFLAGS=-O2"], | ||
| "check": false, | ||
| "run": [["env", "QEMU_LD_PREFIX=/usr/aarch64-linux-gnu", "QEMU_CPU=max", | ||
| "./wolfcrypt/test/testwolfcrypt"]]}, | ||
| {"name": "arm64-no-hw-crypto", "minutes": 6, | ||
| "cc": "ccache aarch64-linux-gnu-gcc", | ||
| "configure": ["--host=aarch64-linux-gnu", "--enable-cryptonly", | ||
| "--enable-all-crypto", "--disable-examples", "--enable-armasm", | ||
| "--enable-aesgcm-siv", "CPPFLAGS=-DWOLFSSL_ARMASM_NO_HW_CRYPTO", | ||
| "CFLAGS=-O2"], | ||
| "check": false, | ||
| "run": [["env", "QEMU_LD_PREFIX=/usr/aarch64-linux-gnu", "QEMU_CPU=max", | ||
| "./wolfcrypt/test/testwolfcrypt"]]}, | ||
| {"name": "armhf-crypto", "minutes": 6, | ||
| "cc": "ccache arm-linux-gnueabihf-gcc", | ||
| "comment": "--disable-aesgcm-stream: WOLFSSL_AESGCM_STREAM's software GHASH only defines its macros for __aarch64__ armasm, not 32-bit __arm__ armasm, so all-crypto + armasm otherwise fails to build aes.c (pre-existing, unrelated to SIV).", | ||
| "configure": ["--host=arm-linux-gnueabihf", "--enable-cryptonly", | ||
| "--enable-all-crypto", "--disable-examples", "--enable-armasm", | ||
| "--enable-aesgcm-siv", "--disable-aesgcm-stream", "CFLAGS=-O2"], | ||
| "check": false, | ||
| "run": [["env", "QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf", "QEMU_CPU=max", | ||
| "./wolfcrypt/test/testwolfcrypt"]]}, | ||
| {"name": "armhf-base", "minutes": 6, | ||
| "cc": "ccache arm-linux-gnueabihf-gcc", | ||
| "comment": "WOLFSSL_ARMASM_NO_HW_CRYPTO selects the AArch32 software-table POLYVAL/CTR (AES_GCMSIV_polyval_base/ctr_base). Run under the DEFAULT qemu CPU (no QEMU_CPU=max) so the crypto path is not taken - this is the only job exercising the base variant at runtime.", | ||
| "configure": ["--host=arm-linux-gnueabihf", "--enable-cryptonly", | ||
| "--enable-all-crypto", "--disable-examples", "--enable-armasm", | ||
| "--enable-aesgcm-siv", "--disable-aesgcm-stream", | ||
| "CPPFLAGS=-DWOLFSSL_ARMASM_NO_HW_CRYPTO", "CFLAGS=-O2"], | ||
| "check": false, | ||
| "run": [["env", "QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf", | ||
| "./wolfcrypt/test/testwolfcrypt"]]} | ||
| ] | ||
| EOF | ||
| .github/scripts/parallel-make-check.py \ | ||
| ${{ github.event_name == 'schedule' && '--build-only' || '' }} \ | ||
| "$RUNNER_TEMP/aesgcm-siv-configs.json" | ||
|
|
||
| - name: ccache stats | ||
| if: always() | ||
| run: ccache -s || true | ||
|
|
||
| - name: Upload logs on failure | ||
| if: failure() | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| retention-days: 7 | ||
| name: aesgcm-siv-cross-logs | ||
| path: | | ||
| build-*/make-check.log | ||
| build-*/test-suite.log | ||
| build-*/config.log | ||
| if-no-files-found: ignore | ||
|
|
||
| # Windows MSVC/MASM: build wolfssl64.sln (AES-NI on by default => the MASM | ||
| # aes_gcm_asm.asm POLYVAL/CTR is assembled with ml64) with WOLFSSL_AESGCM_SIV | ||
| # enabled, and run testsuite.exe - which calls wolfcrypt_test() -> the RFC 8452 | ||
| # KATs incl. the 128-byte multi-block vector. This is the ONLY job that | ||
| # exercises the Windows MASM SIV path; its absence let a High-severity | ||
| # AES_GCMSIV_ctr register-clobber (wrong ciphertext + a 16-byte wild write) | ||
| # ship undetected. x64 only: the AES-NI .asm is x86_64. | ||
| windows_masm: | ||
| name: Windows MASM AES-GCM-SIV (x64) | ||
| if: ${{ (github.repository_owner == 'wolfssl') && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) }} | ||
| runs-on: windows-latest | ||
| timeout-minutes: 12 | ||
| env: | ||
| SOLUTION_FILE_PATH: wolfssl64.sln | ||
| BUILD_CONFIGURATION: Release | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| name: Checkout wolfSSL | ||
|
|
||
| - name: Enable AES-GCM-SIV in user_settings.h | ||
| shell: bash | ||
| run: | | ||
| # Add the define once, right after the first HAVE_AESGCM (AES-NI is | ||
| # already enabled for x64 in this header). | ||
| sed -i '0,/#define HAVE_AESGCM/s//#define HAVE_AESGCM\n#define WOLFSSL_AESGCM_SIV/' \ | ||
| IDE/WIN/user_settings.h | ||
| grep -n 'WOLFSSL_AESGCM_SIV' IDE/WIN/user_settings.h | ||
|
|
||
| - name: Add MSBuild to PATH | ||
| uses: microsoft/setup-msbuild@v3 | ||
|
|
||
| - name: Restore NuGet packages | ||
| run: nuget restore ${{ env.SOLUTION_FILE_PATH }} | ||
|
|
||
| - name: Build (x64, MASM) | ||
| run: msbuild /m /p:PlatformToolset=v142 /p:Platform=x64 /p:Configuration=${{ env.BUILD_CONFIGURATION }} ${{ env.SOLUTION_FILE_PATH }} | ||
|
|
||
| - name: Run wolfCrypt KATs (incl. AES-GCM-SIV) | ||
| run: Release/x64/testsuite.exe | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 [Medium] New AES-GCM-SIV pure-C and assembly POLYVAL/CTR variants (Windows MASM, Thumb2, AArch32/AArch64 base, GCM_WORD32… · Missing Tests
The added workflow provides good RFC 8452 KAT coverage but which POLYVAL multiply / CTR backend it exercises depends on build config. It covers native x86_64
make check(software word64 table + Intel.Sasm) and cross-compiled AArch64 (PMULL/NEON/base) and AArch32 withQEMU_CPU=max(crypto/vmull.p64 path). It does NOT exercise these newly written, security-sensitive paths: the Windows MASM.asmvariant (which in fact contains a correctness+memory-safety bug -- see the AES_GCMSIV_ctr finding -- that this gap allowed through), theword32table variant (GCM_WORD32, AesGcmSivGMult/AesGcmSivPolyvalInitSw word32 block in aes.c), the table-freeGCM_SMALLvariant, the AArch32 base (WC_POLYVAL_ASM_AARCH32_BASE) NO_HW_CRYPTO path (armhf job forcesQEMU_CPU=max, selecting the crypto path), the AArch64 base (AES_GCMSIV_polyval_base, only reached with NEON+HW-crypto both disabled), and Thumb2 (AES_GCMSIV_polyval_thumb2/gcm_siv_thumb2, targeting armv7-m which qemu-user cannot run). A transposition/reduction/register error in any of these would not be caught by CI. Severity views: review flagged this Medium/SUGGEST (test coverage); review-security flagged Medium (missing-tests, and it is the reason the High MASM defect went undetected).Fix: Add a Windows MSVC/MASM job that builds with AES-NI + AES-GCM-SIV and runs the KATs. Add at least one x86
make checkconfig forcing the word32 and GCM_SMALL software multiplies (e.g.CPPFLAGS=-DGCM_WORD32andCPPFLAGS=-DGCM_SMALL) so the two untested pure-C POLYVAL variants run the RFC 8452 KATs at near-zero cost. Add an AArch32 NO_HW_CRYPTO base config (noQEMU_CPU=max) so the generated software-table CTR/POLYVAL variants are exercised. Note the Thumb-2 gap explicitly in release notes if it cannot be emulated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added