nx_argon2id_t1_xvalidate.nx source
↩ module page · 61 lines · 2474 B
1// t=1 cross-validation (libargon2 ref + Python pyref agree).
2// expect_exit: 0
3// Expected: f137f8e186a403a679ccd0606e5ab5dcdafe43c1640855ac8c6e33e9bd63eeb3
4
5import "nx_syscalls_x86_64.nx"
6import "nx_blake2b.nx"
7import "nx_argon2_block.nx"
8import "nx_argon2id.nx"
9const K_MAGIC_1024: i64 = 1024
10const K_MAGIC_2048: i64 = 2048
11
12func make_ctx() -> *NxArgon2idCtx {
13 let raw: *u8 = sys_mmap(NX_ARGON2ID_CTX_BYTES)
14 let ctx: *NxArgon2idCtx = raw as *NxArgon2idCtx
15 ctx.memory_blocks = sys_mmap(8 * K_MAGIC_1024)
16 ctx.h0_buf = sys_mmap(64)
17 ctx.prepend_buf = sys_mmap(K_MAGIC_2048)
18 ctx.prev_buf = sys_mmap(64)
19 ctx.curr_buf = sys_mmap(64)
20 ctx.zero_block = sys_mmap(K_MAGIC_1024)
21 ctx.z_buf = sys_mmap(K_MAGIC_1024)
22 ctx.tmp_block = sys_mmap(K_MAGIC_1024)
23 ctx.addr_block = sys_mmap(K_MAGIC_1024)
24 ctx.final_block = sys_mmap(K_MAGIC_1024)
25 ctx.h0_input = sys_mmap(K_MAGIC_2048)
26 ctx.b2b_ctx = sys_mmap(NX_BLAKE2B_CTX_BYTES) as *NxBlake2b
27 ctx.b2b_buf = sys_mmap(128)
28 ctx.b2b_sv = sys_mmap(128) as *i64
29 ctx.b2b_sm = sys_mmap(128) as *i64
30 ctx.g_r = sys_mmap(K_MAGIC_1024) as *i64
31 ctx.g_rs = sys_mmap(K_MAGIC_1024) as *i64
32 ctx.g_col = sys_mmap(128) as *i64
33 return ctx
34}
35
36func main() -> i64 {
37 let ctx: *NxArgon2idCtx = make_ctx()
38 let tag: *u8 = sys_mmap(64)
39
40 if nx_argon2id_hash(ctx, "password" as *u8, 8, "somesalt" as *u8, 8,
41 1, 32, 8, 1, tag) != NX_AR2_OK { return 1 }
42
43 // Expected: 241 55 248 225 134 164 3 166 121 204 208 96 110 90 181 220
44 // 218 254 67 193 100 8 85 172 140 110 51 233 189 99 238 179
45 let exp: *u8 = sys_mmap(32)
46 exp[0] = 241 as u8; exp[1] = 55 as u8; exp[2] = 248 as u8; exp[3] = 225 as u8
47 exp[4] = 134 as u8; exp[5] = 164 as u8; exp[6] = 3 as u8; exp[7] = 166 as u8
48 exp[8] = 121 as u8; exp[9] = 204 as u8; exp[10] = 208 as u8; exp[11] = 96 as u8
49 exp[12] = 110 as u8; exp[13] = 90 as u8; exp[14] = 181 as u8; exp[15] = 220 as u8
50 exp[16] = 218 as u8; exp[17] = 254 as u8; exp[18] = 67 as u8; exp[19] = 193 as u8
51 exp[20] = 100 as u8; exp[21] = 8 as u8; exp[22] = 85 as u8; exp[23] = 172 as u8
52 exp[24] = 140 as u8; exp[25] = 110 as u8; exp[26] = 51 as u8; exp[27] = 233 as u8
53 exp[28] = 189 as u8; exp[29] = 99 as u8; exp[30] = 238 as u8; exp[31] = 179 as u8
54
55 var i: i64 = 0
56 while i < 32 {
57 if tag[i] != exp[i] { return 100 + i }
58 i = i + 1
59 }
60 return 0
61}