Fix for NAS security bearer id, added encryption test sets, fix for compile warning

master
Paul Sutton 7 years ago
parent 84724d2ab1
commit 516fdc27f1

@ -903,7 +903,7 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea1(uint8 *key,
s3g_generate_keystream(state_ptr, msg_len_block_32, ks);
// Generate output except last block
for (i = 0; i < msg_len_block_32 - 1; i++) {
for (i = 0; i < (int32_t)msg_len_block_32 - 1; i++) {
out[4 * i + 0] = msg[4 * i + 0] ^ ((ks[i] >> 24) & 0xFF);
out[4 * i + 1] = msg[4 * i + 1] ^ ((ks[i] >> 16) & 0xFF);
out[4 * i + 2] = msg[4 * i + 2] ^ ((ks[i] >> 8) & 0xFF);
@ -911,8 +911,7 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea1(uint8 *key,
}
// Process last bytes
for (i = (msg_len_block_32 - 1) * 4; i < msg_len_block_8;
i++) {
for (i = (msg_len_block_32 - 1) * 4; i < (int32_t)msg_len_block_8; i++) {
out[i] = msg[i] ^ ((ks[i / 4] >> ((3 - (i % 4)) * 8)) & 0xFF);
}

@ -29,6 +29,14 @@ add_executable(msg_queue_test msg_queue_test.cc)
target_link_libraries(msg_queue_test srslte_phy srslte_common ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
add_test(msg_queue_test msg_queue_test)
add_executable(test_eea1 test_eea1.cc)
target_link_libraries(test_eea1 srslte_common ${CMAKE_THREAD_LIBS_INIT})
add_test(test_eea1 test_eea1)
add_executable(test_eea2 test_eea2.cc)
target_link_libraries(test_eea2 srslte_common ${CMAKE_THREAD_LIBS_INIT})
add_test(test_eea2 test_eea2)
add_executable(log_filter_test log_filter_test.cc)
target_link_libraries(log_filter_test srslte_phy srslte_common srslte_phy ${SEC_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})

@ -0,0 +1,569 @@
/*
* Includes
*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "srslte/common/liblte_security.h"
/*
* Prototypes
*/
int32 arrcmp(uint8_t const * const a, uint8_t const * const b, uint32 len) {
uint32 i = 0;
for (i = 0; i < len; i++) {
if (a[i] != b[i]) {
return a[i] - b[i];
}
}
return 0;
}
/*
* Tests
*
* Document Reference: 33.401 V13.1.0 Annex C.3
* Specification of the 3GPP Confidentiality and
* Integrity Algorithms UEA2 & UIA2 D4 v1.0
*/
void test_set_1()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1,
0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 };
uint32_t count = 0x398a59b4;
uint8_t bearer = 0x15;
uint8_t direction = 1;
uint32_t len_bits = 253, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb,
0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80,
0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f,
0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 };
uint8_t ct[] = { 0x5d, 0x5b, 0xfe, 0x75, 0xeb, 0x04, 0xf6,
0x8c, 0xe0, 0xa1, 0x23, 0x77, 0xea, 0x00, 0xb3, 0x7d,
0x47, 0xc6, 0xa0, 0xba, 0x06, 0x30, 0x91, 0x55, 0x08,
0x6a, 0x85, 0x9c, 0x43, 0x41, 0xb3, 0x78 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea1(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea1(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
void test_set_2()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0x2b, 0xd6, 0x45, 0x9f, 0x82, 0xc4, 0x40,
0xe0, 0x95, 0x2c, 0x49, 0x10, 0x48, 0x05, 0xff, 0x48 };
uint32_t count = 0xc675a64b;
uint8_t bearer = 0x0c;
uint8_t direction = 1;
uint32_t len_bits = 798, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x7e, 0xc6, 0x12, 0x72, 0x74, 0x3b, 0xf1,
0x61, 0x47, 0x26, 0x44, 0x6a, 0x6c, 0x38, 0xce, 0xd1,
0x66, 0xf6, 0xca, 0x76, 0xeb, 0x54, 0x30, 0x04, 0x42,
0x86, 0x34, 0x6c, 0xef, 0x13, 0x0f, 0x92, 0x92, 0x2b,
0x03, 0x45, 0x0d, 0x3a, 0x99, 0x75, 0xe5, 0xbd, 0x2e,
0xa0, 0xeb, 0x55, 0xad, 0x8e, 0x1b, 0x19, 0x9e, 0x3e,
0xc4, 0x31, 0x60, 0x20, 0xe9, 0xa1, 0xb2, 0x85, 0xe7,
0x62, 0x79, 0x53, 0x59, 0xb7, 0xbd, 0xfd, 0x39, 0xbe,
0xf4, 0xb2, 0x48, 0x45, 0x83, 0xd5, 0xaf, 0xe0, 0x82,
0xae, 0xe6, 0x38, 0xbf, 0x5f, 0xd5, 0xa6, 0x06, 0x19,
0x39, 0x01, 0xa0, 0x8f, 0x4a, 0xb4, 0x1a, 0xab, 0x9b,
0x13, 0x48, 0x80 };
uint8_t ct[] = { 0x3f, 0x67, 0x85, 0x07, 0x14, 0xb8, 0xda,
0x69, 0xef, 0xb7, 0x27, 0xed, 0x7a, 0x6c, 0x0c, 0x50,
0x71, 0x4a, 0xd7, 0x36, 0xc4, 0xf5, 0x60, 0x00, 0x06,
0xe3, 0x52, 0x5b, 0xe8, 0x07, 0xc4, 0x67, 0xc6, 0x77,
0xff, 0x86, 0x4a, 0xf4, 0x5f, 0xba, 0x09, 0xc2, 0x7c,
0xde, 0x38, 0xf8, 0x7a, 0x1f, 0x84, 0xd5, 0x9a, 0xb2,
0x55, 0x40, 0x8f, 0x2c, 0x7b, 0x82, 0xf9, 0xea, 0xd4,
0x1a, 0x1f, 0xe6, 0x5e, 0xab, 0xeb, 0xfb, 0xc1, 0xf3,
0xa4, 0xc5, 0x6c, 0x9a, 0x26, 0xfc, 0xf7, 0xb3, 0xd6,
0x6d, 0x02, 0x20, 0xee, 0x47, 0x75, 0xbc, 0x58, 0x17,
0x0a, 0x2b, 0x12, 0xf3, 0x43, 0x1d, 0x11, 0xb3, 0x44,
0xd6, 0xe3, 0x6c };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea1(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea1(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
void test_set_3()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0, 0x8b,
0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77, 0xfb };
uint32_t count = 0x544d49cd;
uint8_t bearer = 0x04;
uint8_t direction = 0;
uint32_t len_bits = 310, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0xfd, 0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f,
0x65, 0x74, 0x50, 0x95, 0x68, 0x7d, 0x47, 0xba, 0x1d,
0x36, 0xd2, 0x34, 0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c,
0x8e, 0xa9, 0xc4, 0x9d, 0x40, 0xc1, 0x32, 0x71, 0xaf,
0xf2, 0x64, 0xd0, 0xf2, 0x48, 0x00 };
uint8_t ct[] = { 0x48, 0x14, 0x8e, 0x54, 0x52, 0xa2, 0x10,
0xc0, 0x5f, 0x46, 0xbc, 0x80, 0xdc, 0x6f, 0x73, 0x49,
0x5b, 0x02, 0x04, 0x8c, 0x1b, 0x95, 0x8b, 0x02, 0x61,
0x02, 0xca, 0x97, 0x28, 0x02, 0x79, 0xa4, 0xc1, 0x8d,
0x2e, 0xe3, 0x08, 0x92, 0x1c };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea1(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea1(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
void test_set_4()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0xaa, 0x1f, 0x95, 0xae, 0xa5, 0x33, 0xbc,
0xb3, 0x2e, 0xb6, 0x3b, 0xf5, 0x2d, 0x8f, 0x83, 0x1a };
uint32_t count = 0x72d8c671;
uint8_t bearer = 0x10;
uint8_t direction = 1;
uint32_t len_bits = 1022, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0xfb, 0x1b, 0x96, 0xc5, 0xc8, 0xba, 0xdf,
0xb2, 0xe8, 0xe8, 0xed, 0xfd, 0xe7, 0x8e, 0x57, 0xf2,
0xad, 0x81, 0xe7, 0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0x3d, 0xa4, 0x0c, 0x40, 0xdf,
0xd3, 0x93, 0x1c, 0xc1, 0xac, 0x97, 0x23, 0xf6, 0xb4,
0xa9, 0x91, 0x3e, 0x96, 0xb6, 0xdb, 0x7a, 0xbc, 0xac,
0xe4, 0x15, 0x17, 0x7c, 0x1d, 0x01, 0x15, 0xc5, 0xf0,
0x9b, 0x5f, 0xde, 0xa0, 0xb3, 0xad, 0xb8, 0xf9, 0xda,
0x6e, 0x9f, 0x9a, 0x04, 0xc5, 0x43, 0x39, 0x7b, 0x9d,
0x43, 0xf8, 0x73, 0x30 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea1(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea1(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
void test_set_5()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0x96, 0x18, 0xae, 0x46, 0x89, 0x1f, 0x86,
0x57, 0x8e, 0xeb, 0xe9, 0x0e, 0xf7, 0xa1, 0x20, 0x2e };
uint32_t count = 0xc675a64b;
uint8_t bearer = 0x0c;
uint8_t direction = 1;
uint32_t len_bits = 1245, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x8d, 0xaa, 0x17, 0xb1, 0xae, 0x05, 0x05,
0x29, 0xc6, 0x82, 0x7f, 0x28, 0xc0, 0xef, 0x6a, 0x12,
0x42, 0xe9, 0x3f, 0x8b, 0x31, 0x4f, 0xb1, 0x8a, 0x77,
0xf7, 0x90, 0xae, 0x04, 0x9f, 0xed, 0xd6, 0x12, 0x26,
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5, 0xd9,
0xc5, 0xa4, 0x0a, 0xf6, 0x02, 0x28, 0x0b, 0x54, 0x25,
0x97, 0xb0, 0xcb, 0x18, 0x61, 0x9e, 0xeb, 0x35, 0x92,
0x57, 0x59, 0xd1, 0x95, 0xe1, 0x00, 0xe8, 0xe4, 0xaa,
0x0c, 0x38, 0xa3, 0xc2, 0xab, 0xe0, 0xf3, 0xd8, 0xff,
0x04, 0xf3, 0xc3, 0x3c, 0x29, 0x50, 0x69, 0xc2, 0x36,
0x94, 0xb5, 0xbb, 0xea, 0xcd, 0xd5, 0x42, 0xe2, 0x8e,
0x8a, 0x94, 0xed, 0xb9, 0x11, 0x9f, 0x41, 0x2d, 0x05,
0x4b, 0xe1, 0xfa, 0x72, 0x72, 0xb5, 0xff, 0xb2, 0xb2,
0x57, 0x0f, 0x4f, 0x7c, 0xea, 0xf3, 0x83, 0xa8, 0xa9,
0xd9, 0x35, 0x72, 0xf0, 0x4d, 0x6e, 0x3a, 0x6e, 0x29,
0x37, 0x26, 0xec, 0x62, 0xc8 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea1(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea1(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
void test_set_6()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0x54, 0xf4, 0xe2, 0xe0, 0x4c, 0x83, 0x78,
0x6e, 0xec, 0x8f, 0xb5, 0xab, 0xe8, 0xe3, 0x65, 0x66 };
uint32_t count = 0xaca4f50f;
uint8_t bearer = 0x0b;
uint8_t direction = 0;
uint32_t len_bits = 3861, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x40, 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b,
0xfb, 0x42, 0x86, 0xb2, 0x99, 0x78, 0x3d, 0xaf, 0x44,
0x2c, 0x09, 0x9f, 0x7a, 0xb0, 0xf5, 0x8d, 0x5c, 0x8e,
0x46, 0xb1, 0x04, 0xf0, 0x8f, 0x01, 0xb4, 0x1a, 0xb4,
0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x36, 0xbd, 0x1a,
0x3d, 0x90, 0xdc, 0x3a, 0x41, 0xb4, 0x6d, 0x51, 0x67,
0x2a, 0xc4, 0xc9, 0x66, 0x3a, 0x2b, 0xe0, 0x63, 0xda,
0x4b, 0xc8, 0xd2, 0x80, 0x8c, 0xe3, 0x3e, 0x2c, 0xcc,
0xbf, 0xc6, 0x34, 0xe1, 0xb2, 0x59, 0x06, 0x08, 0x76,
0xa0, 0xfb, 0xb5, 0xa4, 0x37, 0xeb, 0xcc, 0x8d, 0x31,
0xc1, 0x9e, 0x44, 0x54, 0x31, 0x87, 0x45, 0xe3, 0xfa,
0x16, 0xbb, 0x11, 0xad, 0xae, 0x24, 0x88, 0x79, 0xfe,
0x52, 0xdb, 0x25, 0x43, 0xe5, 0x3c, 0xf4, 0x45, 0xd3,
0xd8, 0x28, 0xce, 0x0b, 0xf5, 0xc5, 0x60, 0x59, 0x3d,
0x97, 0x27, 0x8a, 0x59, 0x76, 0x2d, 0xd0, 0xc2, 0xc9,
0xcd, 0x68, 0xd4, 0x49, 0x6a, 0x79, 0x25, 0x08, 0x61,
0x40, 0x14, 0xb1, 0x3b, 0x6a, 0xa5, 0x11, 0x28, 0xc1,
0x8c, 0xd6, 0xa9, 0x0b, 0x87, 0x97, 0x8c, 0x2f, 0xf1,
0xca, 0xbe, 0x7d, 0x9f, 0x89, 0x8a, 0x41, 0x1b, 0xfd,
0xb8, 0x4f, 0x68, 0xf6, 0x72, 0x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7, 0xcc, 0x45, 0xa9, 0xb7, 0xc0,
0x7d, 0x83, 0x4e, 0x7b, 0x20, 0xb9, 0x9e, 0xd2, 0x02,
0x42, 0x9c, 0x14, 0xbb, 0x85, 0xff, 0xa4, 0x3b, 0x7c,
0xb6, 0x84, 0x95, 0xcd, 0x75, 0xab, 0x66, 0xd9, 0x64,
0xd4, 0xca, 0xfe, 0x64, 0xdd, 0x94, 0x04, 0xda, 0xe2,
0xdc, 0x51, 0x10, 0x61, 0x7f, 0x19, 0x4f, 0xc3, 0xc1,
0x84, 0xf5, 0x83, 0xcd, 0x0d, 0xef, 0x6d, 0x00 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea1(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea1(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
// set len_bitsgth to multiple of 8 respectively 128
void test_set_1_block_size()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1,
0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 };
uint32_t count = 0x398a59b4;
uint8_t bearer = 0x15;
uint8_t direction = 1;
uint32_t len_bits = 256, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb,
0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80,
0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f,
0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 };
uint8_t ct[] = { 0x5d, 0x5b, 0xfe, 0x75, 0xeb, 0x04, 0xf6,
0x8c, 0xe0, 0xa1, 0x23, 0x77, 0xea, 0x00, 0xb3, 0x7d,
0x47, 0xc6, 0xa0, 0xba, 0x06, 0x30, 0x91, 0x55, 0x08,
0x6a, 0x85, 0x9c, 0x43, 0x41, 0xb3, 0x7c };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea1(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea1(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
// inserted bit flip in msg[0]
void test_set_1_invalid()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1,
0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 };
uint32_t count = 0x398a59b4;
uint8_t bearer = 0x15;
uint8_t direction = 1;
uint32_t len_bits = 253, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x99, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb,
0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80,
0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f,
0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 };
uint8_t ct[] = { 0x5d, 0x5b, 0xfe, 0x75, 0xeb, 0x04, 0xf6,
0x8c, 0xe0, 0xa1, 0x23, 0x77, 0xea, 0x00, 0xb3, 0x7d,
0x47, 0xc6, 0xa0, 0xba, 0x06, 0x30, 0x91, 0x55, 0x08,
0x6a, 0x85, 0x9c, 0x43, 0x41, 0xb3, 0x78 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea1(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp != 0);
// decryption
err_lte = liblte_security_decryption_eea1(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp != 0);
free(out);
}
/*
* Functions
*/
int main(int argc, char * argv[]) {
test_set_1();
test_set_2();
test_set_3();
test_set_4();
test_set_5();
test_set_6();
test_set_1_block_size();
test_set_1_invalid();
}

@ -0,0 +1,567 @@
/*
* Includes
*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "srslte/common/liblte_security.h"
/*
* Prototypes
*/
int32 arrcmp(uint8_t const * const a, uint8_t const * const b, uint32 len) {
uint32 i = 0;
for (i = 0; i < len; i++) {
if (a[i] != b[i]) {
return a[i] - b[i];
}
}
return 0;
}
/*
* Tests
*
* Document Reference: 33.401 V13.1.0 Annex C.1
*/
void test_set_1()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1,
0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 };
uint32_t count = 0x398a59b4;
uint8_t bearer = 0x15;
uint8_t direction = 1;
uint32_t len_bits = 253, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb,
0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80,
0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f,
0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 };
uint8_t ct[] = { 0xe9, 0xfe, 0xd8, 0xa6, 0x3d, 0x15, 0x53,
0x04, 0xd7, 0x1d, 0xf2, 0x0b, 0xf3, 0xe8, 0x22, 0x14,
0xb2, 0x0e, 0xd7, 0xda, 0xd2, 0xf2, 0x33, 0xdc, 0x3c,
0x22, 0xd7, 0xbd, 0xee, 0xed, 0x8e, 0x78 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea2(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea2(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
void test_set_2()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0x2b, 0xd6, 0x45, 0x9f, 0x82, 0xc4, 0x40,
0xe0, 0x95, 0x2c, 0x49, 0x10, 0x48, 0x05, 0xff, 0x48 };
uint32_t count = 0xc675a64b;
uint8_t bearer = 0x0c;
uint8_t direction = 1;
uint32_t len_bits = 798, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x7e, 0xc6, 0x12, 0x72, 0x74, 0x3b, 0xf1,
0x61, 0x47, 0x26, 0x44, 0x6a, 0x6c, 0x38, 0xce, 0xd1,
0x66, 0xf6, 0xca, 0x76, 0xeb, 0x54, 0x30, 0x04, 0x42,
0x86, 0x34, 0x6c, 0xef, 0x13, 0x0f, 0x92, 0x92, 0x2b,
0x03, 0x45, 0x0d, 0x3a, 0x99, 0x75, 0xe5, 0xbd, 0x2e,
0xa0, 0xeb, 0x55, 0xad, 0x8e, 0x1b, 0x19, 0x9e, 0x3e,
0xc4, 0x31, 0x60, 0x20, 0xe9, 0xa1, 0xb2, 0x85, 0xe7,
0x62, 0x79, 0x53, 0x59, 0xb7, 0xbd, 0xfd, 0x39, 0xbe,
0xf4, 0xb2, 0x48, 0x45, 0x83, 0xd5, 0xaf, 0xe0, 0x82,
0xae, 0xe6, 0x38, 0xbf, 0x5f, 0xd5, 0xa6, 0x06, 0x19,
0x39, 0x01, 0xa0, 0x8f, 0x4a, 0xb4, 0x1a, 0xab, 0x9b,
0x13, 0x48, 0x80 };
uint8_t ct[] = { 0x59, 0x61, 0x60, 0x53, 0x53, 0xc6, 0x4b,
0xdc, 0xa1, 0x5b, 0x19, 0x5e, 0x28, 0x85, 0x53, 0xa9,
0x10, 0x63, 0x25, 0x06, 0xd6, 0x20, 0x0a, 0xa7, 0x90,
0xc4, 0xc8, 0x06, 0xc9, 0x99, 0x04, 0xcf, 0x24, 0x45,
0xcc, 0x50, 0xbb, 0x1c, 0xf1, 0x68, 0xa4, 0x96, 0x73,
0x73, 0x4e, 0x08, 0x1b, 0x57, 0xe3, 0x24, 0xce, 0x52,
0x59, 0xc0, 0xe7, 0x8d, 0x4c, 0xd9, 0x7b, 0x87, 0x09,
0x76, 0x50, 0x3c, 0x09, 0x43, 0xf2, 0xcb, 0x5a, 0xe8,
0xf0, 0x52, 0xc7, 0xb7, 0xd3, 0x92, 0x23, 0x95, 0x87,
0xb8, 0x95, 0x60, 0x86, 0xbc, 0xab, 0x18, 0x83, 0x60,
0x42, 0xe2, 0xe6, 0xce, 0x42, 0x43, 0x2a, 0x17, 0x10,
0x5c, 0x53, 0xd0 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea2(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea2(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
void test_set_3()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0, 0x8b,
0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77, 0xfb };
uint32_t count = 0x544d49cd;
uint8_t bearer = 0x04;
uint8_t direction = 0;
uint32_t len_bits = 310, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0xfd, 0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f,
0x65, 0x74, 0x50, 0x95, 0x68, 0x7d, 0x47, 0xba, 0x1d,
0x36, 0xd2, 0x34, 0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c,
0x8e, 0xa9, 0xc4, 0x9d, 0x40, 0xc1, 0x32, 0x71, 0xaf,
0xf2, 0x64, 0xd0, 0xf2, 0x48, 0x00 };
uint8_t ct[] = { 0x75, 0x75, 0x0d, 0x37, 0xb4, 0xbb, 0xa2,
0xa4, 0xde, 0xdb, 0x34, 0x23, 0x5b, 0xd6, 0x8c, 0x66,
0x45, 0xac, 0xda, 0xac, 0xa4, 0x81, 0x38, 0xa3, 0xb0,
0xc4, 0x71, 0xe2, 0xa7, 0x04, 0x1a, 0x57, 0x64, 0x23,
0xd2, 0x92, 0x72, 0x87, 0xf0, 0x00 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea2(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea2(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
void test_set_4()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0xaa, 0x1f, 0x95, 0xae, 0xa5, 0x33, 0xbc,
0xb3, 0x2e, 0xb6, 0x3b, 0xf5, 0x2d, 0x8f, 0x83, 0x1a };
uint32_t count = 0x72d8c671;
uint8_t bearer = 0x10;
uint8_t direction = 1;
uint32_t len_bits = 1022, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0xfb, 0x1b, 0x96, 0xc5, 0xc8, 0xba, 0xdf,
0xb2, 0xe8, 0xe8, 0xed, 0xfd, 0xe7, 0x8e, 0x57, 0xf2,
0xad, 0x81, 0xe7, 0x41, 0x03, 0xfc, 0x43, 0x0a, 0x53,
0x4d, 0xcc, 0x37, 0xaf, 0xce, 0xc7, 0x0e, 0x15, 0x17,
0xbb, 0x06, 0xf2, 0x72, 0x19, 0xda, 0xe4, 0x90, 0x22,
0xdd, 0xc4, 0x7a, 0x06, 0x8d, 0xe4, 0xc9, 0x49, 0x6a,
0x95, 0x1a, 0x6b, 0x09, 0xed, 0xbd, 0xc8, 0x64, 0xc7,
0xad, 0xbd, 0x74, 0x0a, 0xc5, 0x0c, 0x02, 0x2f, 0x30,
0x82, 0xba, 0xfd, 0x22, 0xd7, 0x81, 0x97, 0xc5, 0xd5,
0x08, 0xb9, 0x77, 0xbc, 0xa1, 0x3f, 0x32, 0xe6, 0x52,
0xe7, 0x4b, 0xa7, 0x28, 0x57, 0x60, 0x77, 0xce, 0x62,
0x8c, 0x53, 0x5e, 0x87, 0xdc, 0x60, 0x77, 0xba, 0x07,
0xd2, 0x90, 0x68, 0x59, 0x0c, 0x8c, 0xb5, 0xf1, 0x08,
0x8e, 0x08, 0x2c, 0xfa, 0x0e, 0xc9, 0x61, 0x30, 0x2d,
0x69, 0xcf, 0x3d, 0x44 };
uint8_t ct[] = { 0xdf, 0xb4, 0x40, 0xac, 0xb3, 0x77, 0x35,
0x49, 0xef, 0xc0, 0x46, 0x28, 0xae, 0xb8, 0xd8, 0x15,
0x62, 0x75, 0x23, 0x0b, 0xdc, 0x69, 0x0d, 0x94, 0xb0,
0x0d, 0x8d, 0x95, 0xf2, 0x8c, 0x4b, 0x56, 0x30, 0x7f,
0x60, 0xf4, 0xca, 0x55, 0xeb, 0xa6, 0x61, 0xeb, 0xba,
0x72, 0xac, 0x80, 0x8f, 0xa8, 0xc4, 0x9e, 0x26, 0x78,
0x8e, 0xd0, 0x4a, 0x5d, 0x60, 0x6c, 0xb4, 0x18, 0xde,
0x74, 0x87, 0x8b, 0x9a, 0x22, 0xf8, 0xef, 0x29, 0x59,
0x0b, 0xc4, 0xeb, 0x57, 0xc9, 0xfa, 0xf7, 0xc4, 0x15,
0x24, 0xa8, 0x85, 0xb8, 0x97, 0x9c, 0x42, 0x3f, 0x2f,
0x8f, 0x8e, 0x05, 0x92, 0xa9, 0x87, 0x92, 0x01, 0xbe,
0x7f, 0xf9, 0x77, 0x7a, 0x16, 0x2a, 0xb8, 0x10, 0xfe,
0xb3, 0x24, 0xba, 0x74, 0xc4, 0xc1, 0x56, 0xe0, 0x4d,
0x39, 0x09, 0x72, 0x09, 0x65, 0x3a, 0xc3, 0x3e, 0x5a,
0x5f, 0x2d, 0x88, 0x64 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea2(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea2(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
void test_set_5()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0x96, 0x18, 0xae, 0x46, 0x89, 0x1f, 0x86,
0x57, 0x8e, 0xeb, 0xe9, 0x0e, 0xf7, 0xa1, 0x20, 0x2e };
uint32_t count = 0xc675a64b;
uint8_t bearer = 0x0c;
uint8_t direction = 1;
uint32_t len_bits = 1245, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x8d, 0xaa, 0x17, 0xb1, 0xae, 0x05, 0x05,
0x29, 0xc6, 0x82, 0x7f, 0x28, 0xc0, 0xef, 0x6a, 0x12,
0x42, 0xe9, 0x3f, 0x8b, 0x31, 0x4f, 0xb1, 0x8a, 0x77,
0xf7, 0x90, 0xae, 0x04, 0x9f, 0xed, 0xd6, 0x12, 0x26,
0x7f, 0xec, 0xae, 0xfc, 0x45, 0x01, 0x74, 0xd7, 0x6d,
0x9f, 0x9a, 0xa7, 0x75, 0x5a, 0x30, 0xcd, 0x90, 0xa9,
0xa5, 0x87, 0x4b, 0xf4, 0x8e, 0xaf, 0x70, 0xee, 0xa3,
0xa6, 0x2a, 0x25, 0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0,
0x8b, 0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77,
0xfb, 0x54, 0x4d, 0x49, 0xcd, 0x49, 0x72, 0x0e, 0x21,
0x9d, 0xbf, 0x8b, 0xbe, 0xd3, 0x39, 0x04, 0xe1, 0xfd,
0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f, 0x65, 0x74, 0x50,
0x95, 0x68, 0x7d, 0x47, 0xba, 0x1d, 0x36, 0xd2, 0x34,
0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c, 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xb1, 0xcb, 0xeb, 0x26,
0x58, 0x22, 0x3e, 0x69, 0x38 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea2(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea2(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
void test_set_6()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0x54, 0xf4, 0xe2, 0xe0, 0x4c, 0x83, 0x78,
0x6e, 0xec, 0x8f, 0xb5, 0xab, 0xe8, 0xe3, 0x65, 0x66 };
uint32_t count = 0xaca4f50f;
uint8_t bearer = 0x0b;
uint8_t direction = 0;
uint32_t len_bits = 3861, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x40, 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b,
0xfb, 0x42, 0x86, 0xb2, 0x99, 0x78, 0x3d, 0xaf, 0x44,
0x2c, 0x09, 0x9f, 0x7a, 0xb0, 0xf5, 0x8d, 0x5c, 0x8e,
0x46, 0xb1, 0x04, 0xf0, 0x8f, 0x01, 0xb4, 0x1a, 0xb4,
0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x36, 0xbd, 0x1a,
0x3d, 0x90, 0xdc, 0x3a, 0x41, 0xb4, 0x6d, 0x51, 0x67,
0x2a, 0xc4, 0xc9, 0x66, 0x3a, 0x2b, 0xe0, 0x63, 0xda,
0x4b, 0xc8, 0xd2, 0x80, 0x8c, 0xe3, 0x3e, 0x2c, 0xcc,
0xbf, 0xc6, 0x34, 0xe1, 0xb2, 0x59, 0x06, 0x08,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77,
0x55, 0x57, 0x90, 0x38, 0xe5, 0x79, 0x24, 0xb1, 0xf7,
0x8b, 0x3e, 0x1a, 0xd9, 0x0b, 0xab, 0x2a, 0x07, 0x87,
0x1b, 0x72, 0xdb, 0x5e, 0xef, 0x96, 0xc3, 0x34, 0x04,
0x49, 0x66, 0xdb, 0x0c, 0x37, 0xca, 0xfd, 0x1a, 0x89,
0xe5, 0x64, 0x6a, 0x35, 0x80, 0xeb, 0x64, 0x65, 0xf1,
0x21, 0xdc, 0xe9, 0xcb, 0x88, 0xd8, 0x5b, 0x96, 0xcf,
0x23, 0xcc, 0xcc, 0xd4, 0x28, 0x07, 0x67, 0xbe, 0xe8,
0xee, 0xb2, 0x3d, 0x86, 0x52, 0x46, 0x1d, 0xb6, 0x49,
0x31, 0x03, 0x00, 0x3b, 0xaf, 0x89, 0xf5, 0xe1, 0x82,
0x61, 0xea, 0x43, 0xc8, 0x4a, 0x92, 0xeb, 0xff, 0xff,
0xe4, 0x90, 0x9d, 0xc4, 0x6c, 0x51, 0x92, 0xf8, 0x25,
0xf7, 0x70, 0x60, 0x0b, 0x96, 0x02, 0xc5, 0x57, 0xb5,
0xf8, 0xb4, 0x31, 0xa7, 0x9d, 0x45, 0x97, 0x7d, 0xd9,
0xc4, 0x1b, 0x86, 0x3d, 0xa9, 0xe1, 0x42, 0xe9, 0x00,
0x20, 0xcf, 0xd0, 0x74, 0xd6, 0x92, 0x7b, 0x7a, 0xb3,
0xb6, 0x72, 0x5d, 0x1a, 0x6f, 0x3f, 0x98, 0xb9, 0xc9,
0xda, 0xa8, 0x98, 0x2a, 0xff, 0x06, 0x78, 0x28, 0x00 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea2(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea2(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
// set len_bitsgth to multiple of 8 respectively 128
void test_set_1_block_size()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1,
0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 };
uint32_t count = 0x398a59b4;
uint8_t bearer = 0x15;
uint8_t direction = 1;
uint32_t len_bits = 256, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb,
0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80,
0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f,
0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 };
uint8_t ct[] = { 0xe9, 0xfe, 0xd8, 0xa6, 0x3d, 0x15, 0x53,
0x04, 0xd7, 0x1d, 0xf2, 0x0b, 0xf3, 0xe8, 0x22, 0x14,
0xb2, 0x0e, 0xd7, 0xda, 0xd2, 0xf2, 0x33, 0xdc, 0x3c,
0x22, 0xd7, 0xbd, 0xee, 0xed, 0x8e, 0x78 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea2(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp == 0);
// decryption
err_lte = liblte_security_decryption_eea2(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp == 0);
free(out);
}
// inserted bit flip in msg[0]
void test_set_1_invalid()
{
LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS;
int32 err_cmp = 0;
uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1,
0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 };
uint32_t count = 0x398a59b4;
uint8_t bearer = 0x15;
uint8_t direction = 1;
uint32_t len_bits = 253, len_bytes = (len_bits + 7) / 8;
uint8_t msg[] = { 0x99, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb,
0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80,
0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f,
0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 };
uint8_t ct[] = { 0xe9, 0xfe, 0xd8, 0xa6, 0x3d, 0x15, 0x53,
0x04, 0xd7, 0x1d, 0xf2, 0x0b, 0xf3, 0xe8, 0x22, 0x14,
0xb2, 0x0e, 0xd7, 0xda, 0xd2, 0xf2, 0x33, 0xdc, 0x3c,
0x22, 0xd7, 0xbd, 0xee, 0xed, 0x8e, 0x78 };
uint8_t * out = (uint8_t *) calloc(len_bytes,
sizeof(uint8_t));
// encryption
err_lte = liblte_security_encryption_eea2(key, count, bearer,
direction, msg, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(ct, out, len_bytes);
assert(err_cmp != 0);
// decryption
err_lte = liblte_security_decryption_eea2(key, count, bearer,
direction, ct, len_bits, out);
assert(err_lte == LIBLTE_SUCCESS);
// compare cipher text
err_cmp = arrcmp(msg, out, len_bytes);
assert(err_cmp != 0);
free(out);
}
/*
* Functions
*/
int main(int argc, char * argv[]) {
test_set_1();
test_set_2();
test_set_3();
test_set_4();
test_set_5();
test_set_6();
test_set_1_block_size();
test_set_1_invalid();
}

@ -149,14 +149,13 @@ private:
void integrity_generate(uint8_t *key_128,
uint32_t count,
uint8_t rb_id,
uint8_t direction,
uint8_t *msg,
uint32_t msg_len,
uint8_t *mac);
bool integrity_check(uint32 lcid, byte_buffer_t *pdu);
void cipher_encrypt(uint32 lcid, byte_buffer_t *pdu);
void cipher_decrypt(uint32 lcid, byte_buffer_t *pdu);
bool integrity_check(byte_buffer_t *pdu);
void cipher_encrypt(byte_buffer_t *pdu);
void cipher_decrypt(byte_buffer_t *pdu);
bool check_cap_replay(LIBLTE_MME_UE_SECURITY_CAPABILITIES_STRUCT *caps);

@ -206,8 +206,8 @@ void nas::write_pdu(uint32_t lcid, byte_buffer_t *pdu) {
case LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY:
break;
case LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED:
mac_valid = integrity_check(lcid, pdu);
cipher_decrypt(lcid, pdu);
mac_valid = integrity_check(pdu);
cipher_decrypt(pdu);
break;
case LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED_WITH_NEW_EPS_SECURITY_CONTEXT:
break;
@ -305,7 +305,6 @@ void nas::start_pcap(srslte::nas_pcap *pcap_)
void nas::integrity_generate(uint8_t *key_128,
uint32_t count,
uint8_t rb_id,
uint8_t direction,
uint8_t *msg,
uint32_t msg_len,
@ -316,7 +315,7 @@ void nas::integrity_generate(uint8_t *key_128,
case INTEGRITY_ALGORITHM_ID_128_EIA1:
security_128_eia1(key_128,
count,
rb_id,
0, // Bearer always 0 for NAS
direction,
msg,
msg_len,
@ -325,7 +324,7 @@ void nas::integrity_generate(uint8_t *key_128,
case INTEGRITY_ALGORITHM_ID_128_EIA2:
security_128_eia2(key_128,
count,
rb_id,
0, // Bearer always 0 for NAS
direction,
msg,
msg_len,
@ -339,16 +338,14 @@ void nas::integrity_generate(uint8_t *key_128,
// This function depends to a valid k_nas_int.
// This key is generated in the security mode command.
bool nas::integrity_check(uint32 lcid,
byte_buffer_t *pdu)
bool nas::integrity_check(byte_buffer_t *pdu)
{
uint8_t exp_mac[4];
uint8_t *mac = &pdu->msg[1];
int i;
integrity_generate(&k_nas_int[16],
ctxt.rx_count,
lcid-1,
SECURITY_DIRECTION_DOWNLINK,
&pdu->msg[5],
pdu->N_bytes-5,
@ -357,16 +354,19 @@ bool nas::integrity_check(uint32 lcid,
// Check if expected mac equals the sent mac
for(i=0; i<4; i++){
if(exp_mac[i] != mac[i]){
nas_log->warning("Expected MAC [%02x %02x %02x %02x] does not match sent MAC [%02x %02x %02x %02x]\n", exp_mac[0], exp_mac[1], exp_mac[2], exp_mac[3], mac[0], mac[1], mac[2], mac[3]);
nas_log->warning("Integrity check failure. Local: count=%d, [%02x %02x %02x %02x], "
"Received: count=%d, [%02x %02x %02x %02x]\n",
ctxt.rx_count, exp_mac[0], exp_mac[1], exp_mac[2], exp_mac[3],
pdu->msg[5], mac[0], mac[1], mac[2], mac[3]);
return false;
}
}
nas_log->info("Expected MAC [%02x %02x %02x %02x] equals sent MAC [%02x %02x %02x %02x]\n", exp_mac[0], exp_mac[1], exp_mac[2], exp_mac[3], mac[0], mac[1], mac[2], mac[3]);
nas_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n",
ctxt.rx_count, pdu->msg[5]);
return true;
}
void nas::cipher_encrypt(uint32 lcid,
byte_buffer_t *pdu)
void nas::cipher_encrypt(byte_buffer_t *pdu)
{
byte_buffer_t pdu_tmp;
switch(ctxt.cipher_algo)
@ -376,7 +376,7 @@ void nas::cipher_encrypt(uint32 lcid,
case CIPHERING_ALGORITHM_ID_128_EEA1:
security_128_eea1(&k_nas_enc[16],
pdu->msg[5],
lcid-1,
0, // Bearer always 0 for NAS
SECURITY_DIRECTION_UPLINK,
&pdu->msg[6],
pdu->N_bytes-6,
@ -386,7 +386,7 @@ void nas::cipher_encrypt(uint32 lcid,
case CIPHERING_ALGORITHM_ID_128_EEA2:
security_128_eea2(&k_nas_enc[16],
pdu->msg[5],
lcid-1,
0, // Bearer always 0 for NAS
SECURITY_DIRECTION_UPLINK,
&pdu->msg[6],
pdu->N_bytes-6,
@ -399,8 +399,7 @@ void nas::cipher_encrypt(uint32 lcid,
}
}
void nas::cipher_decrypt(uint32 lcid,
byte_buffer_t *pdu)
void nas::cipher_decrypt(byte_buffer_t *pdu)
{
byte_buffer_t tmp_pdu;
switch(ctxt.cipher_algo)
@ -410,7 +409,7 @@ void nas::cipher_decrypt(uint32 lcid,
case CIPHERING_ALGORITHM_ID_128_EEA1:
security_128_eea1(&k_nas_enc[16],
pdu->msg[5],
lcid-1,
0, // Bearer always 0 for NAS
SECURITY_DIRECTION_DOWNLINK,
&pdu->msg[6],
pdu->N_bytes-6,
@ -420,7 +419,7 @@ void nas::cipher_decrypt(uint32 lcid,
case CIPHERING_ALGORITHM_ID_128_EEA2:
security_128_eea2(&k_nas_enc[16],
pdu->msg[5],
lcid-1,
0, // Bearer always 0 for NAS
SECURITY_DIRECTION_DOWNLINK,
&pdu->msg[6],
pdu->N_bytes-6,
@ -549,10 +548,9 @@ void nas::parse_attach_accept(uint32_t lcid, byte_buffer_t *pdu) {
pcap->write_nas(pdu->msg, pdu->N_bytes);
}
cipher_encrypt(lcid, pdu);
cipher_encrypt(pdu);
integrity_generate(&k_nas_int[16],
ctxt.tx_count,
lcid - 1,
SECURITY_DIRECTION_UPLINK,
&pdu->msg[5],
pdu->N_bytes - 5,
@ -726,7 +724,7 @@ void nas::parse_security_mode_command(uint32_t lcid, byte_buffer_t *pdu)
nas_log->debug("Generating integrity check. integ_algo:%d, count_dl:%d, lcid:%d\n",
ctxt.integ_algo, ctxt.rx_count, lcid);
if (integrity_check(lcid, pdu) != true) {
if (integrity_check(pdu) != true) {
nas_log->warning("Sending Security Mode Reject due to integrity check failure\n");
send_security_mode_reject(LIBLTE_MME_EMM_CAUSE_MAC_FAILURE);
pool->deallocate(pdu);
@ -757,10 +755,9 @@ void nas::parse_security_mode_command(uint32_t lcid, byte_buffer_t *pdu)
if(pcap != NULL) {
pcap->write_nas(sdu->msg, sdu->N_bytes);
}
cipher_encrypt(lcid, sdu);
cipher_encrypt(sdu);
integrity_generate(&k_nas_int[16],
ctxt.tx_count,
lcid - 1,
SECURITY_DIRECTION_UPLINK,
&sdu->msg[5],
sdu->N_bytes - 5,
@ -846,7 +843,6 @@ void nas::send_attach_request() {
// Add MAC
integrity_generate(&k_nas_int[16],
ctxt.tx_count,
cfg.lcid-1,
SECURITY_DIRECTION_UPLINK,
&msg->msg[5],
msg->N_bytes - 5,
@ -919,7 +915,6 @@ void nas::send_service_request() {
uint8_t mac[4];
integrity_generate(&k_nas_int[16],
ctxt.tx_count,
cfg.lcid-1,
SECURITY_DIRECTION_UPLINK,
&msg->msg[0],
2,

Loading…
Cancel
Save