code wiki / (root) / _sha512_kernel_fast.nx

_sha512_kernel_fast.nx source

↩ module page · 25 lines · 820 B

1// _sha512_kernel_fast.nx -- SHA-512 nonlinear-function rotation 2// pattern using FAST nx_bits_rotr64 (rorq intrinsic). 3// 4// Sigma0(x) = rotr(x,28) ^ rotr(x,34) ^ rotr(x,39) 5// Sigma1(x) = rotr(x,14) ^ rotr(x,18) ^ rotr(x,41) 6// 7// Each iteration computes Sigma0(x) + Sigma1(x) = 6 rotates + 4 xor + 1 add. 8 9import "syscalls.nx" 10import "nx_bits.nx" 11 12func main() -> i64 { 13 let iters: i64 = 100000000 14 var acc: i64 = 0 15 var x: i64 = 0xCAFEBABE12345678 16 var i: i64 = 0 17 while i < iters { 18 let s0: i64 = nx_bits_rotr64(x, 28) ^ nx_bits_rotr64(x, 34) ^ nx_bits_rotr64(x, 39) 19 let s1: i64 = nx_bits_rotr64(x, 14) ^ nx_bits_rotr64(x, 18) ^ nx_bits_rotr64(x, 41) 20 acc = acc + s0 + s1 21 x = x * 6364136223846793005 + 1442695040888963407 22 i = i + 1 23 } 24 return acc & 0 25}