Skip to content

Commit

Permalink
Use sha2 instead of openssl to hash in builder
Browse files Browse the repository at this point in the history
  • Loading branch information
sree-revoori1 authored and jhand2 committed Apr 4, 2024
1 parent 85c4b01 commit b4f3e28
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
7 changes: 4 additions & 3 deletions builder/src/sha256.rs
Original file line number Diff line number Diff line change
@@ -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()))
}

0 comments on commit b4f3e28

Please sign in to comment.