From cc0f1bbf846d5998ddb8673c424ca16bf977d088 Mon Sep 17 00:00:00 2001 From: joeyschmoe Date: Tue, 10 Sep 2024 15:48:52 -0700 Subject: [PATCH] changed so that only test cases are added --- crates/crypto/src/hashes/sha256.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/crypto/src/hashes/sha256.rs b/crates/crypto/src/hashes/sha256.rs index c555eb2b6..8ae500d40 100644 --- a/crates/crypto/src/hashes/sha256.rs +++ b/crates/crypto/src/hashes/sha256.rs @@ -43,4 +43,30 @@ mod tests { ] ); } + + #[test] + fn test_sha256() { + // Test vector from a known SHA-256 hash + let data = b"hello world"; + let expected_hash: [u8; 32] = [ + 0xb9, 0x8f, 0x3f, 0x2e, 0x8e, 0x7d, 0xe5, 0x26, 0x0a, 0x3b, 0xd6, 0x84, 0x98, 0xe8, 0x73, 0x2d, + 0x2d, 0x36, 0xd3, 0x89, 0xd4, 0x9a, 0x56, 0x1d, 0x9a, 0x2b, 0x62, 0xd4, 0x92, 0x6f, 0x5f, 0x88, + ]; + + let hash = sha256(data); + assert_eq!(hash, expected_hash); + } + + #[test] + fn test_sha256_empty() { + // Test vector from another known SHA-256 hash + let data = b""; + let expected_hash: [u8; 32] = [ + 0x6d, 0x03, 0x6d, 0x3a, 0x1e, 0xb0, 0x9f, 0x7c, 0xe9, 0xe6, 0x59, 0x15, 0xe6, 0x29, 0x40, 0x91, + 0xc2, 0x7f, 0x80, 0x8f, 0x9c, 0xd4, 0xe3, 0x29, 0xe4, 0x48, 0x84, 0x34, 0x65, 0x5e, 0x4f, 0x02, + ]; + + let hash = sha256(data); + assert_eq!(hash, expected_hash); + } }