nx_ghash_clmul.nx
buildroot/runtime/nx_ghash_clmul.nx
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
imports: nx_syscalls.nx
imported by: nx_ghash.nxnx_ghash_bench.nxnx_ghash_clmul_gate.nx
structs
| none |
consts
| none |
functions
| 27 | func gh_scratch() -> *u8 |
| 33 | func gh_revbyte(b: i64) -> i64 called by 1: gh_revtab |
| 46 | func gh_revtab() -> *u8 |
| 57 | func gh_byterev_bits(src: *u8, dst: *u8) -> i64 called by 4: nx_ghash_reflect16nx_ghash_upd_revnx_ghash_upd_rev4nx_ghash_mul_clmul calls 1: gh_revtab |
| 66 | func gh_lshr(x: i64, n: i64) -> i64 called by 1: gh_clmul_reduce256 |
| 91 | func gh_clmul_mul256_acc(a16: *u8, b16: *u8, acc: *i64) -> i64 |
| 124 | func gh_clmul_reduce256(acc: *i64, out16: *u8) -> i64 |
| 159 | func gh_clmul_core(a16: *u8, b16: *u8, out16: *u8) -> i64 |
| 171 | func nx_ghash_mul_clmul(x16: *u8, h16: *u8, z16: *u8) -> i64 |
| 184 | func main() -> i64 |