From f692025c75f3cf3b94b3061e65aeb84de754192f Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Thu, 12 Oct 2023 22:28:07 -0700 Subject: [PATCH] Chacha20-Poly1305-OpenSSH: Remove use of `ChunksFixed`. Take a step towards removing the `unsafe` in `ChunksFixed`'s implementation. --- src/aead/chacha20_poly1305_openssh.rs | 10 ++++------ src/polyfill/chunks_fixed.rs | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/aead/chacha20_poly1305_openssh.rs b/src/aead/chacha20_poly1305_openssh.rs index b8aa999fbc..015d41787d 100644 --- a/src/aead/chacha20_poly1305_openssh.rs +++ b/src/aead/chacha20_poly1305_openssh.rs @@ -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}; @@ -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), } } } diff --git a/src/polyfill/chunks_fixed.rs b/src/polyfill/chunks_fixed.rs index ac6f180640..4d3f703202 100644 --- a/src/polyfill/chunks_fixed.rs +++ b/src/polyfill/chunks_fixed.rs @@ -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);