diff --git a/openair2/UTIL/OSA/osa_defs.h b/openair2/UTIL/OSA/osa_defs.h index e845315922ceaafe585c1a04adfb2bdb8bd84a60..84cdf4aac3125af770ccbf501d026a2c476abba1 100644 --- a/openair2/UTIL/OSA/osa_defs.h +++ b/openair2/UTIL/OSA/osa_defs.h @@ -61,6 +61,8 @@ int derive_key(algorithm_type_dist_t nas_alg_type, uint8_t nas_enc_alg_id, int nr_derive_key(algorithm_type_dist_t alg_type, uint8_t alg_id, const uint8_t key[32], uint8_t **out); +int nr_derive_key_ng_ran_star(uint16_t pci, uint64_t nr_arfcn_dl, const uint8_t key[32], uint8_t *key_ng_ran_star); + //#define derive_key_nas_enc(aLGiD, kEY, kNAS) derive_key(NAS_ENC_ALG, aLGiD, kEY, kNAS) //#define derive_key_nas_int(aLGiD, kEY, kNAS) derive_key(NAS_INT_ALG, aLGiD, kEY, kNAS) diff --git a/openair2/UTIL/OSA/osa_internal.h b/openair2/UTIL/OSA/osa_internal.h index f4a70c7e95415cef89c805cdaf6de7bc81ee0dfd..d66a42947289c50fc7c2a7efdd470a8c21548ee6 100644 --- a/openair2/UTIL/OSA/osa_internal.h +++ b/openair2/UTIL/OSA/osa_internal.h @@ -37,6 +37,7 @@ #define FC_KASME_TO_CK (0x16) #define NR_FC_ALG_KEY_DER (0x69) +#define NR_FC_ALG_KEY_NG_RAN_STAR_DER (0x70) #ifndef hton_int32 # define hton_int32(x) \ diff --git a/openair2/UTIL/OSA/osa_key_deriver.c b/openair2/UTIL/OSA/osa_key_deriver.c index c02b99949066f301b0291fac20235728c4d8230b..a685eec729709aff75350263631a9469f29c418f 100644 --- a/openair2/UTIL/OSA/osa_key_deriver.c +++ b/openair2/UTIL/OSA/osa_key_deriver.c @@ -127,40 +127,38 @@ int nr_derive_key(algorithm_type_dist_t alg_type, uint8_t alg_id, return 0; } -/* -int derive_keNB(const uint8_t key[32], const uint32_t nas_count, uint8_t **keNB) +int nr_derive_key_ng_ran_star(uint16_t pci, uint64_t nr_arfcn_dl, const uint8_t key[32], uint8_t *key_ng_ran_star) { - uint8_t string[7]; + uint8_t *out; + uint8_t s[10]; - // FC - string[0] = FC_KENB; - // P0 = Uplink NAS count - string[1] = (nas_count & 0xff000000) >> 24; - string[2] = (nas_count & 0x00ff0000) >> 16; - string[3] = (nas_count & 0x0000ff00) >> 8; - string[4] = (nas_count & 0x000000ff); + /* FC */ + s[0] = NR_FC_ALG_KEY_NG_RAN_STAR_DER; - // Length of NAS count - string[5] = 0x00; - string[6] = 0x04; + /* P0 = PCI */ + s[1] = (pci & 0x0000ff00) >> 8; + s[2] = (pci & 0x000000ff); -#if defined(SECU_DEBUG) - { - int i; - char payload[6 * sizeof(string) + 1]; - int index = 0; - - for (i = 0; i < sizeof(string); i++) - index += sprintf(&payload[index], "0x%02x ", string[i]); - LOG_D(OSA, "KeNB deriver input string: %s\n", payload); - } -#endif + /* L0 = length(P0) = 2 */ + s[3] = 0x00; + s[4] = 0x02; + + /* P1 = NR ARFCN */ + s[5] = (nr_arfcn_dl & 0x00ff0000) >> 16; + s[6] = (nr_arfcn_dl & 0x0000ff00) >> 8; + s[7] = (nr_arfcn_dl & 0x000000ff); + + /* L1 = length(P1) = 3 */ + s[8] = 0x00; + s[9] = 0x03; - kdf(string, 7, key, 32, keNB, 32); + kdf(s, 10, key, 32, &out, 32); - return 0; + memcpy(key_ng_ran_star, out, 32); + free(out); + + return 0; } -*/ int derive_skgNB(const uint8_t *keNB, const uint16_t sk_counter, uint8_t *skgNB) {