bitcoin-sha512 0.1.19

SHA-256 and SHA-512 are novel hash functions computed with eight 32-bit and 64-bit words, respectively. They use different shift amounts and additive constants, but their structures are otherwise virtually identical, differing only in the number of rounds. (from wikipedia)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// ---------------- [ File: bitcoin-sha512/src/sha512_beio.rs ]
crate::ix!();

// Small helpers for BE load/store (kept private to this module)
#[inline(always)]
pub fn read_be64(p: *const u8) -> u64 {
    let mut b = [0u8; 8];
    unsafe { ptr::copy_nonoverlapping(p, b.as_mut_ptr(), 8); }
    u64::from_be_bytes(b)
}

#[inline(always)]
pub fn write_be64_into(buf: &mut [u8], off: usize, x: u64) {
    let be = x.to_be_bytes();
    buf[off..off + 8].copy_from_slice(&be);
}