Refactor key derivation logic to properly handle Next Hop (NH) chain synchronization according to 3GPP TS 33.501 specifications for both RRC Reestablishment and Master Key Update procedures. Changes in rrc_gNB.c: - Clarify key derivation in rrc_gNB_generate_RRCReestablishment by explicitly selecting base key (NH or KgNB) based on nh_ncc value - Add comment explaining vertical vs horizontal derivation logic Changes in rrc_UE.c: - Add nr_sync_nh_chain(): Common helper to synchronize NH parameter chain per TS 33.501 Annex A.10, supporting both Master Key Update and RRC Reestablishment procedures - Add nr_derive_kgnb_horizontal(): Derive KNG-RAN* from current KgNB when NCC values match (horizontal derivation per TS 33.501 A.11/A.12) - Add nr_derive_kgnb_vertical(): Derive KNG-RAN* from synchronized NH after NH chain sync (vertical derivation per TS 33.501 A.11/A.12) - Add nr_update_kgnb_from_ncc(): Unified function implementing TS 33.501 6.9.2.3.4 logic for updating KgNB based on received nextHopChainingCount - Refactor as_security_key_update(): Use new nr_update_kgnb_from_ncc() helper function for cleaner, more maintainable code - Fix nr_rrc_ue_process_rrcReestablishment(): Properly handle received nextHopChainingCount and update KgNB using unified helper function - Add debug logging for key derivation process Key NAS deriver utils: - update derive_kgnb documentation and protect input keys with const attribute
42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
#ifndef KEY_NAS_DERIVER_H
|
|
#define KEY_NAS_DERIVER_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
|
|
#define SECURITY_KEY_LEN 32
|
|
|
|
typedef enum {
|
|
NAS_ENC_ALG = 0x01,
|
|
NAS_INT_ALG = 0x02,
|
|
RRC_ENC_ALG = 0x03,
|
|
RRC_INT_ALG = 0x04,
|
|
UP_ENC_ALG = 0x05,
|
|
UP_INT_ALG = 0x06
|
|
} algorithm_type_dist_t;
|
|
|
|
void derive_kgnb(const uint8_t kamf[32], const 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_star(const uint8_t *kenb_32,
|
|
const uint16_t pci,
|
|
const uint32_t earfcn_dl,
|
|
const bool is_rel8_only,
|
|
uint8_t *kenb_star);
|
|
|
|
void derive_key_nas(algorithm_type_dist_t nas_alg_type, uint8_t nas_enc_alg_id, const uint8_t kasme[32], uint8_t knas[32]);
|
|
|
|
void derive_skgNB(const uint8_t *keNB, const uint16_t sk_counter, uint8_t *skgNB);
|
|
|
|
void nr_derive_key(algorithm_type_dist_t alg_type, uint8_t alg_id, const uint8_t key[32], uint8_t out[16]);
|
|
|
|
void 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);
|
|
|
|
void nr_derive_nh(const uint8_t k_amf[SECURITY_KEY_LEN], const uint8_t *sync_input, uint8_t *nh);
|
|
|
|
void log_hex_buffer(const char *label, const uint8_t *buf, const int len);
|
|
|
|
#endif
|