use std::ptr::copy_nonoverlapping;
use std::fmt::{ self, Debug, Display, Formatter };
use crate::number::{ SmallUInt, IntUnion, LongUnion };
#[allow(non_camel_case_types)]
pub type SHA2_256_Expanded<const H0: u32 = 0x6a09e667, const H1: u32 = 0xbb67ae85,
const H2: u32 = 0x3c6ef372, const H3: u32 = 0xa54ff53a,
const H4: u32 = 0x510e527f, const H5: u32 = 0x9b05688c,
const H6: u32 = 0x1f83d9ab, const H7: u32 = 0x5be0cd19,
const ROUND: usize = 64>
= SHA2_256_Generic<8, H0, H1, H2, H3, H4, H5, H6, H7, ROUND>;
#[allow(non_camel_case_types)]
pub type SHA2_224_Expanded<const ROUND: usize = 64>
= SHA2_256_Generic<7, 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4, ROUND>;
#[allow(non_camel_case_types)]
pub type SHA2_256_Generic_HRS_fixed<const ROUND: usize = 64,
const K00: u32 = 0x428a2f98, const K01: u32 = 0x71374491,
const K02: u32 = 0xb5c0fbcf, const K03: u32 = 0xe9b5dba5,
const K04: u32 = 0x3956c25b, const K05: u32 = 0x59f111f1,
const K06: u32 = 0x923f82a4, const K07: u32 = 0xab1c5ed5,
const K08: u32 = 0xd807aa98, const K09: u32 = 0x12835b01,
const K10: u32 = 0x243185be, const K11: u32 = 0x550c7dc3,
const K12: u32 = 0x72be5d74, const K13: u32 = 0x80deb1fe,
const K14: u32 = 0x9bdc06a7, const K15: u32 = 0xc19bf174,
const K16: u32 = 0xe49b69c1, const K17: u32 = 0xefbe4786,
const K18: u32 = 0x0fc19dc6, const K19: u32 = 0x240ca1cc,
const K20: u32 = 0x2de92c6f, const K21: u32 = 0x4a7484aa,
const K22: u32 = 0x5cb0a9dc, const K23: u32 = 0x76f988da,
const K24: u32 = 0x983e5152, const K25: u32 = 0xa831c66d,
const K26: u32 = 0xb00327c8, const K27: u32 = 0xbf597fc7,
const K28: u32 = 0xc6e00bf3, const K29: u32 = 0xd5a79147,
const K30: u32 = 0x06ca6351, const K31: u32 = 0x14292967,
const K32: u32 = 0x27b70a85, const K33: u32 = 0x2e1b2138,
const K34: u32 = 0x4d2c6dfc, const K35: u32 = 0x53380d13,
const K36: u32 = 0x650a7354, const K37: u32 = 0x766a0abb,
const K38: u32 = 0x81c2c92e, const K39: u32 = 0x92722c85,
const K40: u32 = 0xa2bfe8a1, const K41: u32 = 0xa81a664b,
const K42: u32 = 0xc24b8b70, const K43: u32 = 0xc76c51a3,
const K44: u32 = 0xd192e819, const K45: u32 = 0xd6990624,
const K46: u32 = 0xf40e3585, const K47: u32 = 0x106aa070,
const K48: u32 = 0x19a4c116, const K49: u32 = 0x1e376c08,
const K50: u32 = 0x2748774c, const K51: u32 = 0x34b0bcb5,
const K52: u32 = 0x391c0cb3, const K53: u32 = 0x4ed8aa4a,
const K54: u32 = 0x5b9cca4f, const K55: u32 = 0x682e6ff3,
const K56: u32 = 0x748f82ee, const K57: u32 = 0x78a5636f,
const K58: u32 = 0x84c87814, const K59: u32 = 0x8cc70208,
const K60: u32 = 0x90befffa, const K61: u32 = 0xa4506ceb,
const K62: u32 = 0xbef9a3f7, const K63: u32 = 0xc67178f2>
= SHA2_256_Generic<8, 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, ROUND,
K00, K01, K02, K03, K04, K05, K06, K07,
K08, K09, K10, K11, K12, K13, K14, K15,
K16, K17, K18, K19, K20, K21, K22, K23,
K24, K25, K26, K27, K28, K29, K30, K31,
K32, K33, K34, K35, K36, K37, K38, K39,
K40, K41, K42, K43, K44, K45, K46, K47,
K48, K49, K50, K51, K52, K53, K54, K55,
K56, K57, K58, K59,K60, K61, K62, K63,
2, 6, 7, 11, 13, 17, 18, 19, 22, 25, 3, 10>;
#[allow(non_camel_case_types)]
pub type SHA2_224_Generic_HRS_fixed<const ROUND: usize = 64,
const K00: u32 = 0x428a2f98, const K01: u32 = 0x71374491,
const K02: u32 = 0xb5c0fbcf, const K03: u32 = 0xe9b5dba5,
const K04: u32 = 0x3956c25b, const K05: u32 = 0x59f111f1,
const K06: u32 = 0x923f82a4, const K07: u32 = 0xab1c5ed5,
const K08: u32 = 0xd807aa98, const K09: u32 = 0x12835b01,
const K10: u32 = 0x243185be, const K11: u32 = 0x550c7dc3,
const K12: u32 = 0x72be5d74, const K13: u32 = 0x80deb1fe,
const K14: u32 = 0x9bdc06a7, const K15: u32 = 0xc19bf174,
const K16: u32 = 0xe49b69c1, const K17: u32 = 0xefbe4786,
const K18: u32 = 0x0fc19dc6, const K19: u32 = 0x240ca1cc,
const K20: u32 = 0x2de92c6f, const K21: u32 = 0x4a7484aa,
const K22: u32 = 0x5cb0a9dc, const K23: u32 = 0x76f988da,
const K24: u32 = 0x983e5152, const K25: u32 = 0xa831c66d,
const K26: u32 = 0xb00327c8, const K27: u32 = 0xbf597fc7,
const K28: u32 = 0xc6e00bf3, const K29: u32 = 0xd5a79147,
const K30: u32 = 0x06ca6351, const K31: u32 = 0x14292967,
const K32: u32 = 0x27b70a85, const K33: u32 = 0x2e1b2138,
const K34: u32 = 0x4d2c6dfc, const K35: u32 = 0x53380d13,
const K36: u32 = 0x650a7354, const K37: u32 = 0x766a0abb,
const K38: u32 = 0x81c2c92e, const K39: u32 = 0x92722c85,
const K40: u32 = 0xa2bfe8a1, const K41: u32 = 0xa81a664b,
const K42: u32 = 0xc24b8b70, const K43: u32 = 0xc76c51a3,
const K44: u32 = 0xd192e819, const K45: u32 = 0xd6990624,
const K46: u32 = 0xf40e3585, const K47: u32 = 0x106aa070,
const K48: u32 = 0x19a4c116, const K49: u32 = 0x1e376c08,
const K50: u32 = 0x2748774c, const K51: u32 = 0x34b0bcb5,
const K52: u32 = 0x391c0cb3, const K53: u32 = 0x4ed8aa4a,
const K54: u32 = 0x5b9cca4f, const K55: u32 = 0x682e6ff3,
const K56: u32 = 0x748f82ee, const K57: u32 = 0x78a5636f,
const K58: u32 = 0x84c87814, const K59: u32 = 0x8cc70208,
const K60: u32 = 0x90befffa, const K61: u32 = 0xa4506ceb,
const K62: u32 = 0xbef9a3f7, const K63: u32 = 0xc67178f2>
= SHA2_256_Generic<7, 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4, ROUND,
K00, K01, K02, K03, K04, K05, K06, K07,
K08, K09, K10, K11, K12, K13, K14, K15,
K16, K17, K18, K19, K20, K21, K22, K23,
K24, K25, K26, K27, K28, K29, K30, K31,
K32, K33, K34, K35, K36, K37, K38, K39,
K40, K41, K42, K43, K44, K45, K46, K47,
K48, K49, K50, K51, K52, K53, K54, K55,
K56, K57, K58, K59,K60, K61, K62, K63,
2, 6, 7, 11, 13, 17, 18, 19, 22, 25, 3, 10>;
#[allow(non_camel_case_types)]
pub type SHA2_256 = SHA2_256_Generic;
#[allow(non_camel_case_types)]
pub type SHA2_224 = SHA2_256_Generic<7, 0xc1059ed8, 0x367cd507, 0x3070dd17,
0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7,
0xbefa4fa4, 64>;
#[derive(Debug, Clone)]
#[allow(non_camel_case_types)]
pub struct SHA2_256_Generic<const N: usize = 8,
const H0: u32 = 0x6a09e667, const H1: u32 = 0xbb67ae85,
const H2: u32 = 0x3c6ef372, const H3: u32 = 0xa54ff53a,
const H4: u32 = 0x510e527f, const H5: u32 = 0x9b05688c,
const H6: u32 = 0x1f83d9ab, const H7: u32 = 0x5be0cd19,
const ROUND: usize = 64,
const K00: u32 = 0x428a2f98, const K01: u32 = 0x71374491,
const K02: u32 = 0xb5c0fbcf, const K03: u32 = 0xe9b5dba5,
const K04: u32 = 0x3956c25b, const K05: u32 = 0x59f111f1,
const K06: u32 = 0x923f82a4, const K07: u32 = 0xab1c5ed5,
const K08: u32 = 0xd807aa98, const K09: u32 = 0x12835b01,
const K10: u32 = 0x243185be, const K11: u32 = 0x550c7dc3,
const K12: u32 = 0x72be5d74, const K13: u32 = 0x80deb1fe,
const K14: u32 = 0x9bdc06a7, const K15: u32 = 0xc19bf174,
const K16: u32 = 0xe49b69c1, const K17: u32 = 0xefbe4786,
const K18: u32 = 0x0fc19dc6, const K19: u32 = 0x240ca1cc,
const K20: u32 = 0x2de92c6f, const K21: u32 = 0x4a7484aa,
const K22: u32 = 0x5cb0a9dc, const K23: u32 = 0x76f988da,
const K24: u32 = 0x983e5152, const K25: u32 = 0xa831c66d,
const K26: u32 = 0xb00327c8, const K27: u32 = 0xbf597fc7,
const K28: u32 = 0xc6e00bf3, const K29: u32 = 0xd5a79147,
const K30: u32 = 0x06ca6351, const K31: u32 = 0x14292967,
const K32: u32 = 0x27b70a85, const K33: u32 = 0x2e1b2138,
const K34: u32 = 0x4d2c6dfc, const K35: u32 = 0x53380d13,
const K36: u32 = 0x650a7354, const K37: u32 = 0x766a0abb,
const K38: u32 = 0x81c2c92e, const K39: u32 = 0x92722c85,
const K40: u32 = 0xa2bfe8a1, const K41: u32 = 0xa81a664b,
const K42: u32 = 0xc24b8b70, const K43: u32 = 0xc76c51a3,
const K44: u32 = 0xd192e819, const K45: u32 = 0xd6990624,
const K46: u32 = 0xf40e3585, const K47: u32 = 0x106aa070,
const K48: u32 = 0x19a4c116, const K49: u32 = 0x1e376c08,
const K50: u32 = 0x2748774c, const K51: u32 = 0x34b0bcb5,
const K52: u32 = 0x391c0cb3, const K53: u32 = 0x4ed8aa4a,
const K54: u32 = 0x5b9cca4f, const K55: u32 = 0x682e6ff3,
const K56: u32 = 0x748f82ee, const K57: u32 = 0x78a5636f,
const K58: u32 = 0x84c87814, const K59: u32 = 0x8cc70208,
const K60: u32 = 0x90befffa, const K61: u32 = 0xa4506ceb,
const K62: u32 = 0xbef9a3f7, const K63: u32 = 0xc67178f2,
const RR2: u32 = 2, const RR6: u32 = 6, const RR7: u32 = 7,
const RR11: u32 = 11, const RR13: u32 = 13, const RR17: u32 = 17,
const RR18: u32 = 18, const RR19: u32 = 19, const RR22: u32 = 22,
const RR25: u32 = 25, const SR3: i32 = 3, const SR10: i32 = 10>
{
hash_code: [IntUnion; 8],
}
impl<const N: usize, const H0: u32, const H1: u32, const H2: u32, const H3: u32,
const H4: u32, const H5: u32, const H6: u32, const H7: u32, const ROUND: usize,
const K00: u32, const K01: u32, const K02: u32, const K03: u32,
const K04: u32, const K05: u32, const K06: u32, const K07: u32,
const K08: u32, const K09: u32, const K10: u32, const K11: u32,
const K12: u32, const K13: u32, const K14: u32, const K15: u32,
const K16: u32, const K17: u32, const K18: u32, const K19: u32,
const K20: u32, const K21: u32, const K22: u32, const K23: u32,
const K24: u32, const K25: u32, const K26: u32, const K27: u32,
const K28: u32, const K29: u32, const K30: u32, const K31: u32,
const K32: u32, const K33: u32, const K34: u32, const K35: u32,
const K36: u32, const K37: u32, const K38: u32, const K39: u32,
const K40: u32, const K41: u32, const K42: u32, const K43: u32,
const K44: u32, const K45: u32, const K46: u32, const K47: u32,
const K48: u32, const K49: u32, const K50: u32, const K51: u32,
const K52: u32, const K53: u32, const K54: u32, const K55: u32,
const K56: u32, const K57: u32, const K58: u32, const K59: u32,
const K60: u32, const K61: u32, const K62: u32, const K63: u32,
const RR2: u32, const RR6: u32, const RR7: u32, const RR11: u32,
const RR13: u32, const RR17: u32, const RR18: u32, const RR19: u32,
const RR22: u32, const RR25: u32, const SR3: i32, const SR10: i32>
SHA2_256_Generic<N, H0, H1, H2, H3, H4, H5, H6, H7, ROUND,
K00, K01, K02, K03, K04, K05, K06, K07,
K08, K09, K10, K11, K12, K13, K14, K15,
K16, K17, K18, K19, K20, K21, K22, K23,
K24, K25, K26, K27, K28, K29, K30, K31,
K32, K33, K34, K35, K36, K37, K38, K39,
K40, K41, K42, K43, K44, K45, K46, K47,
K48, K49, K50, K51, K52, K53, K54, K55,
K56, K57, K58, K59, K60, K61, K62, K63,
RR2, RR6, RR7, RR11, RR13, RR17, RR18, RR19,
RR22, RR25, SR3, SR10>
{
pub(crate) const DEFUALT_OUTPUT_LENGTH_IN_BYTES: usize = N * 4;
const K: [u32; 64] = [ K00, K01, K02, K03, K04, K05, K06, K07,
K08, K09, K10, K11, K12, K13, K14, K15,
K16, K17, K18, K19, K20, K21, K22, K23,
K24, K25, K26, K27, K28, K29, K30, K31,
K32, K33, K34, K35, K36, K37, K38, K39,
K40, K41, K42, K43, K44, K45, K46, K47,
K48, K49, K50, K51, K52, K53, K54, K55,
K56, K57, K58, K59, K60, K61, K62, K63 ];
const H: [u32; 8] = [ H0, H1, H2, H3, H4, H5, H6, H7 ];
pub fn new() -> Self
{
if (N > 8) | (N == 0)
{ panic!("N cannot be 0 or greater than 8."); }
Self
{
hash_code: [ IntUnion::new_with(Self::H[0]),
IntUnion::new_with(Self::H[1]),
IntUnion::new_with(Self::H[2]),
IntUnion::new_with(Self::H[3]),
IntUnion::new_with(Self::H[4]),
IntUnion::new_with(Self::H[5]),
IntUnion::new_with(Self::H[6]),
IntUnion::new_with(Self::H[7]) ]
}
}
pub fn digest(&mut self, message: *const u8, length_in_bytes: u64)
{
type MessageType = u32;
const SHIFT_NUM: usize = 6;
const CHUNK_NUM: usize = 16;
let mut block: [MessageType; CHUNK_NUM] = [0; CHUNK_NUM];
self.initialize();
let length_done = (length_in_bytes >> SHIFT_NUM) as usize;
for i in 0..length_done
{
unsafe { copy_nonoverlapping(message.add(i << SHIFT_NUM) as *const u8, block.as_mut_ptr() as *mut u8, CHUNK_NUM * 4); }
self.update(&block);
}
self.finalize(unsafe { message.add(length_done << SHIFT_NUM) }, length_in_bytes);
}
#[inline]
pub fn digest_str(&mut self, message: &str)
{
self.digest(message.as_ptr(), message.len() as u64);
}
#[inline]
pub fn digest_string(&mut self, message: &String)
{
self.digest(message.as_ptr(), message.len() as u64);
}
#[inline]
pub fn digest_array<T, const M: usize>(&mut self, message: &[T; M])
where T: SmallUInt + Copy + Clone
{
self.digest(message.as_ptr() as *const u8, (M as u32 * T::size_in_bytes()) as u64);
}
#[inline]
pub fn digest_vec<T>(&mut self, message: &Vec<T>)
where T: SmallUInt + Copy + Clone
{
self.digest(message.as_ptr() as *const u8, (message.len() as u32 * T::size_in_bytes()) as u64);
}
pub fn ruminate(&mut self, n: usize, message: *const u8, length_in_bytes: u64)
{
self.digest(message, length_in_bytes);
for _ in 1..n
{ self.digest_array(&self.get_hash_value_in_array()); }
}
#[inline]
pub fn ruminate_str(&mut self, n: usize, message: &str)
{
self.ruminate(n, message.as_ptr(), message.len() as u64);
}
#[inline]
pub fn ruminate_string(&mut self, n: usize, message: &String)
{
self.ruminate(n, message.as_ptr(), message.len() as u64);
}
#[inline]
pub fn ruminate_array<T, const M: usize>(&mut self, n: usize, message: &[T; M])
where T: SmallUInt + Copy + Clone
{
self.ruminate(n, message.as_ptr() as *const u8, (M as u32 * T::size_in_bytes()) as u64);
}
#[inline]
pub fn ruminate_vec<T>(&mut self, n: usize, message: &Vec<T>)
where T: SmallUInt + Copy + Clone
{
self.ruminate(n, message.as_ptr() as *const u8, (message.len() as u32 * T::size_in_bytes()) as u64);
}
pub fn get_hash_value(&self, hash_value: *mut u8, length: usize)
{
const BYTES: usize = 4;
let n_length = if length < (BYTES * N) {length} else {BYTES * N};
#[cfg(target_endian = "little")]
{
let mut hash_code = [IntUnion::new(); N];
for i in 0..N
{ hash_code[i].set(self.hash_code[i].get().to_be()); }
unsafe { copy_nonoverlapping(hash_code.as_ptr() as *const u8, hash_value, n_length); }
}
#[cfg(target_endian = "big")]
unsafe { copy_nonoverlapping(self.hash_code.as_ptr() as *const u8, hash_value, n_length); }
}
pub fn get_hash_value_in_string(&self) -> String
{
const BYTES: usize = 4;
let mut txt = String::new();
for i in 0..N
{
let hs = self.hash_code[i];
for j in 0..BYTES
{
let byte = hs.get_ubyte_(BYTES-1-j);
txt.push(Self::to_char(byte >> 4));
txt.push(Self::to_char(byte & 0b1111));
}
}
txt
}
pub fn get_hash_value_in_array(&self) -> [u32; N]
{
let mut res = [0_u32; N];
for i in 0..N
{ res[i] = self.hash_code[i].get().to_be(); }
res
}
pub fn get_hash_value_in_vec(&self) -> Vec<u32>
{
let mut res = Vec::new();
for i in 0..N
{ res.push(self.hash_code[i].get().to_be()); }
res
}
pub fn put_hash_value_in_array<T, const M: usize>(&self, out: &mut [T; M])
where T: SmallUInt + Copy + Clone + Display + Debug + ToString
{
let res = self.get_hash_value_in_array();
let out_size = T::size_in_bytes() * M as u32;
let length = if out_size < (u32::size_in_bytes() * N as u32) {out_size} else {u32::size_in_bytes() * N as u32};
unsafe { copy_nonoverlapping(res.as_ptr() as *const u8, out as *mut T as *mut u8, length as usize); }
}
#[inline]
pub fn tangle(&mut self, tangling: u64)
{
let common = LongUnion::new_with(tangling);
let mut m = [0_u32; 10];
for i in 0..8
{ m[i] = self.hash_code[i].get(); }
m[8] = common.get_uint_(0);
m[9] = common.get_uint_(1);
self.finalize(m.as_ptr() as *const u8, 40);
}
fn initialize(&mut self)
{
for i in 0..8_usize
{ self.hash_code[i] = IntUnion::new_with(Self::get_h(i)); }
}
fn update(&mut self, message: &[u32])
{
let mut w = [0_u32; 16];
let mut a = self.hash_code[0].get();
let mut b = self.hash_code[1].get();
let mut c = self.hash_code[2].get();
let mut d = self.hash_code[3].get();
let mut e = self.hash_code[4].get();
let mut f = self.hash_code[5].get();
let mut g = self.hash_code[6].get();
let mut h = self.hash_code[7].get();
for i in 0..16_usize
{
w[i] = message[i].to_be();
let s1 = e.rotate_right(RR6) ^ e.rotate_right(RR11) ^ e.rotate_right(RR25);
let t1 = Self::ch(e, f, g).wrapping_add(h)
.wrapping_add(Self::get_k(i))
.wrapping_add(w[i])
.wrapping_add(s1);
let s0 = a.rotate_right(RR2) ^ a.rotate_right(RR13) ^ a.rotate_right(RR22);
let t2 = Self::maj(a, b, c).wrapping_add(s0);
h = g;
g = f;
f = e;
e = d.wrapping_add(t1);
d = c;
c = b;
b = a;
a = t1.wrapping_add(t2);
}
for i in 16..ROUND {
let j = i & 0b1111;
w[j] = Self::get_w(&w, i);
let s1 = e.rotate_right(RR6) ^ e.rotate_right(RR11) ^ e.rotate_right(RR25);
let t1 = Self::ch(e, f, g).wrapping_add(h)
.wrapping_add(Self::get_k(i))
.wrapping_add(w[j])
.wrapping_add(s1);
let s0 = a.rotate_right(RR2) ^ a.rotate_right(RR13) ^ a.rotate_right(RR22);
let t2 = Self::maj(a, b, c).wrapping_add(s0);
h = g;
g = f;
f = e;
e = d.wrapping_add(t1);
d = c;
c = b;
b = a;
a = t1.wrapping_add(t2);
}
self.hash_code[0].set(self.hash_code[0].get().wrapping_add(a));
self.hash_code[1].set(self.hash_code[1].get().wrapping_add(b));
self.hash_code[2].set(self.hash_code[2].get().wrapping_add(c));
self.hash_code[3].set(self.hash_code[3].get().wrapping_add(d));
self.hash_code[4].set(self.hash_code[4].get().wrapping_add(e));
self.hash_code[5].set(self.hash_code[5].get().wrapping_add(f));
self.hash_code[6].set(self.hash_code[6].get().wrapping_add(g));
self.hash_code[7].set(self.hash_code[7].get().wrapping_add(h));
}
fn finalize(&mut self, message: *const u8, length_in_bytes: u64)
{
type ChunkType = u64;
type PieceType = u32;
const MESSAGE_NUM: usize = 64;
const LAST_BYTES: ChunkType = 0b11_1111;
union MU
{
chunk: [ChunkType; 8],
piece: [PieceType; 16],
txt: [u8; MESSAGE_NUM],
}
let mut mu = MU { txt: [0; MESSAGE_NUM] };
let last_bytes = (length_in_bytes & LAST_BYTES) as usize; unsafe { copy_nonoverlapping(message, mu.txt.as_mut_ptr(), last_bytes); }
unsafe { mu.txt[last_bytes] = 0b1000_0000; }
if last_bytes > 54 {
self.update(unsafe {&mu.piece});
for i in 0..7
{ unsafe { mu.chunk[i] = 0; } }
}
unsafe { mu.chunk[7] = (length_in_bytes << 3).to_be(); } self.update(unsafe {&mu.piece});
}
#[inline] fn get_k(idx: usize) -> u32 { Self::K[idx & 0b11_1111] }
#[inline] fn get_h(idx: usize) -> u32 { Self::H[idx] }
#[inline] fn get_s0(w: &[u32; 16], idx: usize) -> u32 { let ww = w[(idx-15) & 0b1111]; ww.rotate_right(RR7) ^ ww.rotate_right(RR18) ^ (ww >> SR3) }
#[inline] fn get_s1(w: &[u32; 16], idx: usize) -> u32 { let ww = w[(idx-2) & 0b1111]; ww.rotate_right(RR17) ^ ww.rotate_right(RR19) ^ (ww >> SR10) }
#[inline] fn get_w(w: &[u32; 16], idx: usize) -> u32 { w[(idx-16) & 0b1111].wrapping_add(Self::get_s0(w, idx)).wrapping_add(w[(idx-7) & 0b1111]).wrapping_add(Self::get_s1(&w, idx)) }
#[inline] fn ch(x: u32, y: u32, z: u32) -> u32 { z ^ (x & (y ^ z)) } #[inline] fn maj(x: u32, y: u32, z: u32) -> u32 { (x & y) | (z & (x | y)) } #[inline] fn to_char(nibble: u8) -> char { if nibble < 10 { ('0' as u8 + nibble) as u8 as char } else { ('A' as u8 - 10 + nibble) as char } }
}
impl<const N: usize, const H0: u32, const H1: u32, const H2: u32, const H3: u32,
const H4: u32, const H5: u32, const H6: u32, const H7: u32, const ROUND: usize,
const K00: u32, const K01: u32, const K02: u32, const K03: u32,
const K04: u32, const K05: u32, const K06: u32, const K07: u32,
const K08: u32, const K09: u32, const K10: u32, const K11: u32,
const K12: u32, const K13: u32, const K14: u32, const K15: u32,
const K16: u32, const K17: u32, const K18: u32, const K19: u32,
const K20: u32, const K21: u32, const K22: u32, const K23: u32,
const K24: u32, const K25: u32, const K26: u32, const K27: u32,
const K28: u32, const K29: u32, const K30: u32, const K31: u32,
const K32: u32, const K33: u32, const K34: u32, const K35: u32,
const K36: u32, const K37: u32, const K38: u32, const K39: u32,
const K40: u32, const K41: u32, const K42: u32, const K43: u32,
const K44: u32, const K45: u32, const K46: u32, const K47: u32,
const K48: u32, const K49: u32, const K50: u32, const K51: u32,
const K52: u32, const K53: u32, const K54: u32, const K55: u32,
const K56: u32, const K57: u32, const K58: u32, const K59: u32,
const K60: u32, const K61: u32, const K62: u32, const K63: u32,
const RR2: u32, const RR6: u32, const RR7: u32, const RR11: u32,
const RR13: u32, const RR17: u32, const RR18: u32, const RR19: u32,
const RR22: u32, const RR25: u32, const SR3: i32, const SR10: i32>
Display for SHA2_256_Generic<N, H0, H1, H2, H3, H4, H5, H6, H7, ROUND,
K00, K01, K02, K03, K04, K05, K06, K07,
K08, K09, K10, K11, K12, K13, K14, K15,
K16, K17, K18, K19, K20, K21, K22, K23,
K24, K25, K26, K27, K28, K29, K30, K31,
K32, K33, K34, K35, K36, K37, K38, K39,
K40, K41, K42, K43, K44, K45, K46, K47,
K48, K49, K50, K51, K52, K53, K54, K55,
K56, K57, K58, K59, K60, K61, K62, K63,
RR2, RR6, RR7, RR11, RR13, RR17, RR18, RR19,
RR22, RR25, SR3, SR10>
{
fn fmt(&self, f: &mut Formatter) -> fmt::Result
{
write!(f, "{}", self.get_hash_value_in_string())
}
}