I'm using AES256-GCM, but with 12-byte tags for compatibility reasons.
Therefore I need to use the generic AesGcm
Struct aes_gcm::AesGcm source ·
pub struct AesGcm<Aes, NonceSize, TagSize = U16>where TagSize: TagSize,{ /* private fields */ }
AES-GCM: generic over an underlying AES implementation and nonce size.
This type is generic to support substituting alternative AES implementations (e.g. embedded hardware implementations)
It is NOT intended to be instantiated with any block cipher besides AES! Doing so runs the risk of unintended cryptographic properties!
The NonceSize generic parameter can be used to instantiate AES-GCM with other nonce sizes, however it’s recommended to use it with typenum::U12, the default of 96-bits.
The TagSize generic parameter can be used to instantiate AES-GCM with other authorization tag sizes, however it’s recommended to use it with typenum::U16, the default of 128-bits.
If in doubt, use the built-in Aes128Gcm and Aes256Gcm type aliases.
rather than Aes256Gcm.
My error is:
error[E0412]: cannot find type `Aes` in this scope
--> common/src/main.rs:108:39
|
108 | let cipher = <aes_gcm::AesGcm<Aes, aes_gcm::aead::consts::U12, aes_gcm::aead::consts::U12> as aes_gcm::KeyInit>::new(&key.into());
| ^^^ not found in this scope
|
help: you might be missing a type parameter
|
103 | fn test_aesgcm<Aes>() {
| +++++
Using U12
as the TagSize
was trivial, as the default was U16
. Likewise, using U12
as the NonceSize
was obvious.
How do I find out what my options are for the value of the Aes
type parameter?
I'm interested in a general answer for unknown type parameters, as well as the answer to this specific question.
The specific answer is Aes256
i.e. this works:
let cipher = <aes_gcm::AesGcm<Aes256, aes_gcm::aead::consts::U12, aes_gcm::aead::consts::U12> as aes_gcm::KeyInit>::new(&key.into());
I was confused by the alias being pub type Aes256Gcm = AesGcm<Aes256, U12>;
- I had forgotten that their was a default for TagSize
. Therefore I could just copy the Aes256 from this alias.
I am still interested in how to solve this for unknown generic parameters.