mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
197 lines
8.1 KiB
C
197 lines
8.1 KiB
C
4 years ago
|
/**
|
||
8 years ago
|
*
|
||
4 years ago
|
* \section COPYRIGHT
|
||
8 years ago
|
*
|
||
4 years ago
|
* Copyright 2013-2021 Software Radio Systems Limited
|
||
8 years ago
|
*
|
||
4 years ago
|
* By using this file, you agree to the terms and conditions set
|
||
|
* forth in the LICENSE file which can be found at the top level of
|
||
|
* the distribution.
|
||
8 years ago
|
*
|
||
|
*/
|
||
|
|
||
4 years ago
|
#ifndef SRSRAN_SECURITY_H
|
||
|
#define SRSRAN_SECURITY_H
|
||
8 years ago
|
|
||
|
/******************************************************************************
|
||
|
* Common security header - wraps ciphering/integrity check algorithms.
|
||
|
*****************************************************************************/
|
||
|
|
||
4 years ago
|
#include "srsran/common/common.h"
|
||
7 years ago
|
|
||
4 years ago
|
namespace srsran {
|
||
8 years ago
|
|
||
5 years ago
|
typedef enum {
|
||
|
CIPHERING_ALGORITHM_ID_EEA0 = 0,
|
||
|
CIPHERING_ALGORITHM_ID_128_EEA1,
|
||
|
CIPHERING_ALGORITHM_ID_128_EEA2,
|
||
6 years ago
|
CIPHERING_ALGORITHM_ID_128_EEA3,
|
||
5 years ago
|
CIPHERING_ALGORITHM_ID_N_ITEMS,
|
||
|
} CIPHERING_ALGORITHM_ID_ENUM;
|
||
5 years ago
|
static const char ciphering_algorithm_id_text[CIPHERING_ALGORITHM_ID_N_ITEMS][20] = {"EEA0",
|
||
|
"128-EEA1",
|
||
|
"128-EEA2",
|
||
|
"128-EEA3"};
|
||
5 years ago
|
|
||
5 years ago
|
typedef enum {
|
||
|
INTEGRITY_ALGORITHM_ID_EIA0 = 0,
|
||
|
INTEGRITY_ALGORITHM_ID_128_EIA1,
|
||
|
INTEGRITY_ALGORITHM_ID_128_EIA2,
|
||
6 years ago
|
INTEGRITY_ALGORITHM_ID_128_EIA3,
|
||
5 years ago
|
INTEGRITY_ALGORITHM_ID_N_ITEMS,
|
||
|
} INTEGRITY_ALGORITHM_ID_ENUM;
|
||
5 years ago
|
static const char integrity_algorithm_id_text[INTEGRITY_ALGORITHM_ID_N_ITEMS][20] = {"EIA0",
|
||
|
"128-EIA1",
|
||
|
"128-EIA2",
|
||
|
"128-EIA3"};
|
||
5 years ago
|
|
||
|
typedef enum {
|
||
|
SECURITY_DIRECTION_UPLINK = 0,
|
||
|
SECURITY_DIRECTION_DOWNLINK = 1,
|
||
|
SECURITY_DIRECTION_N_ITEMS,
|
||
|
} security_direction_t;
|
||
|
static const char security_direction_text[INTEGRITY_ALGORITHM_ID_N_ITEMS][20] = {"Uplink", "Downlink"};
|
||
7 years ago
|
|
||
5 years ago
|
using as_key_t = std::array<uint8_t, 32>;
|
||
4 years ago
|
struct k_enb_context_t {
|
||
|
as_key_t k_enb;
|
||
|
as_key_t nh;
|
||
|
bool is_first_ncc;
|
||
|
uint32_t ncc;
|
||
|
};
|
||
|
|
||
4 years ago
|
struct k_gnb_context_t {
|
||
|
as_key_t sk_gnb;
|
||
|
};
|
||
|
|
||
5 years ago
|
struct as_security_config_t {
|
||
|
as_key_t k_rrc_int;
|
||
|
as_key_t k_rrc_enc;
|
||
|
as_key_t k_up_int;
|
||
|
as_key_t k_up_enc;
|
||
|
INTEGRITY_ALGORITHM_ID_ENUM integ_algo;
|
||
|
CIPHERING_ALGORITHM_ID_ENUM cipher_algo;
|
||
|
};
|
||
|
|
||
8 years ago
|
/******************************************************************************
|
||
|
* Key Generation
|
||
|
*****************************************************************************/
|
||
5 years ago
|
uint8_t security_generate_k_asme(uint8_t* ck,
|
||
|
uint8_t* ik,
|
||
|
uint8_t* ak,
|
||
|
uint8_t* sqn,
|
||
|
uint16_t mcc,
|
||
|
uint16_t mnc,
|
||
|
uint8_t* k_asme);
|
||
|
|
||
|
uint8_t security_generate_k_enb(uint8_t* k_asme, uint32_t nas_count, uint8_t* k_enb);
|
||
|
|
||
|
uint8_t security_generate_k_enb_star(uint8_t* k_enb, uint32_t pci, uint32_t earfcn, uint8_t* k_enb_star);
|
||
|
|
||
|
uint8_t security_generate_nh(uint8_t* k_asme, uint8_t* sync, uint8_t* nh);
|
||
|
|
||
|
uint8_t security_generate_k_nas(uint8_t* k_asme,
|
||
|
CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
|
||
|
INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
|
||
|
uint8_t* k_nas_enc,
|
||
|
uint8_t* k_nas_int);
|
||
|
|
||
|
uint8_t security_generate_k_rrc(uint8_t* k_enb,
|
||
|
CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
|
||
|
INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
|
||
|
uint8_t* k_rrc_enc,
|
||
|
uint8_t* k_rrc_int);
|
||
|
|
||
|
uint8_t security_generate_k_up(uint8_t* k_enb,
|
||
|
CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
|
||
|
INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
|
||
|
uint8_t* k_up_enc,
|
||
|
uint8_t* k_up_int);
|
||
8 years ago
|
|
||
4 years ago
|
uint8_t security_generate_k_nr_rrc(uint8_t* k_gnb,
|
||
|
CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
|
||
|
INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
|
||
|
uint8_t* k_rrc_enc,
|
||
|
uint8_t* k_rrc_int);
|
||
|
|
||
|
uint8_t security_generate_k_nr_up(uint8_t* k_gnb,
|
||
|
CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
|
||
|
INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
|
||
|
uint8_t* k_up_enc,
|
||
|
uint8_t* k_up_int);
|
||
|
|
||
|
uint8_t security_generate_sk_gnb(uint8_t* k_enb, uint8_t* sk_gnb, uint16_t scg_count);
|
||
|
|
||
8 years ago
|
/******************************************************************************
|
||
|
* Integrity Protection
|
||
|
*****************************************************************************/
|
||
5 years ago
|
uint8_t security_128_eia1(const uint8_t* key,
|
||
|
uint32_t count,
|
||
|
uint32_t bearer,
|
||
|
uint8_t direction,
|
||
|
uint8_t* msg,
|
||
|
uint32_t msg_len,
|
||
|
uint8_t* mac);
|
||
|
|
||
|
uint8_t security_128_eia2(const uint8_t* key,
|
||
|
uint32_t count,
|
||
|
uint32_t bearer,
|
||
|
uint8_t direction,
|
||
|
uint8_t* msg,
|
||
|
uint32_t msg_len,
|
||
|
uint8_t* mac);
|
||
5 years ago
|
|
||
5 years ago
|
uint8_t security_128_eia3(const uint8_t* key,
|
||
|
uint32_t count,
|
||
|
uint32_t bearer,
|
||
|
uint8_t direction,
|
||
|
uint8_t* msg,
|
||
|
uint32_t msg_len,
|
||
|
uint8_t* mac);
|
||
5 years ago
|
|
||
|
uint8_t security_md5(const uint8_t* input, size_t len, uint8_t* output);
|
||
7 years ago
|
|
||
7 years ago
|
/******************************************************************************
|
||
|
* Encryption / Decryption
|
||
|
*****************************************************************************/
|
||
5 years ago
|
uint8_t security_128_eea1(uint8_t* key,
|
||
|
uint32_t count,
|
||
|
uint8_t bearer,
|
||
|
uint8_t direction,
|
||
|
uint8_t* msg,
|
||
|
uint32_t msg_len,
|
||
|
uint8_t* msg_out);
|
||
|
|
||
|
uint8_t security_128_eea2(uint8_t* key,
|
||
|
uint32_t count,
|
||
|
uint8_t bearer,
|
||
|
uint8_t direction,
|
||
|
uint8_t* msg,
|
||
|
uint32_t msg_len,
|
||
|
uint8_t* msg_out);
|
||
|
|
||
|
uint8_t security_128_eea3(uint8_t* key,
|
||
|
uint32_t count,
|
||
|
uint8_t bearer,
|
||
|
uint8_t direction,
|
||
|
uint8_t* msg,
|
||
|
uint32_t msg_len,
|
||
|
uint8_t* msg_out);
|
||
6 years ago
|
|
||
8 years ago
|
/******************************************************************************
|
||
|
* Authentication
|
||
|
*****************************************************************************/
|
||
5 years ago
|
uint8_t compute_opc(uint8_t* k, uint8_t* op, uint8_t* opc);
|
||
|
|
||
|
uint8_t security_milenage_f1(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_t* sqn, uint8_t* amf, uint8_t* mac_a);
|
||
|
|
||
|
uint8_t security_milenage_f1_star(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_t* sqn, uint8_t* amf, uint8_t* mac_s);
|
||
|
|
||
|
uint8_t
|
||
|
security_milenage_f2345(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_t* res, uint8_t* ck, uint8_t* ik, uint8_t* ak);
|
||
8 years ago
|
|
||
5 years ago
|
uint8_t security_milenage_f5_star(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_t* ak);
|
||
8 years ago
|
|
||
4 years ago
|
} // namespace srsran
|
||
|
#endif // SRSRAN_SECURITY_H
|