code wiki / (root) / nx_aes_ctr_helper_test.nx

nx_aes_ctr_helper_test.nx source

↩ module page · 58 lines · 2274 B

1// expect_exit: 0 2// Helper-based 64-byte AES-CTR test. Was failing pre-fix. 3// 4// license_tier: ORIGINAL 5 6import "nx_syscalls.nx" 7import "nx_aes.nx" 8import "nx_aes_ctr.nx" 9 10func main() -> i64 { 11 let key: *u8 = sys_mmap(64) 12 let nonce: *u8 = sys_mmap(32) 13 let icb: *u8 = sys_mmap(64) 14 let pt: *u8 = sys_mmap(128) 15 let ct: *u8 = sys_mmap(128) 16 let sched: *u8 = sys_mmap(AES_EXP_LEN + 16) 17 18 key[0]=0x2b; key[1]=0x7e; key[2]=0x15; key[3]=0x16 19 key[4]=0x28; key[5]=0xae; key[6]=0xd2; key[7]=0xa6 20 key[8]=0xab; key[9]=0xf7; key[10]=0x15; key[11]=0x88 21 key[12]=0x09; key[13]=0xcf; key[14]=0x4f; key[15]=0x3c 22 23 nonce[0]=0xf0; nonce[1]=0xf1; nonce[2]=0xf2; nonce[3]=0xf3 24 nonce[4]=0xf4; nonce[5]=0xf5; nonce[6]=0xf6; nonce[7]=0xf7 25 nonce[8]=0xf8; nonce[9]=0xf9; nonce[10]=0xfa; nonce[11]=0xfb 26 27 aes128_ctr_build_icb(icb, nonce, 0xfcfdfeff) 28 29 pt[0]=0x6b; pt[1]=0xc1; pt[2]=0xbe; pt[3]=0xe2 30 pt[4]=0x2e; pt[5]=0x40; pt[6]=0x9f; pt[7]=0x96 31 pt[8]=0xe9; pt[9]=0x3d; pt[10]=0x7e; pt[11]=0x11 32 pt[12]=0x73; pt[13]=0x93; pt[14]=0x17; pt[15]=0x2a 33 pt[16]=0xae; pt[17]=0x2d; pt[18]=0x8a; pt[19]=0x57 34 pt[20]=0x1e; pt[21]=0x03; pt[22]=0xac; pt[23]=0x9c 35 pt[24]=0x9e; pt[25]=0xb7; pt[26]=0x6f; pt[27]=0xac 36 pt[28]=0x45; pt[29]=0xaf; pt[30]=0x8e; pt[31]=0x51 37 pt[32]=0x30; pt[33]=0xc8; pt[34]=0x1c; pt[35]=0x46 38 pt[36]=0xa3; pt[37]=0x5c; pt[38]=0xe4; pt[39]=0x11 39 pt[40]=0xe5; pt[41]=0xfb; pt[42]=0xc1; pt[43]=0x19 40 pt[44]=0x1a; pt[45]=0x0a; pt[46]=0x52; pt[47]=0xef 41 pt[48]=0xf6; pt[49]=0x9f; pt[50]=0x24; pt[51]=0x45 42 pt[52]=0xdf; pt[53]=0x4f; pt[54]=0x9b; pt[55]=0x17 43 pt[56]=0xad; pt[57]=0x2b; pt[58]=0x41; pt[59]=0x7b 44 pt[60]=0xe6; pt[61]=0x6c; pt[62]=0x37; pt[63]=0x10 45 46 aes128_expand_key(key, sched) 47 aes128_ctr_xor(sched, icb, pt, 64, ct) 48 49 if ((ct[0] as i64) & 0xff) != 0x87 { return 1 } 50 if ((ct[15] as i64) & 0xff) != 0xce { return 2 } 51 if ((ct[16] as i64) & 0xff) != 0x98 { return 3 } 52 if ((ct[31] as i64) & 0xff) != 0xff { return 4 } 53 if ((ct[32] as i64) & 0xff) != 0x5a { return 5 } 54 if ((ct[47] as i64) & 0xff) != 0xab { return 6 } 55 if ((ct[48] as i64) & 0xff) != 0x1e { return 7 } 56 if ((ct[63] as i64) & 0xff) != 0xee { return 8 } 57 return 0 58}