bitcoin-sha256 0.1.20

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
17
18
// ---------------- [ File: bitcoin-sha256/src/majority_and_choice.rs ]
crate::ix!();

/// Choice function: `z ^ (x & (y ^ z))`
#[inline(always)]
pub fn sha256_ch(x: u32, y: u32, z: u32) -> u32 {
    let res = z ^ (x & (y ^ z));
    trace!(target: "sha256", x, y, z, res, "sha256_ch");
    res
}

/// Majority function: `(x & y) | (z & (x | y))`
#[inline(always)]
pub fn sha256_maj(x: u32, y: u32, z: u32) -> u32 {
    let res = (x & y) | (z & (x | y));
    trace!(target: "sha256", x, y, z, res, "sha256_maj");
    res
}