Commit 8bf78981 authored by winckel's avatar winckel

Added support for EIA0 and EEA0 security algorithms.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4541 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent c0f18e0e
......@@ -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;
}
......@@ -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 (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 (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;
}
}
/* Integrity verification succeeded */
......
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