Commit 667b8e5e authored by Cedric Roux's avatar Cedric Roux

nr_pdcp: nia1 implementation

We reuse existing code from eia1 for actual computation. Maybe not the most
efficient. To be revised if needed.

Some hacks in CMakeLists.txt were introduced to compile
phy simulators. To be removed at some point.
parent 72bf1b1d
...@@ -1804,7 +1804,15 @@ set(NR_PDCP_SRC ...@@ -1804,7 +1804,15 @@ set(NR_PDCP_SRC
${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_timer_thread.c ${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_timer_thread.c
${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_security_nea2.c ${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_security_nea2.c
${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_integrity_nia2.c ${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_integrity_nia2.c
${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_integrity_nia1.c
${OPENAIR2_DIR}/LAYER2/nr_pdcp/asn1_utils.c ${OPENAIR2_DIR}/LAYER2/nr_pdcp/asn1_utils.c
#hack: include these files to compile the nr phy simulators
#these files should not be here, will be removed at some point when the
#computation is done directly inside nr_pdcp_integrity_nia1.c instead
#of reusing code of osa_stream_eia.c
${OPENAIR2_DIR}/UTIL/OSA/osa_stream_eia.c
${OPENAIR2_DIR}/UTIL/OSA/osa_snow3g.c
${OPENAIR2_DIR}/UTIL/OSA/osa_rijndael.c
) )
set(NR_SDAP_SRC set(NR_SDAP_SRC
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "nr_pdcp_security_nea2.h" #include "nr_pdcp_security_nea2.h"
#include "nr_pdcp_integrity_nia2.h" #include "nr_pdcp_integrity_nia2.h"
#include "nr_pdcp_integrity_nia1.h"
#include "nr_pdcp_sdu.h" #include "nr_pdcp_sdu.h"
#include "LOG/log.h" #include "LOG/log.h"
...@@ -240,16 +241,21 @@ static void nr_pdcp_entity_set_security(nr_pdcp_entity_t *entity, ...@@ -240,16 +241,21 @@ static void nr_pdcp_entity_set_security(nr_pdcp_entity_t *entity,
} }
if (integrity_algorithm != 0 && integrity_algorithm != -1) { if (integrity_algorithm != 0 && integrity_algorithm != -1) {
if (integrity_algorithm != 2) {
LOG_E(PDCP, "FATAL: only nia2 supported for the moment\n");
exit(1);
}
entity->has_integrity = 1; entity->has_integrity = 1;
if (entity->free_integrity != NULL) if (entity->free_integrity != NULL)
entity->free_integrity(entity->integrity_context); entity->free_integrity(entity->integrity_context);
entity->integrity_context = nr_pdcp_integrity_nia2_init(entity->integrity_key); if (integrity_algorithm == 2) {
entity->integrity = nr_pdcp_integrity_nia2_integrity; entity->integrity_context = nr_pdcp_integrity_nia2_init(entity->integrity_key);
entity->free_integrity = nr_pdcp_integrity_nia2_free_integrity; entity->integrity = nr_pdcp_integrity_nia2_integrity;
entity->free_integrity = nr_pdcp_integrity_nia2_free_integrity;
} else if (integrity_algorithm == 1) {
entity->integrity_context = nr_pdcp_integrity_nia1_init(entity->integrity_key);
entity->integrity = nr_pdcp_integrity_nia1_integrity;
entity->free_integrity = nr_pdcp_integrity_nia1_free_integrity;
} else {
LOG_E(PDCP, "FATAL: only nia1 and nia2 supported for the moment\n");
exit(1);
}
} }
if (ciphering_algorithm == 0) { if (ciphering_algorithm == 0) {
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "nr_pdcp_integrity_nia1.h"
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <openssl/cmac.h>
#include "UTIL/OSA/osa_defs.h"
int stream_compute_integrity_eia1(stream_cipher_t *stream_cipher, uint8_t out[4]);
void *nr_pdcp_integrity_nia1_init(unsigned char *integrity_key)
{
stream_cipher_t *ret;
ret = calloc(1, sizeof(*ret)); if (ret == NULL) abort();
ret->key = malloc(16); if (ret->key == NULL) abort();
memcpy(ret->key, integrity_key, 16);
ret->key_length = 16; /* unused */
return ret;
}
void nr_pdcp_integrity_nia1_integrity(void *integrity_context,
unsigned char *out,
unsigned char *buffer, int length,
int bearer, int count, int direction)
{
stream_cipher_t *ctx = integrity_context;
ctx->message = buffer;
ctx->count = count;
ctx->bearer = bearer-1;
ctx->direction = direction;
ctx->blength = length * 8;
stream_compute_integrity_eia1(ctx, out);
}
void nr_pdcp_integrity_nia1_free_integrity(void *integrity_context)
{
stream_cipher_t *ctx = integrity_context;
free(ctx->key);
free(ctx);
}
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef _NR_PDCP_INTEGRITY_NIA1_H_
#define _NR_PDCP_INTEGRITY_NIA1_H_
void *nr_pdcp_integrity_nia1_init(unsigned char *integrity_key);
void nr_pdcp_integrity_nia1_integrity(void *integrity_context,
unsigned char *out,
unsigned char *buffer, int length,
int bearer, int count, int direction);
void nr_pdcp_integrity_nia1_free_integrity(void *integrity_context);
#endif /* _NR_PDCP_INTEGRITY_NIA1_H_ */
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