Clang-formated liblte_*

master
Pedro Alvarez 5 years ago committed by Andre Puschmann
parent b46a71c2d8
commit 9597cc4c14

@ -40,8 +40,8 @@
INCLUDES INCLUDES
*******************************************************************************/ *******************************************************************************/
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -53,38 +53,40 @@
#define LIBLTE_ASN1_OID_MAXSUBIDS 128 #define LIBLTE_ASN1_OID_MAXSUBIDS 128
// Caution these values must match SRSLTE_ ones in common.h // Caution these values must match SRSLTE_ ones in common.h
#define LIBLTE_MAX_MSG_SIZE_BITS 102048 #define LIBLTE_MAX_MSG_SIZE_BITS 102048
#define LIBLTE_MAX_MSG_SIZE_BYTES 12756 #define LIBLTE_MAX_MSG_SIZE_BYTES 12756
#define LIBLTE_MSG_HEADER_OFFSET 1020 #define LIBLTE_MSG_HEADER_OFFSET 1020
//Macro to make it easier to convert defines into strings // Macro to make it easier to convert defines into strings
#define LIBLTE_CASE_STR(code) case code: return #code #define LIBLTE_CASE_STR(code) \
case code: \
return #code
/******************************************************************************* /*******************************************************************************
TYPEDEFS TYPEDEFS
*******************************************************************************/ *******************************************************************************/
typedef int8_t int8; typedef int8_t int8;
typedef uint8_t uint8; typedef uint8_t uint8;
typedef int16_t int16; typedef int16_t int16;
typedef uint16_t uint16; typedef uint16_t uint16;
typedef int32_t int32; typedef int32_t int32;
typedef uint32_t uint32; typedef uint32_t uint32;
typedef int64_t int64; typedef int64_t int64;
typedef uint64_t uint64; typedef uint64_t uint64;
typedef enum{ typedef enum {
LIBLTE_SUCCESS = 0, LIBLTE_SUCCESS = 0,
LIBLTE_ERROR_INVALID_INPUTS, LIBLTE_ERROR_INVALID_INPUTS,
LIBLTE_ERROR_ENCODE_FAIL, LIBLTE_ERROR_ENCODE_FAIL,
LIBLTE_ERROR_DECODE_FAIL, LIBLTE_ERROR_DECODE_FAIL,
LIBLTE_ERROR_INVALID_CRC, LIBLTE_ERROR_INVALID_CRC,
LIBLTE_ERROR_N_ITEMS LIBLTE_ERROR_N_ITEMS
}LIBLTE_ERROR_ENUM; } LIBLTE_ERROR_ENUM;
static const char liblte_error_text[LIBLTE_ERROR_N_ITEMS][64] = { static const char liblte_error_text[LIBLTE_ERROR_N_ITEMS][64] = {
"Invalid inputs", "Invalid inputs",
"Encode failure", "Encode failure",
"Decode failure", "Decode failure",
}; };
#define LIBLTE_STRING_LEN 128 #define LIBLTE_STRING_LEN 128
@ -92,27 +94,26 @@ static const char liblte_error_text[LIBLTE_ERROR_N_ITEMS][64] = {
typedef void* LIBLTE_ASN1_OPEN_TYPE_STRUCT; typedef void* LIBLTE_ASN1_OPEN_TYPE_STRUCT;
typedef struct { typedef struct {
uint32_t numids; // number of subidentifiers uint32_t numids; // number of subidentifiers
uint32_t subid[LIBLTE_ASN1_OID_MAXSUBIDS]; // subidentifier values uint32_t subid[LIBLTE_ASN1_OID_MAXSUBIDS]; // subidentifier values
} LIBLTE_ASN1_OID_STRUCT; } LIBLTE_ASN1_OID_STRUCT;
typedef struct{ typedef struct {
bool data_valid; bool data_valid;
bool data; bool data;
}LIBLTE_BOOL_MSG_STRUCT; } LIBLTE_BOOL_MSG_STRUCT;
typedef struct{
uint32 N_bits;
uint8 header[LIBLTE_MSG_HEADER_OFFSET];
uint8 msg[LIBLTE_MAX_MSG_SIZE_BITS];
}LIBLTE_BIT_MSG_STRUCT __attribute__ ((aligned (8)));
typedef struct{ typedef struct {
uint32 N_bytes; uint32 N_bits;
uint8 header[LIBLTE_MSG_HEADER_OFFSET]; uint8 header[LIBLTE_MSG_HEADER_OFFSET];
uint8 msg[LIBLTE_MAX_MSG_SIZE_BYTES]; uint8 msg[LIBLTE_MAX_MSG_SIZE_BITS];
}LIBLTE_BYTE_MSG_STRUCT; } LIBLTE_BIT_MSG_STRUCT __attribute__((aligned(8)));
typedef struct {
uint32 N_bytes;
uint8 header[LIBLTE_MSG_HEADER_OFFSET];
uint8 msg[LIBLTE_MAX_MSG_SIZE_BYTES];
} LIBLTE_BYTE_MSG_STRUCT;
/******************************************************************************* /*******************************************************************************
DECLARATIONS DECLARATIONS
@ -123,54 +124,49 @@ typedef struct{
Description: Converts a value to a bit string Description: Converts a value to a bit string
*********************************************************************/ *********************************************************************/
void liblte_value_2_bits(uint32 value, void liblte_value_2_bits(uint32 value, uint8** bits, uint32 N_bits);
uint8 **bits,
uint32 N_bits);
/********************************************************************* /*********************************************************************
Name: liblte_bits_2_value Name: liblte_bits_2_value
Description: Converts a bit string to a value Description: Converts a bit string to a value
*********************************************************************/ *********************************************************************/
uint32 liblte_bits_2_value(uint8 **bits, uint32 liblte_bits_2_value(uint8** bits, uint32 N_bits);
uint32 N_bits);
/********************************************************************* /*********************************************************************
Name: liblte_pack Name: liblte_pack
Description: Pack a bit array into a byte array Description: Pack a bit array into a byte array
*********************************************************************/ *********************************************************************/
void liblte_pack(LIBLTE_BIT_MSG_STRUCT *bits, void liblte_pack(LIBLTE_BIT_MSG_STRUCT* bits, LIBLTE_BYTE_MSG_STRUCT* bytes);
LIBLTE_BYTE_MSG_STRUCT *bytes);
/********************************************************************* /*********************************************************************
Name: liblte_unpack Name: liblte_unpack
Description: Unpack a byte array into a bit array Description: Unpack a byte array into a bit array
*********************************************************************/ *********************************************************************/
void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT *bytes, void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT* bytes, LIBLTE_BIT_MSG_STRUCT* bits);
LIBLTE_BIT_MSG_STRUCT *bits);
/********************************************************************* /*********************************************************************
Name: liblte_pack Name: liblte_pack
Description: Pack a bit array into a byte array Description: Pack a bit array into a byte array
*********************************************************************/ *********************************************************************/
void liblte_pack(uint8_t *bits, uint32_t n_bits, uint8_t *bytes); void liblte_pack(uint8_t* bits, uint32_t n_bits, uint8_t* bytes);
/********************************************************************* /*********************************************************************
Name: liblte_unpack Name: liblte_unpack
Description: Unpack a byte array into a bit array Description: Unpack a byte array into a bit array
*********************************************************************/ *********************************************************************/
void liblte_unpack(uint8_t *bytes, uint32_t n_bytes, uint8_t *bits); void liblte_unpack(uint8_t* bytes, uint32_t n_bytes, uint8_t* bits);
/********************************************************************* /*********************************************************************
Name: liblte_align_up Name: liblte_align_up
Description: Aligns a pointer to a multibyte boundary Description: Aligns a pointer to a multibyte boundary
*********************************************************************/ *********************************************************************/
void liblte_align_up(uint8_t **ptr, uint32_t align); void liblte_align_up(uint8_t** ptr, uint32_t align);
/********************************************************************* /*********************************************************************
Name: liblte_align_up_zero Name: liblte_align_up_zero
@ -178,6 +174,6 @@ void liblte_align_up(uint8_t **ptr, uint32_t align);
Description: Aligns a pointer to a multibyte boundary and zeros Description: Aligns a pointer to a multibyte boundary and zeros
bytes skipped bytes skipped
*********************************************************************/ *********************************************************************/
void liblte_align_up_zero(uint8_t **ptr, uint32_t align); void liblte_align_up_zero(uint8_t** ptr, uint32_t align);
#endif // SRSLTE_LIBLTE_COMMON_H #endif // SRSLTE_LIBLTE_COMMON_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -42,12 +42,10 @@
DEFINES DEFINES
*******************************************************************************/ *******************************************************************************/
/******************************************************************************* /*******************************************************************************
TYPEDEFS TYPEDEFS
*******************************************************************************/ *******************************************************************************/
/******************************************************************************* /*******************************************************************************
DECLARATIONS DECLARATIONS
*******************************************************************************/ *******************************************************************************/
@ -59,9 +57,7 @@
Document Reference: 35.206 v10.0.0 Annex 3 Document Reference: 35.206 v10.0.0 Annex 3
*********************************************************************/ *********************************************************************/
LIBLTE_ERROR_ENUM liblte_compute_opc(uint8 *k, LIBLTE_ERROR_ENUM liblte_compute_opc(uint8* k, uint8* op, uint8* op_c);
uint8 *op,
uint8 *op_c);
/********************************************************************* /*********************************************************************
Name: liblte_security_generate_k_asme Name: liblte_security_generate_k_asme
@ -74,13 +70,8 @@ LIBLTE_ERROR_ENUM liblte_compute_opc(uint8 *k,
// Enums // Enums
// Structs // Structs
// Functions // Functions
LIBLTE_ERROR_ENUM liblte_security_generate_k_asme(uint8 *ck, LIBLTE_ERROR_ENUM
uint8 *ik, liblte_security_generate_k_asme(uint8* ck, uint8* ik, uint8* ak, uint8* sqn, uint16 mcc, uint16 mnc, uint8* k_asme);
uint8 *ak,
uint8 *sqn,
uint16 mcc,
uint16 mnc,
uint8 *k_asme);
/********************************************************************* /*********************************************************************
Name: liblte_security_generate_k_enb Name: liblte_security_generate_k_enb
@ -93,18 +84,11 @@ LIBLTE_ERROR_ENUM liblte_security_generate_k_asme(uint8 *ck,
// Enums // Enums
// Structs // Structs
// Functions // Functions
LIBLTE_ERROR_ENUM liblte_security_generate_k_enb(uint8 *k_asme, LIBLTE_ERROR_ENUM liblte_security_generate_k_enb(uint8* k_asme, uint32 nas_count, uint8* k_enb);
uint32 nas_count,
uint8 *k_enb);
LIBLTE_ERROR_ENUM liblte_security_generate_k_enb_star(uint8 *k_enb, LIBLTE_ERROR_ENUM liblte_security_generate_k_enb_star(uint8* k_enb, uint32 pci, uint32_t earfcn, uint8* k_enb_star);
uint32 pci,
uint32_t earfcn,
uint8 *k_enb_star);
LIBLTE_ERROR_ENUM liblte_security_generate_nh( uint8_t *k_asme, LIBLTE_ERROR_ENUM liblte_security_generate_nh(uint8_t* k_asme, uint8_t* sync, uint8_t* nh);
uint8_t *sync,
uint8_t *nh);
/********************************************************************* /*********************************************************************
Name: liblte_security_generate_k_nas Name: liblte_security_generate_k_nas
@ -115,33 +99,29 @@ LIBLTE_ERROR_ENUM liblte_security_generate_nh( uint8_t *k_asme,
*********************************************************************/ *********************************************************************/
// Defines // Defines
// Enums // Enums
typedef enum{ typedef enum {
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_EEA0 = 0, LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_EEA0 = 0,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_128_EEA1, LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_128_EEA1,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_128_EEA2, LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_128_EEA2,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_N_ITEMS, LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_N_ITEMS,
}LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM; } LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM;
static const char liblte_security_ciphering_algorithm_id_text[LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_N_ITEMS][20] = {"EEA0", static const char liblte_security_ciphering_algorithm_id_text[LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_N_ITEMS][20] = {
"128-EEA1", "EEA0", "128-EEA1", "128-EEA2"};
"128-EEA2"}; typedef enum {
typedef enum{ LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_EIA0 = 0,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_EIA0 = 0, LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_128_EIA1,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_128_EIA1, LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_128_EIA2,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_128_EIA2, LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_N_ITEMS,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_N_ITEMS, } LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM;
}LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM; static const char liblte_security_integrity_algorithm_id_text[LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_N_ITEMS][20] = {
static const char liblte_security_integrity_algorithm_id_text[LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_N_ITEMS][20] = {"EIA0", "EIA0", "128-EIA1", "128-EIA2"};
"128-EIA1",
"128-EIA2"};
// Structs // Structs
// Functions // Functions
LIBLTE_ERROR_ENUM liblte_security_generate_k_nas(uint8 *k_asme, LIBLTE_ERROR_ENUM liblte_security_generate_k_nas(uint8* k_asme,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
uint8 *k_nas_enc, uint8* k_nas_enc,
uint8 *k_nas_int); uint8* k_nas_int);
/********************************************************************* /*********************************************************************
Name: liblte_security_generate_k_rrc Name: liblte_security_generate_k_rrc
@ -154,11 +134,11 @@ LIBLTE_ERROR_ENUM liblte_security_generate_k_nas(uint8
// Enums // Enums
// Structs // Structs
// Functions // Functions
LIBLTE_ERROR_ENUM liblte_security_generate_k_rrc(uint8 *k_enb, LIBLTE_ERROR_ENUM liblte_security_generate_k_rrc(uint8* k_enb,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
uint8 *k_rrc_enc, uint8* k_rrc_enc,
uint8 *k_rrc_int); uint8* k_rrc_int);
/********************************************************************* /*********************************************************************
Name: liblte_security_generate_k_up Name: liblte_security_generate_k_up
@ -172,11 +152,11 @@ LIBLTE_ERROR_ENUM liblte_security_generate_k_rrc(uint8
// Enums // Enums
// Structs // Structs
// Functions // Functions
LIBLTE_ERROR_ENUM liblte_security_generate_k_up(uint8 *k_enb, LIBLTE_ERROR_ENUM liblte_security_generate_k_up(uint8* k_enb,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
uint8 *k_up_enc, uint8* k_up_enc,
uint8 *k_up_int); uint8* k_up_int);
/********************************************************************* /*********************************************************************
Name: liblte_security_128_eia2 Name: liblte_security_128_eia2
@ -188,24 +168,15 @@ LIBLTE_ERROR_ENUM liblte_security_generate_k_up(uint8
RFC4493 RFC4493
*********************************************************************/ *********************************************************************/
// Defines // Defines
#define LIBLTE_SECURITY_DIRECTION_UPLINK 0 #define LIBLTE_SECURITY_DIRECTION_UPLINK 0
#define LIBLTE_SECURITY_DIRECTION_DOWNLINK 1 #define LIBLTE_SECURITY_DIRECTION_DOWNLINK 1
// Enums // Enums
// Structs // Structs
// Functions // Functions
LIBLTE_ERROR_ENUM liblte_security_128_eia2(uint8 *key, LIBLTE_ERROR_ENUM liblte_security_128_eia2(
uint32 count, uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* mac);
uint8 bearer, LIBLTE_ERROR_ENUM liblte_security_128_eia2(
uint8 direction, uint8* key, uint32 count, uint8 bearer, uint8 direction, LIBLTE_BIT_MSG_STRUCT* msg, uint8* mac);
uint8 *msg,
uint32 msg_len,
uint8 *mac);
LIBLTE_ERROR_ENUM liblte_security_128_eia2(uint8 *key,
uint32 count,
uint8 bearer,
uint8 direction,
LIBLTE_BIT_MSG_STRUCT *msg,
uint8 *mac);
/********************************************************************* /*********************************************************************
Name: liblte_security_encryption_eea1 Name: liblte_security_encryption_eea1
@ -217,13 +188,8 @@ LIBLTE_ERROR_ENUM liblte_security_128_eia2(uint8 *key,
Specification of the 3GPP Confidentiality and Specification of the 3GPP Confidentiality and
Integrity Algorithms UEA2 & UIA2 D1 v2.1 Integrity Algorithms UEA2 & UIA2 D1 v2.1
*********************************************************************/ *********************************************************************/
LIBLTE_ERROR_ENUM liblte_security_encryption_eea1(uint8 *key, LIBLTE_ERROR_ENUM liblte_security_encryption_eea1(
uint32 count, uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out);
uint8 bearer,
uint8 direction,
uint8 *msg,
uint32 msg_len,
uint8 *out);
/********************************************************************* /*********************************************************************
Name: liblte_security_decryption_eea1 Name: liblte_security_decryption_eea1
@ -235,13 +201,8 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea1(uint8 *key,
Specification of the 3GPP Confidentiality and Specification of the 3GPP Confidentiality and
Integrity Algorithms UEA2 & UIA2 D1 v2.1 Integrity Algorithms UEA2 & UIA2 D1 v2.1
*********************************************************************/ *********************************************************************/
LIBLTE_ERROR_ENUM liblte_security_decryption_eea1(uint8 *key, LIBLTE_ERROR_ENUM liblte_security_decryption_eea1(
uint32 count, uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* ct, uint32 ct_len, uint8* out);
uint8 bearer,
uint8 direction,
uint8 *ct,
uint32 ct_len,
uint8 *out);
/********************************************************************* /*********************************************************************
Name: liblte_security_encryption_eea2 Name: liblte_security_encryption_eea2
@ -250,13 +211,8 @@ LIBLTE_ERROR_ENUM liblte_security_decryption_eea1(uint8 *key,
Document Reference: 33.401 v13.1.0 Annex B.1.3 Document Reference: 33.401 v13.1.0 Annex B.1.3
*********************************************************************/ *********************************************************************/
LIBLTE_ERROR_ENUM liblte_security_encryption_eea2(uint8 *key, LIBLTE_ERROR_ENUM liblte_security_encryption_eea2(
uint32 count, uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out);
uint8 bearer,
uint8 direction,
uint8 *msg,
uint32 msg_len,
uint8 *out);
/********************************************************************* /*********************************************************************
Name: liblte_security_decryption_eea2 Name: liblte_security_decryption_eea2
@ -265,14 +221,8 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea2(uint8 *key,
Document Reference: 33.401 v13.1.0 Annex B.1.3 Document Reference: 33.401 v13.1.0 Annex B.1.3
*********************************************************************/ *********************************************************************/
LIBLTE_ERROR_ENUM liblte_security_decryption_eea2(uint8 *key, LIBLTE_ERROR_ENUM liblte_security_decryption_eea2(
uint32 count, uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* ct, uint32 ct_len, uint8* out);
uint8 bearer,
uint8 direction,
uint8 *ct,
uint32 ct_len,
uint8 *out);
/********************************************************************* /*********************************************************************
Name: liblte_security_milenage_f1 Name: liblte_security_milenage_f1
@ -288,12 +238,7 @@ LIBLTE_ERROR_ENUM liblte_security_decryption_eea2(uint8 *key,
// Enums // Enums
// Structs // Structs
// Functions // Functions
LIBLTE_ERROR_ENUM liblte_security_milenage_f1(uint8 *k, LIBLTE_ERROR_ENUM liblte_security_milenage_f1(uint8* k, uint8* op, uint8* rand, uint8* sqn, uint8* amf, uint8* mac_a);
uint8 *op,
uint8 *rand,
uint8 *sqn,
uint8 *amf,
uint8 *mac_a);
/********************************************************************* /*********************************************************************
Name: liblte_security_milenage_f1_star Name: liblte_security_milenage_f1_star
@ -309,12 +254,8 @@ LIBLTE_ERROR_ENUM liblte_security_milenage_f1(uint8 *k,
// Enums // Enums
// Structs // Structs
// Functions // Functions
LIBLTE_ERROR_ENUM liblte_security_milenage_f1_star(uint8 *k, LIBLTE_ERROR_ENUM
uint8 *op, liblte_security_milenage_f1_star(uint8* k, uint8* op, uint8* rand, uint8* sqn, uint8* amf, uint8* mac_s);
uint8 *rand,
uint8 *sqn,
uint8 *amf,
uint8 *mac_s);
/********************************************************************* /*********************************************************************
Name: liblte_security_milenage_f2345 Name: liblte_security_milenage_f2345
@ -330,13 +271,8 @@ LIBLTE_ERROR_ENUM liblte_security_milenage_f1_star(uint8 *k,
// Enums // Enums
// Structs // Structs
// Functions // Functions
LIBLTE_ERROR_ENUM liblte_security_milenage_f2345(uint8 *k, LIBLTE_ERROR_ENUM
uint8 *op, liblte_security_milenage_f2345(uint8* k, uint8* op, uint8* rand, uint8* res, uint8* ck, uint8* ik, uint8* ak);
uint8 *rand,
uint8 *res,
uint8 *ck,
uint8 *ik,
uint8 *ak);
/********************************************************************* /*********************************************************************
Name: liblte_security_milenage_f5_star Name: liblte_security_milenage_f5_star
@ -351,9 +287,6 @@ LIBLTE_ERROR_ENUM liblte_security_milenage_f2345(uint8 *k,
// Enums // Enums
// Structs // Structs
// Functions // Functions
LIBLTE_ERROR_ENUM liblte_security_milenage_f5_star(uint8 *k, LIBLTE_ERROR_ENUM liblte_security_milenage_f5_star(uint8* k, uint8* op, uint8* rand, uint8* ak);
uint8 *op,
uint8 *rand,
uint8 *ak);
#endif // SRSLTE_LIBLTE_SECURITY_H #endif // SRSLTE_LIBLTE_SECURITY_H

@ -24,12 +24,15 @@
#ifdef HAVE_POLARSSL #ifdef HAVE_POLARSSL
#include "polarssl/sha256.h"
#include "polarssl/aes.h" #include "polarssl/aes.h"
#include "polarssl/sha256.h"
void sha256(const unsigned char *key, size_t keylen, void sha256(const unsigned char* key,
const unsigned char *input, size_t ilen, size_t keylen,
unsigned char output[32], int is224 ) const unsigned char* input,
size_t ilen,
unsigned char output[32],
int is224)
{ {
sha256_hmac(key, keylen, input, ilen, output, is224); sha256_hmac(key, keylen, input, ilen, output, is224);
} }
@ -38,47 +41,43 @@ void sha256(const unsigned char *key, size_t keylen,
#ifdef HAVE_MBEDTLS #ifdef HAVE_MBEDTLS
#include "mbedtls/md.h"
#include "mbedtls/aes.h" #include "mbedtls/aes.h"
#include "mbedtls/md.h"
typedef mbedtls_aes_context aes_context; typedef mbedtls_aes_context aes_context;
#define AES_ENCRYPT 1 #define AES_ENCRYPT 1
#define AES_DECRYPT 0 #define AES_DECRYPT 0
int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int keysize ) int aes_setkey_enc(aes_context* ctx, const unsigned char* key, unsigned int keysize)
{ {
return mbedtls_aes_setkey_enc(ctx, key, keysize); return mbedtls_aes_setkey_enc(ctx, key, keysize);
} }
int aes_crypt_ecb( aes_context *ctx, int aes_crypt_ecb(aes_context* ctx, int mode, const unsigned char input[16], unsigned char output[16])
int mode,
const unsigned char input[16],
unsigned char output[16] )
{ {
return mbedtls_aes_crypt_ecb(ctx, mode, input, output); return mbedtls_aes_crypt_ecb(ctx, mode, input, output);
} }
int aes_crypt_ctr(aes_context *ctx, int aes_crypt_ctr(aes_context* ctx,
size_t length, size_t length,
size_t *nc_off, size_t* nc_off,
unsigned char nonce_counter[16], unsigned char nonce_counter[16],
unsigned char stream_block[16], unsigned char stream_block[16],
const unsigned char *input, const unsigned char* input,
unsigned char *output ) unsigned char* output)
{ {
return mbedtls_aes_crypt_ctr(ctx, length, nc_off, nonce_counter, return mbedtls_aes_crypt_ctr(ctx, length, nc_off, nonce_counter, stream_block, input, output);
stream_block, input, output);
} }
void sha256(const unsigned char *key, size_t keylen, void sha256(const unsigned char* key,
const unsigned char *input, size_t ilen, size_t keylen,
unsigned char output[32], int is224 ) const unsigned char* input,
size_t ilen,
unsigned char output[32],
int is224)
{ {
mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), key, keylen, input, ilen, output);
key, keylen,
input, ilen,
output );
} }
#endif // HAVE_MBEDTLS #endif // HAVE_MBEDTLS

@ -39,17 +39,14 @@
DEFINES DEFINES
*******************************************************************************/ *******************************************************************************/
/******************************************************************************* /*******************************************************************************
TYPEDEFS TYPEDEFS
*******************************************************************************/ *******************************************************************************/
/******************************************************************************* /*******************************************************************************
GLOBAL VARIABLES GLOBAL VARIABLES
*******************************************************************************/ *******************************************************************************/
/******************************************************************************* /*******************************************************************************
FUNCTIONS FUNCTIONS
*******************************************************************************/ *******************************************************************************/
@ -59,17 +56,14 @@
Description: Converts a value to a bit string Description: Converts a value to a bit string
*********************************************************************/ *********************************************************************/
void liblte_value_2_bits(uint32 value, void liblte_value_2_bits(uint32 value, uint8** bits, uint32 N_bits)
uint8 **bits,
uint32 N_bits)
{ {
uint32 i; uint32 i;
for(i=0; i<N_bits; i++) for (i = 0; i < N_bits; i++) {
{ (*bits)[i] = (value >> (N_bits - i - 1)) & 0x1;
(*bits)[i] = (value >> (N_bits-i-1)) & 0x1; }
} *bits += N_bits;
*bits += N_bits;
} }
/********************************************************************* /*********************************************************************
@ -77,19 +71,17 @@ void liblte_value_2_bits(uint32 value,
Description: Converts a bit string to a value Description: Converts a bit string to a value
*********************************************************************/ *********************************************************************/
uint32 liblte_bits_2_value(uint8 **bits, uint32 liblte_bits_2_value(uint8** bits, uint32 N_bits)
uint32 N_bits)
{ {
uint32 value = 0; uint32 value = 0;
uint32 i; uint32 i;
for(i=0; i<N_bits; i++) for (i = 0; i < N_bits; i++) {
{ value |= (*bits)[i] << (N_bits - i - 1);
value |= (*bits)[i] << (N_bits-i-1); }
} *bits += N_bits;
*bits += N_bits;
return(value); return (value);
} }
/********************************************************************* /*********************************************************************
@ -97,22 +89,19 @@ uint32 liblte_bits_2_value(uint8 **bits,
Description: Pack a bit array into a byte array Description: Pack a bit array into a byte array
*********************************************************************/ *********************************************************************/
void liblte_pack(LIBLTE_BIT_MSG_STRUCT *bits, void liblte_pack(LIBLTE_BIT_MSG_STRUCT* bits, LIBLTE_BYTE_MSG_STRUCT* bytes)
LIBLTE_BYTE_MSG_STRUCT *bytes)
{ {
uint8_t* bit_ptr = bits->msg; uint8_t* bit_ptr = bits->msg;
uint32_t i; uint32_t i;
for(i=0; i<bits->N_bits/8; i++) for (i = 0; i < bits->N_bits / 8; i++) {
{ bytes->msg[i] = liblte_bits_2_value(&bit_ptr, 8);
bytes->msg[i] = liblte_bits_2_value(&bit_ptr, 8); }
} bytes->N_bytes = bits->N_bits / 8;
bytes->N_bytes = bits->N_bits/8; if (bits->N_bits % 8 > 0) {
if(bits->N_bits%8 > 0) bytes->msg[bytes->N_bytes] = liblte_bits_2_value(&bit_ptr, bits->N_bits % 8);
{ bytes->N_bytes++;
bytes->msg[bytes->N_bytes] = liblte_bits_2_value(&bit_ptr, bits->N_bits%8); }
bytes->N_bytes++;
}
} }
/********************************************************************* /*********************************************************************
@ -120,17 +109,15 @@ void liblte_pack(LIBLTE_BIT_MSG_STRUCT *bits,
Description: Unpack a byte array into a bit array Description: Unpack a byte array into a bit array
*********************************************************************/ *********************************************************************/
void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT *bytes, void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT* bytes, LIBLTE_BIT_MSG_STRUCT* bits)
LIBLTE_BIT_MSG_STRUCT *bits)
{ {
uint8_t *bit_ptr = bits->msg; uint8_t* bit_ptr = bits->msg;
uint32_t i; uint32_t i;
for(i=0; i<bytes->N_bytes; i++) for (i = 0; i < bytes->N_bytes; i++) {
{ liblte_value_2_bits(bytes->msg[i], &bit_ptr, 8);
liblte_value_2_bits(bytes->msg[i], &bit_ptr, 8); }
} bits->N_bits = bytes->N_bytes * 8;
bits->N_bits = bytes->N_bytes*8;
} }
/********************************************************************* /*********************************************************************
@ -138,19 +125,17 @@ void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT *bytes,
Description: Pack a bit array into a byte array Description: Pack a bit array into a byte array
*********************************************************************/ *********************************************************************/
void liblte_pack(uint8_t *bits, uint32_t n_bits, uint8_t *bytes) void liblte_pack(uint8_t* bits, uint32_t n_bits, uint8_t* bytes)
{ {
uint8_t* bit_ptr = bits; uint8_t* bit_ptr = bits;
uint32_t i; uint32_t i;
for(i=0; i<n_bits/8; i++) for (i = 0; i < n_bits / 8; i++) {
{ bytes[i] = liblte_bits_2_value(&bit_ptr, 8);
bytes[i] = liblte_bits_2_value(&bit_ptr, 8); }
} if (n_bits % 8 > 0) {
if(n_bits%8 > 0) bytes[n_bits / 8] = liblte_bits_2_value(&bit_ptr, n_bits % 8);
{ }
bytes[n_bits/8] = liblte_bits_2_value(&bit_ptr, n_bits%8);
}
} }
/********************************************************************* /*********************************************************************
@ -158,15 +143,14 @@ void liblte_pack(uint8_t *bits, uint32_t n_bits, uint8_t *bytes)
Description: Unpack a byte array into a bit array Description: Unpack a byte array into a bit array
*********************************************************************/ *********************************************************************/
void liblte_unpack(uint8_t *bytes, uint32_t n_bytes, uint8_t *bits) void liblte_unpack(uint8_t* bytes, uint32_t n_bytes, uint8_t* bits)
{ {
uint8_t *bit_ptr = bits; uint8_t* bit_ptr = bits;
uint32_t i; uint32_t i;
for(i=0; i<n_bytes; i++) for (i = 0; i < n_bytes; i++) {
{ liblte_value_2_bits(bytes[i], &bit_ptr, 8);
liblte_value_2_bits(bytes[i], &bit_ptr, 8); }
}
} }
/********************************************************************* /*********************************************************************
@ -174,10 +158,9 @@ void liblte_unpack(uint8_t *bytes, uint32_t n_bytes, uint8_t *bits)
Description: Aligns a pointer to a multibyte boundary Description: Aligns a pointer to a multibyte boundary
*********************************************************************/ *********************************************************************/
void liblte_align_up(uint8_t **ptr, uint32_t align) void liblte_align_up(uint8_t** ptr, uint32_t align)
{ {
while( (uint64_t)(*ptr) % align > 0) while ((uint64_t)(*ptr) % align > 0) {
{
(*ptr)++; (*ptr)++;
} }
} }
@ -188,10 +171,9 @@ void liblte_align_up(uint8_t **ptr, uint32_t align)
Description: Aligns a pointer to a multibyte boundary and zeros Description: Aligns a pointer to a multibyte boundary and zeros
bytes skipped bytes skipped
*********************************************************************/ *********************************************************************/
void liblte_align_up_zero(uint8_t **ptr, uint32_t align) void liblte_align_up_zero(uint8_t** ptr, uint32_t align)
{ {
while( (uint64_t)(*ptr) % align > 0) while ((uint64_t)(*ptr) % align > 0) {
{
**ptr = 0; **ptr = 0;
(*ptr)++; (*ptr)++;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save