Remove nettle library from OAI, support OpenSSL 3.0 and 1.1
Add byte_array_t structure under common/
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <openair3/NAS/COMMON/NR_NAS_defs.h>
|
||||
#include <openair3/SECU/secu_defs.h>
|
||||
#include <openair3/SECU/kdf.h>
|
||||
|
||||
void servingNetworkName(uint8_t *msg, char * imsiStr, int nmc_size) {
|
||||
//SNN-network-identifier in TS 24.501
|
||||
@@ -59,8 +60,12 @@ int resToresStar(uint8_t *msg, uicc_t* uicc) {
|
||||
uint8_t ckik[sizeof(uicc->ck) +sizeof(uicc->ik)];
|
||||
memcpy(ckik, uicc->ck, sizeof(uicc->ck));
|
||||
memcpy(ckik+sizeof(uicc->ck),uicc->ik, sizeof(uicc->ik));
|
||||
uint8_t out[32];
|
||||
kdf(S, ptr-S, ckik, 32, out, sizeof(out));
|
||||
uint8_t out[32] = {0};
|
||||
assert(ptr-S == 32);
|
||||
//kdf(S, ptr-S, ckik, 32, out, sizeof(out));
|
||||
byte_array_t data = {.buf = ckik, .len = 32};
|
||||
kdf(S, data, 32, out);
|
||||
|
||||
memcpy(msg, out+16, 16);
|
||||
return 16;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "nr_nas_msg_sim.h"
|
||||
#include "aka_functions.h"
|
||||
#include "secu_defs.h"
|
||||
#include "kdf.h"
|
||||
#include "PduSessionEstablishRequest.h"
|
||||
#include "PduSessionEstablishmentAccept.h"
|
||||
#include "intertask_interface.h"
|
||||
@@ -188,18 +189,20 @@ void transferRES(uint8_t ck[16], uint8_t ik[16], uint8_t *input, uint8_t rand[16
|
||||
oldS[33] = 0x08;
|
||||
|
||||
|
||||
uint8_t key[32];
|
||||
uint8_t key[32] = {0};
|
||||
memcpy(&key[0], ck, 16);
|
||||
memcpy(&key[16], ik, 16); //KEY
|
||||
uint8_t out[32];
|
||||
kdf(key, 32, S, 31 + netNamesize, out, 32);
|
||||
for (int i = 0; i < 16; i++)
|
||||
output[i] = out[16 + i];
|
||||
uint8_t out[32] = {0};
|
||||
|
||||
byte_array_t data = {.buf = S, .len = 31 + netNamesize};
|
||||
kdf(key, data, 32, out);
|
||||
|
||||
memcpy(output, out + 16, 16);
|
||||
}
|
||||
|
||||
void derive_kausf(uint8_t ck[16], uint8_t ik[16], uint8_t sqn[6], uint8_t kausf[32], uicc_t *uicc) {
|
||||
uint8_t S[100]={0};
|
||||
uint8_t key[32];
|
||||
uint8_t key[32] = {0};
|
||||
|
||||
memcpy(&key[0], ck, 16);
|
||||
memcpy(&key[16], ik, 16); //KEY
|
||||
@@ -213,7 +216,9 @@ void derive_kausf(uint8_t ck[16], uint8_t ik[16], uint8_t sqn[6], uint8_t kausf[
|
||||
}
|
||||
S[9 + netNamesize] = 0x00;
|
||||
S[10 + netNamesize] = 0x06;
|
||||
kdf(key, 32, S, 11 + netNamesize, kausf, 32);
|
||||
|
||||
byte_array_t data = {.buf = S, .len = 11 + netNamesize};
|
||||
kdf(key, data, 32, kausf);
|
||||
}
|
||||
|
||||
void derive_kseaf(uint8_t kausf[32], uint8_t kseaf[32], uicc_t *uicc) {
|
||||
@@ -223,12 +228,14 @@ void derive_kseaf(uint8_t kausf[32], uint8_t kseaf[32], uicc_t *uicc) {
|
||||
int netNamesize = strlen((char*)S+1);
|
||||
S[1 + netNamesize] = (uint8_t)((netNamesize & 0xff00) >> 8);
|
||||
S[2 + netNamesize] = (uint8_t)(netNamesize & 0x00ff);
|
||||
kdf(kausf, 32, S, 3 + netNamesize, kseaf, 32);
|
||||
|
||||
byte_array_t data = {.buf = S , .len = 3 + netNamesize};
|
||||
kdf(kausf, data, 32, kseaf);
|
||||
}
|
||||
|
||||
void derive_kamf(uint8_t *kseaf, uint8_t *kamf, uint16_t abba, uicc_t* uicc) {
|
||||
int imsiLen = strlen(uicc->imsiStr);
|
||||
uint8_t S[100];
|
||||
uint8_t S[100] = {0};
|
||||
S[0] = 0x6D; //FC = 0x6D
|
||||
memcpy(&S[1], uicc->imsiStr, imsiLen );
|
||||
S[1 + imsiLen] = (uint8_t)((imsiLen & 0xff00) >> 8);
|
||||
@@ -237,12 +244,14 @@ void derive_kamf(uint8_t *kseaf, uint8_t *kamf, uint16_t abba, uicc_t* uicc) {
|
||||
S[4 + imsiLen] = (abba & 0xff00) >> 8;
|
||||
S[5 + imsiLen] = 0x00;
|
||||
S[6 + imsiLen] = 0x02;
|
||||
kdf(kseaf, 32, S, 7 + imsiLen, kamf, 32);
|
||||
|
||||
byte_array_t data = {.buf = S, .len = 7 + imsiLen};
|
||||
kdf(kseaf, data, 32, kamf);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void derive_knas(algorithm_type_dist_t nas_alg_type, uint8_t nas_alg_id, uint8_t kamf[32], uint8_t *knas_int) {
|
||||
uint8_t S[20];
|
||||
uint8_t S[20] = {0};
|
||||
uint8_t out[32] = { 0 };
|
||||
S[0] = 0x69; //FC
|
||||
S[1] = (uint8_t)(nas_alg_type & 0xFF);
|
||||
@@ -251,19 +260,20 @@ void derive_knas(algorithm_type_dist_t nas_alg_type, uint8_t nas_alg_id, uint8_t
|
||||
S[4] = nas_alg_id;
|
||||
S[5] = 0x00;
|
||||
S[6] = 0x01;
|
||||
kdf(kamf, 32, S, 7, out, 32);
|
||||
for (int i = 0; i < 16; i++)
|
||||
knas_int[i] = out[16 + i];
|
||||
|
||||
byte_array_t data = {.buf = S, .len = 7};
|
||||
kdf(kamf, data, 32, out);
|
||||
|
||||
memcpy(knas_int, out+16, 16);
|
||||
}
|
||||
|
||||
void derive_kgnb(uint8_t kamf[32], uint32_t count, uint8_t *kgnb){
|
||||
/* Compute the KDF input parameter
|
||||
* S = FC(0x6E) || UL NAS Count || 0x00 0x04 || 0x01 || 0x00 0x01
|
||||
*/
|
||||
uint8_t input[32];
|
||||
uint8_t input[32] = {0};
|
||||
// uint16_t length = 4;
|
||||
// int offset = 0;
|
||||
uint8_t out[32] = { 0 };
|
||||
|
||||
LOG_TRACE(INFO, "%s with count= %d", __FUNCTION__, count);
|
||||
memset(input, 0, 32);
|
||||
@@ -282,9 +292,9 @@ void derive_kgnb(uint8_t kamf[32], uint32_t count, uint8_t *kgnb){
|
||||
input[8] = 0;
|
||||
input[9] = 1;
|
||||
|
||||
kdf(kamf, 32, input, 10, out, 32);
|
||||
for (int i = 0; i < 32; i++)
|
||||
kgnb[i] = out[i];
|
||||
byte_array_t data = {.buf = input, .len = 10};
|
||||
kdf(kamf, data, 32, kgnb);
|
||||
|
||||
printf("kgnb : ");
|
||||
for(int pp=0;pp<32;pp++)
|
||||
printf("%02x ",kgnb[pp]);
|
||||
|
||||
@@ -67,6 +67,7 @@ Description Defines the authentication EMM procedure executed by the
|
||||
|
||||
#include "usim_api.h"
|
||||
#include "secu_defs.h"
|
||||
#include "kdf.h"
|
||||
#include "Authentication.h"
|
||||
#include "executables/lte-softmodem.h"
|
||||
|
||||
@@ -982,14 +983,10 @@ static int _authentication_kasme(const OctetString *autn,
|
||||
input_s[4],input_s[5],input_s[6],input_s[7],
|
||||
input_s[8],input_s[9],input_s[10],input_s[11],
|
||||
input_s[12],input_s[13]);
|
||||
/* TODO !!! Compute the Kasme key */
|
||||
// todo_hmac_256(key, input_s, kasme->value);
|
||||
kdf(key,
|
||||
ck->length + ik->length , /*key_length*/
|
||||
input_s,
|
||||
offset,
|
||||
kasme->value,
|
||||
kasme->length);
|
||||
|
||||
assert(ck->length + ik->length == 32);
|
||||
byte_array_t data = {.len = offset, .buf = input_s};
|
||||
kdf(key, data, kasme->length, kasme->value);
|
||||
|
||||
LOG_TRACE(INFO,"EMM-PROC KASME (l=%d)%s",
|
||||
kasme->length,
|
||||
|
||||
@@ -63,6 +63,7 @@ Description Defines the security mode control EMM procedure executed by the
|
||||
|
||||
# include "assertions.h"
|
||||
#include "secu_defs.h"
|
||||
#include "kdf.h"
|
||||
#include "SecurityModeControl.h"
|
||||
|
||||
#if defined(NAS_BUILT_IN_UE)
|
||||
@@ -484,7 +485,9 @@ static int _security_kenb(const OctetString *kasme, OctetString *kenb,
|
||||
input[5] = 0;
|
||||
input[6] = 4;
|
||||
|
||||
kdf(kasme->value, 32, input, 7, kenb->value, 32);
|
||||
byte_array_t data = {.len = 7, .buf = input};
|
||||
kdf(kasme->value, data, 32, kenb->value);
|
||||
|
||||
kenb->length = 32;
|
||||
return (RETURNok);
|
||||
}
|
||||
@@ -536,8 +539,12 @@ static int _security_kdf(const OctetString *kasme, OctetString *key,
|
||||
input[5] = 0x00;
|
||||
input[6] = 0x01;
|
||||
|
||||
assert(kasme->length == 32);
|
||||
byte_array_t data = {.len = 7, .buf=input};
|
||||
/* Compute the derived key */
|
||||
kdf(kasme->value, kasme->length, input, 7, output, 32);
|
||||
kdf(kasme->value, data, 32, output);
|
||||
|
||||
|
||||
memcpy(key->value, &output[31 - key->length + 1], key->length);
|
||||
return (RETURNok);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user