Skip to content

aes-gcm 0.11: key and nonce generation move to the Generate trait - #25

Merged
stoatworks-labs merged 1 commit into
mainfrom
chore/aes-gcm-0.11b
Aug 27, 2026
Merged

aes-gcm 0.11: key and nonce generation move to the Generate trait#25
stoatworks-labs merged 1 commit into
mainfrom
chore/aes-gcm-0.11b

Conversation

@stoatworks-labs

Copy link
Copy Markdown
Owner

Supersedes #15, which cannot compile: aes-gcm 0.11 removes aead::OsRng and the generate_key / generate_nonce associated functions.

error[E0432]: unresolved import `aes_gcm::aead::OsRng`
error[E0599]: no associated function named `generate_nonce` found for struct `AesGcm<...>`

RustCrypto moved key and nonce generation onto a Generate trait (crypto-common 0.2), so the calls become:

before after
Aes256Gcm::generate_key(OsRng) Key::<Aes256Gcm>::generate()
Aes256Gcm::generate_nonce(OsRng) Nonce::<<Aes256Gcm as AeadCore>::NonceSize>::generate()

Why this should be equivalent, and where to check me. Generate::generate() draws from the system's ambient CSPRNG (SysRnggetrandom), which is what OsRng was. The nonce type is derived from AeadCore::NonceSize rather than written as a literal, so it stays 12 bytes — the existing NONCE_LEN assertion on the decrypt path still passes. Key size is unchanged at 256 bits.

One behavioural note: generate() panics if the OS RNG fails, where the old OsRng path did the same. try_generate() exists if a Result is preferred.

Verified: cargo build --all-targets clean, and the crypto tests pass — round-trip, key-file persistence across reload, and the legacy-plaintext passthrough.

⚠️ Not self-merging. This is key and nonce generation, and "it compiles and the tests are green" is weak evidence for crypto — a test suite will not notice a weakened RNG or a nonce-size change. Wants a human read before it lands.

aes-gcm 0.11 removes aead::OsRng and the generate_key / generate_nonce
associated functions; RustCrypto moved both onto a Generate trait backed by
the system's ambient CSPRNG.

  Aes256Gcm::generate_key(OsRng)   -> Key::<Aes256Gcm>::generate()
  Aes256Gcm::generate_nonce(OsRng) -> Nonce::<<Aes256Gcm as AeadCore>::NonceSize>::generate()

The nonce type is derived from AeadCore::NonceSize rather than written as a
literal, so it stays 12 bytes and the NONCE_LEN check on the decrypt path
still holds. Key size unchanged at 256 bits.

Verified: cargo build --all-targets clean, crypto tests passing (round-trip,
key-file persistence across reload, legacy-plaintext passthrough).

Rebuilt on current main -- the earlier branch conflicted on Cargo.lock after
the mdns-sd merge landed.
@stoatworks-labs
stoatworks-labs merged commit 350314c into main Aug 27, 2026
1 check was pending
@stoatworks-labs
stoatworks-labs deleted the chore/aes-gcm-0.11b branch August 27, 2026 20:06
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.

1 participant