Skip to content

Require fresh IVs for repeated EVP AEAD encryption - #11593

Open
aidangarske wants to merge 6 commits into
wolfSSL:masterfrom
aidangarske:evp-ccm-sm4-nonce-guards
Open

aidangarske wants to merge 6 commits into
wolfSSL:masterfrom
aidangarske:evp-ccm-sm4-nonce-guards

Conversation

@aidangarske

Copy link
Copy Markdown
Member

@aidangarske aidangarske self-assigned this Sep 29, 2026
@aidangarske
aidangarske requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot September 29, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 High severity · 3 Medium severity

Open (4)
What changed in this PR

This PR enforces “fresh IV required” semantics for repeated AEAD encrypt operations (notably AES-CCM and SM4 GCM/CCM) by tracking whether an IV has already been used for an encryption message and failing subsequent encryptions unless the IV is refreshed or auto-incremented.

Changes:

  • Add authIvUsed state to WOLFSSL_EVP_CIPHER_CTX and reset it on context reset / when a new IV is provided.
  • Reject repeated AEAD encryption attempts with the same IV across EVP_CipherFinal and single-shot EVP_Cipher paths.
  • Add API tests validating failure on IV reuse and success when IV changes / IV generation paths are used.
File Description
wolfssl/​openssl/​evp.h Adds authIvUsed bit to track per-message IV usage for AEAD modes.
wolfcrypt/​src/​evp.c Enforces IV freshness by failing repeated encryptions unless IV is refreshed; updates IV state for SM4 auto-increment.
tests/​api/​test_evp_cipher.h Registers new tests covering “message IV reuse” behavior for AES-CCM and SM4 GCM/CCM.
tests/​api/​test_evp_cipher.c Implements new regression tests for IV reuse prevention and IV re-provisioning behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread wolfcrypt/src/evp.c Resolved
Comment thread tests/api/test_evp_cipher.c Resolved
Comment thread tests/api/test_evp_cipher.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #11593

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer

Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread wolfcrypt/src/evp.c Resolved
Comment thread tests/api/test_evp_cipher.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #11593

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer

Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread wolfcrypt/src/evp.c Resolved
Comment thread src/ssl.c Resolved
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m0plus

  • FLASH: .text +228 B (+0.3%, 72,075 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m3

  • FLASH: .text +768 B (+0.6%, 133,641 B / 262,144 B, total: 51% used)

gcc-arm-cortex-m4

  • FLASH: .text +768 B (+0.4%, 210,984 B / 262,144 B, total: 80% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +256 B (+0.3%, 74,927 B / 262,144 B, total: 29% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .text +256 B (+0.1%, 183,755 B / 262,144 B, total: 70% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +768 B (+0.4%, 198,688 B / 1,048,576 B, total: 19% used)

gcc-arm-cortex-m4-min-ecc

  • FLASH: .text +256 B (+0.4%, 69,393 B / 262,144 B, total: 26% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +1,792 B (+0.2%, 807,940 B / 1,048,576 B, total: 77% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +256 B (+0.1%, 224,972 B / 262,144 B, total: 86% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +960 B (+0.3%, 316,848 B / 1,048,576 B, total: 30% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +1,280 B (+0.4%, 347,368 B / 1,048,576 B, total: 33% used)

gcc-arm-cortex-m4-sp-math

  • FLASH: .text +256 B (+0.4%, 69,393 B / 262,144 B, total: 26% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +768 B (+0.6%, 134,409 B / 262,144 B, total: 51% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +1,024 B (+0.4%, 253,570 B / 262,144 B, total: 97% used)

gcc-arm-cortex-m7

  • FLASH: .text +768 B (+0.4%, 210,984 B / 262,144 B, total: 80% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +1,024 B (+0.3%, 317,744 B / 1,048,576 B, total: 30% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .text +1,024 B (+0.4%, 253,570 B / 262,144 B, total: 97% used)

stm32-sim-stm32h753

  • FLASH: .text +256 B (+0.1%, 209,444 B / 2,097,152 B, total: 10% used)

zephyr-frdm_rw612

  • FLASH: text +280 B (+0.1%, 296,048 B / 67,108,864 B, total: 0% used)

Catch memory regressions in CI with MemBrowse. Free for open source.

@aidangarske

Copy link
Copy Markdown
Member Author

Jenkins retest this please

@aidangarske
aidangarske force-pushed the evp-ccm-sm4-nonce-guards branch from 5114362 to 9612294 Compare November 17, 2026 21:19
@aidangarske aidangarske removed their assignment Nov 17, 2026
@philljj philljj self-assigned this Nov 18, 2026
@philljj

philljj commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

@wolfSSL-Fenrir-bot review max

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #11593

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_evp_cipher.h
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer

Findings: 6
6 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Max

Comment thread wolfcrypt/src/evp.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved
Comment thread tests/api/test_evp_cipher.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved
@philljj philljj assigned aidangarske and unassigned wolfSSL-Bot and philljj Nov 18, 2026

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #11593

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_evp_cipher.h
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread wolfcrypt/src/evp.c Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants