Commit 82404287 authored by Keliang's avatar Keliang

add some license

parent e1d1256e
/*
* 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
brief
author Jian Yang,Fengjiao He,Hongxin Wang
date 2020
email: contact@openairinterface.org
*/
#include "authentication_algorithms_with_5gaka.hpp"
#include <errno.h>
#include <gmp.h>
#include <iostream>
#include <nettle/hmac.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "logger.hpp"
#include <iostream>
#include "OCTET_STRING.h"
#include "logger.hpp"
#include "sha256.hpp"
random_state_t random_state;
......@@ -35,8 +66,7 @@ void Authentication_5gaka::f1(const uint8_t opc[16], const uint8_t k[16],
RijndaelKeySchedule(k);
for (i = 0; i < 16; i++)
rijndaelInput[i] = _rand[i] ^ opc[i];
for (i = 0; i < 16; i++) rijndaelInput[i] = _rand[i] ^ opc[i];
RijndaelEncrypt(rijndaelInput, temp);
......@@ -54,21 +84,17 @@ void Authentication_5gaka::f1(const uint8_t opc[16], const uint8_t k[16],
* 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] ^ opc[i];
for (i = 0; i < 16; i++) rijndaelInput[(i + 8) % 16] = in1[i] ^ opc[i];
/*
* XOR on the value temp computed before
*/
for (i = 0; i < 16; i++)
rijndaelInput[i] ^= temp[i];
for (i = 0; i < 16; i++) rijndaelInput[i] ^= temp[i];
RijndaelEncrypt(rijndaelInput, out1);
for (i = 0; i < 16; i++)
out1[i] ^= opc[i];
for (i = 0; i < 16; i++) out1[i] ^= opc[i];
for (i = 0; i < 8; i++)
mac_a[i] = out1[i];
for (i = 0; i < 8; i++) mac_a[i] = out1[i];
return;
}
......@@ -92,8 +118,7 @@ void Authentication_5gaka::f2345(const uint8_t opc[16], const uint8_t k[16],
RijndaelKeySchedule(k);
for (i = 0; i < 16; i++)
rijndaelInput[i] = _rand[i] ^ opc[i];
for (i = 0; i < 16; i++) rijndaelInput[i] = _rand[i] ^ opc[i];
RijndaelEncrypt(rijndaelInput, temp);
......@@ -102,54 +127,44 @@ void Authentication_5gaka::f2345(const uint8_t opc[16], const uint8_t k[16],
* * * * 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] ^ opc[i];
for (i = 0; i < 16; i++) rijndaelInput[i] = temp[i] ^ opc[i];
rijndaelInput[15] ^= 1;
RijndaelEncrypt(rijndaelInput, out);
for (i = 0; i < 16; i++)
out[i] ^= opc[i];
for (i = 0; i < 16; i++) out[i] ^= opc[i];
for (i = 0; i < 8; i++)
res[i] = out[i + 8];
for (i = 0; i < 8; i++) res[i] = out[i + 8];
for (i = 0; i < 6; i++)
ak[i] = out[i];
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] ^ opc[i];
for (i = 0; i < 16; i++) rijndaelInput[(i + 12) % 16] = temp[i] ^ opc[i];
rijndaelInput[15] ^= 2;
RijndaelEncrypt(rijndaelInput, out);
for (i = 0; i < 16; i++)
out[i] ^= opc[i];
for (i = 0; i < 16; i++) out[i] ^= opc[i];
for (i = 0; i < 16; i++)
ck[i] = out[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] ^ opc[i];
for (i = 0; i < 16; i++) rijndaelInput[(i + 8) % 16] = temp[i] ^ opc[i];
rijndaelInput[15] ^= 4;
RijndaelEncrypt(rijndaelInput, out);
for (i = 0; i < 16; i++)
out[i] ^= opc[i];
for (i = 0; i < 16; i++) out[i] ^= opc[i];
for (i = 0; i < 16; i++)
ik[i] = out[i];
for (i = 0; i < 16; i++) ik[i] = out[i];
return;
} /* end of function f2345 */
......@@ -175,8 +190,7 @@ void Authentication_5gaka::f1star(const uint8_t opc[16], const uint8_t k[16],
RijndaelKeySchedule(k);
for (i = 0; i < 16; i++)
rijndaelInput[i] = _rand[i] ^ opc[i];
for (i = 0; i < 16; i++) rijndaelInput[i] = _rand[i] ^ opc[i];
RijndaelEncrypt(rijndaelInput, temp);
......@@ -194,22 +208,18 @@ void Authentication_5gaka::f1star(const uint8_t opc[16], const uint8_t k[16],
* 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] ^ opc[i];
for (i = 0; i < 16; i++) rijndaelInput[(i + 8) % 16] = in1[i] ^ opc[i];
/*
* XOR on the value temp computed before
*/
for (i = 0; i < 16; i++)
rijndaelInput[i] ^= temp[i];
for (i = 0; i < 16; i++) rijndaelInput[i] ^= temp[i];
RijndaelEncrypt(rijndaelInput, out1);
for (i = 0; i < 16; i++)
out1[i] ^= opc[i];
for (i = 0; i < 16; i++) out1[i] ^= opc[i];
for (i = 0; i < 8; i++)
mac_s[i] = out1[i + 8];
for (i = 0; i < 8; i++) mac_s[i] = out1[i + 8];
return;
}
......@@ -231,8 +241,7 @@ void Authentication_5gaka::f5star(const uint8_t opc[16], const uint8_t k[16],
RijndaelKeySchedule(k);
for (i = 0; i < 16; i++)
rijndaelInput[i] = _rand[i] ^ opc[i];
for (i = 0; i < 16; i++) rijndaelInput[i] = _rand[i] ^ opc[i];
RijndaelEncrypt(rijndaelInput, temp);
......@@ -241,17 +250,14 @@ void Authentication_5gaka::f5star(const uint8_t opc[16], const uint8_t k[16],
* * * * 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] ^ opc[i];
for (i = 0; i < 16; i++) rijndaelInput[(i + 4) % 16] = temp[i] ^ opc[i];
rijndaelInput[15] ^= 8;
RijndaelEncrypt(rijndaelInput, out);
for (i = 0; i < 16; i++)
out[i] ^= opc[i];
for (i = 0; i < 16; i++) out[i] ^= opc[i];
for (i = 0; i < 6; i++)
ak[i] = out[i];
for (i = 0; i < 6; i++) ak[i] = out[i];
return;
}
......@@ -277,8 +283,7 @@ void Authentication_5gaka::ComputeOPc(const uint8_t kP[16],
// 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];
for (i = 0; i < 16; i++) opcP[i] ^= opP[i];
// FPRINTF_DEBUG
// ("\tOut:\t%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
......@@ -312,13 +317,15 @@ void Authentication_5gaka::kdf(uint8_t *key, uint16_t key_len, uint8_t *s,
void Authentication_5gaka::derive_kseaf(std::string serving_network,
uint8_t kausf[32], uint8_t kseaf[32]) {
Logger::ausf_server().debug("derive_kseaf ...");
// Logger::ausf_server().debug("inputstring: snn(%s)", serving_network.c_str());
// Logger::ausf_server().debug("inputstring: snn(%s)",
// serving_network.c_str());
OCTET_STRING_t netName;
OCTET_STRING_fromBuf(&netName, serving_network.c_str(),
serving_network.length());
// print_buffer("ausf_server", "inputstring: snn(hex)", netName.buf, netName.size);
// print_buffer("ausf_server", "inputstring: snn(hex)", netName.buf,
// netName.size);
uint8_t S[100];
S[0] = 0x6C; // FC
S[0] = 0x6C; // FC
memcpy(&S[1], netName.buf, netName.size);
// memcpy (&S[1+netName.size], &netName.size, 2);
S[1 + netName.size] = (uint8_t)((netName.size & 0xff00) >> 8);
......@@ -335,15 +342,17 @@ void Authentication_5gaka::derive_kausf(uint8_t ck[16], uint8_t ik[16],
uint8_t sqn[6], uint8_t ak[6],
uint8_t kausf[32]) {
Logger::ausf_server().debug("derive_kausf ...");
// Logger::ausf_server().debug("inputstring: snn(%s)", serving_network.c_str());
// Logger::ausf_server().debug("inputstring: snn(%s)",
// serving_network.c_str());
OCTET_STRING_t netName;
OCTET_STRING_fromBuf(&netName, serving_network.c_str(),
serving_network.length());
// print_buffer("ausf_server", "inputstring: snn(hex)", netName.buf, netName.size);
// print_buffer("ausf_server", "inputstring: snn(hex)", netName.buf,
// netName.size);
uint8_t S[100];
uint8_t key[32];
memcpy(&key[0], ck, 16);
memcpy(&key[16], ik, 16); // KEY
memcpy(&key[16], ik, 16); // KEY
S[0] = 0x6A;
memcpy(&S[1], netName.buf, netName.size);
// memcpy (&S[1+netName.size], &netName.size, 2);
......@@ -364,7 +373,7 @@ void Authentication_5gaka::derive_kausf(uint8_t ck[16], uint8_t ik[16],
void Authentication_5gaka::derive_kamf(std::string imsi, uint8_t *kseaf,
uint8_t *kamf, uint16_t abba) {
Logger::ausf_server().debug("derive_kamf ...");
std::string ueSupi = imsi; // OK
std::string ueSupi = imsi; // OK
// Logger::ausf_server().debug("inputstring: supi(%s)", ueSupi.c_str());
// int supiLen = (imsi.length()*sizeof(unsigned char))/2;
// unsigned char * supi = (unsigned char*)calloc(1, supiLen);
......@@ -375,7 +384,7 @@ void Authentication_5gaka::derive_kamf(std::string imsi, uint8_t *kseaf,
int supiLen = supi.size;
// print_buffer("ausf_server", "inputstring: supi(hex)", supi.buf, supiLen);
uint8_t S[100];
S[0] = 0x6D; // FC = 0x6D
S[0] = 0x6D; // FC = 0x6D
memcpy(&S[1], supi.buf, supiLen);
// memcpy (&S[1+supiLen], &supiLen, 2);
S[1 + supiLen] = (uint8_t)((supiLen & 0xff00) >> 8);
......@@ -398,7 +407,7 @@ void Authentication_5gaka::derive_knas(algorithm_type_dist_t nas_alg_type,
uint8_t S[20];
uint8_t out[32] = {0};
S[0] = 0x69; // FC
S[0] = 0x69; // FC
S[1] = (uint8_t)(nas_alg_type & 0xFF);
S[2] = 0x00;
S[3] = 0x01;
......@@ -409,8 +418,7 @@ void Authentication_5gaka::derive_knas(algorithm_type_dist_t nas_alg_type,
// print_buffer("ausf_server", "key KEY", kamf, 32);
kdf(kamf, 32, S, 7, out, 32);
// memcpy (knas, &out[31 - 16 + 1], 16);
for (int i = 0; i < 16; i++)
knas[i] = out[16 + i];
for (int i = 0; i < 16; i++) knas[i] = out[16 + i];
// print_buffer("ausf_server", "knas", knas, 16);
// Logger::ausf_server().debug("derive knas finished!");
}
......@@ -563,7 +571,6 @@ uint8_t *Authentication_5gaka::sqn_ms_derive(const uint8_t opc[16],
return sqn_ms;
}
//---------------------------udm---------------------------------------------------
// ck, ik, vector.xres, vector.rand, serving_network, vector.xresStar
......@@ -579,12 +586,10 @@ void Authentication_5gaka::annex_a_4_33501(uint8_t ck[16], uint8_t ik[16],
memcpy(&S[1], netName.buf, netName.size);
S[1 + netName.size] = (netName.size & 0xff00) >> 8;
S[2 + netName.size] = (netName.size & 0x00ff);
for (int i = 0; i < 16; i++)
S[3 + netName.size + i] = rand[i];
for (int i = 0; i < 16; i++) S[3 + netName.size + i] = rand[i];
S[19 + netName.size] = 0x00;
S[20 + netName.size] = 0x10;
for (int i = 0; i < 8; i++)
S[21 + netName.size + i] = input[i];
for (int i = 0; i < 8; i++) S[21 + netName.size + i] = input[i];
S[29 + netName.size] = 0x00;
S[30 + netName.size] = 0x08;
/*
......@@ -606,12 +611,11 @@ void Authentication_5gaka::annex_a_4_33501(uint8_t ck[16], uint8_t ik[16],
// 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
memcpy(&key[16], ik, 16); // KEY
// Authentication_5gaka::kdf(key, 32, oldS, 33, output, 16);
uint8_t out[32];
Authentication_5gaka::kdf(key, 32, S, 31 + netName.size, out, 32);
for (int i = 0; i < 16; i++)
output[i] = out[16 + i];
for (int i = 0; i < 16; i++) output[i] = out[16 + i];
// print_buffer("udm_ueau", "XRES*(new)", out, 32);
}
......@@ -627,8 +631,7 @@ void Authentication_5gaka::generate_random(uint8_t *random_p, ssize_t length) {
mpz_export(random_p, NULL, 1, length, 0, 0, random_nb);
int r = 0, mask = 0, shift;
for (int i = 0; i < length; i++) {
if ((i % sizeof(i)) == 0)
r = rand();
if ((i % sizeof(i)) == 0) r = rand();
shift = 8 * (i % sizeof(i));
mask = 0xFF << shift;
random_p[i] = (r & mask) >> shift;
......@@ -638,65 +641,59 @@ void Authentication_5gaka::generate_random(uint8_t *random_p, ssize_t length) {
/*---------------------ausf-----------------------------*/
//h(x)
// h(x)
Sha256 ctx;
void Authentication_5gaka::sha256(unsigned char *message, int msg_len, unsigned char *output)
{
void Authentication_5gaka::sha256(unsigned char *message, int msg_len,
unsigned char *output) {
memset(output, 0, Sha256::DIGEST_SIZE);
ctx.init();
ctx.update(message, msg_len);
ctx.finalResult(output);
}
//hxres
void Authentication_5gaka::generate_Hxres(uint8_t rand[16],uint8_t xresStar[16],
uint8_t *hxresStar) {
uint8_t inputString[40];
// hxres
void Authentication_5gaka::generate_Hxres(uint8_t rand[16],
uint8_t xresStar[16],
uint8_t *hxresStar) {
uint8_t inputString[40];
memcpy(&inputString[0], rand, 16);
memcpy(&inputString[16], xresStar, 16);
memcpy(&inputString[0], rand, 16);
memcpy(&inputString[16], xresStar, 16);
// cout << "\ninputString" << std::endl;
// for (int i = 0; i < 40; i++)printf("%x ", inputString[i]);
// cout << endl;
// cout << "\ninputString" << std::endl;
// for (int i = 0; i < 40; i++)printf("%x ", inputString[i]);
// cout << endl;
unsigned char sha256Out[Sha256::DIGEST_SIZE];
Authentication_5gaka::sha256((unsigned char *)inputString, 32, sha256Out);
for (int j = 0; j < 16; j++)
hxresStar[j] = (uint8_t)sha256Out[j];
unsigned char sha256Out[Sha256::DIGEST_SIZE];
Authentication_5gaka::sha256((unsigned char *)inputString, 32, sha256Out);
for (int j = 0; j < 16; j++) hxresStar[j] = (uint8_t)sha256Out[j];
// cout << "hxresStar" << std::endl;
// for (int i = 0; i < 16; i++)printf("%x ", hxresStar[i]);
// cout << endl;
// cout << "hxresStar" << std::endl;
// for (int i = 0; i < 16; i++)printf("%x ", hxresStar[i]);
// cout << endl;
}
//may not be appropriate
// 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++)
// 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) {
// }
for (int i = 0; i < msg_len; i++)
{
if (oldVal[i] != newVal[i])
return false;
};
bool Authentication_5gaka::equal_uint8(uint8_t *oldVal, uint8_t *newVal,
int msg_len) {
for (int i = 0; i < msg_len; i++) {
if (oldVal[i] != newVal[i]) return false;
};
return true;
}
\ No newline at end of file
/*
* 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
brief
author Jian Yang,Fengjiao He,Hongxin Wang
date 2020
email: contact@openairinterface.org
*/
#ifndef _5GAKA_H_
#define _5GAKA_H_
......@@ -6,8 +34,9 @@
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <string>
#include <unistd.h>
#include <string>
//}
#define SQN_LENGTH_BITS (48)
......@@ -39,9 +68,9 @@ typedef struct {
uint8_t xresStar[16];
uint8_t autn[16];
uint8_t kausf[32];
} _5G_HE_AV_t; // clause 6.3.6.2.5, ts33.501
} _5G_HE_AV_t; // clause 6.3.6.2.5, ts33.501
typedef struct _5G_AV_s{
typedef struct _5G_AV_s {
uint8_t avType;
uint8_t rand[16];
uint8_t hxres[16];
......@@ -74,7 +103,7 @@ typedef enum {
} algorithm_type_dist_t;
class Authentication_5gaka {
public:
public:
/****** sequence number functions ********/
// struct sqn_ue_s *sqn_exists(uint64_t imsi);
// void sqn_insert(struct sqn_ue_s *item);
......@@ -82,11 +111,11 @@ public:
// struct sqn_ue_s *sqn_new(uint64_t imsi);
// void sqn_list_init(void);
// void sqn_get(uint64_t imsi, uint8_t sqn[6]);
public:
public:
/****** random number functions *********/
// void random_init(void);
// void generate_random(uint8_t *random, ssize_t length);
public:
public:
/****** internal algorithms f1 f2 f3 f4 f5 ********/
static void f1(const uint8_t opc[16], const uint8_t k[16],
const uint8_t _rand[16], const uint8_t sqn[6],
......@@ -100,7 +129,7 @@ public:
static void f5star(const uint8_t kP[16], const uint8_t k[16],
const uint8_t rand[16], uint8_t ak[6]);
public:
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);
......@@ -120,7 +149,7 @@ public:
static uint8_t *sqn_ms_derive(const uint8_t opc[16], uint8_t *key,
uint8_t *auts, uint8_t *rand);
public:
public:
/****** general functions ********/
static void ComputeOPc(const uint8_t kP[16], const uint8_t opP[16],
uint8_t opcP[16]);
......@@ -135,20 +164,20 @@ public:
uint8_t *output);
static void generate_random(uint8_t *random_p, ssize_t length);
static void sha256(unsigned char *message, int msg_len, unsigned char *output);
static void generate_Hxres(uint8_t rand[16],uint8_t xresStar[16],
uint8_t *hxresStar);
static void sha256(unsigned char *message, int msg_len,
unsigned char *output);
static void generate_Hxres(uint8_t rand[16], uint8_t xresStar[16],
uint8_t *hxresStar);
// static void generate_authCtxId(uint8_t autn[16],
// uint8_t *authCtxId);
static bool equal_uint8(uint8_t *oldVal,uint8_t *newVal,
int msg_len);
// uint8_t *authCtxId);
static bool equal_uint8(uint8_t *oldVal, uint8_t *newVal, int msg_len);
public:
public:
/****** Rijndael ********/
static void RijndaelKeySchedule(const uint8_t key[16]);
static void RijndaelEncrypt(const uint8_t in[16], uint8_t out[16]);
private:
private:
auc_vector_t auc_vector;
};
......
/*
* 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
brief
author Jian Yang,Fengjiao He,Hongxin Wang
date 2020
email: contact@openairinterface.org
*/
/*-------------------------------------------------------------------
* Example algorithms f1, f1*, f2, f3, f4, f5, f5*
*-------------------------------------------------------------------
......@@ -49,8 +77,7 @@ void f5star(u8 k[16], u8 rand[16], u8 ak[6]);
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]);
for (int i = 0; i < 16; i++) printf("0x%x", op_c[i]);
printf("\n");
// u8 op_c[16];
u8 temp[16];
......@@ -63,8 +90,7 @@ void f1(u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], u8 mac_a[8]) {
// ComputeOPc( op_c );
for (i = 0; i < 16; i++)
rijndaelInput[i] = rand[i] ^ op_c[i];
for (i = 0; i < 16; i++) rijndaelInput[i] = rand[i] ^ op_c[i];
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, temp);
for (i = 0; i < 6; i++) {
......@@ -79,20 +105,16 @@ void f1(u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], u8 mac_a[8]) {
/* 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];
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];
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 < 16; i++) out1[i] ^= op_c[i];
for (i = 0; i < 8; i++)
mac_a[i] = out1[i];
for (i = 0; i < 8; i++) mac_a[i] = out1[i];
return;
} /* end of function f1 */
......@@ -117,56 +139,45 @@ void f2345(u8 k[16], u8 rand[16], u8 res[8], u8 ck[16], u8 ik[16], u8 ak[6]) {
// ComputeOPc( op_c );
for (i = 0; i < 16; i++)
rijndaelInput[i] = rand[i] ^ op_c[i];
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];
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 < 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];
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];
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++) out[i] ^= op_c[i];
for (i = 0; i < 16; i++)
ck[i] = out[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];
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++) out[i] ^= op_c[i];
for (i = 0; i < 16; i++)
ik[i] = out[i];
for (i = 0; i < 16; i++) ik[i] = out[i];
return;
} /* end of function f2345 */
......@@ -193,8 +204,7 @@ void f1star(u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], u8 mac_s[8]) {
// ComputeOPc( op_c );
for (i = 0; i < 16; i++)
rijndaelInput[i] = rand[i] ^ op_c[i];
for (i = 0; i < 16; i++) rijndaelInput[i] = rand[i] ^ op_c[i];
Authentication_5gaka::RijndaelEncrypt(rijndaelInput, temp);
for (i = 0; i < 6; i++) {
......@@ -209,20 +219,16 @@ void f1star(u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], u8 mac_s[8]) {
/* 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];
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];
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 < 16; i++) out1[i] ^= op_c[i];
for (i = 0; i < 8; i++)
mac_s[i] = out1[i + 8];
for (i = 0; i < 8; i++) mac_s[i] = out1[i + 8];
return;
} /* end of function f1star */
......@@ -247,24 +253,20 @@ void f5star(u8 k[16], u8 rand[16], u8 ak[6]) {
// ComputeOPc( op_c );
for (i = 0; i < 16; i++)
rijndaelInput[i] = rand[i] ^ op_c[i];
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];
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 < 16; i++) out[i] ^= op_c[i];
for (i = 0; i < 6; i++)
ak[i] = out[i];
for (i = 0; i < 6; i++) ak[i] = out[i];
return;
} /* end of function f5star */
/*
* 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
brief
author Jian Yang,Fengjiao He,Hongxin Wang
date 2020
email: contact@openairinterface.org
*/
#include "authentication_algorithms_with_5gaka.hpp"
typedef uint8_t u8;
......@@ -87,14 +115,12 @@ void Authentication_5gaka::RijndaelKeySchedule(const uint8_t key[16]) {
/************ internal functions ******************/
void KeyAdd(u8 state[4][4], u8 roundKeys[11][4][4], int round) {
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
state[i][j] ^= roundKeys[round][i][j];
for (int j = 0; j < 4; j++) state[i][j] ^= roundKeys[round][i][j];
return;
}
int ByteSub(u8 state[4][4]) {
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
state[i][j] = S[state[i][j]];
for (int j = 0; j < 4; j++) state[i][j] = S[state[i][j]];
return 0;
}
......@@ -155,14 +181,12 @@ void Authentication_5gaka::RijndaelEncrypt(const uint8_t input[16],
uint8_t output[16]) {
int i = 0, r = 0;
u8 state[4][4];
for (i = 0; i < 16; i++)
state[i & 0x3][i >> 2] = input[i];
for (i = 0; i < 16; i++) state[i & 0x3][i >> 2] = input[i];
KeyAdd(state, roundKeys, 0);
#if AUTH_ALG_ON
printf("end of round(%d)\n0x", 0);
#endif
for (int i = 0; i < 16; i++)
printf("%x ", state[i & 0x3][i >> 2]);
for (int i = 0; i < 16; i++) printf("%x ", state[i & 0x3][i >> 2]);
printf("\n");
for (r = 1; r <= 9; r++) {
ByteSub(state);
......@@ -171,8 +195,7 @@ void Authentication_5gaka::RijndaelEncrypt(const uint8_t input[16],
KeyAdd(state, roundKeys, r);
#if AUTH_ALG_ON
printf("end of round(%d)\n0x", r);
for (i = 0; i < 16; i++)
printf("%x ", state[i & 0x3][i >> 2]);
for (i = 0; i < 16; i++) printf("%x ", state[i & 0x3][i >> 2]);
printf("\n");
#endif
}
......@@ -181,16 +204,13 @@ void Authentication_5gaka::RijndaelEncrypt(const uint8_t input[16],
KeyAdd(state, roundKeys, r);
#if AUTH_ALG_ON
printf("end of round(%d)\n0x", r);
for (int i = 0; i < 16; i++)
printf("%x ", state[i & 0x3][i >> 2]);
for (int i = 0; i < 16; i++) printf("%x ", state[i & 0x3][i >> 2]);
printf("\n");
#endif
for (i = 0; i < 16; i++)
output[i] = state[i & 0x3][i >> 2];
for (i = 0; i < 16; i++) output[i] = state[i & 0x3][i >> 2];
#if AUTH_ALG_ON
printf("output_encrypt: ");
for (i = 0; i < 16; i++)
printf("%x", output[i]);
for (i = 0; i < 16; i++) printf("%x", output[i]);
printf("\n");
#endif
return;
......
/*
* 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
brief
author Jian Yang,Fengjiao He,Hongxin Wang
date 2020
email: contact@openairinterface.org
*/
#include "sha256.hpp"
#include <cstring>
#include <fstream>
Sha256::Sha256() {}
Sha256::~Sha256() {}
const unsigned int Sha256::sha256_k[64] = // UL = uint32
const unsigned int Sha256::sha256_k[64] = // UL = uint32
{0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
......@@ -108,20 +137,18 @@ void Sha256::finalResult(unsigned char *digest) {
}
}
std::string sha256(std::string input)
{
unsigned char digest[Sha256::DIGEST_SIZE];
memset(digest,0,Sha256::DIGEST_SIZE);
Sha256 ctx = Sha256();
ctx.init();
ctx.update( (unsigned char*)input.c_str(), input.length());
ctx.finalResult(digest);
char buf[2*Sha256::DIGEST_SIZE+1];
buf[2*Sha256::DIGEST_SIZE] = 0;
for (int i = 0; i < Sha256::DIGEST_SIZE; i++)
sprintf(buf+i*2, "%02x", digest[i]);
return std::string(buf);
}
std::string sha256(std::string input) {
unsigned char digest[Sha256::DIGEST_SIZE];
memset(digest, 0, Sha256::DIGEST_SIZE);
Sha256 ctx = Sha256();
ctx.init();
ctx.update((unsigned char *)input.c_str(), input.length());
ctx.finalResult(digest);
char buf[2 * Sha256::DIGEST_SIZE + 1];
buf[2 * Sha256::DIGEST_SIZE] = 0;
for (int i = 0; i < Sha256::DIGEST_SIZE; i++)
sprintf(buf + i * 2, "%02x", digest[i]);
return std::string(buf);
}
/*
* 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
brief
author Jian Yang,Fengjiao He,Hongxin Wang
date 2020
email: contact@openairinterface.org
*/
#ifndef Sha256_H
#define Sha256_H
#include <string>
class Sha256 {
protected:
protected:
typedef unsigned char uint8;
typedef unsigned int uint32;
typedef unsigned long long uint64;
......@@ -11,7 +39,7 @@ protected:
const static uint32 sha256_k[];
static const unsigned int SHA224_256_BLOCK_SIZE = (512 / 8);
public:
public:
Sha256();
~Sha256();
void init();
......@@ -19,7 +47,7 @@ public:
void finalResult(unsigned char *digest);
static const unsigned int DIGEST_SIZE = (256 / 8);
protected:
protected:
void transform(const unsigned char *message, unsigned int block_nb);
unsigned int m_tot_len;
unsigned int m_len;
......@@ -38,16 +66,16 @@ std::string sha256(std::string input);
#define Sha256_F2(x) (SHA2_ROTR(x, 6) ^ SHA2_ROTR(x, 11) ^ SHA2_ROTR(x, 25))
#define Sha256_F3(x) (SHA2_ROTR(x, 7) ^ SHA2_ROTR(x, 18) ^ SHA2_SHFR(x, 3))
#define Sha256_F4(x) (SHA2_ROTR(x, 17) ^ SHA2_ROTR(x, 19) ^ SHA2_SHFR(x, 10))
#define SHA2_UNPACK32(x, str) \
{ \
*((str) + 3) = (uint8)((x)); \
*((str) + 2) = (uint8)((x) >> 8); \
*((str) + 1) = (uint8)((x) >> 16); \
*((str) + 0) = (uint8)((x) >> 24); \
#define SHA2_UNPACK32(x, str) \
{ \
*((str) + 3) = (uint8)((x)); \
*((str) + 2) = (uint8)((x) >> 8); \
*((str) + 1) = (uint8)((x) >> 16); \
*((str) + 0) = (uint8)((x) >> 24); \
}
#define SHA2_PACK32(str, x) \
{ \
*(x) = ((uint32) * ((str) + 3)) | ((uint32) * ((str) + 2) << 8) | \
((uint32) * ((str) + 1) << 16) | ((uint32) * ((str) + 0) << 24); \
#define SHA2_PACK32(str, x) \
{ \
*(x) = ((uint32) * ((str) + 3)) | ((uint32) * ((str) + 2) << 8) | \
((uint32) * ((str) + 1) << 16) | ((uint32) * ((str) + 0) << 24); \
}
#endif
/*
* 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
brief
author Jian Yang,Fengjiao He,Hongxin Wang
date 2020
email: contact@openairinterface.org
*/
#ifndef _TEST_HPP_
#define _TEST_HPP_
#include <stdlib.h>
#include "OCTET_STRING.h"
#include "authentication_algorithms_with_5gaka.hpp"
#include "f12345.h"
#include <stdlib.h>
// uint8_t key[16] = {0x46, 0x5b, 0x5c, 0xe8, 0xb1, 0x99, 0xb4, 0x9f, 0xaa,
// 0x5f, 0x0a, 0x2e, 0xe2, 0x38, 0xa6, 0xbc}; uint8_t key[16] = {0x03, 0x96,
......@@ -121,8 +150,7 @@ void kdf_test() {
Authentication_5gaka::kdf(Key, 32, M.buf, M.size, O, 16);
// Authentication_5gaka::kdf(K.buf, K.size, M.buf, M.size, O, 16);
printf("KDF test ...\n");
for (int i = 0; i < 16; i++)
printf("%x ", O[i]);
for (int i = 0; i < 16; i++) printf("%x ", O[i]);
printf("\n");
}
......@@ -140,8 +168,7 @@ void rijndael_test() {
uint8_t txt_enc[16];
Authentication_5gaka::RijndaelEncrypt(txt, txt_enc);
printf("encrypted text ...\n");
for (int i = 0; i < 16; i++)
printf("%x ", txt_enc[i]);
for (int i = 0; i < 16; i++) printf("%x ", txt_enc[i]);
printf("\n");
}
......@@ -158,11 +185,9 @@ void f1_test() {
Authentication_5gaka::f1(opc, key, rand, sqn, amf, mac_a);
Authentication_5gaka::f1star(opc, key, rand, sqn, amf, mac_s);
printf("testing f1...\n");
for (int i = 0; i < 8; i++)
printf("%x ", mac_a[i]);
for (int i = 0; i < 8; i++) printf("%x ", mac_a[i]);
printf("\n");
for (int i = 0; i < 8; i++)
printf("%x ", mac_s[i]);
for (int i = 0; i < 8; i++) printf("%x ", mac_s[i]);
printf("\n");
}
......@@ -183,26 +208,21 @@ void f2345_test() {
uint8_t res[8], ck[16], ik[16], ak[6];
Authentication_5gaka::f2345(opc, key, rand, res, ck, ik, ak);
printf("res: 0x\n");
for (int i = 0; i < 8; i++)
printf("%x", res[i]);
for (int i = 0; i < 8; i++) printf("%x", res[i]);
printf("\n");
printf("ak: 0x");
for (int i = 0; i < 6; i++)
printf("%x", ak[i]);
for (int i = 0; i < 6; i++) printf("%x", ak[i]);
printf("\n");
printf("ck: 0x\n");
for (int i = 0; i < 16; i++)
printf("%x", ck[i]);
for (int i = 0; i < 16; i++) printf("%x", ck[i]);
printf("\n");
printf("ik: 0x\n");
for (int i = 0; i < 16; i++)
printf("%x", ik[i]);
for (int i = 0; i < 16; i++) printf("%x", ik[i]);
printf("\n");
uint8_t ak2[6];
Authentication_5gaka::f5star(opc, key, rand, ak2);
printf("ak2: 0x");
for (int i = 0; i < 6; i++)
printf("%x ", ak2[i]);
for (int i = 0; i < 6; i++) printf("%x ", ak2[i]);
printf("\n");
}
......@@ -234,16 +254,13 @@ void res_test() {
Authentication_5gaka::kdf(key, 32, S, 3 + netName.size, output, 16);
printf("inputstring ...\n");
// for(int i=0; i< 1; i++)
for (int i = 0; i < 3 + netName.size; i++)
printf("%c", S[i]);
for (int i = 0; i < 3 + netName.size; i++) printf("%c", S[i]);
printf("\n");
printf("key ...\n");
for (int i = 0; i < 32; i++)
printf("%x", key[i]);
for (int i = 0; i < 32; i++) printf("%x", key[i]);
printf("\n");
printf("out ...\n");
for (int i = 0; i < 16; i++)
printf("%x ", output[i]);
for (int i = 0; i < 16; i++) printf("%x ", output[i]);
printf("\n");
}
......@@ -298,7 +315,6 @@ void buffer_test() {
}
void xresStar_test() {
uint8_t opc[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
uint8_t key[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
......@@ -317,23 +333,20 @@ void xresStar_test() {
printf("snn length(0x%x)\n", netName.size);
S[1 + netName.size] = (netName.size & 0xff00) >> 8;
S[2 + netName.size] = (netName.size & 0x00ff);
for (int i = 0; i < 16; i++)
S[3 + netName.size + i] = rand[i];
for (int i = 0; i < 16; i++) S[3 + netName.size + i] = rand[i];
S[19 + netName.size] = 0x00;
S[20 + netName.size] = 0x10;
for (int i = 0; i < 8; i++)
S[21 + netName.size + i] = res[i];
for (int i = 0; i < 8; i++) S[21 + netName.size + i] = res[i];
S[29 + netName.size] = 0x00;
S[30 + netName.size] = 0x08;
uint8_t ckik[32];
memcpy(&key[0], ck, 16);
memcpy(&key[16], ik, 16); // KEY
memcpy(&key[16], ik, 16); // KEY
uint8_t out[32], output[16];
Authentication_5gaka::kdf(ckik, 32, S, 31 + netName.size, out, 32);
for (int i = 0; i < 16; i++)
output[i] = out[16 + i];
for (int i = 0; i < 16; i++) output[i] = out[16 + i];
print_buffer("amf_n1", "XRES*", output, 16);
}
......@@ -394,8 +407,7 @@ void mac_test() {
// uint8_t sqnak[6] = {0xcb, 0x9f, 0x58, 0xa7, 0x8d, 0x98};
uint8_t sqnak[6] = {0x97, 0x77, 0x9b, 0x30, 0x56, 0x86};
uint8_t sqn[6];
for (int i = 0; i < 6; i++)
sqn[i] = sqnak[i] ^ ak[i];
for (int i = 0; i < 6; i++) sqn[i] = sqnak[i] ^ ak[i];
print_buffer("amf_n1", "sqn", sqn, 6);
uint8_t amf[2] = {0x90, 0x01};
uint8_t mac_a[8];
......
/*
* 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
brief
author Jian Yang,Fengjiao He,Hongxin Wang
date 2020
email: contact@openairinterface.org
*/
#ifndef _PRINT_BUFFER_H
#define _PRINT_BUFFER_H
#include <string>
#include "iostream"
#include "logger.hpp"
#include <string>
using namespace std;
void print_buffer(const string app, const string commit, uint8_t *buf,
int len) {
if (!app.compare("ausf_server"))
cout << commit.c_str() << endl;
if (!app.compare("ausf_server")) cout << commit.c_str() << endl;
Logger::ausf_server().debug(commit.c_str());
for (int i = 0; i < len; i++)
printf("%x ", buf[i]);
for (int i = 0; i < len; i++) printf("%x ", buf[i]);
printf("\n");
}
......
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -32,9 +32,9 @@
#include <arpa/inet.h>
#include <stdint.h>
#define RETURNclear (int)2
#define RETURNerror (int)1
#define RETURNok (int)0
#define RETURNclear (int)2
#define RETURNerror (int)1
#define RETURNok (int)0
typedef enum {
/* Fatal errors - received message should not be processed */
......@@ -49,8 +49,8 @@ typedef enum {
TLV_MANDATORY_FIELD_NOT_PRESENT = -3,
TLV_UNEXPECTED_IEI = -2,
// RETURNerror = -1,
// RETURNok = 0,
// RETURNerror = -1,
// RETURNok = 0,
TLV_ERROR_OK = RETURNok,
/* Defines error code limit below which received message should be discarded
......@@ -59,91 +59,90 @@ typedef enum {
} error_code_e;
//------------------------------------------------------------------------------
#define DECODE_U8(bUFFER, vALUE, sIZE) \
vALUE = *(uint8_t*)(bUFFER); \
sIZE += sizeof(uint8_t)
#define DECODE_U8(bUFFER, vALUE, sIZE) \
vALUE = *(uint8_t *)(bUFFER); \
sIZE += sizeof(uint8_t)
#define DECODE_U16(bUFFER, vALUE, sIZE) \
vALUE = ntohs(*(uint16_t*)(bUFFER)); \
sIZE += sizeof(uint16_t)
#define DECODE_U16(bUFFER, vALUE, sIZE) \
vALUE = ntohs(*(uint16_t *)(bUFFER)); \
sIZE += sizeof(uint16_t)
#define DECODE_U24(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t*)(bUFFER)) >> 8; \
sIZE += sizeof(uint8_t) + sizeof(uint16_t)
#define DECODE_U24(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t *)(bUFFER)) >> 8; \
sIZE += sizeof(uint8_t) + sizeof(uint16_t)
#define DECODE_U32(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t*)(bUFFER)); \
sIZE += sizeof(uint32_t)
#define DECODE_U32(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t *)(bUFFER)); \
sIZE += sizeof(uint32_t)
#if (BYTE_ORDER == LITTLE_ENDIAN)
# define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \
vALUE = ((*(bUFFER)) << 8) | (*((bUFFER) + 1)); \
sIZE += sizeof(uint16_t)
#define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \
vALUE = ((*(bUFFER)) << 8) | (*((bUFFER) + 1)); \
sIZE += sizeof(uint16_t)
#else
# define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \
vALUE = (*(bUFFER)) | (*((bUFFER) + 1) << 8); \
sIZE += sizeof(uint16_t)
#define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \
vALUE = (*(bUFFER)) | (*((bUFFER) + 1) << 8); \
sIZE += sizeof(uint16_t)
#endif
#define ENCODE_U8(buffer, value, size) \
*(uint8_t*)(buffer) = value; \
size += sizeof(uint8_t)
#define ENCODE_U16(buffer, value, size) \
*(uint16_t*)(buffer) = htons(value); \
size += sizeof(uint16_t)
#define ENCODE_U24(buffer, value, size) \
*(uint32_t*)(buffer) = htonl(value); \
size += sizeof(uint8_t) + sizeof(uint16_t)
#define ENCODE_U32(buffer, value, size) \
*(uint32_t*)(buffer) = htonl(value); \
size += sizeof(uint32_t)
#define IPV4_STR_ADDR_TO_INT_NWBO(AdDr_StR,NwBo,MeSsAgE ) do {\
struct in_addr inp;\
if ( inet_aton(AdDr_StR, &inp ) < 0 ) {\
AssertFatal (0, MeSsAgE);\
} else {\
NwBo = inp.s_addr;\
}\
} while (0)
#define NIPADDR(addr) \
(uint8_t)(addr & 0x000000FF), \
(uint8_t)((addr & 0x0000FF00) >> 8), \
(uint8_t)((addr & 0x00FF0000) >> 16), \
(uint8_t)((addr & 0xFF000000) >> 24)
#define HIPADDR(addr) \
(uint8_t)((addr & 0xFF000000) >> 24),\
(uint8_t)((addr & 0x00FF0000) >> 16),\
(uint8_t)((addr & 0x0000FF00) >> 8), \
(uint8_t)(addr & 0x000000FF)
#define NIP6ADDR(addr) \
ntohs((addr)->s6_addr16[0]), \
ntohs((addr)->s6_addr16[1]), \
ntohs((addr)->s6_addr16[2]), \
ntohs((addr)->s6_addr16[3]), \
ntohs((addr)->s6_addr16[4]), \
ntohs((addr)->s6_addr16[5]), \
ntohs((addr)->s6_addr16[6]), \
ntohs((addr)->s6_addr16[7])
#define IN6_ARE_ADDR_MASKED_EQUAL(a,b,m) \
(((((__const uint32_t *) (a))[0] & (((__const uint32_t *) (m))[0])) == (((__const uint32_t *) (b))[0] & (((__const uint32_t *) (m))[0]))) \
&& ((((__const uint32_t *) (a))[1] & (((__const uint32_t *) (m))[1])) == (((__const uint32_t *) (b))[1] & (((__const uint32_t *) (m))[1]))) \
&& ((((__const uint32_t *) (a))[2] & (((__const uint32_t *) (m))[2])) == (((__const uint32_t *) (b))[2] & (((__const uint32_t *) (m))[2]))) \
&& ((((__const uint32_t *) (a))[3] & (((__const uint32_t *) (m))[3])) == (((__const uint32_t *) (b))[3] & (((__const uint32_t *) (m))[3]))))
#define ENCODE_U8(buffer, value, size) \
*(uint8_t *)(buffer) = value; \
size += sizeof(uint8_t)
#define ENCODE_U16(buffer, value, size) \
*(uint16_t *)(buffer) = htons(value); \
size += sizeof(uint16_t)
#define ENCODE_U24(buffer, value, size) \
*(uint32_t *)(buffer) = htonl(value); \
size += sizeof(uint8_t) + sizeof(uint16_t)
#define ENCODE_U32(buffer, value, size) \
*(uint32_t *)(buffer) = htonl(value); \
size += sizeof(uint32_t)
#define IPV4_STR_ADDR_TO_INT_NWBO(AdDr_StR, NwBo, MeSsAgE) \
do { \
struct in_addr inp; \
if (inet_aton(AdDr_StR, &inp) < 0) { \
AssertFatal(0, MeSsAgE); \
} else { \
NwBo = inp.s_addr; \
} \
} while (0)
#define NIPADDR(addr) \
(uint8_t)(addr & 0x000000FF), (uint8_t)((addr & 0x0000FF00) >> 8), \
(uint8_t)((addr & 0x00FF0000) >> 16), \
(uint8_t)((addr & 0xFF000000) >> 24)
#define HIPADDR(addr) \
(uint8_t)((addr & 0xFF000000) >> 24), (uint8_t)((addr & 0x00FF0000) >> 16), \
(uint8_t)((addr & 0x0000FF00) >> 8), (uint8_t)(addr & 0x000000FF)
#define NIP6ADDR(addr) \
ntohs((addr)->s6_addr16[0]), ntohs((addr)->s6_addr16[1]), \
ntohs((addr)->s6_addr16[2]), ntohs((addr)->s6_addr16[3]), \
ntohs((addr)->s6_addr16[4]), ntohs((addr)->s6_addr16[5]), \
ntohs((addr)->s6_addr16[6]), ntohs((addr)->s6_addr16[7])
#define IN6_ARE_ADDR_MASKED_EQUAL(a, b, m) \
(((((__const uint32_t *)(a))[0] & (((__const uint32_t *)(m))[0])) == \
(((__const uint32_t *)(b))[0] & (((__const uint32_t *)(m))[0]))) && \
((((__const uint32_t *)(a))[1] & (((__const uint32_t *)(m))[1])) == \
(((__const uint32_t *)(b))[1] & (((__const uint32_t *)(m))[1]))) && \
((((__const uint32_t *)(a))[2] & (((__const uint32_t *)(m))[2])) == \
(((__const uint32_t *)(b))[2] & (((__const uint32_t *)(m))[2]))) && \
((((__const uint32_t *)(a))[3] & (((__const uint32_t *)(m))[3])) == \
(((__const uint32_t *)(b))[3] & (((__const uint32_t *)(m))[3]))))
////////////
#define IPV4_STR_ADDR_TO_INADDR(AdDr_StR,InAdDr,MeSsAgE ) do {\
if ( inet_aton(AdDr_StR, &InAdDr ) <= 0 ) {\
throw (MeSsAgE);\
}\
} while (0)
#define IPV4_STR_ADDR_TO_INADDR(AdDr_StR, InAdDr, MeSsAgE) \
do { \
if (inet_aton(AdDr_StR, &InAdDr) <= 0) { \
throw(MeSsAgE); \
} \
} while (0)
#ifndef UNUSED
#define UNUSED(x) (void)(x)
......
......@@ -26,20 +26,17 @@
*/
#include "conversions.hpp"
#include <arpa/inet.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string.h>
#include <iomanip>
#include <iostream>
#include <sstream>
static const char hex_to_ascii_table[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
......@@ -81,27 +78,21 @@ int conv::ascii_to_hex(uint8_t *dst, const char *h) {
for (;;) {
int high, low;
while (*hex && isspace(*hex))
hex++;
while (*hex && isspace(*hex)) hex++;
if (!*hex)
return 1;
if (!*hex) return 1;
high = ascii_to_hex_table[*hex++];
if (high < 0)
return 0;
if (high < 0) return 0;
while (*hex && isspace(*hex))
hex++;
while (*hex && isspace(*hex)) hex++;
if (!*hex)
return 0;
if (!*hex) return 0;
low = ascii_to_hex_table[*hex++];
if (low < 0)
return 0;
if (low < 0) return 0;
dst[i++] = (high << 4) | low;
}
......@@ -163,7 +154,8 @@ std::string conv::toString(const struct in6_addr &in6addr) {
return s;
}
//------------------------------from udm------------------------------------------------
//------------------------------from
//udm------------------------------------------------
std::string conv::uint8_to_hex_string(const uint8_t *v, const size_t s) {
std::stringstream ss;
......@@ -176,37 +168,34 @@ std::string conv::uint8_to_hex_string(const uint8_t *v, const size_t s) {
return ss.str();
}
void conv::hex_str_to_uint8(const char* string, uint8_t *des) {
void conv::hex_str_to_uint8(const char *string, uint8_t *des) {
if (string == NULL) return;
if (string == NULL)
return;
size_t slength = strlen(string);
if ((slength % 2) != 0) // must be even
return;
size_t slength = strlen(string);
if ((slength % 2) != 0) // must be even
return;
size_t dlength = slength / 2;
size_t dlength = slength / 2;
// des = (uint8_t*)malloc(dlength);
//des = (uint8_t*)malloc(dlength);
memset(des, 0, dlength);
memset(des, 0, dlength);
size_t index = 0;
while (index < slength) {
char c = string[index];
int value = 0;
if (c >= '0' && c <= '9')
value = (c - '0');
else if (c >= 'A' && c <= 'F')
value = (10 + (c - 'A'));
else if (c >= 'a' && c <= 'f')
value = (10 + (c - 'a'));
else
return;
size_t index = 0;
while (index < slength) {
char c = string[index];
int value = 0;
if (c >= '0' && c <= '9')
value = (c - '0');
else if (c >= 'A' && c <= 'F')
value = (10 + (c - 'A'));
else if (c >= 'a' && c <= 'f')
value = (10 + (c - 'a'));
else
return;
des[(index / 2)] += value << (((index + 1) % 2) * 4);
index++;
}
des[(index / 2)] += value << (((index + 1) % 2) * 4);
index++;
}
}
......@@ -30,21 +30,22 @@
#define FILE_CONVERSIONS_HPP_SEEN
#include <netinet/in.h>
#include <stdint.h>
#include <string>
/* Used to format an uint32_t containing an ipv4 address */
#define IN_ADDR_FMT "%u.%u.%u.%u"
#define PRI_IN_ADDR(aDDRESS) \
(uint8_t)((aDDRESS.s_addr) & 0x000000ff), \
(uint8_t)(((aDDRESS.s_addr) & 0x0000ff00) >> 8), \
(uint8_t)(((aDDRESS.s_addr) & 0x00ff0000) >> 16), \
#define PRI_IN_ADDR(aDDRESS) \
(uint8_t)((aDDRESS.s_addr) & 0x000000ff), \
(uint8_t)(((aDDRESS.s_addr) & 0x0000ff00) >> 8), \
(uint8_t)(((aDDRESS.s_addr) & 0x00ff0000) >> 16), \
(uint8_t)(((aDDRESS.s_addr) & 0xff000000) >> 24)
#define IPV4_ADDR_DISPLAY_8(aDDRESS) \
#define IPV4_ADDR_DISPLAY_8(aDDRESS) \
(aDDRESS)[0], (aDDRESS)[1], (aDDRESS)[2], (aDDRESS)[3]
class conv {
public:
public:
static void hexa_to_ascii(uint8_t *from, char *to, size_t length);
static int ascii_to_hex(uint8_t *dst, const char *h);
static struct in_addr fromString(const std::string addr4);
......@@ -55,7 +56,6 @@ public:
static std::string mncToString(const uint8_t digit1, const uint8_t digit2,
const uint8_t digit3);
static std::string uint8_to_hex_string(const uint8_t *v, const size_t s);
static void hex_str_to_uint8(const char* string, uint8_t *des);
static void hex_str_to_uint8(const char *string, uint8_t *des);
};
#endif /* FILE_CONVERSIONS_HPP_SEEN */
......@@ -29,15 +29,15 @@
#ifndef FILE_ENDPOINT_HPP_SEEN
#define FILE_ENDPOINT_HPP_SEEN
#include "conversions.hpp"
#include <arpa/inet.h>
#include <inttypes.h>
#include <string.h>
#include <sys/socket.h>
#include "conversions.hpp"
class endpoint {
public:
public:
struct sockaddr_storage addr_storage;
socklen_t addr_storage_len;
endpoint()
......
/*
* 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
brief
author Jian Yang,Fengjiao He,Hongxin Wang
date 2020
email: contact@openairinterface.org
*/
#include "logger.hpp"
#include "spdlog/sinks/syslog_sink.h"
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include "spdlog/sinks/syslog_sink.h"
Logger *Logger::m_singleton = NULL;
void Logger::_init(const char *app, const bool log_stdout,
......@@ -171,23 +200,23 @@ void _Logger::log(_LogType lt, const char *format, va_list &args) {
vsnprintf(buffer, sizeof(buffer), format, args);
switch (lt) {
case _ltTrace:
m_log.trace(buffer);
break;
case _ltDebug:
m_log.debug(buffer);
break;
case _ltInfo:
m_log.info(buffer);
break;
case _ltStartup:
m_log.warn(buffer);
break;
case _ltWarn:
m_log.error(buffer);
break;
case _ltError:
m_log.critical(buffer);
break;
case _ltTrace:
m_log.trace(buffer);
break;
case _ltDebug:
m_log.debug(buffer);
break;
case _ltInfo:
m_log.info(buffer);
break;
case _ltStartup:
m_log.warn(buffer);
break;
case _ltWarn:
m_log.error(buffer);
break;
case _ltError:
m_log.critical(buffer);
break;
}
}
/*
* 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
brief
author Jian Yang,Fengjiao He,Hongxin Wang
date 2020
email: contact@openairinterface.org
*/
#ifndef __LOGGER_H
#define __LOGGER_H
......@@ -5,20 +33,20 @@
#include <stdexcept>
#include <vector>
#define SPDLOG_LEVEL_NAMES \
#define SPDLOG_LEVEL_NAMES \
{"trace", "debug", "info ", "start", "warn ", "error", "off "};
#define SPDLOG_ENABLE_SYSLOG
#include "spdlog/spdlog.h"
class LoggerException : public std::runtime_error {
public:
public:
explicit LoggerException(const char *m) : std::runtime_error(m) {}
explicit LoggerException(const std::string &m) : std::runtime_error(m) {}
};
class _Logger {
public:
public:
_Logger(const char *category, std::vector<spdlog::sink_ptr> &sinks,
const char *pattern);
......@@ -35,7 +63,7 @@ public:
void error(const char *format, ...);
void error(const std::string &format, ...);
private:
private:
_Logger();
enum _LogType { _ltTrace, _ltDebug, _ltInfo, _ltStartup, _ltWarn, _ltError };
......@@ -44,7 +72,7 @@ private:
};
class Logger {
public:
public:
static void init(const char *app, const bool log_stdout,
const bool log_rot_file) {
singleton()._init(app, log_stdout, log_rot_file);
......@@ -56,8 +84,8 @@ public:
// static _Logger &async_cmd(){return *singleton().m_async_cmd;}
// static _Logger &amf_app(){return *singleton().m_amf_app;}
static _Logger &config(){return *singleton().m_config;}
static _Logger &system(){return *singleton().m_system;}
static _Logger &config() { return *singleton().m_config; }
static _Logger &system() { return *singleton().m_system; }
// static _Logger &sctp(){return *singleton().m_sctp;}
// static _Logger &nas_mm(){return *singleton().m_nas_mm;}
// static _Logger &ngap(){return *singleton().m_ngap;}
......@@ -71,11 +99,10 @@ public:
static _Logger &ausf_server() { return *singleton().m_ausf_server; }
// static _Logger &udm_ueau() { return *singleton().m_udm_ueau; }
private:
private:
static Logger *m_singleton;
static Logger &singleton() {
if (!m_singleton)
m_singleton = new Logger();
if (!m_singleton) m_singleton = new Logger();
return *m_singleton;
}
......
......@@ -14,12 +14,13 @@
* limitations under the License.
*/
#include "options.hpp"
#include <getopt.h>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include "options.hpp"
#include <iostream>
int Options::options;
......@@ -43,7 +44,6 @@ void Options::help() {
}
bool Options::parse(int argc, char **argv) {
bool ret = true;
ret = parseInputOptions(argc, argv);
......@@ -68,62 +68,63 @@ bool Options::parseInputOptions(int argc, char **argv) {
// Loop on arguments
while (1) {
c = getopt_long(argc, argv, "horc:", long_options, &option_index);
if (c == -1)
break; // Exit from the loop.
if (c == -1) break; // Exit from the loop.
switch (c) {
case 'h': {
help();
exit(0);
break;
}
case 'c': {
m_libconfigcfg = optarg;
options |= libconfigcfg;
break;
}
case 'o': {
m_log_stdout = true;
options |= log_stdout;
break;
}
case 'r': {
m_log_rot_file_log = true;
options |= log_rot_file_log;
break;
}
case '?': {
switch (optopt) {
case 'h': {
help();
exit(0);
break;
}
case 'c': {
std::cout << "Option -l (libconfig config) requires an argument"
<< std::endl;
m_libconfigcfg = optarg;
options |= libconfigcfg;
break;
}
case 'o': {
std::cout << "Option -o do not requires an argument, can be also set "
"with option -r."
<< std::endl;
m_log_stdout = true;
options |= log_stdout;
break;
}
case 'r': {
std::cout << "Option -r do not requires an argument, can be also set "
"with option -o."
<< std::endl;
m_log_rot_file_log = true;
options |= log_rot_file_log;
break;
}
default: {
std::cout << "Unrecognized option [" << c << "]" << std::endl;
case '?': {
switch (optopt) {
case 'c': {
std::cout << "Option -l (libconfig config) requires an argument"
<< std::endl;
break;
}
case 'o': {
std::cout
<< "Option -o do not requires an argument, can be also set "
"with option -r."
<< std::endl;
break;
}
case 'r': {
std::cout
<< "Option -r do not requires an argument, can be also set "
"with option -o."
<< std::endl;
break;
}
default: {
std::cout << "Unrecognized option [" << c << "]" << std::endl;
break;
}
}
result = false;
break;
}
default: {
std::cout << "Unrecognized option [" << c << "]" << std::endl;
result = false;
}
result = false;
break;
}
default: {
std::cout << "Unrecognized option [" << c << "]" << std::endl;
result = false;
}
}
}
return result;
......
......@@ -18,10 +18,11 @@
#define __OPTIONS_H
#include <stdint.h>
#include <string>
class Options {
public:
public:
static bool parse(int argc, char **argv);
static bool parseInputOptions(int argc, char **argv);
static bool parseJson();
......@@ -31,7 +32,7 @@ public:
static const bool &getlogRotFilelog() { return m_log_rot_file_log; }
static const bool &getlogStdout() { return m_log_stdout; }
private:
private:
enum OptionsSelected {
libconfigcfg = 0x01,
log_stdout = 0x02,
......@@ -47,4 +48,4 @@ private:
static std::string m_libconfigcfg;
};
#endif // #define __OPTIONS_H
#endif // #define __OPTIONS_H
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