|
1 | | -use secure::ring::aead::{seal_in_place, open_in_place, Algorithm, AES_256_GCM}; |
| 1 | +use secure::ring::aead::{seal_in_place, open_in_place, Aad, Algorithm, Nonce, AES_256_GCM}; |
2 | 2 | use secure::ring::aead::{OpeningKey, SealingKey}; |
3 | 3 | use secure::ring::rand::{SecureRandom, SystemRandom}; |
4 | 4 | use secure::{base64, Key}; |
@@ -46,9 +46,11 @@ impl<'a> PrivateJar<'a> { |
46 | 46 | return Err("length of decoded data is <= NONCE_LEN"); |
47 | 47 | } |
48 | 48 |
|
49 | | - let ad = name.as_bytes(); |
| 49 | + let ad = Aad::from(name.as_bytes()); |
50 | 50 | let key = OpeningKey::new(ALGO, &self.key).expect("opening key"); |
51 | 51 | let (nonce, sealed) = data.split_at_mut(NONCE_LEN); |
| 52 | + let nonce = Nonce::try_assume_unique_for_key(nonce) |
| 53 | + .expect("invalid length of `nonce`"); |
52 | 54 | let unsealed = open_in_place(&key, nonce, ad, 0, sealed) |
53 | 55 | .map_err(|_| "invalid key/nonce/value: bad seal")?; |
54 | 56 |
|
@@ -156,9 +158,11 @@ impl<'a> PrivateJar<'a> { |
156 | 158 | let (nonce, in_out) = data.split_at_mut(NONCE_LEN); |
157 | 159 | SystemRandom::new().fill(nonce).expect("couldn't random fill nonce"); |
158 | 160 | in_out[..cookie_val.len()].copy_from_slice(cookie_val); |
| 161 | + let nonce = Nonce::try_assume_unique_for_key(nonce) |
| 162 | + .expect("invalid length of `nonce`"); |
159 | 163 |
|
160 | 164 | // Use cookie's name as associated data to prevent value swapping. |
161 | | - let ad = cookie.name().as_bytes(); |
| 165 | + let ad = Aad::from(cookie.name().as_bytes()); |
162 | 166 |
|
163 | 167 | // Perform the actual sealing operation and get the output length. |
164 | 168 | seal_in_place(&key, nonce, ad, in_out, overhead).expect("in-place seal") |
|
0 commit comments