Created
January 25, 2024 14:58
-
-
Save akashin/b4e3c6f08a4b877cb88bcab2fd424710 to your computer and use it in GitHub Desktop.
SHA256
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
#![no_main] | |
#![no_std] | |
use panic_halt as _; | |
use sha2::{Digest, Sha256}; | |
extern "C" { | |
fn assert_eq_i64(actual: u64, expected: u64); | |
} | |
// fn assert_eq_i64(actual: u64, expected: u64) { | |
// assert_eq!(actual, expected); | |
// } | |
fn assert_eq_array(expected: &[u8], actual: &[u8]) { | |
for i in 0..32 { | |
unsafe { | |
assert_eq_i64(expected[i] as u64, actual[i] as u64); | |
} | |
} | |
} | |
#[no_mangle] | |
pub fn main() { | |
let hash = Sha256::digest(b"Hello, world!"); | |
let expected = [ | |
49, 95, 91, 219, 118, 208, 120, 196, 59, 138, 192, 6, 78, 74, 1, 100, 97, 43, 31, 206, 119, | |
200, 105, 52, 91, 252, 148, 199, 88, 148, 237, 211, | |
]; | |
assert_eq_array(&expected, &hash) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment