|
|
|
@ -191,35 +191,35 @@ auth_result_t usim::generate_authentication_response(uint8_t* rand,
|
|
|
|
|
uint16_t mnc,
|
|
|
|
|
uint8_t* res,
|
|
|
|
|
int* res_len,
|
|
|
|
|
uint8_t* k_asme)
|
|
|
|
|
uint8_t* k_asme_)
|
|
|
|
|
{
|
|
|
|
|
if (auth_algo_xor == auth_algo) {
|
|
|
|
|
return gen_auth_res_xor(rand, autn_enb, mcc, mnc, res, res_len, k_asme);
|
|
|
|
|
return gen_auth_res_xor(rand, autn_enb, mcc, mnc, res, res_len, k_asme_);
|
|
|
|
|
} else {
|
|
|
|
|
return gen_auth_res_milenage(rand, autn_enb, mcc, mnc, res, res_len, k_asme);
|
|
|
|
|
return gen_auth_res_milenage(rand, autn_enb, mcc, mnc, res, res_len, k_asme_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void usim::generate_nas_keys(uint8_t* k_asme,
|
|
|
|
|
void usim::generate_nas_keys(uint8_t* k_asme_,
|
|
|
|
|
uint8_t* k_nas_enc,
|
|
|
|
|
uint8_t* k_nas_int,
|
|
|
|
|
CIPHERING_ALGORITHM_ID_ENUM cipher_algo,
|
|
|
|
|
INTEGRITY_ALGORITHM_ID_ENUM integ_algo)
|
|
|
|
|
{
|
|
|
|
|
// Generate K_nas_enc and K_nas_int
|
|
|
|
|
security_generate_k_nas(k_asme, cipher_algo, integ_algo, k_nas_enc, k_nas_int);
|
|
|
|
|
security_generate_k_nas(k_asme_, cipher_algo, integ_algo, k_nas_enc, k_nas_int);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
RRC interface
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
void usim::generate_as_keys(uint8_t* k_asme, uint32_t count_ul, srslte::as_security_config_t* sec_cfg)
|
|
|
|
|
void usim::generate_as_keys(uint8_t* k_asme_, uint32_t count_ul, srslte::as_security_config_t* sec_cfg)
|
|
|
|
|
{
|
|
|
|
|
// Generate K_enb
|
|
|
|
|
security_generate_k_enb(k_asme, count_ul, k_enb);
|
|
|
|
|
security_generate_k_enb(k_asme_, count_ul, k_enb);
|
|
|
|
|
|
|
|
|
|
memcpy(this->k_asme, k_asme, 32);
|
|
|
|
|
memcpy(k_asme, k_asme_, 32);
|
|
|
|
|
|
|
|
|
|
// Save initial k_enb
|
|
|
|
|
memcpy(k_enb_initial, k_enb, 32);
|
|
|
|
@ -348,71 +348,70 @@ auth_result_t usim::gen_auth_res_xor(uint8_t* rand,
|
|
|
|
|
uint16_t mnc,
|
|
|
|
|
uint8_t* res,
|
|
|
|
|
int* res_len,
|
|
|
|
|
uint8_t* k_asme)
|
|
|
|
|
uint8_t* k_asme_)
|
|
|
|
|
{
|
|
|
|
|
auth_result_t result = AUTH_OK;
|
|
|
|
|
uint32_t i;
|
|
|
|
|
uint8_t sqn[6];
|
|
|
|
|
uint8_t xdout[16];
|
|
|
|
|
uint8_t cdout[8];
|
|
|
|
|
|
|
|
|
|
// Use RAND and K to compute RES, CK, IK and AK
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 16; i++) {
|
|
|
|
|
xdout[i] = k[i] ^ rand[i];
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 16; i++) {
|
|
|
|
|
res[i] = xdout[i];
|
|
|
|
|
ck[i] = xdout[(i + 1) % 16];
|
|
|
|
|
ik[i] = xdout[(i + 2) % 16];
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 6; i++) {
|
|
|
|
|
ak[i] = xdout[i + 3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*res_len = 8;
|
|
|
|
|
|
|
|
|
|
// Extract sqn from autn
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 6; i++) {
|
|
|
|
|
sqn[i] = autn_enb[i] ^ ak[i];
|
|
|
|
|
}
|
|
|
|
|
// Extract AMF from autn
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 2; i++) {
|
|
|
|
|
amf[i] = autn_enb[6 + i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate cdout
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 6; i++) {
|
|
|
|
|
cdout[i] = sqn[i];
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 2; i++) {
|
|
|
|
|
cdout[6 + i] = amf[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate MAC
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 8; i++) {
|
|
|
|
|
mac[i] = xdout[i] ^ cdout[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Construct AUTN
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 6; i++) {
|
|
|
|
|
autn[i] = sqn[i] ^ ak[i];
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 2; i++) {
|
|
|
|
|
autn[6 + i] = amf[i];
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 8; i++) {
|
|
|
|
|
autn[8 + i] = mac[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compare AUTNs
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
|
for (uint32_t i = 0; i < 16; i++) {
|
|
|
|
|
if (autn[i] != autn_enb[i]) {
|
|
|
|
|
result = AUTH_FAILED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate K_asme
|
|
|
|
|
security_generate_k_asme(ck, ik, ak, sqn, mcc, mnc, k_asme);
|
|
|
|
|
security_generate_k_asme(ck, ik, ak, sqn, mcc, mnc, k_asme_);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|