diff --git a/CMakeLists.txt b/CMakeLists.txt index bef6278246a2481b9abfef3792d09c6c8dfe7723..eb6707c4182ffb5cb81cb218e1b6023e88b70ed1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,10 +300,6 @@ target_link_libraries(lte_rrc PRIVATE nr_rrc) add_library(nr_rrc ${OPENAIR2_DIR}/RRC/NR/MESSAGES/asn1_msg.c) target_link_libraries(nr_rrc PUBLIC asn1_nr_rrc asn1_lte_rrc) - -# S1AP and NGAP need crypt library -pkg_check_modules(libcrypt REQUIRED libcrypt) - # S1AP ############## set(S1AP_DIR ${OPENAIR3_DIR}/S1AP) diff --git a/openair3/NGAP/ngap_gNB.c b/openair3/NGAP/ngap_gNB.c index f877e9d4ba24566222ec9f188600ccd758246054..09dc9321a18d9eb3baf69d8edb0a545e82778c42 100644 --- a/openair3/NGAP/ngap_gNB.c +++ b/openair3/NGAP/ngap_gNB.c @@ -33,7 +33,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> -#include <crypt.h> +#include "openair3/SECU/kdf.h" #include "tree.h" #include "queue.h" @@ -71,17 +71,20 @@ void ngap_gNB_handle_register_gNB(instance_t instance, ngap_register_gnb_req_t * void ngap_gNB_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp); -uint32_t ngap_generate_gNB_id(void) { - char *out; - char hostname[50]; - int ret; - uint32_t gNB_id; +uint32_t ngap_generate_gNB_id(void) +{ /* Retrieve the host name */ - ret = gethostname(hostname, sizeof(hostname)); + char hostname[32] = {0}; + int const ret = gethostname(hostname, sizeof(hostname)); DevAssert(ret == 0); - out = crypt(hostname, "eurecom"); - DevAssert(out != NULL); - gNB_id = ((out[0] << 24) | (out[1] << 16) | (out[2] << 8) | out[3]); + + uint8_t key[32] = {"eurecom"}; + byte_array_t data = {.len = 32, .buf = (uint8_t *)hostname}; + + uint8_t out[32] = {0}; + kdf(key, data, 32, out); + + uint32_t const gNB_id = ((out[0] << 24) | (out[1] << 16) | (out[2] << 8) | out[3]); return gNB_id; } diff --git a/openair3/S1AP/s1ap_eNB.c b/openair3/S1AP/s1ap_eNB.c index 700148f05e32754ed3f27100abb5e4fe5f23b54e..2baf315599c6c000664f12211047ae490d6d5b44 100644 --- a/openair3/S1AP/s1ap_eNB.c +++ b/openair3/S1AP/s1ap_eNB.c @@ -32,7 +32,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> -#include <crypt.h> +#include "openair3/SECU/kdf.h" #include "tree.h" #include "queue.h" @@ -108,17 +108,20 @@ int s1ap_timer_remove(long timer_id) return ret; } -uint32_t s1ap_generate_eNB_id(void) { - char *out; - char hostname[50]; - int ret; - uint32_t eNB_id; +uint32_t s1ap_generate_eNB_id(void) +{ /* Retrieve the host name */ - ret = gethostname(hostname, sizeof(hostname)); + char hostname[32] = {0}; + int const ret = gethostname(hostname, sizeof(hostname)); DevAssert(ret == 0); - out = crypt(hostname, "eurecom"); - DevAssert(out != NULL); - eNB_id = ((out[0] << 24) | (out[1] << 16) | (out[2] << 8) | out[3]); + + uint8_t key[32] = {"eurecom"}; + byte_array_t data = {.len = 32, .buf = (uint8_t *)hostname}; + + uint8_t out[32] = {0}; + kdf(key, data, 32, out); + + uint32_t const eNB_id = ((out[0] << 24) | (out[1] << 16) | (out[2] << 8) | out[3]); return eNB_id; } diff --git a/openair3/SECU/kdf.h b/openair3/SECU/kdf.h index 9567296bd2cd593f85cb8dc9c7b2d6e44c52ea6e..ad8a842fada24f4d2b96b2643c9c12a90a66f083 100644 --- a/openair3/SECU/kdf.h +++ b/openair3/SECU/kdf.h @@ -24,7 +24,7 @@ #include <stdint.h> #include <stdlib.h> -#include "byte_array.h" +#include "common/utils/ds/byte_array.h" void kdf(const uint8_t key[32], byte_array_t data, size_t len, uint8_t out[len]);