Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/sha2/src/sha256/soft_compact.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / sha2 / src / sha256 / soft_compact.rs` 66 lines ยท 1922 bytes Raw Blame History 1 use crate::consts::K32; 2 3 fn to_u32s(block: &[u8; 64]) -> [u32; 16] { 4 use core::convert::TryInto; 5 let mut res = [0u32; 16]; 6 for i in 0..16 { 7 let chunk = block[4 * i..][..4].try_into().unwrap(); 8 res[i] = u32::from_be_bytes(chunk); 9 } 10 res 11 } 12 13 fn compress_u32(state: &mut [u32; 8], block: [u32; 16]) { 14 let [mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h] = *state; 15 16 let mut w = [0; 64]; 17 w[..16].copy_from_slice(&block); 18 19 for i in 16..64 { 20 let w15 = w[i - 15]; 21 let s0 = (w15.rotate_right(7)) ^ (w15.rotate_right(18)) ^ (w15 >> 3); 22 let w2 = w[i - 2]; 23 let s1 = (w2.rotate_right(17)) ^ (w2.rotate_right(19)) ^ (w2 >> 10); 24 w[i] = w[i - 16] 25 .wrapping_add(s0) 26 .wrapping_add(w[i - 7]) 27 .wrapping_add(s1); 28 } 29 30 for i in 0..64 { 31 let s1 = e.rotate_right(6) ^ e.rotate_right(11) ^ e.rotate_right(25); 32 let ch = (e & f) ^ ((!e) & g); 33 let t1 = s1 34 .wrapping_add(ch) 35 .wrapping_add(K32[i]) 36 .wrapping_add(w[i]) 37 .wrapping_add(h); 38 let s0 = a.rotate_right(2) ^ a.rotate_right(13) ^ a.rotate_right(22); 39 let maj = (a & b) ^ (a & c) ^ (b & c); 40 let t2 = s0.wrapping_add(maj); 41 42 h = g; 43 g = f; 44 f = e; 45 e = d.wrapping_add(t1); 46 d = c; 47 c = b; 48 b = a; 49 a = t1.wrapping_add(t2); 50 } 51 52 state[0] = state[0].wrapping_add(a); 53 state[1] = state[1].wrapping_add(b); 54 state[2] = state[2].wrapping_add(c); 55 state[3] = state[3].wrapping_add(d); 56 state[4] = state[4].wrapping_add(e); 57 state[5] = state[5].wrapping_add(f); 58 state[6] = state[6].wrapping_add(g); 59 state[7] = state[7].wrapping_add(h); 60 } 61 62 pub fn compress(state: &mut [u32; 8], blocks: &[[u8; 64]]) { 63 for block in blocks.iter() { 64 compress_u32(state, to_u32s(block)); 65 } 66 }