Move derive_kgnb to key_nas_deriver lib
This commit is contained in:
@@ -71,6 +71,7 @@
|
|||||||
#include "fgmm_service_accept.h"
|
#include "fgmm_service_accept.h"
|
||||||
#include "fgmm_service_reject.h"
|
#include "fgmm_service_reject.h"
|
||||||
#include "ds/byte_array.h"
|
#include "ds/byte_array.h"
|
||||||
|
#include "key_nas_deriver.h"
|
||||||
|
|
||||||
#define MAX_NAS_UE 4
|
#define MAX_NAS_UE 4
|
||||||
|
|
||||||
@@ -444,41 +445,6 @@ void derive_knas(algorithm_type_dist_t nas_alg_type, uint8_t nas_alg_id, uint8_t
|
|||||||
memcpy(knas, out + 16, 16);
|
memcpy(knas, out + 16, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void derive_kgnb(uint8_t kamf[32], uint32_t count, uint8_t *kgnb)
|
|
||||||
{
|
|
||||||
/* Compute the KDF input parameter
|
|
||||||
* S = FC(0x6E) || UL NAS Count || 0x00 0x04 || 0x01 || 0x00 0x01
|
|
||||||
*/
|
|
||||||
uint8_t input[32] = {0};
|
|
||||||
// uint16_t length = 4;
|
|
||||||
// int offset = 0;
|
|
||||||
|
|
||||||
LOG_TRACE(INFO, "%s with count= %d", __FUNCTION__, count);
|
|
||||||
memset(input, 0, 32);
|
|
||||||
input[0] = 0x6E;
|
|
||||||
// P0
|
|
||||||
input[1] = count >> 24;
|
|
||||||
input[2] = (uint8_t)(count >> 16);
|
|
||||||
input[3] = (uint8_t)(count >> 8);
|
|
||||||
input[4] = (uint8_t)count;
|
|
||||||
// L0
|
|
||||||
input[5] = 0;
|
|
||||||
input[6] = 4;
|
|
||||||
// P1
|
|
||||||
input[7] = 0x01;
|
|
||||||
// L1
|
|
||||||
input[8] = 0;
|
|
||||||
input[9] = 1;
|
|
||||||
|
|
||||||
byte_array_t data = {.buf = input, .len = 10};
|
|
||||||
kdf(kamf, data, 32, kgnb);
|
|
||||||
|
|
||||||
printf("kgnb : ");
|
|
||||||
for (int pp = 0; pp < 32; pp++)
|
|
||||||
printf("%02x ", kgnb[pp]);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void derive_ue_keys(uint8_t *buf, nr_ue_nas_t *nas)
|
static void derive_ue_keys(uint8_t *buf, nr_ue_nas_t *nas)
|
||||||
{
|
{
|
||||||
uint8_t ak[6];
|
uint8_t ak[6];
|
||||||
|
|||||||
@@ -139,6 +139,38 @@ void nr_derive_key(algorithm_type_dist_t alg_type, uint8_t alg_id, const uint8_t
|
|||||||
* NOTE: knas is dynamically allocated by the KDF function
|
* NOTE: knas is dynamically allocated by the KDF function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @brief KgNB derivation (A.9 3GPP TS 33.501) */
|
||||||
|
void derive_kgnb(uint8_t kamf[32], uint32_t count, uint8_t *kgnb)
|
||||||
|
{
|
||||||
|
/* Compute the KDF input parameter
|
||||||
|
* S = FC(0x6E) || UL NAS Count || 0x00 0x04 || 0x01 || 0x00 0x01
|
||||||
|
*/
|
||||||
|
uint8_t input[32] = {0};
|
||||||
|
|
||||||
|
input[0] = 0x6E;
|
||||||
|
// P0
|
||||||
|
input[1] = count >> 24;
|
||||||
|
input[2] = (uint8_t)(count >> 16);
|
||||||
|
input[3] = (uint8_t)(count >> 8);
|
||||||
|
input[4] = (uint8_t)count;
|
||||||
|
// L0
|
||||||
|
input[5] = 0;
|
||||||
|
input[6] = 4;
|
||||||
|
// P1
|
||||||
|
input[7] = 0x01;
|
||||||
|
// L1
|
||||||
|
input[8] = 0;
|
||||||
|
input[9] = 1;
|
||||||
|
|
||||||
|
byte_array_t data = {.buf = input, .len = 10};
|
||||||
|
kdf(kamf, data, 32, kgnb);
|
||||||
|
|
||||||
|
printf("kgnb : ");
|
||||||
|
for (int pp = 0; pp < 32; pp++)
|
||||||
|
printf("%02x ", kgnb[pp]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
void derive_keNB(const uint8_t kasme[32], const uint32_t nas_count, uint8_t *keNB)
|
void derive_keNB(const uint8_t kasme[32], const uint32_t nas_count, uint8_t *keNB)
|
||||||
{
|
{
|
||||||
uint8_t s[7] = {0};
|
uint8_t s[7] = {0};
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ typedef enum {
|
|||||||
UP_INT_ALG = 0x06
|
UP_INT_ALG = 0x06
|
||||||
} algorithm_type_dist_t;
|
} algorithm_type_dist_t;
|
||||||
|
|
||||||
|
void derive_kgnb(uint8_t kamf[32], uint32_t count, uint8_t *kgnb);
|
||||||
|
|
||||||
void derive_keNB(const uint8_t kasme[32], const uint32_t nas_count, uint8_t *keNB);
|
void derive_keNB(const uint8_t kasme[32], const uint32_t nas_count, uint8_t *keNB);
|
||||||
|
|
||||||
void derive_keNB_star(const uint8_t *kenb_32,
|
void derive_keNB_star(const uint8_t *kenb_32,
|
||||||
|
|||||||
Reference in New Issue
Block a user