From 75c5e476f1c87a80ce7397d5fe1092f16fa8a90e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 18 Jun 2018 15:19:04 +0100 Subject: [PATCH] Added OPc option to UE. (needs testing.) --- lib/include/srslte/common/liblte_security.h | 11 +++++++ lib/include/srslte/common/security.h | 3 ++ lib/src/common/liblte_security.cc | 27 +++++++++++----- lib/src/common/security.cc | 8 +++++ srsue/hdr/upper/usim.h | 1 + srsue/src/upper/usim.cc | 34 ++++++++++++++------- 6 files changed, 65 insertions(+), 19 deletions(-) diff --git a/lib/include/srslte/common/liblte_security.h b/lib/include/srslte/common/liblte_security.h index 8dc31f341..b82168696 100644 --- a/lib/include/srslte/common/liblte_security.h +++ b/lib/include/srslte/common/liblte_security.h @@ -52,6 +52,17 @@ DECLARATIONS *******************************************************************************/ +/********************************************************************* + Name: compute_OPc + + Description: Computes OPc from OP and K. + + Document Reference: 35.206 v10.0.0 Annex 3 +*********************************************************************/ +LIBLTE_ERROR_ENUM liblte_compute_opc(uint8 *k, + uint8 *op, + uint8 *op_c); + /********************************************************************* Name: liblte_security_generate_k_asme diff --git a/lib/include/srslte/common/security.h b/lib/include/srslte/common/security.h index 5dc8a6305..29bd6000c 100644 --- a/lib/include/srslte/common/security.h +++ b/lib/include/srslte/common/security.h @@ -151,6 +151,9 @@ uint8_t security_128_eea2(uint8_t *key, /****************************************************************************** * Authentication *****************************************************************************/ +uint8_t compute_opc( uint8_t *k, + uint8_t *op, + uint8_t *opc); uint8_t security_milenage_f1( uint8_t *k, uint8_t *op, diff --git a/lib/src/common/liblte_security.cc b/lib/src/common/liblte_security.cc index 14514320d..5723afe00 100644 --- a/lib/src/common/liblte_security.cc +++ b/lib/src/common/liblte_security.cc @@ -1418,24 +1418,35 @@ LIBLTE_ERROR_ENUM liblte_security_milenage_f5_star(uint8 *k, } /********************************************************************* - Name: compute_OPc + Name: liblte_compute_opc Description: Computes OPc from OP and K. Document Reference: 35.206 v10.0.0 Annex 3 *********************************************************************/ -void compute_OPc(uint8 *k, - uint8 *op, - uint8 *op_c) + +LIBLTE_ERROR_ENUM liblte_compute_opc(uint8 *k, + uint8 *op, + uint8 *op_c) { uint32 i; ROUND_KEY_STRUCT round_keys; - rijndael_key_schedule(k, &round_keys); - rijndael_encrypt(op, &round_keys, op_c); - for(i=0; i<16; i++) + LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; + + if(k != NULL && + op != NULL && + op_c != NULL) { - op_c[i] ^= op[i]; + + rijndael_key_schedule(k, &round_keys); + rijndael_encrypt(op, &round_keys, op_c); + for(i=0; i<16; i++) + { + op_c[i] ^= op[i]; + } + err = LIBLTE_SUCCESS; } + return err; } /******************************************************************************* diff --git a/lib/src/common/security.cc b/lib/src/common/security.cc index 63cd478c0..65ef5e0c4 100644 --- a/lib/src/common/security.cc +++ b/lib/src/common/security.cc @@ -229,6 +229,14 @@ uint8_t security_128_eea2(uint8_t *key, /****************************************************************************** * Authentication *****************************************************************************/ +uint8_t compute_opc( uint8_t *k, + uint8_t *op, + uint8_t *opc) +{ + return liblte_compute_opc(k, + op, + opc); +} uint8_t security_milenage_f1( uint8_t *k, uint8_t *op, diff --git a/srsue/hdr/upper/usim.h b/srsue/hdr/upper/usim.h index f36ae545f..ce42e3022 100644 --- a/srsue/hdr/upper/usim.h +++ b/srsue/hdr/upper/usim.h @@ -110,6 +110,7 @@ private: auth_algo_t auth_algo; uint8_t amf[2]; // 3GPP 33.102 v10.0.0 Annex H uint8_t op[16]; + uint8_t opc[16]; uint64_t imsi; uint64_t imei; uint8_t k[16]; diff --git a/srsue/src/upper/usim.cc b/srsue/src/upper/usim.cc index af3cb3fbb..b90f65d8a 100644 --- a/srsue/src/upper/usim.cc +++ b/srsue/src/upper/usim.cc @@ -46,11 +46,30 @@ int usim::init(usim_args_t *args, srslte::log *usim_log_) const char *imei_c = args->imei.c_str(); uint32_t i; - if(32 == args->op.length()) { - str_to_hex(args->op, op); + if(32 == args->k.length()) { + str_to_hex(args->k, k); } else { - usim_log->error("Invalid length for OP: %zu should be %d\n", args->op.length(), 32); - usim_log->console("Invalid length for OP: %zu should be %d\n", args->op.length(), 32); + usim_log->error("Invalid length for K: %zu should be %d\n", args->k.length(), 32); + usim_log->console("Invalid length for K: %zu should be %d\n", args->k.length(), 32); + } + + if(args->using_op) + { + if(32 == args->op.length()) { + str_to_hex(args->op, op); + compute_opc(k,op,opc); + } else { + usim_log->error("Invalid length for OP: %zu should be %d\n", args->op.length(), 32); + usim_log->console("Invalid length for OP: %zu should be %d\n", args->op.length(), 32); + } + } + else{ + if(32 == args->opc.length()) { + str_to_hex(args->opc, opc); + } else { + usim_log->error("Invalid length for OPc: %zu should be %d\n", args->opc.length(), 32); + usim_log->console("Invalid length for OPc: %zu should be %d\n", args->opc.length(), 32); + } } if(15 == args->imsi.length()) { @@ -77,13 +96,6 @@ int usim::init(usim_args_t *args, srslte::log *usim_log_) usim_log->console("Invalid length for IMEI: %zu should be %d\n", args->imei.length(), 15); } - if(32 == args->k.length()) { - str_to_hex(args->k, k); - } else { - usim_log->error("Invalid length for K: %zu should be %d\n", args->k.length(), 32); - usim_log->console("Invalid length for K: %zu should be %d\n", args->k.length(), 32); - } - auth_algo = auth_algo_milenage; if("xor" == args->algo) { auth_algo = auth_algo_xor;