code wiki / (root) / _aes128_gcm_throughput_bench.nx

_aes128_gcm_throughput_bench.nx source

↩ module page · 55 lines · 2091 B

1// _aes128_gcm_throughput_bench.nx -- pure-software AES-128-GCM 2// throughput baseline. Encrypts a 4 KiB plaintext buffer N times 3// (= 16 MiB total) so paired wall-clock timing converts to MB/s. 4// 5// Target use: 6// Establish the BASELINE for the pure-software substrate AES-128-GCM 7// path so future silicon-ROI claims have a fixed number to beat: 8// - vs OpenSSL software AES (~150 MB/s on modern x86_64) 9// - vs OpenSSL AES-NI (~5000 MB/s on modern x86_64) 10// - vs hypothetical Nishi-silicon AES instruction (Tier B+ MPW) 11// 12// Cardinal 25 ("build intelligence, never strip features"): this is 13// ADDITIVE -- existing KAT smoke (nx_aes128_gcm_kat_smoke.sh) keeps 14// guarding correctness; this script adds the throughput dimension. 15// 16// Algorithm under test: 17// nx_aes128_gcm_seal(key, iv, aad=NULL, aad_len=0, pt, pt_len=4096, 18// ct, tag) 19// 20// Returns: 0 (success); non-zero returns indicate setup failure that 21// the wrapping smoke script will report. 22 23import "nx_syscalls.nx" 24import "nx_aes128_gcm.nx" 25 26func main() -> i64 { 27 let key: *u8 = sys_mmap(16) 28 let iv: *u8 = sys_mmap(12) 29 let pt: *u8 = sys_mmap(4096) 30 let ct: *u8 = sys_mmap(4096) 31 let tag: *u8 = sys_mmap(16) 32 33 // Deterministic, repeatable inputs. Key + IV all-zero matches 34 // NIST SP 800-38D Test Case 2 conventions; pt is a known sawtooth 35 // pattern so the compiler can't const-fold the encryption away. 36 var i: i64 = 0 37 while i < 16 { key[i] = 0 as u8; i = i + 1 } 38 i = 0 39 while i < 12 { iv[i] = 0 as u8; i = i + 1 } 40 i = 0 41 while i < 4096 { pt[i] = (i & 0xff) as u8; i = i + 1 } 42 43 let null_aad: *u8 = (0 as i64) as *u8 44 let iters: i64 = 4096 // 4096 * 4 KiB = 16 MiB total processed 45 var n: i64 = 0 46 while n < iters { 47 nx_aes128_gcm_seal(key, iv, null_aad, 0, pt, 4096, ct, tag) 48 n = n + 1 49 } 50 51 // Defeat dead-code-elimination: fold a byte from the final tag 52 // into the exit code (masked so the process still exits cleanly). 53 let sentinel: i64 = (tag[0] as i64) & 0 54 return sentinel 55}