aes-gcm 0.11: key and nonce generation move to the Generate trait - #25
Merged
Conversation
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Supersedes #15, which cannot compile: aes-gcm 0.11 removes
aead::OsRngand thegenerate_key/generate_nonceassociated functions.RustCrypto moved key and nonce generation onto a
Generatetrait (crypto-common0.2), so the calls become: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 (SysRng→getrandom), which is whatOsRngwas. The nonce type is derived fromAeadCore::NonceSizerather than written as a literal, so it stays 12 bytes — the existingNONCE_LENassertion 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 oldOsRngpath did the same.try_generate()exists if aResultis preferred.Verified:
cargo build --all-targetsclean, and the crypto tests pass — round-trip, key-file persistence across reload, and the legacy-plaintext passthrough.