Skip to content

Commit

Permalink
Chacha20-Poly1305-OpenSSH: Remove use of ChunksFixed.
Browse files Browse the repository at this point in the history
Take a step towards removing the `unsafe` in `ChunksFixed`'s implementation.
  • Loading branch information
briansmith committed Oct 31, 2023
1 parent a9b8882 commit 6c1d378
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/aead/chacha20_poly1305_openssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
use super::{
chacha::{self, *},
chacha20_poly1305::derive_poly1305_key,
cpu, poly1305,
polyfill::ChunksFixed,
Nonce, Tag,
cpu, poly1305, Nonce, Tag,
};
use crate::{constant_time, error};

Expand Down Expand Up @@ -152,10 +150,10 @@ struct Key {
impl Key {
fn new(key_material: &[u8; KEY_LEN], cpu_features: cpu::Features) -> Self {
// The first half becomes K_2 and the second half becomes K_1.
let &[k_2, k_1]: &[[u8; chacha::KEY_LEN]; 2] = key_material.chunks_fixed();
let (k_2, k_1) = key_material.split_at(chacha::KEY_LEN);
Self {
k_1: chacha::Key::new(k_1, cpu_features),
k_2: chacha::Key::new(k_2, cpu_features),
k_1: chacha::Key::new(k_1.try_into().unwrap(), cpu_features),
k_2: chacha::Key::new(k_2.try_into().unwrap(), cpu_features),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/polyfill/chunks_fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ macro_rules! define_chunks_fixed {
}

// Sorted by the first value, then the second value.
define_chunks_fixed!(64, 32);
define_chunks_fixed!(80, 20);

0 comments on commit 6c1d378

Please sign in to comment.