static void do_f1_f1star ( uint8_t * key, uint8_t * rand, uint8_t * sqn, uint8_t * amf, uint8_t * op, uint8_t * f1_exp, uint8_t * f1star_exp) { uint8_t res[8]; SetOPc (op); f1 (key, rand, sqn, amf, res); if (compare_buffer (res, 8, f1_exp, 8) != 0) { fail ("Fail: f1"); } f1star (key, rand, sqn, amf, res); if (compare_buffer (res, 8, f1star_exp, 8) != 0) { fail ("Fail: f1*"); } }
static void do_f2f3f5(uint8_t *key, uint8_t *rand, uint8_t *op, uint8_t *f2_exp, uint8_t *f5_exp, uint8_t *f3_exp) { uint8_t res_f2[8]; uint8_t res_f5[6]; uint8_t res_f3[16]; uint8_t res_f4[16]; SetOPc(op); f2345(key, rand, res_f2, res_f3, res_f4, res_f5); if (compare_buffer(res_f2, 8, f2_exp, 8) != 0) { fail("Fail: f2"); } if (compare_buffer(res_f5, 6, f5_exp, 6) != 0) { fail("Fail: f5"); } if (compare_buffer(res_f3, 16, f3_exp, 16) != 0) { fail("Fail: f3"); } }
/* * Derive the Kasme using the KDF (key derive function). * See 3GPP TS.33401 Annex A.2 * The input String S to the KDF is composed of 14 bytes: * FC = 0x10 * P0 = SN id = PLMN * L0 = length(SN id) = 0x00 0x03 * P1 = SQN xor AK * L1 = length(P1) = 0x00 0x06 */ inline void derive_kasme(uint8_t ck[16], uint8_t ik[16], uint8_t plmn[3], uint8_t sqn[6], uint8_t ak[6], uint8_t *kasme) { uint8_t s[14]; int i; uint8_t key[32]; /* The input key is equal to the concatenation of CK and IK */ memcpy(&key[0], ck, 16); memcpy(&key[16], ik, 16); SetOPc(opc); /* FC */ s[0] = 0x10; /* SN id is composed of MCC and MNC * Octets: * 1 MCC digit 2 | MCC digit 1 * 2 MNC digit 3 | MCC digit 3 * 3 MNC digit 2 | MNC digit 1 */ memcpy(&s[1], plmn, 3); /* L0 */ s[4] = 0x00; s[5] = 0x03; /* P1 */ for (i = 0; i < 6; i++) { s[6 + i] = sqn[i] ^ ak[i]; } /* L1 */ s[12] = 0x00; s[13] = 0x06; #if defined(DEBUG_AUC_KDF) for (i = 0; i < 32; i++) printf("0x%02x ", key[i]); printf("\n"); for (i = 0; i < 14; i++) printf("0x%02x ", s[i]); printf("\n"); #endif kdf(key, 32, s, 14, kasme, 32); }
static void do_f4f5star(uint8_t *key, uint8_t *rand, uint8_t *op, uint8_t *f4_exp, uint8_t *f5star_exp) { uint8_t res_f2[8]; uint8_t res_f5[6]; uint8_t res_f3[16]; uint8_t res_f4[16]; uint8_t res_f5star[6]; SetOPc(op); f2345(key, rand, res_f2, res_f3, res_f4, res_f5); if (compare_buffer(res_f4, 16, f4_exp, 16) != 0) { fail("Fail: f4"); } f5star(key, rand, res_f5star); if (compare_buffer(res_f5star, 6, f5star_exp, 6) != 0) { fail("Fail: f5star"); } }