code wiki / (root) / nx_ghash_clmul.nx

nx_ghash_clmul.nx

buildroot/runtime/nx_ghash_clmul.nx

7793 B186 linesdepth 2pulls 2 transitivereach 596 importersview sourcekind tooltopic ghash
docsdependenciesstructsconstsfunctions

about

nx_ghash_clmul.nx -- hardware PCLMULQDQ backend for GF(2^128) multiply (GHASH core). Byte-IDENTICAL drop-in for nx_ghash.nx's nx_ghash_mul, ~hardware speed vs the ~1 MB/s bit-by-bit reference. Gated against that reference as the oracle (KAT-equality). Bridge from GCM's bit convention to PCLMULQDQ: GCM (SP 800-38D) stores coeff(x^i) MSB-FIRST: byte (i>>3), bit position (7-(i&7)). PCLMULQDQ multiplies polynomials where integer-bit k = coeff(x^k) (LSB-first). A BYTEWISE bit-reversal (reverse the 8 bits WITHIN each byte; byte order unchanged) maps GCM coeff(x^k) onto little-endian integer-bit k -- exactly pclmulqdq's input. So: bitrev each input -> 4 clmuls (schoolbook 128x128 -> 256) -> reduce mod P(x)=x^128+x^7+x^2+x+1 -> bitrev the 128-bit result back to GCM byte order. The reduction uses x^128 = x^7+x^2+x+1 (mod P): fold the high 128 bits H by H*(x^7+x^2+x+1) (two folds -- the first leaves <=7 overflow bits past bit 127, the second clears them). NishiLang `>>` is ARITHMETIC, so gh_lshr() masks to emulate a logical shift. license_tier: ORIGINAL (composes nx_ghash.nx conventions; new CLMUL lowering) genealogy_id: international-research-sources/intel/clmul-gcm lineage_id: nishi_ghash_clmul_q1

dependencies 1 imports · 3 importers

nx_syscalls.nx nx_ghash_clmul.nx nx_ghash.nx nx_ghash_bench.nx nx_ghash_clmul_gate.nx

imports: nx_syscalls.nx

imported by: nx_ghash.nxnx_ghash_bench.nxnx_ghash_clmul_gate.nx

structs

none

consts

none

functions

27func gh_scratch() -> *u8
33func gh_revbyte(b: i64) -> i64
called by 1: gh_revtab
46func gh_revtab() -> *u8
called by 1: gh_byterev_bits calls 2: sys_mmapgh_revbyte
57func gh_byterev_bits(src: *u8, dst: *u8) -> i64
66func gh_lshr(x: i64, n: i64) -> i64
called by 1: gh_clmul_reduce256
91func gh_clmul_mul256_acc(a16: *u8, b16: *u8, acc: *i64) -> i64
124func gh_clmul_reduce256(acc: *i64, out16: *u8) -> i64
159func gh_clmul_core(a16: *u8, b16: *u8, out16: *u8) -> i64
171func nx_ghash_mul_clmul(x16: *u8, h16: *u8, z16: *u8) -> i64
184func main() -> i64