code wiki / (root) / nx_argon2id_xvalidate_test.nx

nx_argon2id_xvalidate_test.nx source

↩ module page · 82 lines · 3034 B

1// nx_argon2id_xvalidate_test.nx -- byte-exact cross-validation vs 2// argon2_ref C reference output. 3// 4// expect_exit: 0 5// 6// Reference tag generated 2026-05-17 with libargon2-1 (20190702): 7// /tmp/argon2id_ref_harness password somesalt 8 2 1 32 8// -> fdb4ddb6d5887131b66f0b2a3740c077dd05b755845861f6b5a1dde8b1071646 9// 10// Closes the verdict gap from NOT_YET_EVALUATED to OK if PASSES; 11// surfaces the first mismatching byte index + 100 if FAILS so the 12// bisect path stays open. 13// 14// Per cardinal feedback-honest-perf-verdict-no-aspirational-claims: 15// a from-scratch Argon2id implementation matching reference output 16// byte-exact on the first run is rare. Expect to bisect. 17// 18// license_tier: ORIGINAL 19 20import "nx_syscalls_x86_64.nx" 21import "nx_blake2b.nx" 22import "nx_argon2_block.nx" 23import "nx_argon2id.nx" 24 25func make_ctx(m_kib_cap: i64) -> *NxArgon2idCtx { 26 let raw: *u8 = sys_mmap(NX_ARGON2ID_CTX_BYTES) 27 let ctx: *NxArgon2idCtx = raw as *NxArgon2idCtx 28 ctx.memory_blocks = sys_mmap(m_kib_cap * 1024) 29 ctx.h0_buf = sys_mmap(64) 30 ctx.prepend_buf = sys_mmap(2048) 31 ctx.prev_buf = sys_mmap(64) 32 ctx.curr_buf = sys_mmap(64) 33 ctx.zero_block = sys_mmap(1024) 34 ctx.z_buf = sys_mmap(1024) 35 ctx.tmp_block = sys_mmap(1024) 36 ctx.addr_block = sys_mmap(1024) 37 ctx.final_block = sys_mmap(1024) 38 ctx.h0_input = sys_mmap(2048) 39 ctx.b2b_ctx = sys_mmap(NX_BLAKE2B_CTX_BYTES) as *NxBlake2b 40 ctx.b2b_buf = sys_mmap(128) 41 ctx.b2b_sv = sys_mmap(128) as *i64 42 ctx.b2b_sm = sys_mmap(128) as *i64 43 ctx.g_r = sys_mmap(1024) as *i64 44 ctx.g_rs = sys_mmap(1024) as *i64 45 ctx.g_col = sys_mmap(128) as *i64 46 return ctx 47} 48 49func write_expected(out: *u8) -> i64 { 50 out[0] = 253 as u8; out[1] = 180 as u8; out[2] = 221 as u8; out[3] = 182 as u8 51 out[4] = 213 as u8; out[5] = 136 as u8; out[6] = 113 as u8; out[7] = 49 as u8 52 out[8] = 182 as u8; out[9] = 111 as u8; out[10] = 11 as u8; out[11] = 42 as u8 53 out[12] = 55 as u8; out[13] = 64 as u8; out[14] = 192 as u8; out[15] = 119 as u8 54 out[16] = 221 as u8; out[17] = 5 as u8; out[18] = 183 as u8; out[19] = 85 as u8 55 out[20] = 132 as u8; out[21] = 88 as u8; out[22] = 97 as u8; out[23] = 246 as u8 56 out[24] = 181 as u8; out[25] = 161 as u8; out[26] = 221 as u8; out[27] = 232 as u8 57 out[28] = 177 as u8; out[29] = 7 as u8; out[30] = 22 as u8; out[31] = 70 as u8 58 return 0 59} 60 61func main() -> i64 { 62 let ctx: *NxArgon2idCtx = make_ctx(8) 63 let tag: *u8 = sys_mmap(64) 64 let expected: *u8 = sys_mmap(64) 65 write_expected(expected) 66 67 let password: *u8 = "password" as *u8 68 let salt: *u8 = "somesalt" as *u8 69 70 if nx_argon2id_hash(ctx, password, 8, salt, 8, 71 1, 32, 8, 2, 72 tag) != NX_AR2_OK { return 1 } 73 74 // Byte-by-byte compare; return 100 + first mismatch index for 75 // bisection. PASS = exit 0. 76 var i: i64 = 0 77 while i < 32 { 78 if tag[i] != expected[i] { return 100 + i } 79 i = i + 1 80 } 81 return 0 82}