#! [allow(non_snake_case)]
#! [allow(non_upper_case_globals)]
#! [allow(non_camel_case_types)]
#! [allow(unused_assignments)]
#! [allow(unreachable_patterns)]
#! [allow(dead_code)]
//! This module contains generated hacl code.
use libcrux_hacl_rs::prelude::*;
use libcrux_macros as krml;
pub const h224: [u32; 8 ] = [
0 xc1059ed8u32,
0 x367cd507u32,
0 x3070dd17u32,
0 xf70e5939u32,
0 xffc00b31u32,
0 x68581511u32,
0 x64f98fa7u32,
0 xbefa4fa4u32,
];
pub const h256: [u32; 8 ] = [
0 x6a09e667u32,
0 xbb67ae85u32,
0 x3c6ef372u32,
0 xa54ff53au32,
0 x510e527fu32,
0 x9b05688cu32,
0 x1f83d9abu32,
0 x5be0cd19u32,
];
pub const h384: [u64; 8 ] = [
0 xcbbb9d5dc1059ed8u64,
0 x629a292a367cd507u64,
0 x9159015a3070dd17u64,
0 x152fecd8f70e5939u64,
0 x67332667ffc00b31u64,
0 x8eb44a8768581511u64,
0 xdb0c2e0d64f98fa7u64,
0 x47b5481dbefa4fa4u64,
];
pub const h512: [u64; 8 ] = [
0 x6a09e667f3bcc908u64,
0 xbb67ae8584caa73bu64,
0 x3c6ef372fe94f82bu64,
0 xa54ff53a5f1d36f1u64,
0 x510e527fade682d1u64,
0 x9b05688c2b3e6c1fu64,
0 x1f83d9abfb41bd6bu64,
0 x5be0cd19137e2179u64,
];
pub const k224_256: [u32; 64 ] = [
0 x428a2f98u32,
0 x71374491u32,
0 xb5c0fbcfu32,
0 xe9b5dba5u32,
0 x3956c25bu32,
0 x59f111f1u32,
0 x923f82a4u32,
0 xab1c5ed5u32,
0 xd807aa98u32,
0 x12835b01u32,
0 x243185beu32,
0 x550c7dc3u32,
0 x72be5d74u32,
0 x80deb1feu32,
0 x9bdc06a7u32,
0 xc19bf174u32,
0 xe49b69c1u32,
0 xefbe4786u32,
0 x0fc19dc6u32,
0 x240ca1ccu32,
0 x2de92c6fu32,
0 x4a7484aau32,
0 x5cb0a9dcu32,
0 x76f988dau32,
0 x983e5152u32,
0 xa831c66du32,
0 xb00327c8u32,
0 xbf597fc7u32,
0 xc6e00bf3u32,
0 xd5a79147u32,
0 x06ca6351u32,
0 x14292967u32,
0 x27b70a85u32,
0 x2e1b2138u32,
0 x4d2c6dfcu32,
0 x53380d13u32,
0 x650a7354u32,
0 x766a0abbu32,
0 x81c2c92eu32,
0 x92722c85u32,
0 xa2bfe8a1u32,
0 xa81a664bu32,
0 xc24b8b70u32,
0 xc76c51a3u32,
0 xd192e819u32,
0 xd6990624u32,
0 xf40e3585u32,
0 x106aa070u32,
0 x19a4c116u32,
0 x1e376c08u32,
0 x2748774cu32,
0 x34b0bcb5u32,
0 x391c0cb3u32,
0 x4ed8aa4au32,
0 x5b9cca4fu32,
0 x682e6ff3u32,
0 x748f82eeu32,
0 x78a5636fu32,
0 x84c87814u32,
0 x8cc70208u32,
0 x90befffau32,
0 xa4506cebu32,
0 xbef9a3f7u32,
0 xc67178f2u32,
];
pub const k384_512: [u64; 80 ] = [
0 x428a2f98d728ae22u64,
0 x7137449123ef65cdu64,
0 xb5c0fbcfec4d3b2fu64,
0 xe9b5dba58189dbbcu64,
0 x3956c25bf348b538u64,
0 x59f111f1b605d019u64,
0 x923f82a4af194f9bu64,
0 xab1c5ed5da6d8118u64,
0 xd807aa98a3030242u64,
0 x12835b0145706fbeu64,
0 x243185be4ee4b28cu64,
0 x550c7dc3d5ffb4e2u64,
0 x72be5d74f27b896fu64,
0 x80deb1fe3b1696b1u64,
0 x9bdc06a725c71235u64,
0 xc19bf174cf692694u64,
0 xe49b69c19ef14ad2u64,
0 xefbe4786384f25e3u64,
0 x0fc19dc68b8cd5b5u64,
0 x240ca1cc77ac9c65u64,
0 x2de92c6f592b0275u64,
0 x4a7484aa6ea6e483u64,
0 x5cb0a9dcbd41fbd4u64,
0 x76f988da831153b5u64,
0 x983e5152ee66dfabu64,
0 xa831c66d2db43210u64,
0 xb00327c898fb213fu64,
0 xbf597fc7beef0ee4u64,
0 xc6e00bf33da88fc2u64,
0 xd5a79147930aa725u64,
0 x06ca6351e003826fu64,
0 x142929670a0e6e70u64,
0 x27b70a8546d22ffcu64,
0 x2e1b21385c26c926u64,
0 x4d2c6dfc5ac42aedu64,
0 x53380d139d95b3dfu64,
0 x650a73548baf63deu64,
0 x766a0abb3c77b2a8u64,
0 x81c2c92e47edaee6u64,
0 x92722c851482353bu64,
0 xa2bfe8a14cf10364u64,
0 xa81a664bbc423001u64,
0 xc24b8b70d0f89791u64,
0 xc76c51a30654be30u64,
0 xd192e819d6ef5218u64,
0 xd69906245565a910u64,
0 xf40e35855771202au64,
0 x106aa07032bbd1b8u64,
0 x19a4c116b8d2d0c8u64,
0 x1e376c085141ab53u64,
0 x2748774cdf8eeb99u64,
0 x34b0bcb5e19b48a8u64,
0 x391c0cb3c5c95a63u64,
0 x4ed8aa4ae3418acbu64,
0 x5b9cca4f7763e373u64,
0 x682e6ff3d6b2b8a3u64,
0 x748f82ee5defb2fcu64,
0 x78a5636f43172f60u64,
0 x84c87814a1f0ab72u64,
0 x8cc702081a6439ecu64,
0 x90befffa23631e28u64,
0 xa4506cebde82bde9u64,
0 xbef9a3f7b2c67915u64,
0 xc67178f2e372532bu64,
0 xca273eceea26619cu64,
0 xd186b8c721c0c207u64,
0 xeada7dd6cde0eb1eu64,
0 xf57d4f7fee6ed178u64,
0 x06f067aa72176fbau64,
0 x0a637dc5a2c898a6u64,
0 x113f9804bef90daeu64,
0 x1b710b35131c471bu64,
0 x28db77f523047d84u64,
0 x32caab7b40c72493u64,
0 x3c9ebe0a15c9bebcu64,
0 x431d67c49c100d4cu64,
0 x4cc5d4becb3e42b6u64,
0 x597f299cfc657e2au64,
0 x5fcb6fab3ad6faecu64,
0 x6c44198c4a475817u64,
];
pub fn sha256_init(hash: &mut [u32]) {
krml::unroll_for!(8 , "i" , 0 u32, 1 u32, {
let x: u32 = (&crate ::hacl::h256)[i as usize];
let os: (&mut [u32], &mut [u32]) = hash.split_at_mut(0 usize);
os.1 [i as usize] = x
})
}
#[ inline]
fn sha256_update(b: &[u8], hash: &mut [u32]) {
let mut hash_old: [u32; 8 ] = [0 u32; 8 usize];
let mut ws: [u32; 16 ] = [0 u32; 16 usize];
((&mut hash_old)[0 usize..8 usize]).copy_from_slice(&hash[e='color: green'>0 usize..8 usize]);
let b1: &[u8] = b;
let u: u32 = lowstar::endianness::load32_be(&b1[0 usize..]);
(&mut ws)[0 usize] = u;
let u0: u32 = lowstar::endianness::load32_be(&b1[4 usize..]);
(&mut ws)[1 usize] = u0;
let u1: u32 = lowstar::endianness::load32_be(&b1[8 usize..]);
(&mut ws)[2 usize] = u1;
let u2: u32 = lowstar::endianness::load32_be(&b1[12 usize..]);
(&mut ws)[3 usize] = u2;
let u3: u32 = lowstar::endianness::load32_be(&b1[16 usize..]);
(&mut ws)[4 usize] = u3;
let u4: u32 = lowstar::endianness::load32_be(&b1[20 usize..]);
(&mut ws)[5 usize] = u4;
let u5: u32 = lowstar::endianness::load32_be(&b1[24 usize..]);
(&mut ws)[6 usize] = u5;
let u6: u32 = lowstar::endianness::load32_be(&b1[28 usize..]);
(&mut ws)[7 usize] = u6;
let u7: u32 = lowstar::endianness::load32_be(&b1[32 usize..]);
(&mut ws)[8 usize] = u7;
let u8: u32 = lowstar::endianness::load32_be(&b1[36 usize..]);
(&mut ws)[9 usize] = u8;
let u9: u32 = lowstar::endianness::load32_be(&b1[40 usize..]);
(&mut ws)[10 usize] = u9;
let u10: u32 = lowstar::endianness::load32_be(&b1[44 usize..]);
(&mut ws)[11 usize] = u10;
let u11: u32 = lowstar::endianness::load32_be(&b1[48 usize..]);
(&mut ws)[12 usize] = u11;
let u12: u32 = lowstar::endianness::load32_be(&b1[52 usize..]);
(&mut ws)[13 usize] = u12;
let u13: u32 = lowstar::endianness::load32_be(&b1[56 usize..]);
(&mut ws)[14 usize] = u13;
let u14: u32 = lowstar::endianness::load32_be(&b1[60 usize..]);
(&mut ws)[15 usize] = u14;
krml::unroll_for!(4 , "i" , 0 u32, 1 u32, {
krml::unroll_for!(16 , "i0" , 0 u32, 1 u32, {
let k_t: u32 =
(&crate ::hacl::k224_256)[16 u32.wrapping_mul(i).wrapping_add(i0) as usize];
let ws_t: u32 = (&ws)[i0 as usize];
let a0: u32 = hash[0 usize];
let b0: u32 = hash[1 usize];
let c0: u32 = hash[2 usize];
let d0: u32 = hash[3 usize];
let e0: u32 = hash[4 usize];
let f0: u32 = hash[5 usize];
let g0: u32 = hash[6 usize];
let h02: u32 = hash[7 usize];
let k_e_t: u32 = k_t;
let t1: u32 = h02
.wrapping_add(
(e0.wrapping_shl(26 u32) | e0.wrapping_shr(6 u32))
^ ((e0.wrapping_shl(21 u32) | e0.wrapping_shr(11 u32))
^ (e0.wrapping_shl(7 u32) | e0.wrapping_shr(25 u32))),
)
.wrapping_add(e0 & f0 ^ !e0 & g0)
.wrapping_add(k_e_t)
.wrapping_add(ws_t);
let t2: u32 = ((a0.wrapping_shl(30 u32) | a0.wrapping_shr(2 u32))
^ ((a0.wrapping_shl(19 u32) | a0.wrapping_shr(13 u32))
^ (a0.wrapping_shl(10 u32) | a0.wrapping_shr(22 u32))))
.wrapping_add(a0 & b0 ^ (a0 & c0 ^ b0 & c0));
let a1: u32 = t1.wrapping_add(t2);
let b10: u32 = a0;
let c1: u32 = b0;
let d1: u32 = c0;
let e1: u32 = d0.wrapping_add(t1);
let f1: u32 = e0;
let g1: u32 = f0;
let h12: u32 = g0;
hash[0 usize] = a1;
hash[1 usize] = b10;
hash[2 usize] = c1;
hash[3 usize] = d1;
hash[4 usize] = e1;
hash[5 usize] = f1;
hash[6 usize] = g1;
hash[7 usize] = h12
});
if i < 3 u32 {
krml::unroll_for!(16 , "i0" , 0 u32, 1 u32, {
let t16: u32 = (&ws)[i0 as usize];
let t15: u32 = (&ws)[i0.wrapping_add(1 u32).wrapping_rem(16 u32) as usize];
let t7: u32 = (&ws)[i0.wrapping_add(9 u32).wrapping_rem(16 u32) as usize];
let t2: u32 = (&ws)[i0.wrapping_add(14 u32).wrapping_rem(16 u32) as usize];
let s1: u32 = (t2.wrapping_shl(15 u32) | t2.wrapping_shr(17 u32))
^ ((t2.wrapping_shl(13 u32) | t2.wrapping_shr(19 u32)) ^ t2.wrapping_shr(10 u32));
let s0: u32 = (t15.wrapping_shl(25 u32) | t15.wrapping_shr(7 u32))
^ ((t15.wrapping_shl(14 u32) | t15.wrapping_shr(18 u32))
^ t15.wrapping_shr(3 u32));
(&mut ws)[i0 as usize] = s1.wrapping_add(t7).wrapping_add(s0).wrapping_add(t16)
})
}
});
krml::unroll_for!(8 , "i" , 0 u32, 1 u32, {
let x: u32 = (hash[i as usize]).wrapping_add((&hash_old)[i as usize]);
let os: (&mut [u32], &mut [u32]) = hash.split_at_mut(0 usize);
os.1 [i as usize] = x
})
}
pub fn sha256_update_nblocks(len: u32, b: &[u8], st: &mut [u32]) {
let blocks: u32 = len.wrapping_div(64 u32);
for i in 0 u32..blocks {
let b0: &[u8] = b;
let mb: (&[u8], &[u8]) = b0.split_at(i.wrapping_mul(64 u32) as usize);
crate ::hacl::sha256_update(mb.1 , st)
}
}
pub fn sha256_update_last(totlen: u64, len: u32, b: &[u8], hash: &mut [u32]) {
let blocks: u32 = if len.wrapping_add(8 u32).wrapping_add(1 u32) <= 64 u32 {
1 u32
} else {
2 u32
};
let fin: u32 = blocks.wrapping_mul(64 u32);
let mut last: [u8; 128 ] = [0 u8; 128 usize];
let mut totlen_buf: [u8; 8 ] = [0 u8; 8 usize];
let total_len_bits: u64 = totlen.wrapping_shl(3 u32);
lowstar::endianness::store64_be(&mut totlen_buf, total_len_bits);
let b0: &[u8] = b;
((&mut last)[0 usize..len as usize]).copy_from_slice(&b0[e='color: green'>0 usize..len as usize]);
(&mut last)[len as usize] = 0 x80u8;
((&mut last)[fin.wrapping_sub(8 u32) as usize..fin.wrapping_sub(8 u32) as usize + 8 usize])
.copy_from_slice(&(&totlen_buf)[0 usize..8 usize]);
let last0: (&[u8], &[u8]) = last.split_at(0 usize);
let last1: (&[u8], &[u8]) = last0.1 .split_at(64 usize);
let l0: &[u8] = last1.0 ;
let l1: &[u8] = last1.1 ;
let lb0: &[u8] = l0;
let lb1: &[u8] = l1;
let last00: &[u8] = lb0;
let last10: &[u8] = lb1;
crate ::hacl::sha256_update(last00, hash);
if blocks > 1 u32 {
crate ::hacl::sha256_update(last10, hash)
}
}
pub fn sha256_finish(st: &[u32], h: &mut [u8]) {
let mut hbuf: [u8; 32 ] = [0 u8; 32 usize];
krml::unroll_for!(
8 ,
"i" ,
0 u32,
1 u32,
lowstar::endianness::store32_be(
&mut (&mut hbuf)[i.wrapping_mul(4 u32) as usize..],
st[i as usize]
)
);
(h[0 usize..32 usize]).copy_from_slice(&(&(&hbuf)[0 usize..])[0 usize..32 usize])
}
#[ inline]
fn sha224_init(hash: &mut [u32]) {
krml::unroll_for!(8 , "i" , 0 u32, 1 u32, {
let x: u32 = (&crate ::hacl::h224)[i as usize];
let os: (&mut [u32], &mut [u32]) = hash.split_at_mut(0 usize);
os.1 [i as usize] = x
})
}
#[ inline]
fn sha224_update_nblocks(len: u32, b: &[u8], st: &mut [u32]) {
crate ::hacl::sha256_update_nblocks(len, b, st)
}
fn sha224_update_last(totlen: u64, len: u32, b: &[u8], st: &mut [u32]) {
crate ::hacl::sha256_update_last(totlen, len, b, st)
}
#[ inline]
fn sha224_finish(st: &[u32], h: &mut [u8]) {
let mut hbuf: [u8; 32 ] = [0 u8; 32 usize];
krml::unroll_for!(
8 ,
"i" ,
0 u32,
1 u32,
lowstar::endianness::store32_be(
&mut (&mut hbuf)[i.wrapping_mul(4 u32) as usize..],
st[i as usize]
)
);
(h[0 usize..28 usize]).copy_from_slice(&(&(&hbuf)[0 usize..])[0 usize..28 usize])
}
pub fn sha512_init(hash: &mut [u64]) {
krml::unroll_for!(8 , "i" , 0 u32, 1 u32, {
let x: u64 = (&crate ::hacl::h512)[i as usize];
let os: (&mut [u64], &mut [u64]) = hash.split_at_mut(0 usize);
os.1 [i as usize] = x
})
}
#[ inline]
fn sha512_update(b: &[u8], hash: &mut [u64]) {
let mut hash_old: [u64; 8 ] = [0 u64; 8 usize];
let mut ws: [u64; 16 ] = [0 u64; 16 usize];
((&mut hash_old)[0 usize..8 usize]).copy_from_slice(&hash[e='color: green'>0 usize..8 usize]);
let b1: &[u8] = b;
let u: u64 = lowstar::endianness::load64_be(&b1[0 usize..]);
(&mut ws)[0 usize] = u;
let u0: u64 = lowstar::endianness::load64_be(&b1[8 usize..]);
(&mut ws)[1 usize] = u0;
let u1: u64 = lowstar::endianness::load64_be(&b1[16 usize..]);
(&mut ws)[2 usize] = u1;
let u2: u64 = lowstar::endianness::load64_be(&b1[24 usize..]);
(&mut ws)[3 usize] = u2;
let u3: u64 = lowstar::endianness::load64_be(&b1[32 usize..]);
(&mut ws)[4 usize] = u3;
let u4: u64 = lowstar::endianness::load64_be(&b1[40 usize..]);
(&mut ws)[5 usize] = u4;
let u5: u64 = lowstar::endianness::load64_be(&b1[48 usize..]);
(&mut ws)[6 usize] = u5;
let u6: u64 = lowstar::endianness::load64_be(&b1[56 usize..]);
(&mut ws)[7 usize] = u6;
let u7: u64 = lowstar::endianness::load64_be(&b1[64 usize..]);
(&mut ws)[8 usize] = u7;
let u8: u64 = lowstar::endianness::load64_be(&b1[72 usize..]);
(&mut ws)[9 usize] = u8;
let u9: u64 = lowstar::endianness::load64_be(&b1[80 usize..]);
(&mut ws)[10 usize] = u9;
let u10: u64 = lowstar::endianness::load64_be(&b1[88 usize..]);
(&mut ws)[11 usize] = u10;
let u11: u64 = lowstar::endianness::load64_be(&b1[96 usize..]);
(&mut ws)[12 usize] = u11;
let u12: u64 = lowstar::endianness::load64_be(&b1[104 usize..]);
(&mut ws)[13 usize] = u12;
let u13: u64 = lowstar::endianness::load64_be(&b1[112 usize..]);
(&mut ws)[14 usize] = u13;
let u14: u64 = lowstar::endianness::load64_be(&b1[120 usize..]);
(&mut ws)[15 usize] = u14;
krml::unroll_for!(5 , "i" , 0 u32, 1 u32, {
krml::unroll_for!(16 , "i0" , 0 u32, 1 u32, {
let k_t: u64 =
(&crate ::hacl::k384_512)[16 u32.wrapping_mul(i).wrapping_add(i0) as usize];
let ws_t: u64 = (&ws)[i0 as usize];
let a0: u64 = hash[0 usize];
let b0: u64 = hash[1 usize];
let c0: u64 = hash[2 usize];
let d0: u64 = hash[3 usize];
let e0: u64 = hash[4 usize];
let f0: u64 = hash[5 usize];
let g0: u64 = hash[6 usize];
let h02: u64 = hash[7 usize];
let k_e_t: u64 = k_t;
let t1: u64 = h02
.wrapping_add(
(e0.wrapping_shl(50 u32) | e0.wrapping_shr(14 u32))
^ ((e0.wrapping_shl(46 u32) | e0.wrapping_shr(18 u32))
^ (e0.wrapping_shl(23 u32) | e0.wrapping_shr(41 u32))),
)
.wrapping_add(e0 & f0 ^ !e0 & g0)
.wrapping_add(k_e_t)
.wrapping_add(ws_t);
let t2: u64 = ((a0.wrapping_shl(36 u32) | a0.wrapping_shr(28 u32))
^ ((a0.wrapping_shl(30 u32) | a0.wrapping_shr(34 u32))
^ (a0.wrapping_shl(25 u32) | a0.wrapping_shr(39 u32))))
.wrapping_add(a0 & b0 ^ (a0 & c0 ^ b0 & c0));
let a1: u64 = t1.wrapping_add(t2);
let b10: u64 = a0;
let c1: u64 = b0;
let d1: u64 = c0;
let e1: u64 = d0.wrapping_add(t1);
let f1: u64 = e0;
let g1: u64 = f0;
let h12: u64 = g0;
hash[0 usize] = a1;
hash[1 usize] = b10;
hash[2 usize] = c1;
hash[3 usize] = d1;
hash[4 usize] = e1;
hash[5 usize] = f1;
hash[6 usize] = g1;
hash[7 usize] = h12
});
if i < 4 u32 {
krml::unroll_for!(16 , "i0" , 0 u32, 1 u32, {
let t16: u64 = (&ws)[i0 as usize];
let t15: u64 = (&ws)[i0.wrapping_add(1 u32).wrapping_rem(16 u32) as usize];
let t7: u64 = (&ws)[i0.wrapping_add(9 u32).wrapping_rem(16 u32) as usize];
let t2: u64 = (&ws)[i0.wrapping_add(14 u32).wrapping_rem(16 u32) as usize];
let s1: u64 = (t2.wrapping_shl(45 u32) | t2.wrapping_shr(19 u32))
^ ((t2.wrapping_shl(3 u32) | t2.wrapping_shr(61 u32)) ^ t2.wrapping_shr(6 u32));
let s0: u64 = (t15.wrapping_shl(63 u32) | t15.wrapping_shr(1 u32))
^ ((t15.wrapping_shl(56 u32) | t15.wrapping_shr(8 u32)) ^ t15.wrapping_shr(7 u32));
(&mut ws)[i0 as usize] = s1.wrapping_add(t7).wrapping_add(s0).wrapping_add(t16)
})
}
});
krml::unroll_for!(8 , "i" , 0 u32, 1 u32, {
let x: u64 = (hash[i as usize]).wrapping_add((&hash_old)[i as usize]);
let os: (&mut [u64], &mut [u64]) = hash.split_at_mut(0 usize);
os.1 [i as usize] = x
})
}
pub fn sha512_update_nblocks(len: u32, b: &[u8], st: &mut [u64]) {
let blocks: u32 = len.wrapping_div(128 u32);
for i in 0 u32..blocks {
let b0: &[u8] = b;
let mb: (&[u8], &[u8]) = b0.split_at(i.wrapping_mul(128 u32) as usize);
crate ::hacl::sha512_update(mb.1 , st)
}
}
pub fn sha512_update_last(totlen: fstar::uint128::uint128, len: u32, b: &[u8], hash: &style='color:red'>mut [u64]) {
let blocks: u32 = if len.wrapping_add(16 u32).wrapping_add(1 u32) <= 128 u32 {
1 u32
} else {
2 u32
};
let fin: u32 = blocks.wrapping_mul(128 u32);
let mut last: [u8; 256 ] = [0 u8; 256 usize];
let mut totlen_buf: [u8; 16 ] = [0 u8; 16 usize];
let total_len_bits: fstar::uint128::uint128 = fstar::uint128::shift_left(totlen, 3 u32);
lowstar::endianness::store128_be(&mut totlen_buf, total_len_bits);
let b0: &[u8] = b;
((&mut last)[0 usize..len as usize]).copy_from_slice(&b0[e='color: green'>0 usize..len as usize]);
(&mut last)[len as usize] = 0 x80u8;
((&mut last)[fin.wrapping_sub(16 u32) as usize..fin.wrapping_sub(16 u32) as usize + 16 usize])
.copy_from_slice(&(&totlen_buf)[0 usize..16 usize]);
let last0: (&[u8], &[u8]) = last.split_at(0 usize);
let last1: (&[u8], &[u8]) = last0.1 .split_at(128 usize);
let l0: &[u8] = last1.0 ;
let l1: &[u8] = last1.1 ;
let lb0: &[u8] = l0;
let lb1: &[u8] = l1;
let last00: &[u8] = lb0;
let last10: &[u8] = lb1;
crate ::hacl::sha512_update(last00, hash);
if blocks > 1 u32 {
crate ::hacl::sha512_update(last10, hash)
}
}
pub fn sha512_finish(st: &[u64], h: &mut [u8]) {
let mut hbuf: [u8; 64 ] = [0 u8; 64 usize];
krml::unroll_for!(
8 ,
"i" ,
0 u32,
1 u32,
lowstar::endianness::store64_be(
&mut (&mut hbuf)[i.wrapping_mul(8 u32) as usize..],
st[i as usize]
)
);
(h[0 usize..64 usize]).copy_from_slice(&(&(&hbuf)[0 usize..])[0 usize..64 usize])
}
pub fn sha384_init(hash: &mut [u64]) {
krml::unroll_for!(8 , "i" , 0 u32, 1 u32, {
let x: u64 = (&crate ::hacl::h384)[i as usize];
let os: (&mut [u64], &mut [u64]) = hash.split_at_mut(0 usize);
os.1 [i as usize] = x
})
}
pub fn sha384_update_nblocks(len: u32, b: &[u8], st: &mut [u64]) {
crate ::hacl::sha512_update_nblocks(len, b, st)
}
pub fn sha384_update_last(totlen: fstar::uint128::uint128, len: u32, b: &[u8], st: &yle='color:red'>mut [u64]) {
crate ::hacl::sha512_update_last(totlen, len, b, st)
}
pub fn sha384_finish(st: &[u64], h: &mut [u8]) {
let mut hbuf: [u8; 64 ] = [0 u8; 64 usize];
krml::unroll_for!(
8 ,
"i" ,
0 u32,
1 u32,
lowstar::endianness::store64_be(
&mut (&mut hbuf)[i.wrapping_mul(8 u32) as usize..],
st[i as usize]
)
);
(h[0 usize..48 usize]).copy_from_slice(&(&(&hbuf)[0 usize..])[0 usize..48 usize])
}
pub type state_t_224 = streaming_types::state_32;
pub type state_t_256 = streaming_types::state_32;
pub type state_t_384 = streaming_types::state_64;
pub type state_t_512 = streaming_types::state_64;
/**
Allocate initial state for the SHA2_256 hash . The state is to be freed by
calling ` free_256 ` .
*/
pub fn malloc_256() -> Box <[streaming_types::state_32]> {
let buf: Box <[u8]> = vec![0 u8; 64 usize].into_boxed_slice();
let mut block_state: Box <[u32]> = vec![0 u32; 8 usize].into_boxed_slice();
crate ::hacl::sha256_init(&mut block_state);
let s: streaming_types::state_32 = streaming_types::state_32 {
block_state,
buf,
total_len: 0 u32 as u64,
};
let p: Box <[streaming_types::state_32]> = vec![s].into_boxed_slice();
p
}
/**
Copies the state passed as argument into a newly allocated state ( deep copy ) .
The state is to be freed by calling ` free_256 ` . Cloning the state this way is
useful , for instance , if your control - flow diverges and you need to feed
more ( different ) data into the hash in each branch .
*/
pub fn copy_256(state: &[streaming_types::state_32]) -> Box <[streaming_types::state_32]> {
let block_state0: &[u32] = &(state[0 usize]).block_state;
let buf0: &[u8] = &(state[0 usize]).buf;
let total_len0: u64 = (state[0 usize]).total_len;
let mut buf: Box <[u8]> = vec![0 u8; 64 usize].into_boxed_slice();
((&mut buf)[0 usize..64 usize]).copy_from_slice(&buf0[0 usize..64 usize]);
let mut block_state: Box <[u32]> = vec![0 u32; 8 usize].into_boxed_slice();
((&mut block_state)[0 usize..8 usize]).copy_from_slice(&block_state0[tyle='color: green'>0 usize..8 usize]);
let s: streaming_types::state_32 = streaming_types::state_32 {
block_state,
buf,
total_len: total_len0,
};
let p: Box <[streaming_types::state_32]> = vec![s].into_boxed_slice();
p
}
/**
Reset an existing state to the initial hash state with empty data .
*/
pub fn reset_256(state: &mut [streaming_types::state_32]) {
let block_state: &mut [u32] = &mut (state[0 usize]).block_state;
crate ::hacl::sha256_init(block_state);
let total_len: u64 = 0 u32 as u64;
(state[0 usize]).total_len = total_len
}
#[ inline]
fn update_224_256(
state: &mut [streaming_types::state_32],
chunk: &[u8],
chunk_len: u32,
) -> streaming_types::error_code {
let block_state: &mut [u32] = &mut (state[0 usize]).block_state;
let total_len: u64 = (state[0 usize]).total_len;
if chunk_len as u64 > 2305843009213693951 u64.wrapping_sub(total_len) {
streaming_types::error_code::MaximumLengthExceeded
} else {
let sz: u32 = if total_len.wrapping_rem(64 u32 as u64) == 0 u64 && total_len > 0 u64 {
64 u32
} else {
total_len.wrapping_rem(64 u32 as u64) as u32
};
if chunk_len <= 64 u32.wrapping_sub(sz) {
let buf: &mut [u8] = &mut (state[0 usize]).buf;
let total_len1: u64 = (state[0 usize]).total_len;
let sz1: u32 = if total_len1.wrapping_rem(64 u32 as u64) == 0 u64 && total_len1 > 0 u64 {
64 u32
} else {
total_len1.wrapping_rem(64 u32 as u64) as u32
};
let buf2: (&mut [u8], &mut [u8]) = buf.split_at_mut(sz1 as usize);
(buf2.1 [0 usize..chunk_len as usize])
.copy_from_slice(&chunk[0 usize..chunk_len as usize]);
let total_len2: u64 = total_len1.wrapping_add(chunk_len as u64);
(state[0 usize]).total_len = total_len2
} else if sz == 0 u32 {
let buf: &mut [u8] = &mut (state[0 usize]).buf;
let total_len1: u64 = (state[0 usize]).total_len;
let sz1: u32 = if total_len1.wrapping_rem(64 u32 as u64) == 0 u64 && total_len1 > 0 u64 {
64 u32
} else {
total_len1.wrapping_rem(64 u32 as u64) as u32
};
if sz1 != 0 u32 {
crate ::hacl::sha256_update_nblocks(64 u32, buf, block_state)
};
let ite: u32 = if (chunk_len as u64).wrapping_rem(64 u32 as u64) == 0 u64
&& chunk_len as u64 > 0 u64
{
64 u32
} else {
(chunk_len as u64).wrapping_rem(64 u32 as u64) as u32
};
let n_blocks: u32 = chunk_len.wrapping_sub(ite).wrapping_div(64 u32);
let data1_len: u32 = n_blocks.wrapping_mul(64 u32);
let data2_len: u32 = chunk_len.wrapping_sub(data1_len);
let data1: (&[u8], &[u8]) = chunk.split_at(0 usize);
let data2: (&[u8], &[u8]) = data1.1 .split_at(data1_len as usize);
crate ::hacl::sha256_update_nblocks(
data1_len.wrapping_div(64 u32).wrapping_mul(64 u32),
data2.0 ,
block_state,
);
let dst: (&mut [u8], &mut [u8]) = buf.split_at_mut(0 usize);
(dst.1 [0 usize..data2_len as usize])
.copy_from_slice(&data2.1 [0 usize..data2_len as usize]);
(state[0 usize]).total_len = total_len1.wrapping_add(chunk_len as u64)
} else {
let diff: u32 = 64 u32.wrapping_sub(sz);
let chunk1: (&[u8], &[u8]) = chunk.split_at(0 usize);
let chunk2: (&[u8], &[u8]) = chunk1.1 .split_at(diff as usize);
let buf: &mut [u8] = &mut (state[0 usize]).buf;
let total_len1: u64 = (state[0 usize]).total_len;
let sz1: u32 = if total_len1.wrapping_rem(64 u32 as u64) == 0 u64 && total_len1 > 0 u64 {
64 u32
} else {
total_len1.wrapping_rem(64 u32 as u64) as u32
};
let buf2: (&mut [u8], &mut [u8]) = buf.split_at_mut(sz1 as usize);
(buf2.1 [0 usize..diff as usize]).copy_from_slice(&chunk2.0 [0 usize..diff as usize]);
let total_len2: u64 = total_len1.wrapping_add(diff as u64);
(state[0 usize]).total_len = total_len2;
let buf0: &mut [u8] = &mut (state[0 usize]).buf;
let total_len10: u64 = (state[0 usize]).total_len;
let sz10: u32 = if total_len10.wrapping_rem(64 u32 as u64) == 0 u64 && total_len10 > 0 u64
{
64 u32
} else {
total_len10.wrapping_rem(64 u32 as u64) as u32
};
if sz10 != 0 u32 {
crate ::hacl::sha256_update_nblocks(64 u32, buf0, block_state)
};
let ite: u32 = if (chunk_len.wrapping_sub(diff) as u64).wrapping_rem(64 u32 as u64)
== 0 u64
&& chunk_len.wrapping_sub(diff) as u64 > 0 u64
{
64 u32
} else {
(chunk_len.wrapping_sub(diff) as u64).wrapping_rem(64 u32 as u64) as u32
};
let n_blocks: u32 = chunk_len
.wrapping_sub(diff)
.wrapping_sub(ite)
.wrapping_div(64 u32);
let data1_len: u32 = n_blocks.wrapping_mul(64 u32);
let data2_len: u32 = chunk_len.wrapping_sub(diff).wrapping_sub(data1_len);
let data1: (&[u8], &[u8]) = chunk2.1 .split_at(0 usize);
let data2: (&[u8], &[u8]) = data1.1 .split_at(data1_len as usize);
crate ::hacl::sha256_update_nblocks(
data1_len.wrapping_div(64 u32).wrapping_mul(64 u32),
data2.0 ,
block_state,
);
let dst: (&mut [u8], &mut [u8]) = buf0.split_at_mut(0 usize);
(dst.1 [0 usize..data2_len as usize])
.copy_from_slice(&data2.1 [0 usize..data2_len as usize]);
(state[0 usize]).total_len =
total_len10.wrapping_add(chunk_len.wrapping_sub(diff) as u64)
};
streaming_types::error_code::Success
}
}
/**
Feed an arbitrary amount of data into the hash . This function returns 0 for
success , or 1 if the combined length of all of the data passed to ` update_256 `
( since the last call to ` reset_256 ` ) exceeds 2 ^ 61 - 1 bytes .
This function is identical to the update function for SHA2_224 .
*/
pub fn update_256(
state: &mut [streaming_types::state_32],
input: &[u8],
input_len: u32,
) -> streaming_types::error_code {
crate ::hacl::update_224_256(state, input, input_len)
}
/**
Write the resulting hash into ` output ` , an array of 32 bytes . The state remains
valid after a call to ` digest_256 ` , meaning the user may feed more data into
the hash via ` update_256 ` . ( The digest_256 function operates on an internal copy of
the state and therefore does not invalidate the client - held state ` p ` . )
*/
pub fn digest_256(state: &[streaming_types::state_32], output: &mut [u8]) {
let block_state: &[u32] = &(state[0 usize]).block_state;
let buf_: &[u8] = &(state[0 usize]).buf;
let total_len: u64 = (state[0 usize]).total_len;
let r: u32 = if total_len.wrapping_rem(64 u32 as u64) == 0 u64 && total_len > 0 u64 {
64 u32
} else {
total_len.wrapping_rem(64 u32 as u64) as u32
};
let buf_1: (&[u8], &[u8]) = buf_.split_at(0 usize);
let mut tmp_block_state: [u32; 8 ] = [0 u32; 8 usize];
((&mut tmp_block_state)[0 usize..8 usize]).copy_from_slice(&block_state[an style='color: green'>0usize..8 usize]);
let buf_multi: (&[u8], &[u8]) = buf_1.1 .split_at(0 usize);
let ite: u32 = if r.wrapping_rem(64 u32) == 0 u32 && r > 0 u32 {
64 u32
} else {
r.wrapping_rem(64 u32)
};
let buf_last: (&[u8], &[u8]) = buf_multi.1 .split_at(r.wrapping_sub(ite) as usize);
crate ::hacl::sha256_update_nblocks(0 u32, buf_last.0 , &mut tmp_block_state);
let prev_len_last: u64 = total_len.wrapping_sub(r as u64);
crate ::hacl::sha256_update_last(
prev_len_last.wrapping_add(r as u64),
r,
buf_last.1 ,
&mut tmp_block_state,
);
crate ::hacl::sha256_finish(&tmp_block_state, output)
}
/**
Hash ` input ` , of len ` input_len ` , into ` output ` , an array of 32 bytes .
*/
pub fn hash_256(output: &mut [u8], input: &[u8], input_len: u32) {
let ib: &[u8] = input;
let rb: &mut [u8] = output;
let mut st: [u32; 8 ] = [0 u32; 8 usize];
crate ::hacl::sha256_init(&mut st);
let rem: u32 = input_len.wrapping_rem(64 u32);
let len·: u64 = input_len as u64;
crate ::hacl::sha256_update_nblocks(input_len, ib, &mut st);
let rem1: u32 = input_len.wrapping_rem(64 u32);
let b0: &[u8] = ib;
let lb: (&[u8], &[u8]) = b0.split_at(input_len.wrapping_sub(rem1) as usize);
crate ::hacl::sha256_update_last(len·, rem, lb.1 , &mut st);
crate ::hacl::sha256_finish(&st, rb)
}
pub fn malloc_224() -> Box <[streaming_types::state_32]> {
let buf: Box <[u8]> = vec![0 u8; 64 usize].into_boxed_slice();
let mut block_state: Box <[u32]> = vec![0 u32; 8 usize].into_boxed_slice();
crate ::hacl::sha224_init(&mut block_state);
let s: streaming_types::state_32 = streaming_types::state_32 {
block_state,
buf,
total_len: 0 u32 as u64,
};
let p: Box <[streaming_types::state_32]> = vec![s].into_boxed_slice();
p
}
pub fn reset_224(state: &mut [streaming_types::state_32]) {
let block_state: &mut [u32] = &mut (state[0 usize]).block_state;
crate ::hacl::sha224_init(block_state);
let total_len: u64 = 0 u32 as u64;
(state[0 usize]).total_len = total_len
}
pub fn update_224(
state: &mut [streaming_types::state_32],
input: &[u8],
input_len: u32,
) -> streaming_types::error_code {
crate ::hacl::update_224_256(state, input, input_len)
}
/**
Write the resulting hash into ` output ` , an array of 28 bytes . The state remains
valid after a call to ` digest_224 ` , meaning the user may feed more data into
the hash via ` update_224 ` .
*/
pub fn digest_224(state: &[streaming_types::state_32], output: &mut [u8]) {
let block_state: &[u32] = &(state[0 usize]).block_state;
let buf_: &[u8] = &(state[0 usize]).buf;
let total_len: u64 = (state[0 usize]).total_len;
let r: u32 = if total_len.wrapping_rem(64 u32 as u64) == 0 u64 && total_len > 0 u64 {
64 u32
} else {
total_len.wrapping_rem(64 u32 as u64) as u32
};
let buf_1: (&[u8], &[u8]) = buf_.split_at(0 usize);
let mut tmp_block_state: [u32; 8 ] = [0 u32; 8 usize];
((&mut tmp_block_state)[0 usize..8 usize]).copy_from_slice(&block_state[an style='color: green'>0usize..8 usize]);
let buf_multi: (&[u8], &[u8]) = buf_1.1 .split_at(0 usize);
let ite: u32 = if r.wrapping_rem(64 u32) == 0 u32 && r > 0 u32 {
64 u32
} else {
r.wrapping_rem(64 u32)
};
let buf_last: (&[u8], &[u8]) = buf_multi.1 .split_at(r.wrapping_sub(ite) as usize);
crate ::hacl::sha224_update_nblocks(0 u32, buf_last.0 , &mut tmp_block_state);
let prev_len_last: u64 = total_len.wrapping_sub(r as u64);
crate ::hacl::sha224_update_last(
prev_len_last.wrapping_add(r as u64),
r,
buf_last.1 ,
&mut tmp_block_state,
);
crate ::hacl::sha224_finish(&tmp_block_state, output)
}
/**
Hash ` input ` , of len ` input_len ` , into ` output ` , an array of 28 bytes .
*/
pub fn hash_224(output: &mut [u8], input: &[u8], input_len: u32) {
let ib: &[u8] = input;
let rb: &mut [u8] = output;
let mut st: [u32; 8 ] = [0 u32; 8 usize];
crate ::hacl::sha224_init(&mut st);
let rem: u32 = input_len.wrapping_rem(64 u32);
let len·: u64 = input_len as u64;
crate ::hacl::sha224_update_nblocks(input_len, ib, &mut st);
let rem1: u32 = input_len.wrapping_rem(64 u32);
let b0: &[u8] = ib;
let lb: (&[u8], &[u8]) = b0.split_at(input_len.wrapping_sub(rem1) as usize);
crate ::hacl::sha224_update_last(len·, rem, lb.1 , &mut st);
crate ::hacl::sha224_finish(&st, rb)
}
pub fn malloc_512() -> Box <[streaming_types::state_64]> {
let buf: Box <[u8]> = vec![0 u8; 128 usize].into_boxed_slice();
let mut block_state: Box <[u64]> = vec![0 u64; 8 usize].into_boxed_slice();
crate ::hacl::sha512_init(&mut block_state);
let s: streaming_types::state_64 = streaming_types::state_64 {
block_state,
buf,
total_len: 0 u32 as u64,
};
let p: Box <[streaming_types::state_64]> = vec![s].into_boxed_slice();
p
}
/**
Copies the state passed as argument into a newly allocated state ( deep copy ) .
The state is to be freed by calling ` free_512 ` . Cloning the state this way is
useful , for instance , if your control - flow diverges and you need to feed
more ( different ) data into the hash in each branch .
*/
pub fn copy_512(state: &[streaming_types::state_64]) -> Box <[streaming_types::state_64]> {
let block_state0: &[u64] = &(state[0 usize]).block_state;
let buf0: &[u8] = &(state[0 usize]).buf;
let total_len0: u64 = (state[0 usize]).total_len;
let mut buf: Box <[u8]> = vec![0 u8; 128 usize].into_boxed_slice();
((&mut buf)[0 usize..128 usize]).copy_from_slice(&buf0[0 usize..128 usize]);
let mut block_state: Box <[u64]> = vec![0 u64; 8 usize].into_boxed_slice();
((&mut block_state)[0 usize..8 usize]).copy_from_slice(&block_state0[tyle='color: green'>0 usize..8 usize]);
let s: streaming_types::state_64 = streaming_types::state_64 {
block_state,
buf,
total_len: total_len0,
};
let p: Box <[streaming_types::state_64]> = vec![s].into_boxed_slice();
p
}
pub fn reset_512(state: &mut [streaming_types::state_64]) {
let block_state: &mut [u64] = &mut (state[0 usize]).block_state;
crate ::hacl::sha512_init(block_state);
let total_len: u64 = 0 u32 as u64;
(state[0 usize]).total_len = total_len
}
#[ inline]
fn update_384_512(
state: &mut [streaming_types::state_64],
chunk: &[u8],
chunk_len: u32,
) -> streaming_types::error_code {
let block_state: &mut [u64] = &mut (state[0 usize]).block_state;
let total_len: u64 = (state[0 usize]).total_len;
if chunk_len as u64 > 18446744073709551615 u64.wrapping_sub(total_len) {
streaming_types::error_code::MaximumLengthExceeded
} else {
let sz: u32 = if total_len.wrapping_rem(128 u32 as u64) == 0 u64 && total_len > 0 u64 {
128 u32
} else {
total_len.wrapping_rem(128 u32 as u64) as u32
};
if chunk_len <= 128 u32.wrapping_sub(sz) {
let buf: &mut [u8] = &mut (state[0 usize]).buf;
let total_len1: u64 = (state[0 usize]).total_len;
let sz1: u32 = if total_len1.wrapping_rem(128 u32 as u64) == 0 u64 && total_len1 > 0 u64 {
128 u32
} else {
total_len1.wrapping_rem(128 u32 as u64) as u32
};
let buf2: (&mut [u8], &mut [u8]) = buf.split_at_mut(sz1 as usize);
(buf2.1 [0 usize..chunk_len as usize])
.copy_from_slice(&chunk[0 usize..chunk_len as usize]);
let total_len2: u64 = total_len1.wrapping_add(chunk_len as u64);
(state[0 usize]).total_len = total_len2
} else if sz == 0 u32 {
let buf: &mut [u8] = &mut (state[0 usize]).buf;
let total_len1: u64 = (state[0 usize]).total_len;
let sz1: u32 = if total_len1.wrapping_rem(128 u32 as u64) == 0 u64 && total_len1 > 0 u64 {
128 u32
} else {
total_len1.wrapping_rem(128 u32 as u64) as u32
};
if sz1 != 0 u32 {
crate ::hacl::sha512_update_nblocks(128 u32, buf, block_state)
};
let ite: u32 = if (chunk_len as u64).wrapping_rem(128 u32 as u64) == 0 u64
&& chunk_len as u64 > 0 u64
{
128 u32
} else {
(chunk_len as u64).wrapping_rem(128 u32 as u64) as u32
};
let n_blocks: u32 = chunk_len.wrapping_sub(ite).wrapping_div(128 u32);
let data1_len: u32 = n_blocks.wrapping_mul(128 u32);
let data2_len: u32 = chunk_len.wrapping_sub(data1_len);
let data1: (&[u8], &[u8]) = chunk.split_at(0 usize);
let data2: (&[u8], &[u8]) = data1.1 .split_at(data1_len as usize);
crate ::hacl::sha512_update_nblocks(
data1_len.wrapping_div(128 u32).wrapping_mul(128 u32),
data2.0 ,
block_state,
);
let dst: (&mut [u8], &mut [u8]) = buf.split_at_mut(0 usize);
(dst.1 [0 usize..data2_len as usize])
.copy_from_slice(&data2.1 [0 usize..data2_len as usize]);
(state[0 usize]).total_len = total_len1.wrapping_add(chunk_len as u64)
} else {
let diff: u32 = 128 u32.wrapping_sub(sz);
let chunk1: (&[u8], &[u8]) = chunk.split_at(0 usize);
let chunk2: (&[u8], &[u8]) = chunk1.1 .split_at(diff as usize);
let buf: &mut [u8] = &mut (state[0 usize]).buf;
let total_len1: u64 = (state[0 usize]).total_len;
let sz1: u32 = if total_len1.wrapping_rem(128 u32 as u64) == 0 u64 && total_len1 > 0 u64 {
128 u32
} else {
total_len1.wrapping_rem(128 u32 as u64) as u32
};
let buf2: (&mut [u8], &mut [u8]) = buf.split_at_mut(sz1 as usize);
(buf2.1 [0 usize..diff as usize]).copy_from_slice(&chunk2.0 [0 usize..diff as usize]);
let total_len2: u64 = total_len1.wrapping_add(diff as u64);
(state[0 usize]).total_len = total_len2;
let buf0: &mut [u8] = &mut (state[0 usize]).buf;
let total_len10: u64 = (state[0 usize]).total_len;
let sz10: u32 = if total_len10.wrapping_rem(128 u32 as u64) == 0 u64 && total_len10 > 0 u64
{
128 u32
} else {
total_len10.wrapping_rem(128 u32 as u64) as u32
};
if sz10 != 0 u32 {
crate ::hacl::sha512_update_nblocks(128 u32, buf0, block_state)
};
let ite: u32 = if (chunk_len.wrapping_sub(diff) as u64).wrapping_rem(128 u32 as u64)
== 0 u64
&& chunk_len.wrapping_sub(diff) as u64 > 0 u64
{
128 u32
} else {
(chunk_len.wrapping_sub(diff) as u64).wrapping_rem(128 u32 as u64) as u32
};
let n_blocks: u32 = chunk_len
.wrapping_sub(diff)
.wrapping_sub(ite)
.wrapping_div(128 u32);
let data1_len: u32 = n_blocks.wrapping_mul(128 u32);
let data2_len: u32 = chunk_len.wrapping_sub(diff).wrapping_sub(data1_len);
let data1: (&[u8], &[u8]) = chunk2.1 .split_at(0 usize);
let data2: (&[u8], &[u8]) = data1.1 .split_at(data1_len as usize);
crate ::hacl::sha512_update_nblocks(
data1_len.wrapping_div(128 u32).wrapping_mul(128 u32),
data2.0 ,
block_state,
);
let dst: (&mut [u8], &mut [u8]) = buf0.split_at_mut(0 usize);
(dst.1 [0 usize..data2_len as usize])
.copy_from_slice(&data2.1 [0 usize..data2_len as usize]);
(state[0 usize]).total_len =
total_len10.wrapping_add(chunk_len.wrapping_sub(diff) as u64)
};
streaming_types::error_code::Success
}
}
/**
Feed an arbitrary amount of data into the hash . This function returns 0 for
success , or 1 if the combined length of all of the data passed to ` update_512 `
( since the last call to ` reset_512 ` ) exceeds 2 ^ 125 - 1 bytes .
This function is identical to the update function for SHA2_384 .
*/
pub fn update_512(
state: &mut [streaming_types::state_64],
input: &[u8],
input_len: u32,
) -> streaming_types::error_code {
crate::hacl::update_384_512(state, input, input_len)
}
/**
Write the resulting hash into `output`, an array of 64 bytes. The state remains
valid after a call to `digest_512`, meaning the user may feed more data into
the hash via `update_512`. (The digest_512 function operates on an internal copy of
the state and therefore does not invalidate the client-held state `p`.)
*/
pub fn digest_512(state: &[streaming_types::state_64], output: &mut [u8]) {
let block_state: &[u64] = &(state[0 usize]).block_state;
let buf_: &[u8] = &(state[0 usize]).buf;
let total_len: u64 = (state[0 usize]).total_len;
let r: u32 = if total_len.wrapping_rem(128 u32 as u64) == 0 u64 && total_len > 0 u64 {
128 u32
} else {
total_len.wrapping_rem(128 u32 as u64) as u32
};
let buf_1: (&[u8], &[u8]) = buf_.split_at(0 usize);
let mut tmp_block_state: [u64; 8 ] = [0 u64; 8 usize];
((&mut tmp_block_state)[0 usize..8 usize]).copy_from_slice(&block_state[0 usize..8 usize]);
let buf_multi: (&[u8], &[u8]) = buf_1.1 .split_at(0 usize);
let ite: u32 = if r.wrapping_rem(128 u32) == 0 u32 && r > 0 u32 {
128 u32
} else {
r.wrapping_rem(128 u32)
};
let buf_last: (&[u8], &[u8]) = buf_multi.1 .split_at(r.wrapping_sub(ite) as usize);
crate::hacl::sha512_update_nblocks(0 u32, buf_last.0 , &mut tmp_block_state);
let prev_len_last: u64 = total_len.wrapping_sub(r as u64);
crate::hacl::sha512_update_last(
fstar::uint128::add(
fstar::uint128::uint64_to_uint128(prev_len_last),
fstar::uint128::uint64_to_uint128(r as u64),
),
r,
buf_last.1 ,
&mut tmp_block_state,
);
crate::hacl::sha512_finish(&tmp_block_state, output)
}
/**
Hash `input`, of len `input_len`, into `output`, an array of 64 bytes.
*/
pub fn hash_512(output: &mut [u8], input: &[u8], input_len: u32) {
let ib: &[u8] = input;
let rb: &mut [u8] = output;
let mut st: [u64; 8 ] = [0 u64; 8 usize];
crate::hacl::sha512_init(&mut st);
let rem: u32 = input_len.wrapping_rem(128 u32);
let len·: fstar::uint128::uint128 = fstar::uint128::uint64_to_uint128(input_len as u64);
crate::hacl::sha512_update_nblocks(input_len, ib, &mut st);
let rem1: u32 = input_len.wrapping_rem(128 u32);
let b0: &[u8] = ib;
let lb: (&[u8], &[u8]) = b0.split_at(input_len.wrapping_sub(rem1) as usize);
crate::hacl::sha512_update_last(len·, rem, lb.1 , &mut st);
crate::hacl::sha512_finish(&st, rb)
}
pub fn malloc_384() -> Box<[streaming_types::state_64]> {
let buf: Box<[u8]> = vec![0 u8; 128 usize].into_boxed_slice();
let mut block_state: Box<[u64]> = vec![0 u64; 8 usize].into_boxed_slice();
crate::hacl::sha384_init(&mut block_state);
let s: streaming_types::state_64 = streaming_types::state_64 {
block_state,
buf,
total_len: 0 u32 as u64,
};
let p: Box<[streaming_types::state_64]> = vec![s].into_boxed_slice();
p
}
pub fn reset_384(state: &mut [streaming_types::state_64]) {
let block_state: &mut [u64] = &mut (state[0 usize]).block_state;
crate::hacl::sha384_init(block_state);
let total_len: u64 = 0 u32 as u64;
(state[0 usize]).total_len = total_len
}
pub fn update_384(
state: &mut [streaming_types::state_64],
input: &[u8],
input_len: u32,
) -> streaming_types::error_code {
crate::hacl::update_384_512(state, input, input_len)
}
/**
Write the resulting hash into `output`, an array of 48 bytes. The state remains
valid after a call to `digest_384`, meaning the user may feed more data into
the hash via `update_384`.
*/
pub fn digest_384(state: &[streaming_types::state_64], output: &mut [u8]) {
let block_state: &[u64] = &(state[0 usize]).block_state;
let buf_: &[u8] = &(state[0 usize]).buf;
let total_len: u64 = (state[0 usize]).total_len;
let r: u32 = if total_len.wrapping_rem(128 u32 as u64) == 0 u64 && total_len > 0 u64 {
128 u32
} else {
total_len.wrapping_rem(128 u32 as u64) as u32
};
let buf_1: (&[u8], &[u8]) = buf_.split_at(0 usize);
let mut tmp_block_state: [u64; 8 ] = [0 u64; 8 usize];
((&mut tmp_block_state)[0 usize..8 usize]).copy_from_slice(&block_state[0 usize..8 usize]);
let buf_multi: (&[u8], &[u8]) = buf_1.1 .split_at(0 usize);
let ite: u32 = if r.wrapping_rem(128 u32) == 0 u32 && r > 0 u32 {
128 u32
} else {
r.wrapping_rem(128 u32)
};
let buf_last: (&[u8], &[u8]) = buf_multi.1 .split_at(r.wrapping_sub(ite) as usize);
crate::hacl::sha384_update_nblocks(0 u32, buf_last.0 , &mut tmp_block_state);
let prev_len_last: u64 = total_len.wrapping_sub(r as u64);
crate::hacl::sha384_update_last(
fstar::uint128::add(
fstar::uint128::uint64_to_uint128(prev_len_last),
fstar::uint128::uint64_to_uint128(r as u64),
),
r,
buf_last.1 ,
&mut tmp_block_state,
);
crate::hacl::sha384_finish(&tmp_block_state, output)
}
/**
Hash `input`, of len `input_len`, into `output`, an array of 48 bytes.
*/
pub fn hash_384(output: &mut [u8], input: &[u8], input_len: u32) {
let ib: &[u8] = input;
let rb: &mut [u8] = output;
let mut st: [u64; 8 ] = [0 u64; 8 usize];
crate::hacl::sha384_init(&mut st);
let rem: u32 = input_len.wrapping_rem(128 u32);
let len·: fstar::uint128::uint128 = fstar::uint128::uint64_to_uint128(input_len as u64);
crate::hacl::sha384_update_nblocks(input_len, ib, &mut st);
let rem1: u32 = input_len.wrapping_rem(128 u32);
let b0: &[u8] = ib;
let lb: (&[u8], &[u8]) = b0.split_at(input_len.wrapping_sub(rem1) as usize);
crate::hacl::sha384_update_last(len·, rem, lb.1 , &mut st);
crate::hacl::sha384_finish(&st, rb)
}
Messung V0.5 in Prozent C=91 H=93 G=91
¤ Dauer der Verarbeitung: 0.25 Sekunden
(vorverarbeitet am 2026-08-25)
¤
*© Formatika GbR, Deutschland