Skip to content

Commit

Permalink
Digest/Polyfill: Remove SHA-1 use of ChunksFixed and delete it.
Browse files Browse the repository at this point in the history
This is the last step in the removal of `ChunksFixed`, which contains
one line of `unsafe` code.
  • Loading branch information
briansmith committed Oct 13, 2023
1 parent f692025 commit e201e1f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 41 deletions.
15 changes: 8 additions & 7 deletions src/digest/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

use super::sha2::{ch, maj, Word};
use crate::{c, polyfill::ChunksFixed};
use crate::c;
use core::num::Wrapping;

pub const BLOCK_LEN: usize = 512 / 8;
Expand Down Expand Up @@ -63,11 +63,10 @@ fn block_data_order_(mut H: State, M: &[[<W32 as Word>::InputBytes; 16]]) -> Sta
let [a, b, c, d, e] = H;

// FIPS 180-4 6.1.2 Step 3 with constants and functions from FIPS 180-4 {4.1.1, 4.2.1}
let W: &[[W32; 20]; 4] = W.chunks_fixed();
let (a, b, c, d, e) = step3(a, b, c, d, e, W[0], Wrapping(0x5a827999), ch);
let (a, b, c, d, e) = step3(a, b, c, d, e, W[1], Wrapping(0x6ed9eba1), parity);
let (a, b, c, d, e) = step3(a, b, c, d, e, W[2], Wrapping(0x8f1bbcdc), maj);
let (a, b, c, d, e) = step3(a, b, c, d, e, W[3], Wrapping(0xca62c1d6), parity);
let (a, b, c, d, e) = step3(a, b, c, d, e, &W, 0, Wrapping(0x5a827999), ch);
let (a, b, c, d, e) = step3(a, b, c, d, e, &W, 20, Wrapping(0x6ed9eba1), parity);
let (a, b, c, d, e) = step3(a, b, c, d, e, &W, 40, Wrapping(0x8f1bbcdc), maj);
let (a, b, c, d, e) = step3(a, b, c, d, e, &W, 60, Wrapping(0xca62c1d6), parity);

// FIPS 180-4 6.1.2 Step 4
H[0] += a;
Expand All @@ -87,10 +86,12 @@ fn step3(
mut c: W32,
mut d: W32,
mut e: W32,
W: [W32; 20],
W: &[W32; 80],
t: usize,
k: W32,
f: impl Fn(W32, W32, W32) -> W32,
) -> (W32, W32, W32, W32, W32) {
let W = &W[t..(t + 20)];
for W_t in W.iter() {
let T = rotl(a, 5) + f(b, c, d) + e + k + W_t;
e = d;
Expand Down
5 changes: 1 addition & 4 deletions src/polyfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ pub fn usize_from_u32(x: u32) -> usize {
x as usize
}

#[macro_use]
mod chunks_fixed;

mod array_flat_map;
mod array_flatten;
mod array_split_map;
Expand All @@ -41,7 +38,7 @@ mod unwrap_const;

pub use self::{
array_flat_map::ArrayFlatMap, array_flatten::ArrayFlatten, array_split_map::ArraySplitMap,
chunks_fixed::*, unwrap_const::unwrap_const,
unwrap_const::unwrap_const,
};

#[cfg(feature = "alloc")]
Expand Down
30 changes: 0 additions & 30 deletions src/polyfill/chunks_fixed.rs

This file was deleted.

0 comments on commit e201e1f

Please sign in to comment.