Commit 522d11a5 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Code cleanup

parent e11e05f5
......@@ -243,31 +243,15 @@ void Authentication_5gaka::ComputeOPc(
print_buffer("ausf_app", "ComputeOPc kP : ", kP, 16);
// FPRINTF_DEBUG ("Compute
// opc:\n\tK:\t%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
// kP[0], kP[1], kP[2], kP[3], kP[4], kP[5], kP[6], kP[7], kP[8], kP[9],
// kP[10], kP[11], kP[12], kP[13], kP[14], kP[15]);
RijndaelEncrypt(opP, opcP);
print_buffer("ausf_app", "ComputeOPc opP : ", opP, 16);
print_buffer("ausf_app", "ComputeOPc opcP : ", opcP, 16);
// FPRINTF_DEBUG
// ("\tIn:\t%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n\tRinj:\t%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
// opP[0], opP[1], opP[2], opP[3], opP[4], opP[5], opP[6], opP[7],
// opP[8], opP[9], opP[10], opP[11], opP[12], opP[13], opP[14],
// opP[15], opcP[0], opcP[1], opcP[2], opcP[3], opcP[4], opcP[5],
// opcP[6], opcP[7], opcP[8], opcP[9], opcP[10], opcP[11], opcP[12],
// opcP[13], opcP[14], opcP[15]);
for (i = 0; i < 16; i++) opcP[i] ^= opP[i];
print_buffer("ausf_app", "ComputeOPc opcP : ", opcP, 16);
// FPRINTF_DEBUG
// ("\tOut:\t%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
// opcP[0], opcP[1], opcP[2], opcP[3], opcP[4], opcP[5], opcP[6], opcP[7],
// opcP[8], opcP[9], opcP[10], opcP[11], opcP[12], opcP[13], opcP[14],
// opcP[15]);
return;
}
......@@ -576,7 +560,7 @@ void Authentication_5gaka::annex_a_4_33501(
oldS[32] = 0x00;
oldS[33] = 0x08;
*/
// print_buffer("udm_ueau", "Input string: ", S, 31 + netName.size);
uint8_t key[32];
memcpy(&key[0], ck, 16);
memcpy(&key[16], ik, 16); // KEY
......@@ -632,23 +616,6 @@ void Authentication_5gaka::generate_Hxres(
for (int j = 0; j < 16; j++) hxresStar[j] = (uint8_t) sha256Out[j];
}
//------------------------------------------------------------------------------
// may not be appropriate
// void Authentication_5gaka::generate_authCtxId(uint8_t autn[16],
// uint8_t *authCtxId) {
// unsigned char sha256Out[Sha256::DIGEST_SIZE];
// Authentication_5gaka::sha256((unsigned char *)autn, 32, sha256Out);
// //note risk in type change for (int j = 0; j < 16; j++)
// authCtxId[j] = (uint8_t)sha256Out[j];
// cout << "authCtxId" << std::endl;
// for (int i = 0; i < 16; i++)printf("%x ", authCtxId[i]);
// cout << endl;
// }
//------------------------------------------------------------------------------
bool Authentication_5gaka::equal_uint8(
uint8_t* oldVal, uint8_t* newVal, int msg_len) {
......
......@@ -168,7 +168,6 @@ class Authentication_5gaka {
uint8_t ak[6]);
public:
/****** key derive ***********/
static void kdf(
uint8_t* key, uint16_t key_len, uint8_t* s, uint16_t s_len, uint8_t* out,
uint16_t out_len);
......@@ -234,7 +233,6 @@ class Authentication_5gaka {
static bool equal_uint8(uint8_t* oldVal, uint8_t* newVal, int msg_len);
public:
/****** Rijndael ********/
static void RijndaelKeySchedule(const uint8_t key[16]);
static void RijndaelEncrypt(const uint8_t in[16], uint8_t out[16]);
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file f12345.h
\brief Example algorithms f1, f1*, f2, f3, f4, f5, f5
\brief Based on https://github.com/OPENAIRINTERFACE/openair-hss
\author Jian Yang, Fengjiao He, Hongxin Wang
\company
\date 2020
\email: email: contact@openairinterface.org
*/
/*-------------------------------------------------------------------
* Example algorithms f1, f1*, f2, f3, f4, f5, f5*
*-------------------------------------------------------------------
*
* A sample implementation of the example 3GPP authentication and
* key agreement functions f1, f1*, f2, f3, f4, f5 and f5*. This is
* a byte-oriented implementation of the functions, and of the block
* cipher kernel function Rijndael.
*
* This has been coded for clarity, not necessarily for efficiency.
*
* The functions f2, f3, f4 and f5 share the same inputs and have
* been coded together as a single function. f1, f1* and f5* are
* all coded separately.
*
*-----------------------------------------------------------------*/
/************************ 3gpp 35.206 *****************************/
#include "authentication_algorithms_with_5gaka.hpp"
typedef unsigned char u8;
/*--------- Operator Variant Algorithm Configuration Field --------*/
/*------- Insert your value of OP here -------*/
u8 OP[16] = {0x63, 0xbf, 0xa5, 0x0e, 0xe6, 0x52, 0x33, 0x65,
0xff, 0x14, 0xc1, 0xf4, 0x5f, 0x88, 0x73, 0x7d};
/*------- Insert your value of OP here -------*/
uint8_t op_c[16] = {0xcd, 0x63, 0xcb, 0x71, 0x95, 0x4a, 0x9f, 0x4e,
0x48, 0xa5, 0x99, 0x4e, 0x37, 0xa0, 0x2b, 0xaf};
/*--------------------------- prototypes --------------------------*/
void f1(u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], u8 mac_a[8]);
void f2345(u8 k[16], u8 rand[16], u8 res[8], u8 ck[16], u8 ik[16], u8 ak[6]);
void f1star(u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], u8 mac_s[8]);
void f5star(u8 k[16], u8 rand[16], u8 ak[6]);
/*-------------------------------------------------------------------
* Algorithm f1
*-------------------------------------------------------------------
*
* Computes network authentication code MAC-A from key K, random
* challenge RAND, sequence number SQN and authentication management
* field AMF.
*
*-----------------------------------------------------------------*/
void f1(u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], u8 mac_a[8]) {
printf("opc: ");
for (int i = 0; i < 16; i++) printf("0x%x", op_c[i]);
printf("\n");
// u8 op_c[16];
u8 temp[16];
u8 in1[16];
u8 out1[16];
u8 rijndaelInput[16];
u8 i;
Authentication_5gaka::RijndaelKeySchedule(k);
// ComputeOPc( op_c );
for (i = 0; i < 16; i++) rijndaelInput[i] = rand[i] ^ op_c[i];
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, temp);
for (i = 0; i < 6; i++) {
in1[i] = sqn[i];
in1[i + 8] = sqn[i];
}
for (i = 0; i < 2; i++) {
in1[i + 6] = amf[i];
in1[i + 14] = amf[i];
}
/* XOR op_c and in1, rotate by r1=64, and XOR *
* on the constant c1 (which is all zeroes) */
for (i = 0; i < 16; i++) rijndaelInput[(i + 8) % 16] = in1[i] ^ op_c[i];
/* XOR on the value temp computed before */
for (i = 0; i < 16; i++) rijndaelInput[i] ^= temp[i];
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, out1);
for (i = 0; i < 16; i++) out1[i] ^= op_c[i];
for (i = 0; i < 8; i++) mac_a[i] = out1[i];
return;
} /* end of function f1 */
/*-------------------------------------------------------------------
* Algorithms f2-f5
*-------------------------------------------------------------------
*
* Takes key K and random challenge RAND, and returns response RES,
* confidentiality key CK, integrity key IK and anonymity key AK.
*
*-----------------------------------------------------------------*/
void f2345(u8 k[16], u8 rand[16], u8 res[8], u8 ck[16], u8 ik[16], u8 ak[6]) {
// u8 op_c[16];
u8 temp[16];
u8 out[16];
u8 rijndaelInput[16];
u8 i;
Authentication_5gaka::RijndaelKeySchedule(k);
// ComputeOPc( op_c );
for (i = 0; i < 16; i++) rijndaelInput[i] = rand[i] ^ op_c[i];
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, temp);
/* To obtain output block OUT2: XOR OPc and TEMP, *
* rotate by r2=0, and XOR on the constant c2 (which *
* is all zeroes except that the last bit is 1). */
for (i = 0; i < 16; i++) rijndaelInput[i] = temp[i] ^ op_c[i];
rijndaelInput[15] ^= 1;
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, out);
for (i = 0; i < 16; i++) out[i] ^= op_c[i];
for (i = 0; i < 8; i++) res[i] = out[i + 8];
for (i = 0; i < 6; i++) ak[i] = out[i];
/* To obtain output block OUT3: XOR OPc and TEMP, *
* rotate by r3=32, and XOR on the constant c3 (which *
* is all zeroes except that the next to last bit is 1). */
for (i = 0; i < 16; i++) rijndaelInput[(i + 12) % 16] = temp[i] ^ op_c[i];
rijndaelInput[15] ^= 2;
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, out);
for (i = 0; i < 16; i++) out[i] ^= op_c[i];
for (i = 0; i < 16; i++) ck[i] = out[i];
/* To obtain output block OUT4: XOR OPc and TEMP, *
* rotate by r4=64, and XOR on the constant c4 (which *
* is all zeroes except that the 2nd from last bit is 1). */
for (i = 0; i < 16; i++) rijndaelInput[(i + 8) % 16] = temp[i] ^ op_c[i];
rijndaelInput[15] ^= 4;
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, out);
for (i = 0; i < 16; i++) out[i] ^= op_c[i];
for (i = 0; i < 16; i++) ik[i] = out[i];
return;
} /* end of function f2345 */
/*-------------------------------------------------------------------
* Algorithm f1*
*-------------------------------------------------------------------
*
* Computes resynch authentication code MAC-S from key K, random
* challenge RAND, sequence number SQN and authentication management
* field AMF.
*
*-----------------------------------------------------------------*/
void f1star(u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], u8 mac_s[8]) {
// u8 op_c[16];
u8 temp[16];
u8 in1[16];
u8 out1[16];
u8 rijndaelInput[16];
u8 i;
Authentication_5gaka::RijndaelKeySchedule(k);
// ComputeOPc( op_c );
for (i = 0; i < 16; i++) rijndaelInput[i] = rand[i] ^ op_c[i];
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, temp);
for (i = 0; i < 6; i++) {
in1[i] = sqn[i];
in1[i + 8] = sqn[i];
}
for (i = 0; i < 2; i++) {
in1[i + 6] = amf[i];
in1[i + 14] = amf[i];
}
/* XOR op_c and in1, rotate by r1=64, and XOR *
* on the constant c1 (which is all zeroes) */
for (i = 0; i < 16; i++) rijndaelInput[(i + 8) % 16] = in1[i] ^ op_c[i];
/* XOR on the value temp computed before */
for (i = 0; i < 16; i++) rijndaelInput[i] ^= temp[i];
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, out1);
for (i = 0; i < 16; i++) out1[i] ^= op_c[i];
for (i = 0; i < 8; i++) mac_s[i] = out1[i + 8];
return;
} /* end of function f1star */
/*-------------------------------------------------------------------
* Algorithm f5*
*-------------------------------------------------------------------
*
* Takes key K and random challenge RAND, and returns resynch
* anonymity key AK.
*
*-----------------------------------------------------------------*/
void f5star(u8 k[16], u8 rand[16], u8 ak[6]) {
// u8 op_c[16];
u8 temp[16];
u8 out[16];
u8 rijndaelInput[16];
u8 i;
Authentication_5gaka::RijndaelKeySchedule(k);
// ComputeOPc( op_c );
for (i = 0; i < 16; i++) rijndaelInput[i] = rand[i] ^ op_c[i];
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, temp);
/* To obtain output block OUT5: XOR OPc and TEMP, *
* rotate by r5=96, and XOR on the constant c5 (which *
* is all zeroes except that the 3rd from last bit is 1). */
for (i = 0; i < 16; i++) rijndaelInput[(i + 4) % 16] = temp[i] ^ op_c[i];
rijndaelInput[15] ^= 8;
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, out);
for (i = 0; i < 16; i++) out[i] ^= op_c[i];
for (i = 0; i < 6; i++) ak[i] = out[i];
return;
} /* end of function f5star */
This diff is collapsed.
......@@ -21,7 +21,7 @@
/*! \file ausf_app.cpp
\brief
\author Tien-Thinh NGUYEN
\author Tien-Thinh NGUYEN, Jian Yang, Fengjiao He, Hongxin Wang
\company Eurecom
\date 2021
\email: Tien-Thinh.Nguyen@eurecom.fr
......
......@@ -21,7 +21,7 @@
/*! \file ausf_client.cpp
\brief
\author Tien-Thinh NGUYEN
\author Tien-Thinh NGUYEN, Jian Yang, Fengjiao He, Hongxin Wang
\company Eurecom
\date 2020
\email: Tien-Thinh.Nguyen@eurecom.fr
......@@ -106,7 +106,7 @@ void ausf_client::curl_http_client(
Logger::ausf_app().info(
"Request sent by interface " + ausf_cfg.sbi.if_name);
// response information.
// Response information.
long httpCode = {0};
std::unique_ptr<std::string> httpData(new std::string());
std::unique_ptr<std::string> httpHeaderData(new std::string());
......@@ -124,9 +124,8 @@ void ausf_client::curl_http_client(
res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
// get the response
// Process the response
response = *httpData.get();
std::string resMsg = "";
bool is_response_ok = true;
Logger::ausf_app().info("Get response with httpcode (%d)", httpCode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment