use sha3::{
Shake128, Shake128Reader, Shake256, Shake256Reader,
digest::{ExtendableOutput, Update, XofReader},
};
use crate::utils::Reader;
pub(crate) trait RandomOracle {
type Hasher<const SEP: u8>: Hasher + Default + Clone;
fn h0_init() -> Self::Hasher<0> {
Self::Hasher::default()
}
fn h1_init() -> Self::Hasher<1> {
Self::Hasher::default()
}
fn h2_0_init() -> Self::Hasher<8> {
Self::Hasher::default()
}
fn h2_1_init() -> Self::Hasher<9> {
Self::Hasher::default()
}
fn h2_2_init() -> Self::Hasher<10> {
Self::Hasher::default()
}
fn h2_3_init() -> Self::Hasher<11> {
Self::Hasher::default()
}
fn h3_init() -> Self::Hasher<3> {
Self::Hasher::default()
}
fn h4_init() -> Self::Hasher<4> {
Self::Hasher::default()
}
}
pub(crate) trait Hasher {
type Reader: Reader;
fn update(&mut self, data: &[u8]);
fn finish(self) -> Self::Reader;
}
pub(crate) struct RandomOracleShake128 {}
#[derive(Debug, Default, Clone)]
pub(crate) struct Hasher128<const SEP: u8> {
hasher: Shake128,
}
pub(crate) struct Hasher128Reader(Shake128Reader);
impl Reader for Hasher128Reader {
fn read(&mut self, dst: &mut [u8]) {
self.0.read(dst);
}
}
impl RandomOracle for RandomOracleShake128 {
type Hasher<const SEP: u8> = Hasher128<SEP>;
}
impl<const SEP: u8> Hasher for Hasher128<SEP> {
type Reader = Hasher128Reader;
fn update(&mut self, data: &[u8]) {
self.hasher.update(data);
}
fn finish(mut self) -> Self::Reader {
self.hasher.update(&[SEP]);
Hasher128Reader(self.hasher.finalize_xof())
}
}
impl<const SEP: u8> Hasher for Hasher256<SEP> {
type Reader = Hasher256Reader;
fn update(&mut self, data: &[u8]) {
self.hasher.update(data);
}
fn finish(mut self) -> Self::Reader {
self.hasher.update(&[SEP]);
Hasher256Reader(self.hasher.finalize_xof())
}
}
pub(crate) struct RandomOracleShake256 {}
#[derive(Debug, Default, Clone)]
pub(crate) struct Hasher256<const SEP: u8> {
hasher: Shake256,
}
pub(crate) struct Hasher256Reader(Shake256Reader);
impl Reader for Hasher256Reader {
fn read(&mut self, dst: &mut [u8]) {
self.0.read(dst);
}
}
impl RandomOracle for RandomOracleShake256 {
type Hasher<const SEP: u8> = Hasher256<SEP>;
}
#[cfg(test)]
mod test {
use super::*;
#[cfg(not(feature = "std"))]
use alloc::vec;
fn verify(mut hasher: impl Hasher, input: &[u8], output: &[u8]) {
hasher.update(input);
let mut reader = hasher.finish();
let mut res = vec![0; output.len()];
reader.read(&mut res);
assert_eq!(res, output);
}
#[test]
fn test_h0_128() {
let input = [
0xe1, 0x52, 0x3a, 0x89, 0x80, 0xc1, 0x62, 0x83, 0xcb, 0xc8, 0x5e, 0x71, 0x70, 0x3a,
0x04, 0xd1,
];
let output = [
0xcb, 0xbf, 0x57, 0xa9, 0x0b, 0x61, 0x87, 0x53, 0xc6, 0x97, 0x04, 0x23, 0xe7, 0x0c,
0x5f, 0x23, 0x06, 0x07, 0xfe, 0x36, 0x71, 0x99, 0xe5, 0x2a, 0x87, 0x5d, 0x50, 0x69,
0x74, 0xb3, 0x2b, 0xda, 0x4b, 0xca, 0x01, 0xfc, 0x29, 0x60, 0x18, 0xd6, 0xf1, 0x14,
0x6d, 0x59, 0x47, 0x4b, 0x79, 0x43,
];
let hasher = RandomOracleShake128::h0_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h0_256() {
let input = [
0xd7, 0xfc, 0xc8, 0xac, 0x79, 0x23, 0xae, 0x97, 0x1b, 0x08, 0xc7, 0xa2, 0xfc, 0x1f,
0x0a, 0x81,
];
let output = [
0xaa, 0x9d, 0x0a, 0xb0, 0x35, 0x9d, 0x51, 0xd9, 0xea, 0x43, 0x03, 0xe8, 0x49, 0xf5,
0xa3, 0xb7, 0x63, 0xb0, 0xb7, 0xe5, 0xf4, 0xf4, 0x70, 0x06, 0xa8, 0x6b, 0x93, 0x76,
0xa0, 0x5b, 0x82, 0xda, 0x65, 0x1e, 0xb2, 0x5a, 0xa7, 0xd9, 0x3a, 0x12, 0x44, 0x58,
0x69, 0x94, 0x9c, 0xd4, 0x42, 0x81, 0x38, 0xa2, 0x18, 0x99, 0xc0, 0x59, 0xc2, 0x0b,
0x4d, 0x35, 0x6e, 0x38, 0xae, 0x83, 0x48, 0x40, 0xfe, 0x47, 0x00, 0x2f, 0x91, 0xf3,
0x44, 0x2f, 0x5a, 0x32, 0x9a, 0x26, 0x2e, 0x5b, 0x50, 0xab, 0x97, 0xfe, 0xd4, 0x57,
0x8c, 0x00, 0xed, 0x7f, 0x3b, 0xe7, 0xfb, 0xb9, 0x10, 0xde, 0x8f, 0x0c,
];
let hasher = RandomOracleShake256::h0_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h1_128() {
let input = [
0xd2, 0x33, 0x1c, 0x8b, 0xd9, 0x1b, 0x1e, 0x01, 0x56, 0x59, 0x09, 0x44, 0x47, 0x2d,
0x2d, 0xd3,
];
let output = [
0x93, 0xe3, 0x5f, 0xee, 0x73, 0x82, 0xc6, 0xce, 0x22, 0xe9, 0x34, 0x49, 0x4a, 0xbf,
0x2c, 0x90, 0x1c, 0x58, 0xb5, 0x1a, 0xa3, 0x40, 0x24, 0x24, 0xd2, 0x7d, 0xa5, 0x8e,
0x5c, 0x4f, 0xdd, 0xd9,
];
let hasher = RandomOracleShake128::h1_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h1_256() {
let input = [
0xd5, 0xb2, 0x51, 0x15, 0xaa, 0x4c, 0x5b, 0x3c, 0x1a, 0x96, 0x20, 0x95, 0xcd, 0xdb,
0x31, 0xba,
];
let output = [
0x89, 0x7e, 0x86, 0xb9, 0x69, 0x7f, 0x4c, 0x2d, 0x6b, 0x26, 0x76, 0x71, 0xf2, 0x43,
0x19, 0x57, 0x01, 0x27, 0x16, 0x2b, 0x3b, 0xd5, 0xf5, 0x6d, 0x30, 0x49, 0xc4, 0x5c,
0x02, 0x42, 0x0b, 0xd0, 0x56, 0xbe, 0x22, 0xf4, 0xa0, 0x56, 0xd4, 0xa5, 0x1f, 0xb1,
0xe8, 0x25, 0x53, 0x43, 0x13, 0x7e, 0xe4, 0x5f, 0x12, 0xc7, 0x34, 0x77, 0x4a, 0x4c,
0xbc, 0xe7, 0x35, 0xd0, 0xb6, 0x74, 0x6d, 0x01,
];
let hasher = RandomOracleShake256::h1_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h2_0_128() {
let input = [
0x46, 0x2c, 0x15, 0x0b, 0x96, 0xcb, 0x0e, 0xc4, 0x07, 0x1a, 0x05, 0x46, 0x74, 0xcd,
0x35, 0x2e, 0xd4, 0xda, 0x35, 0x33, 0x8b, 0xea, 0x59, 0xad, 0x66, 0x06, 0x08, 0xc1,
0x2f, 0x86, 0xe8, 0xeb, 0x59, 0x47, 0x75, 0xa7, 0x31, 0xdf, 0x92, 0x8c, 0x81, 0x9b,
0x2d, 0x2a, 0xe2, 0xd8, 0x95, 0x9c,
];
let output = [
0x8a, 0xf9, 0x90, 0xd0, 0x3e, 0xcd, 0xc1, 0x0e, 0xbf, 0x71, 0x16, 0x9f, 0x2e, 0x2d,
0x1d, 0xa7, 0xcb, 0x66, 0x1a, 0x44, 0xc9, 0x38, 0xc7, 0xcd, 0x01, 0x1a, 0x2a, 0x21,
0x3f, 0xb6, 0xbd, 0x52,
];
let hasher = RandomOracleShake128::h2_0_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h2_0_256() {
let input = [
0xc0, 0x84, 0xc7, 0xfd, 0xf5, 0x98, 0x10, 0x76, 0xac, 0x49, 0xfa, 0x76, 0xb1, 0xb6,
0x28, 0x15, 0xb9, 0xce, 0xb2, 0xc6, 0xd8, 0x54, 0x6a, 0xcf, 0x26, 0x75, 0x79, 0x7e,
0xdb, 0xc7, 0xc2, 0x57, 0xe5, 0xca, 0xea, 0x36, 0x99, 0xe1, 0xe7, 0x98, 0xbf, 0x7d,
0xc8, 0x1c, 0x1d, 0x89, 0x10, 0x29, 0xe6, 0x28, 0xe7, 0x77, 0x13, 0xa1, 0xd3, 0xe9,
0xa9, 0xad, 0x82, 0x6c, 0xff, 0x77, 0x21, 0x2b, 0xb2, 0x7b, 0x5a, 0xf4, 0x89, 0x36,
0x8f, 0x32, 0xf5, 0x7a, 0xe9, 0xd1, 0x0c, 0xfc, 0x2d, 0xec, 0x7b, 0x97, 0x0e, 0x06,
0x3f, 0x85, 0xdd, 0x46, 0x66, 0x39, 0xfc, 0x80, 0x07, 0x4c, 0x19, 0x4b,
];
let output = [
0xa2, 0xe0, 0x31, 0xd8, 0xc4, 0xe6, 0xc6, 0x4b, 0xff, 0x74, 0xa7, 0x37, 0xe3, 0x3b,
0x82, 0xdf, 0xf2, 0x06, 0xce, 0x82, 0x59, 0xda, 0xd2, 0x0b, 0xda, 0x68, 0xbb, 0xe1,
0xb0, 0x59, 0xc2, 0x69, 0x82, 0xa9, 0xfe, 0xa8, 0x84, 0xb0, 0x0d, 0x0e, 0x34, 0xe9,
0xaa, 0xa1, 0xcc, 0x20, 0x85, 0x6d, 0x70, 0xfa, 0x60, 0xc8, 0x3a, 0x25, 0x87, 0xcc,
0x68, 0x94, 0xf0, 0x18, 0x94, 0x50, 0xec, 0xa5,
];
let hasher = RandomOracleShake256::h2_0_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h2_1_128() {
let input = [
0x2a, 0x52, 0xca, 0x6f, 0x92, 0xb7, 0xb1, 0x8e, 0x4c, 0x58, 0x01, 0xda, 0x83, 0xd0,
0x6d, 0x44, 0x1a, 0x84, 0x89, 0xec, 0xb9, 0xb9, 0xe0, 0xb0, 0xd2, 0xe1, 0x15, 0x79,
0x77, 0x10, 0x74, 0xf1, 0xab, 0x33, 0x81, 0x46, 0x57, 0xc2, 0xb4, 0x39, 0x53, 0x43,
0xf1, 0x42, 0x9a, 0xe5, 0xf2, 0x87, 0x70, 0x99, 0x40, 0xc3, 0x2d, 0x74, 0x72, 0x49,
0x8d, 0x3e, 0x71, 0xc7, 0xa6, 0x5b, 0x6d, 0x52, 0xff, 0x54, 0x3c, 0xf8, 0xe5, 0x33,
0x41, 0xe5, 0x59, 0x06, 0xea, 0x2c, 0xcd, 0x96, 0x08, 0x2f, 0x54, 0x2f, 0xe8, 0xb2,
0x31, 0x46, 0x4d, 0x83, 0xb8, 0x86, 0xa2, 0xf1, 0x6d, 0xa8, 0xce, 0xe0,
];
let output = [
0xf1, 0xd0, 0x11, 0x0e, 0xfc, 0x8e, 0x48, 0x32, 0x31, 0xd2, 0xb2, 0x82, 0x73, 0x1f,
0xee, 0x4e, 0x36, 0xa7, 0x69, 0xbd, 0x5b, 0x41, 0x43, 0xdc, 0xce, 0x73, 0x0d, 0xfc,
0xa4, 0x38, 0x63, 0x25, 0xc9, 0x1a, 0x82, 0x71, 0x9d, 0x1b, 0x2c, 0xb0, 0x11, 0xb8,
0x93, 0xab, 0xa9, 0x44, 0x8b, 0x1d, 0xd7, 0x91, 0x48, 0xba, 0xfd, 0xcf, 0xc6, 0x9d,
0x26, 0x94, 0x33, 0x8b, 0xd2, 0x2a, 0xd1, 0x16, 0xc4, 0xe2, 0x46, 0x99, 0x4b, 0x2d,
0xde, 0x0b, 0x5f, 0x57, 0x24, 0xf8, 0x79, 0x6b, 0xf1, 0x50, 0x8b, 0x03, 0x8f, 0x37,
0x67, 0xc4, 0x71, 0x51,
];
let hasher = RandomOracleShake128::h2_1_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h2_1_256() {
let input = [
0xbf, 0xbb, 0x6c, 0x34, 0xe9, 0xc8, 0xd6, 0xa4, 0xa9, 0xc9, 0x06, 0x4e, 0x9f, 0x17,
0xa0, 0x1a, 0xdb, 0xbc, 0x39, 0xc1, 0xa5, 0xee, 0xd8, 0x83, 0xb1, 0x93, 0x2d, 0xe2,
0xa9, 0xfe, 0xec, 0x28, 0xf6, 0x73, 0x7b, 0x30, 0x90, 0xce, 0x01, 0x20, 0x46, 0xb4,
0x8e, 0xe9, 0xe0, 0x77, 0xe8, 0xe7, 0xa7, 0xf1, 0x94, 0x92, 0x81, 0x7a, 0xe7, 0x80,
0x3a, 0x40, 0x1e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26, 0xd7, 0x6e, 0x9c, 0x41,
0x97, 0x89, 0x33, 0x73, 0x34, 0x47, 0xf6, 0xb9, 0x51, 0xb7, 0x7d, 0xd8, 0x89, 0x9f,
0x91, 0x3e, 0x63, 0x41, 0x84, 0x95, 0xe2, 0x01, 0xd5, 0x81, 0xd9, 0xe8, 0x99, 0x7b,
0xc4, 0x70, 0xf5, 0xc3, 0x7e, 0x33, 0x11, 0xb3, 0x61, 0x42, 0xe6, 0x13, 0x72, 0x21,
0x8f, 0x52, 0xe6, 0x20, 0xb0, 0xd9, 0x90, 0x30, 0x5f, 0x6f, 0xba, 0x9d, 0x71, 0xe5,
0x6d, 0x3b, 0xca, 0x67, 0x8f, 0xdf, 0x9d, 0xfd, 0x2e, 0xf9, 0x38, 0x35, 0x9e, 0x4a,
0xe9, 0x3c, 0x4d, 0x07, 0xf7, 0x94, 0x3c, 0xda, 0x18, 0x7f, 0xb9, 0x0b, 0x91, 0xb4,
0xb9, 0x81, 0x4a, 0x53, 0xef, 0x80, 0xc2, 0x55, 0x19, 0xc7, 0x03, 0x06, 0x37, 0x70,
];
let hasher = RandomOracleShake256::h2_1_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h2_2_128() {
let input = [
0x61, 0xcf, 0xa6, 0x5d, 0x01, 0x6d, 0xa4, 0x5b, 0x95, 0xba, 0x06, 0x97, 0xf0, 0xa1,
0xb7, 0x36, 0x09, 0x9a, 0x50, 0xb6, 0xf2, 0x19, 0xab, 0xab, 0xdc, 0x45, 0x3c, 0x2e,
0x2a, 0xae, 0xd1, 0xe1, 0x02, 0xdd, 0xa9, 0x72, 0xbe, 0xbc, 0x85, 0xed, 0x38, 0xe8,
0x9b, 0x68, 0x7c, 0x74, 0x50, 0x5e, 0x15, 0x83, 0x3a, 0x73, 0x12, 0x07, 0x9f, 0x77,
0xb1, 0x77, 0x06, 0x1e, 0x0c, 0x9b, 0x54, 0x6a, 0x10, 0xd3, 0x3e, 0xb0, 0x9a, 0xbc,
0x41, 0x8a, 0x73, 0x79, 0x87, 0x40, 0x42, 0x84, 0xea, 0x0d, 0x08, 0x0b, 0x79, 0x40,
0xd9, 0x13, 0x91, 0x3b, 0x1d, 0x59, 0xf3, 0x66, 0x1e, 0xe3, 0xbe, 0x75, 0xe5, 0xfb,
0x28, 0xec, 0x8f, 0x59, 0x44, 0x26, 0x74, 0x47, 0xc3, 0xa4, 0x3d, 0xf5, 0x2b, 0xa3,
0x47, 0x42, 0x72, 0x18, 0x7b, 0x21, 0x7d, 0xfd, 0x68, 0xda, 0x72, 0x44, 0xd0, 0x29,
0x06, 0xd0,
];
let output = [
0x24, 0x1e, 0x1e, 0x89, 0x24, 0xa9, 0x69, 0xc6, 0xa5, 0x05, 0x01, 0x25, 0x32, 0xe1,
0xce, 0xeb, 0xc6, 0x56, 0x61, 0x8b, 0x8d, 0x41, 0x7d, 0xa2, 0x09, 0xc2, 0x20, 0xfc,
0x6c, 0x75, 0xac, 0xaf, 0x06, 0x66, 0x71, 0xe3, 0xd9, 0xd3, 0xbc, 0xed, 0xef, 0x45,
0x9e, 0x23, 0x44, 0x15, 0x64, 0xa2, 0x4e, 0xb7, 0x39, 0xa6, 0xe0, 0x49, 0xda, 0x6b,
];
let hasher = RandomOracleShake128::h2_2_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h2_2_256() {
let input = [
0x52, 0x20, 0x08, 0x66, 0xe1, 0x1b, 0x7a, 0xe3, 0x0d, 0xc8, 0xa1, 0xf2, 0x86, 0xbf,
0x94, 0xa5, 0x77, 0x3f, 0xce, 0xff, 0x71, 0x78, 0xcd, 0x66, 0x1d, 0x95, 0x75, 0x1f,
0xaa, 0x07, 0x3b, 0x30, 0x75, 0x4d, 0xdb, 0xc4, 0x8d, 0x9e, 0xbe, 0xc4, 0xca, 0xd2,
0xed, 0x91, 0xa9, 0xff, 0x60, 0x65, 0x2d, 0x2d, 0x08, 0x02, 0x74, 0xf9, 0xd7, 0xd7,
0xfd, 0xa8, 0x5f, 0x81, 0xbb, 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0x45, 0x25, 0xac, 0xfc, 0x64,
0xf1, 0x6a, 0xe6, 0xbf,
];
let output = [
0x0f, 0x03, 0xc0, 0xe7, 0x61, 0x79, 0x3e, 0xf2, 0x5c, 0x6b, 0x33, 0xbe, 0x8d, 0x42,
0x47, 0x70, 0x80, 0xac, 0x0d, 0x50, 0x55, 0xc6, 0x70, 0xd6, 0xb7, 0x8e, 0x81, 0x85,
0x10, 0xb6, 0xa2, 0x00, 0xb5, 0x6c, 0x02, 0x67, 0x3f, 0x8a, 0xb7, 0x29, 0x62, 0x95,
0xa1, 0xb7, 0xc0, 0xd0, 0x29, 0x6e, 0x41, 0x16, 0x47, 0xf7, 0x70, 0xbc, 0x32, 0xa7,
0xce, 0xbb, 0x7f, 0x6f, 0xad, 0x2c, 0x92, 0x07, 0x4c, 0x32, 0xf8, 0x65, 0x57, 0x52,
0x5a, 0x31, 0x9f, 0x32, 0xf6, 0x38, 0x58, 0x6a, 0x6c, 0x94, 0x8c, 0xa8, 0xf6, 0xa0,
0x2f, 0x9e, 0x8e, 0xd5, 0x1b, 0x17, 0x1c, 0x22, 0x8d, 0x49, 0x8f, 0x8f, 0x46, 0xab,
0xb0, 0x24, 0xc5, 0xb5, 0xa6, 0xb8,
];
let hasher = RandomOracleShake256::h2_2_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h2_3_128() {
let input = [
0x10, 0xf0, 0xca, 0x30, 0xbe, 0x9c, 0x04, 0xa8, 0x7d, 0xb4, 0xd9, 0xe8, 0xab, 0xac,
0xa2, 0xa3, 0x9c, 0x66, 0xe3, 0xf8, 0x77, 0x45, 0x51, 0x50, 0xc7, 0xb7, 0xc3, 0x39,
0x06, 0x6c, 0xf7, 0xf9, 0x08, 0x7d, 0xf2, 0x95, 0xb2, 0x0c, 0x14, 0xb0, 0x50, 0x7b,
0x07, 0xc9, 0xba, 0x32, 0xb9, 0xc1, 0xe0, 0xd3, 0x95, 0x67, 0xc3, 0xb1, 0xde, 0x56,
0xa0, 0x1d, 0x1e, 0xb8, 0x39, 0xc4, 0xfa, 0x16, 0xef, 0x16, 0xc8, 0x72, 0x89, 0xc7,
0xdd, 0x28, 0x00, 0x62, 0x1f, 0x3d, 0x4c, 0x4a, 0x3a, 0x54, 0x22, 0xe1, 0xc1, 0x9e,
0xb6, 0xec, 0xa3, 0xb8, 0xc8, 0x9d, 0x42, 0x93, 0x0f, 0x67, 0x09, 0x38, 0xeb, 0x5d,
0x6a, 0xa9, 0x44, 0x64, 0xe4, 0x50, 0xb7, 0x71, 0x7c, 0xa0,
];
let output = [
0x37, 0xfd, 0x54, 0xb1, 0x3b, 0x2b, 0xe1, 0xaf, 0xe1, 0x31, 0x42, 0x0e, 0x0c, 0x07,
0xd8, 0xad,
];
let hasher = RandomOracleShake128::h2_3_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h2_3_256() {
let input = [
0x0a, 0xe0, 0xd7, 0xbe, 0xd3, 0xb7, 0x5d, 0x3d, 0xc4, 0xcd, 0xad, 0xb5, 0xdb, 0xaf,
0x4f, 0x13, 0x2d, 0xd8, 0x20, 0x1d, 0xd7, 0xe7, 0xce, 0x69, 0x0d, 0x25, 0xf8, 0x12,
0x43, 0xfa, 0x74, 0x27, 0xbd, 0x3f, 0x55, 0x91, 0xe3, 0xeb, 0x9f, 0x21, 0xc6, 0xbe,
0xbe, 0x09, 0x91, 0x03, 0x75, 0xf4, 0x42, 0x63, 0xfe, 0x0a, 0xa8, 0x57, 0xe1, 0x61,
0xdd, 0xb7, 0x1d, 0x38, 0xcc, 0x9e, 0x5a, 0xef, 0x2e, 0x95, 0xff, 0x93, 0x8e, 0x72,
0x26, 0x7f, 0x85, 0x1f, 0x24, 0x2a, 0xbc, 0x1a, 0x43, 0xc6, 0x3d, 0x1d, 0x3e, 0xc9,
0xf0, 0x8c, 0xad, 0xb2, 0x7d, 0x7d, 0x8c, 0x33, 0x2d, 0x3d, 0xe4, 0xed, 0xaf, 0x48,
0x62, 0x0f, 0x7e, 0xd5, 0x29, 0x6b, 0x67, 0x2d, 0xa1, 0x8d, 0x10, 0x3a, 0x81, 0xf2,
0xc4, 0xb5, 0x0b, 0x0f, 0xa8, 0xa9, 0x0d, 0xa1, 0x48, 0x3c, 0x67, 0xc0, 0x4c, 0x9d,
0x1f, 0xfa, 0x39, 0x1c, 0x48, 0xba, 0xe3, 0xa5, 0x34, 0xf9, 0x89, 0xe0, 0x72, 0x33,
0x67, 0x99, 0x6d, 0x3a, 0x76, 0xe5, 0xaf, 0xc5, 0xa2, 0x35, 0x1e, 0xcb, 0x5c, 0x47,
0xc8, 0x7a, 0x2f, 0x33, 0x4b, 0x2c, 0x91, 0x36, 0x3d, 0xfb, 0xb1, 0x7f, 0xf9, 0xe4,
0x12, 0x2f, 0x02, 0xb8, 0x3f, 0xb9, 0xe6, 0x69, 0xc6, 0xa4, 0xcd, 0x2e, 0xca, 0x29,
0x99, 0xcd, 0x17, 0xff, 0xbb, 0xdc, 0x7d, 0x53, 0x4b, 0xf9, 0x56, 0xc6, 0xa7, 0x1d,
0x90, 0xdd, 0xa9, 0xf2, 0xda, 0x98, 0xf6, 0xac,
];
let output = [
0x76, 0x38, 0x46, 0x6e, 0xb5, 0xad, 0xf5, 0xf2, 0xed, 0x55, 0x67, 0x09, 0xa7, 0xa2,
0x7c, 0x22, 0xcb, 0xe6, 0x92, 0x61, 0x8c, 0x47, 0x43, 0x9f, 0x62, 0x9a, 0x75, 0xcc,
0x3d, 0x07, 0xe2, 0x18,
];
let hasher = RandomOracleShake256::h2_3_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h3_128() {
let input = [
0x56, 0xb7, 0xfc, 0xbb, 0x3f, 0xa1, 0x2b, 0xc2, 0x67, 0xec, 0x1d, 0x42, 0x9a, 0xf8,
0x2d, 0xdf, 0xf0, 0x94, 0x74, 0xb7, 0x06, 0x57, 0xcf, 0x61, 0xcb, 0x68, 0xec, 0x70,
0x13, 0xf0, 0x52, 0x00, 0x7f, 0xb9, 0xeb, 0xd7, 0x24, 0xd1, 0xc6, 0xc9, 0x88, 0x6a,
0x8e, 0xed, 0x45, 0xcd, 0x66, 0x7e, 0xb5, 0x9b, 0xa4, 0xac, 0x91, 0xb9, 0x89, 0x78,
0xf7, 0xab, 0x54, 0x13, 0x30, 0xe6, 0x3d, 0x47,
];
let output = [
0xfb, 0xf3, 0xbe, 0xc0, 0x9d, 0x99, 0x68, 0x17, 0x4c, 0x85, 0x92, 0x47, 0xbe, 0x3f,
0x60, 0xb9, 0x97, 0x1e, 0xa8, 0x29, 0x32, 0xea, 0xae, 0x36, 0x2e, 0xb6, 0xe9, 0x7d,
0xb6, 0xbd, 0x5d, 0x3a,
];
let hasher = RandomOracleShake128::h3_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h3_256() {
let input = [
0x6f, 0x35, 0xd9, 0x66, 0xa9, 0x79, 0x23, 0x24, 0xc7, 0xfb, 0x72, 0xc8, 0x9a, 0x11,
0x78, 0x02, 0x67, 0xf6, 0xb1, 0x3c, 0xca, 0x50, 0x11, 0x54, 0xc1, 0xb7, 0x37, 0x6f,
0x2f, 0x83, 0x32, 0x53, 0xd6, 0xfc, 0x05, 0x28, 0xdc, 0x10, 0x4a, 0x11, 0x21, 0xca,
0xf3, 0xd2, 0xe6, 0x40, 0x1b, 0x0c, 0x0f, 0x49, 0x21, 0x63, 0xe9, 0x9e, 0xef, 0x40,
0xe7, 0x2c, 0x18, 0x1c, 0xc8, 0x65, 0x10, 0x40, 0xcc, 0xdc, 0xb6, 0xb4, 0x48, 0xaa,
0xb4, 0xe6, 0x40, 0x82, 0xe5, 0x2f, 0x75, 0xf6, 0xed, 0x10, 0x96, 0x6a, 0x21, 0x56,
0x1c, 0x5e, 0x64, 0x2a, 0x1b, 0x55, 0x68, 0xc0, 0x2c, 0xc6, 0xde, 0x59, 0x09, 0x5c,
0xa4, 0x54, 0x67, 0x8c, 0x4c, 0x7d, 0x44, 0x36, 0x41, 0x46, 0xa1, 0xa0, 0x4d, 0x91,
0x2d, 0xf9, 0x1e, 0xd2, 0xb5, 0xbd, 0x9e, 0x8a, 0x3a, 0x69, 0x5c, 0x44, 0x8d, 0xfe,
0xad, 0x5d,
];
let output = [
0x73, 0xe9, 0xb5, 0x90, 0x33, 0x13, 0x07, 0x21, 0x43, 0xec, 0xb7, 0x63, 0x52, 0x69,
0x0e, 0x33, 0x14, 0xa7, 0xf8, 0xca, 0x84, 0x85, 0x76, 0x7b, 0xae, 0x11, 0xdc, 0x24,
0x4d, 0x2d, 0x7d, 0x6b, 0x84, 0x2e, 0xa9, 0xef, 0xcd, 0x65, 0x60, 0xc3, 0x1c, 0x0f,
0x10, 0x05, 0x99, 0xb7, 0x04, 0x09,
];
let hasher = RandomOracleShake256::h3_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h4_128() {
let input = [
0x51, 0xa0, 0x92, 0xff, 0xdc, 0x6a, 0xb1, 0x00, 0x4d, 0xc0, 0xe4, 0xa1, 0x14, 0x7f,
0x47, 0x6a,
];
let output = [
0xe4, 0x4e, 0x9d, 0xb8, 0xaa, 0x34, 0xfe, 0xc3, 0x1b, 0x39, 0xe1, 0xae, 0x22, 0x29,
0x75, 0x70,
];
let hasher = RandomOracleShake128::h4_init();
verify(hasher, &input, &output);
}
#[test]
fn test_h4_256() {
let input = [
0xb2, 0xe7, 0x47, 0x98, 0x5d, 0x6e, 0x18, 0x40, 0x49, 0xc1, 0xc3, 0xad, 0x4a, 0xa0,
0x5e, 0x8b,
];
let output = [
0x68, 0x82, 0xf5, 0x3c, 0xab, 0x68, 0x8e, 0xb6, 0x12, 0xa6, 0xa8, 0x94, 0xe9, 0x12,
0x61, 0x4d,
];
let hasher = RandomOracleShake256::h4_init();
verify(hasher, &input, &output);
}
}