use sha3_const::Sha3_224;
use sha3_const::Sha3_256;
use sha3_const::Sha3_384;
use sha3_const::Sha3_512;
#[test]
fn sha3_224_empty_string() {
assert_eq!(
[
0x6b, 0x4e, 0x03, 0x42, 0x36, 0x67, 0xdb, 0xb7, 0x3b, 0x6e, 0x15, 0x45, 0x4f, 0x0e,
0xb1, 0xab, 0xd4, 0x59, 0x7f, 0x9a, 0x1b, 0x07, 0x8e, 0x3f, 0x5b, 0x5a, 0x6b, 0xc7
],
Sha3_224::new().finalize(),
);
}
#[test]
fn sha3_224_ascii() {
let output = Sha3_224::new()
.update(b"The quick brown fox jumps over the lazy dog")
.finalize();
assert_eq!(
[
0xd1, 0x5d, 0xad, 0xce, 0xaa, 0x4d, 0x5d, 0x7b, 0xb3, 0xb4, 0x8f, 0x44, 0x64, 0x21,
0xd5, 0x42, 0xe0, 0x8a, 0xd8, 0x88, 0x73, 0x05, 0xe2, 0x8d, 0x58, 0x33, 0x57, 0x95
],
output,
);
}
#[test]
fn sha3_224_utf8() {
let output = Sha3_224::new()
.update("訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一".as_bytes())
.finalize();
assert_eq!(
[
0x13, 0x5c, 0x13, 0xde, 0xb7, 0x1f, 0xdf, 0x6f, 0xb7, 0x7b, 0x52, 0xb7, 0x20, 0xc4,
0x3d, 0xdd, 0x6c, 0xe7, 0x46, 0x7f, 0x91, 0x47, 0xa7, 0x42, 0x48, 0x55, 0x71, 0x14
],
output,
);
}
#[test]
fn sha3_224_updates() {
let output = Sha3_224::new()
.update("訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸".as_bytes())
.update("完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。".as_bytes())
.finalize();
assert_eq!(
[
0xbd, 0x05, 0x58, 0x1e, 0x02, 0x44, 0x5c, 0x53, 0xe0, 0x5a, 0xad, 0x20, 0x14, 0xf6,
0xa3, 0x81, 0x9d, 0x77, 0xa9, 0xdf, 0xf9, 0x18, 0xb8, 0xc6, 0xbf, 0x60, 0xbd, 0x06
],
output,
);
}
#[test]
fn sha3_256_empty_string() {
assert_eq!(
[
0xa7, 0xff, 0xc6, 0xf8, 0xbf, 0x1e, 0xd7, 0x66, 0x51, 0xc1, 0x47, 0x56, 0xa0, 0x61,
0xd6, 0x62, 0xf5, 0x80, 0xff, 0x4d, 0xe4, 0x3b, 0x49, 0xfa, 0x82, 0xd8, 0x0a, 0x4b,
0x80, 0xf8, 0x43, 0x4a
],
Sha3_256::new().finalize(),
);
}
#[test]
fn sha3_256_ascii() {
let output = Sha3_256::new()
.update(b"The quick brown fox jumps over the lazy dog")
.finalize();
assert_eq!(
[
0x69, 0x07, 0x0d, 0xda, 0x01, 0x97, 0x5c, 0x8c, 0x12, 0x0c, 0x3a, 0xad, 0xa1, 0xb2,
0x82, 0x39, 0x4e, 0x7f, 0x03, 0x2f, 0xa9, 0xcf, 0x32, 0xf4, 0xcb, 0x22, 0x59, 0xa0,
0x89, 0x7d, 0xfc, 0x04
],
output,
);
}
#[test]
fn sha3_256_utf8() {
let output = Sha3_256::new()
.update("訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一".as_bytes())
.finalize();
assert_eq!(
[
0x4b, 0x2f, 0x36, 0xe4, 0x32, 0x0b, 0x86, 0xe6, 0xea, 0xd0, 0xad, 0x00, 0x1e, 0x47,
0xe6, 0xd9, 0xe7, 0xfc, 0xf0, 0x04, 0x4c, 0xd5, 0xa5, 0xfd, 0x65, 0x49, 0x0a, 0x63,
0x3c, 0x03, 0x72, 0xa4
],
output,
);
}
#[test]
fn sha3_256_updates() {
let output = Sha3_256::new()
.update("訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸".as_bytes())
.update("完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。".as_bytes())
.finalize();
assert_eq!(
[
0x55, 0x8a, 0x7f, 0x84, 0x3b, 0x1a, 0xc5, 0xe7, 0xa8, 0xbb, 0xef, 0x90, 0x35, 0x78,
0x76, 0xbc, 0xce, 0x06, 0x12, 0x99, 0x2d, 0x0d, 0xfa, 0x29, 0x07, 0xe9, 0x55, 0x21,
0x61, 0x2f, 0x50, 0x7f
],
output,
);
}
#[test]
fn sha3_384_empty_string() {
let hasher = Sha3_384::new();
let output = hasher.finalize();
assert_eq!(
[
0x0c, 0x63, 0xa7, 0x5b, 0x84, 0x5e, 0x4f, 0x7d, 0x01, 0x10, 0x7d, 0x85, 0x2e, 0x4c,
0x24, 0x85, 0xc5, 0x1a, 0x50, 0xaa, 0xaa, 0x94, 0xfc, 0x61, 0x99, 0x5e, 0x71, 0xbb,
0xee, 0x98, 0x3a, 0x2a, 0xc3, 0x71, 0x38, 0x31, 0x26, 0x4a, 0xdb, 0x47, 0xfb, 0x6b,
0xd1, 0xe0, 0x58, 0xd5, 0xf0, 0x04
],
output,
);
}
#[test]
fn sha3_384_ascii() {
let output = Sha3_384::new()
.update(b"The quick brown fox jumps over the lazy dog")
.finalize();
assert_eq!(
[
0x70, 0x63, 0x46, 0x5e, 0x08, 0xa9, 0x3b, 0xce, 0x31, 0xcd, 0x89, 0xd2, 0xe3, 0xca,
0x8f, 0x60, 0x24, 0x98, 0x69, 0x6e, 0x25, 0x35, 0x92, 0xed, 0x26, 0xf0, 0x7b, 0xf7,
0xe7, 0x03, 0xcf, 0x32, 0x85, 0x81, 0xe1, 0x47, 0x1a, 0x7b, 0xa7, 0xab, 0x11, 0x9b,
0x1a, 0x9e, 0xbd, 0xf8, 0xbe, 0x41
],
output,
);
}
#[test]
fn sha3_384_utf8() {
let output = Sha3_384::new()
.update("訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一".as_bytes())
.finalize();
assert_eq!(
[
0x7d, 0x0f, 0x80, 0xfe, 0x5c, 0x79, 0xa0, 0x4a, 0x2a, 0x37, 0xa3, 0x0a, 0x44, 0x0e,
0x0c, 0xc0, 0x68, 0xeb, 0x78, 0xfe, 0x6c, 0x31, 0x82, 0x24, 0x6e, 0xde, 0x29, 0x64,
0x5c, 0x14, 0x4b, 0x5d, 0x33, 0xc4, 0x46, 0x07, 0xcb, 0x2c, 0x31, 0x11, 0xba, 0x77,
0xff, 0xc6, 0x61, 0x07, 0xf1, 0xcd
],
output,
);
}
#[test]
fn sha3_384_updates() {
let output = Sha3_384::new()
.update("訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸".as_bytes())
.update("完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。".as_bytes())
.finalize();
assert_eq!(
[
0xe3, 0x44, 0xb9, 0x5c, 0x6a, 0x96, 0x1a, 0x27, 0x79, 0x3e, 0xff, 0x00, 0xfa, 0x51,
0x03, 0xef, 0x78, 0xb4, 0x18, 0x0f, 0xe4, 0x1c, 0x93, 0xfc, 0x60, 0xa3, 0x1a, 0xff,
0x49, 0xb3, 0xb5, 0xe9, 0x5a, 0x92, 0xc8, 0x4f, 0xda, 0x9a, 0x6c, 0x80, 0xfa, 0x40,
0x3b, 0x7d, 0xf5, 0x8d, 0xb5, 0x9f
],
output,
);
}
#[test]
fn sha3_512_empty_string() {
let hasher = Sha3_512::new();
let output = hasher.finalize();
assert_eq!(
[
0xa6, 0x9f, 0x73, 0xcc, 0xa2, 0x3a, 0x9a, 0xc5, 0xc8, 0xb5, 0x67, 0xdc, 0x18, 0x5a,
0x75, 0x6e, 0x97, 0xc9, 0x82, 0x16, 0x4f, 0xe2, 0x58, 0x59, 0xe0, 0xd1, 0xdc, 0xc1,
0x47, 0x5c, 0x80, 0xa6, 0x15, 0xb2, 0x12, 0x3a, 0xf1, 0xf5, 0xf9, 0x4c, 0x11, 0xe3,
0xe9, 0x40, 0x2c, 0x3a, 0xc5, 0x58, 0xf5, 0x00, 0x19, 0x9d, 0x95, 0xb6, 0xd3, 0xe3,
0x01, 0x75, 0x85, 0x86, 0x28, 0x1d, 0xcd, 0x26,
],
output,
);
}
#[test]
fn sha3_512_ascii() {
let output = Sha3_512::new()
.update(b"The quick brown fox jumps over the lazy dog")
.finalize();
assert_eq!(
[
0x01, 0xde, 0xdd, 0x5d, 0xe4, 0xef, 0x14, 0x64, 0x24, 0x45, 0xba, 0x5f, 0x5b, 0x97,
0xc1, 0x5e, 0x47, 0xb9, 0xad, 0x93, 0x13, 0x26, 0xe4, 0xb0, 0x72, 0x7c, 0xd9, 0x4c,
0xef, 0xc4, 0x4f, 0xff, 0x23, 0xf0, 0x7b, 0xf5, 0x43, 0x13, 0x99, 0x39, 0xb4, 0x91,
0x28, 0xca, 0xf4, 0x36, 0xdc, 0x1b, 0xde, 0xe5, 0x4f, 0xcb, 0x24, 0x02, 0x3a, 0x08,
0xd9, 0x40, 0x3f, 0x9b, 0x4b, 0xf0, 0xd4, 0x50
],
output,
);
}
#[test]
fn sha3_512_utf8() {
let output = Sha3_512::new()
.update("訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一".as_bytes())
.finalize();
assert_eq!(
[
0xac, 0xcb, 0x12, 0x7b, 0xb2, 0x4b, 0x0f, 0xfb, 0xb7, 0x55, 0x0d, 0xc6, 0x37, 0x22,
0x2d, 0x2f, 0x78, 0x53, 0x8a, 0x8a, 0x18, 0x6c, 0x98, 0xbc, 0x5e, 0xfd, 0xad, 0x68,
0x5b, 0x9b, 0x39, 0x66, 0x39, 0xf3, 0x41, 0x48, 0xbf, 0x0b, 0x94, 0xed, 0x47, 0x0f,
0x0e, 0x9c, 0x36, 0x65, 0xdc, 0x3b, 0x4c, 0x1c, 0xb3, 0x21, 0xba, 0xcd, 0x32, 0xdd,
0x31, 0x7a, 0x64, 0x62, 0x95, 0xe0, 0x73, 0xd9,
],
output,
);
}
#[test]
fn sha3_512_updates() {
let output = Sha3_512::new()
.update("訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸".as_bytes())
.update("完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。".as_bytes())
.finalize();
assert_eq!(
[
0x5b, 0x70, 0xea, 0xad, 0x08, 0x3f, 0x1b, 0x86, 0xfd, 0x53, 0x5b, 0x68, 0x12, 0xe0,
0x2f, 0x5f, 0x28, 0x76, 0xa4, 0xbd, 0x8b, 0x43, 0xae, 0xde, 0x8d, 0x62, 0xae, 0x71,
0xbb, 0x17, 0x43, 0xeb, 0xd9, 0x19, 0xdc, 0x41, 0xbe, 0x56, 0xd7, 0x3b, 0xa4, 0x5b,
0x67, 0xb2, 0x87, 0x6f, 0xf2, 0x15, 0xd0, 0x57, 0x57, 0x88, 0x56, 0x0e, 0x7b, 0x0c,
0x92, 0xb8, 0x79, 0xf8, 0xa2, 0xfc, 0x31, 0x11
],
output,
);
}