-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update builder to use ImageGeneratorCrypto
Update builder so that all the image generation code uses the ImageGeneratorCrypto trait. This makes it easier to swap out the crypto implementation as needed for different integrations. This ensures the whole image build can use the same crypto library.
- Loading branch information
Showing
7 changed files
with
26 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
// Licensed under the Apache-2.0 license | ||
use sha2::{Digest, Sha256}; | ||
use caliptra_image_gen::ImageGeneratorCrypto; | ||
use caliptra_image_openssl::OsslCrypto; | ||
use std::io::{self, ErrorKind}; | ||
|
||
pub fn sha256_word_reversed(bytes: &[u8]) -> [u32; 8] { | ||
let mut sha = Sha256::new(); | ||
pub fn sha256_word_reversed(bytes: &[u8]) -> io::Result<[u32; 8]> { | ||
let crypto = OsslCrypto::default(); | ||
|
||
let mut reversed = Vec::<u8>::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()); | ||
reversed.extend_from_slice(&word.swap_bytes().to_le_bytes()); | ||
} | ||
let result_bytes = sha.finalize(); | ||
core::array::from_fn(|i| u32::from_be_bytes(result_bytes[i * 4..][..4].try_into().unwrap())) | ||
|
||
crypto | ||
.sha256_digest(&reversed) | ||
.map_err(|e| io::Error::new(ErrorKind::Other, e)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters