From b4f3e284b4f09f41855ed687af36dc3ccdcc99f2 Mon Sep 17 00:00:00 2001 From: Sree Revoori Date: Thu, 4 Apr 2024 21:53:19 +0000 Subject: [PATCH] Use sha2 instead of openssl to hash in builder --- Cargo.lock | 2 +- builder/Cargo.toml | 2 +- builder/src/sha256.rs | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3af7bf523f..c700493d2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -232,7 +232,7 @@ dependencies = [ "hex", "nix 0.26.2", "once_cell", - "openssl", + "sha2", "zerocopy", ] diff --git a/builder/Cargo.toml b/builder/Cargo.toml index 2519ca16ac..e76960fb83 100644 --- a/builder/Cargo.toml +++ b/builder/Cargo.toml @@ -19,8 +19,8 @@ elf.workspace = true hex.workspace = true nix.workspace = true once_cell.workspace = true -openssl.workspace = true zerocopy.workspace = true +sha2.workspace = true [features] slow_tests = [] diff --git a/builder/src/sha256.rs b/builder/src/sha256.rs index 40da04324d..03cfecbce9 100644 --- a/builder/src/sha256.rs +++ b/builder/src/sha256.rs @@ -1,11 +1,12 @@ // Licensed under the Apache-2.0 license +use sha2::{Digest, Sha256}; pub fn sha256_word_reversed(bytes: &[u8]) -> [u32; 8] { - let mut sha = openssl::sha::Sha256::new(); + let mut sha = Sha256::new(); for i in 0..bytes.len() / 4 { let word = u32::from_le_bytes(bytes[i * 4..][..4].try_into().unwrap()); - sha.update(&word.swap_bytes().to_le_bytes()); + sha.update(word.swap_bytes().to_le_bytes()); } - let result_bytes = sha.finish(); + let result_bytes = sha.finalize(); core::array::from_fn(|i| u32::from_be_bytes(result_bytes[i * 4..][..4].try_into().unwrap())) }