From 8bf78981dac43c773ff18accbba311c9f99d6c3e Mon Sep 17 00:00:00 2001 From: winckel Date: Thu, 28 Nov 2013 10:42:46 +0000 Subject: [PATCH] Added support for EIA0 and EEA0 security algorithms. git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4541 818b1a75-f10b-46b9-bf7c-635c3b92a50f --- openair2/UTIL/OSA/osa_stream_eea.c | 35 +++++++++++++++++++++++++++--- openair2/UTIL/OSA/osa_stream_eia.c | 28 ++++++++++++------------ 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/openair2/UTIL/OSA/osa_stream_eea.c b/openair2/UTIL/OSA/osa_stream_eea.c index 7412669bc4..b74cf69f3c 100644 --- a/openair2/UTIL/OSA/osa_stream_eea.c +++ b/openair2/UTIL/OSA/osa_stream_eea.c @@ -13,6 +13,35 @@ #include "osa_defs.h" #include "osa_internal.h" +int stream_encrypt_eea0(stream_cipher_t *stream_cipher, uint8_t **out) +{ + uint8_t *data = NULL; + + uint32_t byte_length; + + DevAssert(stream_cipher != NULL); + DevAssert(out != NULL); + + LOG_D(OSA, "Entering stream_encrypt_eea0, bits length %u, bearer %u, " + "count %u, direction %s\n", stream_cipher->blength, + stream_cipher->bearer, stream_cipher->count, stream_cipher->direction == SECU_DIRECTION_DOWNLINK ? + "Downlink" : "Uplink"); + + byte_length = (stream_cipher->blength + 7) >> 3; + + if (*out == NULL) { + /* User provided output buffer */ + data = malloc(byte_length); + *out = data; + } else { + data = *out; + } + + memcpy (data, stream_cipher->message, byte_length); + + return 0; +} + int stream_encrypt_eea2(stream_cipher_t *stream_cipher, uint8_t **out) { uint8_t m[16]; @@ -98,13 +127,13 @@ int stream_encrypt_eea2(stream_cipher_t *stream_cipher, uint8_t **out) int stream_encrypt(uint8_t algorithm, stream_cipher_t *stream_cipher, uint8_t **out) { if (algorithm == EEA0_ALG_ID) { -// return stream_encrypt_eea0(stream_cipher, out); + return stream_encrypt_eea0(stream_cipher, out); } else if (algorithm == EEA1_128_ALG_ID) { - LOG_E(OSA, "SNOW-3G algorithms are currently not implemented\n"); + LOG_E(OSA, "SNOW-3G algorithms are currently not implemented for encryption\n"); return -1; } else if (algorithm == EEA2_128_ALG_ID) { return stream_encrypt_eea2(stream_cipher, out); } - LOG_E(OSA, "Provided algorithm is currently not supported = %u\n", algorithm); + LOG_E(OSA, "Provided encryption algorithm is currently not supported = %u\n", algorithm); return -1; } diff --git a/openair2/UTIL/OSA/osa_stream_eia.c b/openair2/UTIL/OSA/osa_stream_eia.c index 1a2a1cb5ec..820086cbb2 100644 --- a/openair2/UTIL/OSA/osa_stream_eia.c +++ b/openair2/UTIL/OSA/osa_stream_eia.c @@ -82,15 +82,13 @@ int stream_compute_integrity_eia2(stream_cipher_t *stream_cipher, uint8_t out[4] int stream_compute_integrity(uint8_t algorithm, stream_cipher_t *stream_cipher, uint8_t out[4]) { - if (algorithm == EIA0_ALG_ID) { - // return stream_encrypt_eea0(stream_cipher, out); - } else if (algorithm == EIA1_128_ALG_ID) { - LOG_E(OSA, "SNOW-3G algorithms are currently not implemented\n"); + if (algorithm == EIA1_128_ALG_ID) { + LOG_E(OSA, "SNOW-3G algorithms are currently not implemented for integrity\n"); return -1; } else if (algorithm == EIA2_128_ALG_ID) { return stream_compute_integrity_eia2(stream_cipher, out); } - LOG_E(OSA, "Provided algorithm is currently not supported = %u\n", algorithm); + LOG_E(OSA, "Provided integrity algorithm is currently not supported = %u\n", algorithm); return -1; } @@ -98,16 +96,18 @@ int stream_check_integrity(uint8_t algorithm, stream_cipher_t *stream_cipher, ui { uint8_t result[4]; - if (stream_compute_integrity(algorithm, stream_cipher, result) != 0) { - return -1; - } + if (algorithm != EIA0_ALG_ID) { + if (stream_compute_integrity(algorithm, stream_cipher, result) != 0) { + return -1; + } - if (memcmp(result, expected, 4) != 0) { - LOG_E(OSA, "Mismatch found in integrity for algorithm %u,\n" - "\tgot %02x.%02x.%02x.%02x, expecting %02x.%02x.%02x.%02x\n", - algorithm, result[0], result[1], result[2], result[3], expected[0], - expected[1], expected[2], expected[3]); - return -1; + if (memcmp(result, expected, 4) != 0) { + LOG_E(OSA, "Mismatch found in integrity for algorithm %u,\n" + "\tgot %02x.%02x.%02x.%02x, expecting %02x.%02x.%02x.%02x\n", + algorithm, result[0], result[1], result[2], result[3], expected[0], + expected[1], expected[2], expected[3]); + return -1; + } } /* Integrity verification succeeded */