Derive keys from kgnb
This commit is contained in:
@@ -55,6 +55,8 @@ typedef enum {
|
||||
|
||||
int derive_key(algorithm_type_dist_t nas_alg_type, uint8_t nas_enc_alg_id,
|
||||
const uint8_t key[32], uint8_t **out);
|
||||
int nr_derive_key(algorithm_type_dist_t alg_type, uint8_t alg_id,
|
||||
const uint8_t key[32], uint8_t **out);
|
||||
|
||||
//#define derive_key_nas_enc(aLGiD, kEY, kNAS) derive_key(NAS_ENC_ALG, aLGiD, kEY, kNAS)
|
||||
|
||||
@@ -72,6 +74,19 @@ int derive_key(algorithm_type_dist_t nas_alg_type, uint8_t nas_enc_alg_id,
|
||||
#define derive_key_up_int(aLGiD, kEY, kNAS) \
|
||||
derive_key(UP_INT_ALG, aLGiD, kEY, kNAS)
|
||||
|
||||
// 5G SA
|
||||
#define nr_derive_key_rrc_enc(aLGiD, kEY, kRRC) \
|
||||
nr_derive_key(RRC_ENC_ALG, aLGiD, kEY, kRRC)
|
||||
|
||||
#define nr_derive_key_rrc_int(aLGiD, kEY, kRRC) \
|
||||
nr_derive_key(RRC_INT_ALG, aLGiD, kEY, kRRC)
|
||||
|
||||
#define nr_derive_key_up_enc(aLGiD, kEY, kUP) \
|
||||
nr_derive_key(UP_ENC_ALG, aLGiD, kEY, kUP)
|
||||
|
||||
#define nr_derive_key_up_int(aLGiD, kEY, kUP) \
|
||||
nr_derive_key(UP_INT_ALG, aLGiD, kEY, kUP)
|
||||
|
||||
typedef struct {
|
||||
uint8_t *key;
|
||||
uint32_t key_length;
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#define FC_ALG_KEY_DER (0x15)
|
||||
#define FC_KASME_TO_CK (0x16)
|
||||
|
||||
#define NR_FC_ALG_KEY_DER (0x69)
|
||||
|
||||
#ifndef hton_int32
|
||||
# define hton_int32(x) \
|
||||
(((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8) | \
|
||||
|
||||
@@ -97,6 +97,34 @@ int derive_key(algorithm_type_dist_t alg_type, uint8_t alg_id,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nr_derive_key(algorithm_type_dist_t alg_type, uint8_t alg_id,
|
||||
const uint8_t key[32], uint8_t **out)
|
||||
{
|
||||
uint8_t string[7];
|
||||
|
||||
/* FC */
|
||||
string[0] = NR_FC_ALG_KEY_DER;
|
||||
|
||||
/* P0 = algorithm type distinguisher */
|
||||
string[1] = (uint8_t)(alg_type & 0xFF);
|
||||
|
||||
/* L0 = length(P0) = 1 */
|
||||
string[2] = 0x00;
|
||||
string[3] = 0x01;
|
||||
|
||||
/* P1 */
|
||||
string[4] = alg_id;
|
||||
|
||||
/* L1 = length(P1) = 1 */
|
||||
string[5] = 0x00;
|
||||
string[6] = 0x01;
|
||||
|
||||
kdf(string, 7, key, 32, out, 32);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
int derive_keNB(const uint8_t key[32], const uint32_t nas_count, uint8_t **keNB)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user