Introduced Subscription identifier de-concealing

o Generate the private key as below.
   $ openssl genpkey -algorithm X25519 -out /etc/open5gs/hnet/curve25519-1.key
   $ openssl ecparam -name prime256v1 -genkey -conv_form compressed -out /etc/open5gs/hnet/secp256r1-2.key

 o The private and public keys can be viewed with the command.
   The public key is used when creating the SIM.
   $ openssl pkey -in /etc/open5gs/hnet/curve25519-1.key -text
   $ openssl ec -in /etc/open5gs/hnet/secp256r1-2.key -conv_form compressed -text

In ausf/udm.yaml

 hnet:
    o Home network public key identifier(PKI) value : 1
      Protection scheme identifier : ECIES scheme profile A
    - id: 1
      scheme: 1
      key: /etc/open5gs/hnet/curve25519-1.key

    o Home network public key identifier(PKI) value : 2
      Protection scheme identifier : ECIES scheme profile B
    - id: 2
      scheme: 2
      key: /etc/open5gs/hnet/secp256r1-2.key

    o Home network public key identifier(PKI) value : 3
      Protection scheme identifier : ECIES scheme profile A
    - id: 3
      scheme: 1
      key: /etc/open5gs/hnet/curve25519-1.key

    o Home network public key identifier(PKI) value : 4
      Protection scheme identifier : ECIES scheme profile B
    - id: 4
      scheme: 2
      key: /etc/open5gs/hnet/secp256r1-2.key

Related to #1779
This commit is contained in:
Sukchan Lee 2022-12-24 20:22:45 +09:00
parent 0ebe07c83d
commit 79d46be086
120 changed files with 5342 additions and 1199 deletions

View File

@ -59,6 +59,61 @@ tls:
key: @sysconfdir@/open5gs/tls/ausf.key
cert: @sysconfdir@/open5gs/tls/ausf.crt
#
# o Generate the private key as below.
# $ openssl genpkey -algorithm X25519 -out /etc/open5gs/hnet/curve25519-1.key
# $ openssl ecparam -name prime256v1 -genkey -conv_form compressed -out /etc/open5gs/hnet/secp256r1-2.key
#
# o The private and public keys can be viewed with the command.
# The public key is used when creating the SIM.
# $ openssl pkey -in /etc/open5gs/hnet/curve25519-1.key -text
# $ openssl ec -in /etc/open5gs/hnet/secp256r1-2.key -conv_form compressed -text
#
# hnet:
# o Home network public key identifier(PKI) value : 1
# Protection scheme identifier : ECIES scheme profile A
# - id: 1
# scheme: 1
# key: /etc/open5gs/hnet/curve25519-1.key
#
# o Home network public key identifier(PKI) value : 2
# Protection scheme identifier : ECIES scheme profile B
# - id: 2
# scheme: 2
# key: /etc/open5gs/hnet/secp256r1-2.key
#
# o Home network public key identifier(PKI) value : 3
# Protection scheme identifier : ECIES scheme profile A
# - id: 3
# scheme: 1
# key: /etc/open5gs/hnet/curve25519-1.key
#
# o Home network public key identifier(PKI) value : 4
# Protection scheme identifier : ECIES scheme profile B
# - id: 4
# scheme: 2
# key: /etc/open5gs/hnet/secp256r1-2.key
#
hnet:
- id: 1
scheme: 1
key: @sysconfdir@/open5gs/hnet/curve25519-1.key
- id: 2
scheme: 2
key: @sysconfdir@/open5gs/hnet/secp256r1-2.key
- id: 3
scheme: 1
key: @sysconfdir@/open5gs/hnet/curve25519-3.key
- id: 4
scheme: 2
key: @sysconfdir@/open5gs/hnet/secp256r1-4.key
- id: 5
scheme: 1
key: @sysconfdir@/open5gs/hnet/curve25519-5.key
- id: 6
scheme: 2
key: @sysconfdir@/open5gs/hnet/secp256r1-6.key
#
# ausf:
#

View File

@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VuBCIEIBDJxn6GGlYloduPaEEjiW2bNQYZnT3xlo4HtshEi7FH
-----END PRIVATE KEY-----

View File

@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VuBCIEIFAK2WjCQjB8TU7COXwdIKVhKGjPa+SJuyOVObjfW9hM
-----END PRIVATE KEY-----

View File

@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VuBCIEIHh8rsYF8otbnyb8bcrhD1AAV5C9iBtjTlYJY3k5k0dt
-----END PRIVATE KEY-----

View File

@ -0,0 +1,38 @@
# Copyright (C) 2022 by Sukchan Lee <acetcom@gmail.com>
# This file is part of Open5GS.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
hnet_sysconfdir = join_paths(open5gs_sysconfdir, 'hnet')
meson.add_install_script(python3_exe, '-c',
mkdir_p.format(hnet_sysconfdir))
hnet_security = '''
curve25519-1.key
secp256r1-2.key
curve25519-3.key
secp256r1-4.key
curve25519-5.key
secp256r1-6.key
'''.split()
foreach file : hnet_security
gen = configure_file(
input : file,
output : file,
configuration : conf_data)
meson.add_install_script(python3_exe, '-c',
install_conf.format(gen, hnet_sysconfdir))
endforeach

View File

@ -0,0 +1,8 @@
-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIHSp+RhHH1bzvv2lxR1zij+U9aUtS8nbl5n1Il+8zd5BoAoGCCqGSM49
AwEHoUQDQgAEre/NExfRzoVi7CW5G0gAEg4SNtbiZh6kI1qE48hdokS8QqWUz1YS
9J6PvihX2OSZ+RMixzf8zxu9tuTUJKgKlQ==
-----END EC PRIVATE KEY-----

View File

@ -0,0 +1,8 @@
-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIAGZvsOAU0YMHhBK33hRkGMPkA3Xefq5b5hPQD6qnf5goAoGCCqGSM49
AwEHoUQDQgAEdXfTAGY+0ibQoO9bfmk7+M/l//BiMzO6lNIUEMSj1k3k9SQPygGY
jAuUHpVM4Uo6cWxuyurEn8pWn1vF3tVhbg==
-----END EC PRIVATE KEY-----

View File

@ -0,0 +1,8 @@
-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIG3VKSXh/3WK0HzCkN1DgeUjF7TSLgAUyMn/WGHsxrZ3oAoGCCqGSM49
AwEHoUQDQgAENU1ibHe7oWu4m6M8P0XoA78ZNKtdIsJgVU0nCk/c5sC3V+/4GuxU
owtbASEXQZg4SGvts+1Yqz0p4WwCAAcwpQ==
-----END EC PRIVATE KEY-----

View File

@ -48,3 +48,4 @@ foreach file : open5gs_conf
endforeach
subdir('tls')
subdir('hnet')

View File

@ -59,6 +59,61 @@ tls:
key: @sysconfdir@/open5gs/tls/udm.key
cert: @sysconfdir@/open5gs/tls/udm.crt
#
# o Generate the private key as below.
# $ openssl genpkey -algorithm X25519 -out /etc/open5gs/hnet/curve25519-1.key
# $ openssl ecparam -name prime256v1 -genkey -conv_form compressed -out /etc/open5gs/hnet/secp256r1-2.key
#
# o The private and public keys can be viewed with the command.
# The public key is used when creating the SIM.
# $ openssl pkey -in /etc/open5gs/hnet/curve25519-1.key -text
# $ openssl ec -in /etc/open5gs/hnet/secp256r1-2.key -conv_form compressed -text
#
# hnet:
# o Home network public key identifier(PKI) value : 1
# Protection scheme identifier : ECIES scheme profile A
# - id: 1
# scheme: 1
# key: /etc/open5gs/hnet/curve25519-1.key
#
# o Home network public key identifier(PKI) value : 2
# Protection scheme identifier : ECIES scheme profile B
# - id: 2
# scheme: 2
# key: /etc/open5gs/hnet/secp256r1-2.key
#
# o Home network public key identifier(PKI) value : 3
# Protection scheme identifier : ECIES scheme profile A
# - id: 3
# scheme: 1
# key: /etc/open5gs/hnet/curve25519-1.key
#
# o Home network public key identifier(PKI) value : 4
# Protection scheme identifier : ECIES scheme profile B
# - id: 4
# scheme: 2
# key: /etc/open5gs/hnet/secp256r1-2.key
#
hnet:
- id: 1
scheme: 1
key: @sysconfdir@/open5gs/hnet/curve25519-1.key
- id: 2
scheme: 2
key: @sysconfdir@/open5gs/hnet/secp256r1-2.key
- id: 3
scheme: 1
key: @sysconfdir@/open5gs/hnet/curve25519-3.key
- id: 4
scheme: 2
key: @sysconfdir@/open5gs/hnet/secp256r1-4.key
- id: 5
scheme: 1
key: @sysconfdir@/open5gs/hnet/curve25519-5.key
- id: 6
scheme: 2
key: @sysconfdir@/open5gs/hnet/secp256r1-6.key
#
# udm:
#

View File

@ -13,6 +13,14 @@ tls:
key: @build_configs_dir@/open5gs/tls/testclient.key
cert: @build_configs_dir@/open5gs/tls/testclient.crt
hnet:
- id: 1
scheme: 1
key: @build_configs_dir@/open5gs/hnet/curve25519-1.key
- id: 2
scheme: 2
key: @build_configs_dir@/open5gs/hnet/secp256r1-2.key
parameter:
# no_nrf: true
# no_scp: true

View File

@ -2,4 +2,6 @@ usr/lib/*/libogs*.so*
usr/lib/*/libfd*.so*
usr/lib/*/freeDiameter/*.fdx
configs/open5gs/tls/ca.crt /etc/open5gs/tls
configs/open5gs/hnet/curve25519-*.key /etc/open5gs/hnet
configs/open5gs/hnet/secp256r1-*.key /etc/open5gs/hnet
configs/logrotate/open5gs /etc/logrotate.d

View File

@ -20,7 +20,7 @@
#ifndef OGS_APP_H
#define OGS_APP_H
#include "proto/ogs-proto.h"
#include "crypt/ogs-crypt.h"
#define OGS_APP_INSIDE

View File

@ -62,44 +62,6 @@ ogs_app_context_t *ogs_app()
return &self;
}
bool ogs_app_tls_server_enabled(void)
{
if (self.tls.enabled == OGS_APP_TLS_ENABLED_AUTO) {
if (self.tls.server.key && self.tls.server.cert)
return true;
else
return false;
} else if (self.tls.enabled == OGS_APP_TLS_ENABLED_YES) {
ogs_assert(self.tls.server.key);
ogs_assert(self.tls.server.cert);
return true;
} else if (self.tls.enabled == OGS_APP_TLS_ENABLED_NO) {
return false;
} else {
ogs_error("Unknown TLS enabled mode [%d]", self.tls.enabled);
return false;
}
}
bool ogs_app_tls_client_enabled(void)
{
if (self.tls.enabled == OGS_APP_TLS_ENABLED_AUTO) {
if (self.tls.client.key && self.tls.client.cert)
return true;
else
return false;
} else if (self.tls.enabled == OGS_APP_TLS_ENABLED_YES) {
ogs_assert(self.tls.client.key);
ogs_assert(self.tls.client.cert);
return true;
} else if (self.tls.enabled == OGS_APP_TLS_ENABLED_NO) {
return false;
} else {
ogs_error("Unknown TLS enabled mode [%d]", self.tls.enabled);
return false;
}
}
static void recalculate_pool_size(void)
{
self.pool.packet = self.max.ue * OGS_MAX_NUM_OF_PACKET_BUFFER;
@ -205,8 +167,6 @@ static void regenerate_all_timer_duration(void)
static void app_context_prepare(void)
{
self.tls.enabled = OGS_APP_TLS_ENABLED_AUTO;
#define USRSCTP_LOCAL_UDP_PORT 9899
self.usrsctp.udp_port = USRSCTP_LOCAL_UDP_PORT;
@ -274,27 +234,6 @@ static int app_context_validation(void)
return OGS_ERROR;
}
if (self.tls.enabled == OGS_APP_TLS_ENABLED_YES) {
if (!self.tls.server.key) {
ogs_error("No Server Key");
return OGS_ERROR;
}
if (!self.tls.server.cert) {
ogs_error("No Server Certificate");
return OGS_ERROR;
}
if (!self.tls.client.key) {
ogs_error("No Client Key");
return OGS_ERROR;
}
if (!self.tls.client.cert) {
ogs_error("No Client Certificate");
return OGS_ERROR;
}
}
return OGS_OK;
}
@ -329,65 +268,6 @@ int ogs_app_context_parse_config(void)
ogs_yaml_iter_value(&logger_iter);
}
}
} else if (!strcmp(root_key, "tls")) {
ogs_yaml_iter_t tls_iter;
ogs_yaml_iter_recurse(&root_iter, &tls_iter);
while (ogs_yaml_iter_next(&tls_iter)) {
const char *tls_key = ogs_yaml_iter_key(&tls_iter);
ogs_assert(tls_key);
if (!strcmp(tls_key, "enabled")) {
const char *v = ogs_yaml_iter_value(&tls_iter);
if (!strcmp(v, "auto"))
self.tls.enabled = OGS_APP_TLS_ENABLED_AUTO;
else if (!strcmp(v, "yes"))
self.tls.enabled = OGS_APP_TLS_ENABLED_YES;
else if (!strcmp(v, "no"))
self.tls.enabled = OGS_APP_TLS_ENABLED_NO;
else
ogs_warn("unknown 'tls.enabled' value `%s`", v);
} else if (!strcmp(tls_key, "server")) {
ogs_yaml_iter_t server_iter;
ogs_yaml_iter_recurse(&tls_iter, &server_iter);
while (ogs_yaml_iter_next(&server_iter)) {
const char *server_key =
ogs_yaml_iter_key(&server_iter);
ogs_assert(server_key);
if (!strcmp(server_key, "cacert")) {
self.tls.server.cacert =
ogs_yaml_iter_value(&server_iter);
} else if (!strcmp(server_key, "cert")) {
self.tls.server.cert =
ogs_yaml_iter_value(&server_iter);
} else if (!strcmp(server_key, "key")) {
self.tls.server.key =
ogs_yaml_iter_value(&server_iter);
} else
ogs_warn("unknown key `%s`", server_key);
}
} else if (!strcmp(tls_key, "client")) {
ogs_yaml_iter_t client_iter;
ogs_yaml_iter_recurse(&tls_iter, &client_iter);
while (ogs_yaml_iter_next(&client_iter)) {
const char *client_key =
ogs_yaml_iter_key(&client_iter);
ogs_assert(client_key);
if (!strcmp(client_key, "cacert")) {
self.tls.client.cacert =
ogs_yaml_iter_value(&client_iter);
} else if (!strcmp(client_key, "cert")) {
self.tls.client.cert =
ogs_yaml_iter_value(&client_iter);
} else if (!strcmp(client_key, "key")) {
self.tls.client.key =
ogs_yaml_iter_value(&client_iter);
} else
ogs_warn("unknown key `%s`", client_key);
}
} else
ogs_warn("unknown key `%s`", tls_key);
}
} else if (!strcmp(root_key, "parameter")) {
ogs_yaml_iter_t parameter_iter;
ogs_yaml_iter_recurse(&root_iter, &parameter_iter);

View File

@ -28,12 +28,6 @@
extern "C" {
#endif
typedef enum {
OGS_APP_TLS_ENABLED_AUTO = 0,
OGS_APP_TLS_ENABLED_YES,
OGS_APP_TLS_ENABLED_NO,
} ogs_app_tls_enabled_mode_e;
typedef struct ogs_app_context_s {
const char *version;
@ -49,15 +43,6 @@ typedef struct ogs_app_context_s {
const char *domain;
} logger;
struct {
ogs_app_tls_enabled_mode_e enabled;
struct {
const char *cacert;
const char *cert;
const char *key;
} server, client;
} tls;
ogs_queue_t *queue;
ogs_timer_mgr_t *timer_mgr;
ogs_pollset_t *pollset;

View File

@ -261,6 +261,7 @@ libcore_sources = files('''
ogs-hash.h
ogs-misc.h
ogs-getopt.h
ogs-file.h
abts.h
ogs-abort.c
@ -296,6 +297,7 @@ libcore_sources = files('''
ogs-hash.c
ogs-misc.c
ogs-getopt.c
ogs-file.c
ogs-core.c
abts.c
'''.split())

View File

@ -29,7 +29,7 @@
#include "ogs-core.h"
void *ogs_ascii_to_hex(char *in, int in_len, void *out, int out_len)
int ogs_ascii_to_hex(char *in, int in_len, void *out, int out_len)
{
int i = 0, j = 0, k = 0, hex;
uint8_t *out_p = out;
@ -49,7 +49,7 @@ void *ogs_ascii_to_hex(char *in, int in_len, void *out, int out_len)
i++;
}
return out;
return j;
}
void *ogs_hex_to_ascii(void *in, int in_len, void *out, int out_len)

View File

@ -28,8 +28,14 @@
extern "C" {
#endif
#define OGS_HEX(I, I_LEN, O) ogs_ascii_to_hex((char*)I, I_LEN, O, sizeof(O))
void *ogs_ascii_to_hex(char *in, int in_len, void *out, int out_len);
int ogs_ascii_to_hex(char *in, int in_len, void *out, int out_len);
static ogs_inline void *ogs_hex_from_string(
const char *str, void *out, int out_len)
{
ogs_ascii_to_hex((char*)str, strlen(str), out, out_len);
return out;
}
void *ogs_hex_to_ascii(void *in, int in_len, void *out, int out_len);
void *ogs_uint64_to_buffer(uint64_t num, int size, void *buffer);
uint64_t ogs_buffer_to_uint64(void *buffer, int size);

View File

@ -62,6 +62,7 @@
#include "core/ogs-hash.h"
#include "core/ogs-misc.h"
#include "core/ogs-getopt.h"
#include "core/ogs-file.h"
#undef OGS_CORE_INSIDE

51
lib/core/ogs-file.c Normal file
View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 2022 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ogs-core.h"
int ogs_file_read_full(
const char *filename, void *buf, size_t nbytes, size_t *bytes_read)
{
FILE *fp = NULL;
size_t total_read = 0, amt;
ogs_assert(filename);
ogs_assert(buf);
ogs_assert(nbytes);
fp = fopen(filename, "rb");
if (!fp) {
ogs_error("Cannot find file [%s]", filename);
return OGS_ERROR;
}
amt = fread(buf, 1, nbytes, fp);
if (bytes_read != NULL)
*bytes_read = amt;
fclose(fp);
if (amt > 0)
return OGS_OK;
ogs_error("Cannot read file [name:%s,amt:%d,total_read:%d]",
filename, (int)amt, (int)total_read);
return OGS_ERROR;
}

38
lib/core/ogs-file.h Normal file
View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2022 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION)
#error "This header cannot be included directly."
#endif
#ifndef OGS_FILE_H
#define OGS_FILE_H
#ifdef __cplusplus
extern "C" {
#endif
int ogs_file_read_full(
const char *filename, void *buf, size_t nbytes, size_t *bytes_read);
#ifdef __cplusplus
}
#endif
#endif /* OGS_FILE_H */

View File

@ -0,0 +1,864 @@
/* Copyright 2008, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* curve25519-donna: Curve25519 elliptic curve, public key function
*
* http://code.google.com/p/curve25519-donna/
*
* Adam Langley <agl@imperialviolet.org>
*
* Derived from public domain C code by Daniel J. Bernstein <djb@cr.yp.to>
*
* More information about curve25519 can be found here
* http://cr.yp.to/ecdh.html
*
* djb's sample implementation of curve25519 is written in a special assembly
* language called qhasm and uses the floating point registers.
*
* This is, almost, a clean room reimplementation from the curve25519 paper. It
* uses many of the tricks described therein. Only the crecip function is taken
* from the sample implementation. */
#if 0 /* modified by acetcom */
#include <string.h>
#include <stdint.h>
#ifdef _MSC_VER
#define inline __inline
#endif
#else
#include "ogs-crypt.h"
#endif
typedef uint8_t u8;
typedef int32_t s32;
typedef int64_t limb;
/* Field element representation:
*
* Field elements are written as an array of signed, 64-bit limbs, least
* significant first. The value of the field element is:
* x[0] + 2^26·x[1] + x^51·x[2] + 2^102·x[3] + ...
*
* i.e. the limbs are 26, 25, 26, 25, ... bits wide. */
/* Sum two numbers: output += in */
static void fsum(limb *output, const limb *in) {
unsigned i;
for (i = 0; i < 10; i += 2) {
output[0+i] = output[0+i] + in[0+i];
output[1+i] = output[1+i] + in[1+i];
}
}
/* Find the difference of two numbers: output = in - output
* (note the order of the arguments!). */
static void fdifference(limb *output, const limb *in) {
unsigned i;
for (i = 0; i < 10; ++i) {
output[i] = in[i] - output[i];
}
}
/* Multiply a number by a scalar: output = in * scalar */
static void fscalar_product(limb *output, const limb *in, const limb scalar) {
unsigned i;
for (i = 0; i < 10; ++i) {
output[i] = in[i] * scalar;
}
}
/* Multiply two numbers: output = in2 * in
*
* output must be distinct to both inputs. The inputs are reduced coefficient
* form, the output is not.
*
* output[x] <= 14 * the largest product of the input limbs. */
static void fproduct(limb *output, const limb *in2, const limb *in) {
output[0] = ((limb) ((s32) in2[0])) * ((s32) in[0]);
output[1] = ((limb) ((s32) in2[0])) * ((s32) in[1]) +
((limb) ((s32) in2[1])) * ((s32) in[0]);
output[2] = 2 * ((limb) ((s32) in2[1])) * ((s32) in[1]) +
((limb) ((s32) in2[0])) * ((s32) in[2]) +
((limb) ((s32) in2[2])) * ((s32) in[0]);
output[3] = ((limb) ((s32) in2[1])) * ((s32) in[2]) +
((limb) ((s32) in2[2])) * ((s32) in[1]) +
((limb) ((s32) in2[0])) * ((s32) in[3]) +
((limb) ((s32) in2[3])) * ((s32) in[0]);
output[4] = ((limb) ((s32) in2[2])) * ((s32) in[2]) +
2 * (((limb) ((s32) in2[1])) * ((s32) in[3]) +
((limb) ((s32) in2[3])) * ((s32) in[1])) +
((limb) ((s32) in2[0])) * ((s32) in[4]) +
((limb) ((s32) in2[4])) * ((s32) in[0]);
output[5] = ((limb) ((s32) in2[2])) * ((s32) in[3]) +
((limb) ((s32) in2[3])) * ((s32) in[2]) +
((limb) ((s32) in2[1])) * ((s32) in[4]) +
((limb) ((s32) in2[4])) * ((s32) in[1]) +
((limb) ((s32) in2[0])) * ((s32) in[5]) +
((limb) ((s32) in2[5])) * ((s32) in[0]);
output[6] = 2 * (((limb) ((s32) in2[3])) * ((s32) in[3]) +
((limb) ((s32) in2[1])) * ((s32) in[5]) +
((limb) ((s32) in2[5])) * ((s32) in[1])) +
((limb) ((s32) in2[2])) * ((s32) in[4]) +
((limb) ((s32) in2[4])) * ((s32) in[2]) +
((limb) ((s32) in2[0])) * ((s32) in[6]) +
((limb) ((s32) in2[6])) * ((s32) in[0]);
output[7] = ((limb) ((s32) in2[3])) * ((s32) in[4]) +
((limb) ((s32) in2[4])) * ((s32) in[3]) +
((limb) ((s32) in2[2])) * ((s32) in[5]) +
((limb) ((s32) in2[5])) * ((s32) in[2]) +
((limb) ((s32) in2[1])) * ((s32) in[6]) +
((limb) ((s32) in2[6])) * ((s32) in[1]) +
((limb) ((s32) in2[0])) * ((s32) in[7]) +
((limb) ((s32) in2[7])) * ((s32) in[0]);
output[8] = ((limb) ((s32) in2[4])) * ((s32) in[4]) +
2 * (((limb) ((s32) in2[3])) * ((s32) in[5]) +
((limb) ((s32) in2[5])) * ((s32) in[3]) +
((limb) ((s32) in2[1])) * ((s32) in[7]) +
((limb) ((s32) in2[7])) * ((s32) in[1])) +
((limb) ((s32) in2[2])) * ((s32) in[6]) +
((limb) ((s32) in2[6])) * ((s32) in[2]) +
((limb) ((s32) in2[0])) * ((s32) in[8]) +
((limb) ((s32) in2[8])) * ((s32) in[0]);
output[9] = ((limb) ((s32) in2[4])) * ((s32) in[5]) +
((limb) ((s32) in2[5])) * ((s32) in[4]) +
((limb) ((s32) in2[3])) * ((s32) in[6]) +
((limb) ((s32) in2[6])) * ((s32) in[3]) +
((limb) ((s32) in2[2])) * ((s32) in[7]) +
((limb) ((s32) in2[7])) * ((s32) in[2]) +
((limb) ((s32) in2[1])) * ((s32) in[8]) +
((limb) ((s32) in2[8])) * ((s32) in[1]) +
((limb) ((s32) in2[0])) * ((s32) in[9]) +
((limb) ((s32) in2[9])) * ((s32) in[0]);
output[10] = 2 * (((limb) ((s32) in2[5])) * ((s32) in[5]) +
((limb) ((s32) in2[3])) * ((s32) in[7]) +
((limb) ((s32) in2[7])) * ((s32) in[3]) +
((limb) ((s32) in2[1])) * ((s32) in[9]) +
((limb) ((s32) in2[9])) * ((s32) in[1])) +
((limb) ((s32) in2[4])) * ((s32) in[6]) +
((limb) ((s32) in2[6])) * ((s32) in[4]) +
((limb) ((s32) in2[2])) * ((s32) in[8]) +
((limb) ((s32) in2[8])) * ((s32) in[2]);
output[11] = ((limb) ((s32) in2[5])) * ((s32) in[6]) +
((limb) ((s32) in2[6])) * ((s32) in[5]) +
((limb) ((s32) in2[4])) * ((s32) in[7]) +
((limb) ((s32) in2[7])) * ((s32) in[4]) +
((limb) ((s32) in2[3])) * ((s32) in[8]) +
((limb) ((s32) in2[8])) * ((s32) in[3]) +
((limb) ((s32) in2[2])) * ((s32) in[9]) +
((limb) ((s32) in2[9])) * ((s32) in[2]);
output[12] = ((limb) ((s32) in2[6])) * ((s32) in[6]) +
2 * (((limb) ((s32) in2[5])) * ((s32) in[7]) +
((limb) ((s32) in2[7])) * ((s32) in[5]) +
((limb) ((s32) in2[3])) * ((s32) in[9]) +
((limb) ((s32) in2[9])) * ((s32) in[3])) +
((limb) ((s32) in2[4])) * ((s32) in[8]) +
((limb) ((s32) in2[8])) * ((s32) in[4]);
output[13] = ((limb) ((s32) in2[6])) * ((s32) in[7]) +
((limb) ((s32) in2[7])) * ((s32) in[6]) +
((limb) ((s32) in2[5])) * ((s32) in[8]) +
((limb) ((s32) in2[8])) * ((s32) in[5]) +
((limb) ((s32) in2[4])) * ((s32) in[9]) +
((limb) ((s32) in2[9])) * ((s32) in[4]);
output[14] = 2 * (((limb) ((s32) in2[7])) * ((s32) in[7]) +
((limb) ((s32) in2[5])) * ((s32) in[9]) +
((limb) ((s32) in2[9])) * ((s32) in[5])) +
((limb) ((s32) in2[6])) * ((s32) in[8]) +
((limb) ((s32) in2[8])) * ((s32) in[6]);
output[15] = ((limb) ((s32) in2[7])) * ((s32) in[8]) +
((limb) ((s32) in2[8])) * ((s32) in[7]) +
((limb) ((s32) in2[6])) * ((s32) in[9]) +
((limb) ((s32) in2[9])) * ((s32) in[6]);
output[16] = ((limb) ((s32) in2[8])) * ((s32) in[8]) +
2 * (((limb) ((s32) in2[7])) * ((s32) in[9]) +
((limb) ((s32) in2[9])) * ((s32) in[7]));
output[17] = ((limb) ((s32) in2[8])) * ((s32) in[9]) +
((limb) ((s32) in2[9])) * ((s32) in[8]);
output[18] = 2 * ((limb) ((s32) in2[9])) * ((s32) in[9]);
}
/* Reduce a long form to a short form by taking the input mod 2^255 - 19.
*
* On entry: |output[i]| < 14*2^54
* On exit: |output[0..8]| < 280*2^54 */
static void freduce_degree(limb *output) {
/* Each of these shifts and adds ends up multiplying the value by 19.
*
* For output[0..8], the absolute entry value is < 14*2^54 and we add, at
* most, 19*14*2^54 thus, on exit, |output[0..8]| < 280*2^54. */
output[8] += output[18] << 4;
output[8] += output[18] << 1;
output[8] += output[18];
output[7] += output[17] << 4;
output[7] += output[17] << 1;
output[7] += output[17];
output[6] += output[16] << 4;
output[6] += output[16] << 1;
output[6] += output[16];
output[5] += output[15] << 4;
output[5] += output[15] << 1;
output[5] += output[15];
output[4] += output[14] << 4;
output[4] += output[14] << 1;
output[4] += output[14];
output[3] += output[13] << 4;
output[3] += output[13] << 1;
output[3] += output[13];
output[2] += output[12] << 4;
output[2] += output[12] << 1;
output[2] += output[12];
output[1] += output[11] << 4;
output[1] += output[11] << 1;
output[1] += output[11];
output[0] += output[10] << 4;
output[0] += output[10] << 1;
output[0] += output[10];
}
#if (-1 & 3) != 3
#error "This code only works on a two's complement system"
#endif
/* return v / 2^26, using only shifts and adds.
*
* On entry: v can take any value. */
static inline limb
div_by_2_26(const limb v)
{
/* High word of v; no shift needed. */
const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32);
/* Set to all 1s if v was negative; else set to 0s. */
const int32_t sign = ((int32_t) highword) >> 31;
/* Set to 0x3ffffff if v was negative; else set to 0. */
const int32_t roundoff = ((uint32_t) sign) >> 6;
/* Should return v / (1<<26) */
return (v + roundoff) >> 26;
}
/* return v / (2^25), using only shifts and adds.
*
* On entry: v can take any value. */
static inline limb
div_by_2_25(const limb v)
{
/* High word of v; no shift needed*/
const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32);
/* Set to all 1s if v was negative; else set to 0s. */
const int32_t sign = ((int32_t) highword) >> 31;
/* Set to 0x1ffffff if v was negative; else set to 0. */
const int32_t roundoff = ((uint32_t) sign) >> 7;
/* Should return v / (1<<25) */
return (v + roundoff) >> 25;
}
/* Reduce all coefficients of the short form input so that |x| < 2^26.
*
* On entry: |output[i]| < 280*2^54 */
static void freduce_coefficients(limb *output) {
unsigned i;
output[10] = 0;
for (i = 0; i < 10; i += 2) {
limb over = div_by_2_26(output[i]);
/* The entry condition (that |output[i]| < 280*2^54) means that over is, at
* most, 280*2^28 in the first iteration of this loop. This is added to the
* next limb and we can approximate the resulting bound of that limb by
* 281*2^54. */
output[i] -= over << 26;
output[i+1] += over;
/* For the first iteration, |output[i+1]| < 281*2^54, thus |over| <
* 281*2^29. When this is added to the next limb, the resulting bound can
* be approximated as 281*2^54.
*
* For subsequent iterations of the loop, 281*2^54 remains a conservative
* bound and no overflow occurs. */
over = div_by_2_25(output[i+1]);
output[i+1] -= over << 25;
output[i+2] += over;
}
/* Now |output[10]| < 281*2^29 and all other coefficients are reduced. */
output[0] += output[10] << 4;
output[0] += output[10] << 1;
output[0] += output[10];
output[10] = 0;
/* Now output[1..9] are reduced, and |output[0]| < 2^26 + 19*281*2^29
* So |over| will be no more than 2^16. */
{
limb over = div_by_2_26(output[0]);
output[0] -= over << 26;
output[1] += over;
}
/* Now output[0,2..9] are reduced, and |output[1]| < 2^25 + 2^16 < 2^26. The
* bound on |output[1]| is sufficient to meet our needs. */
}
/* A helpful wrapper around fproduct: output = in * in2.
*
* On entry: |in[i]| < 2^27 and |in2[i]| < 2^27.
*
* output must be distinct to both inputs. The output is reduced degree
* (indeed, one need only provide storage for 10 limbs) and |output[i]| < 2^26. */
static void
fmul(limb *output, const limb *in, const limb *in2) {
limb t[19];
fproduct(t, in, in2);
/* |t[i]| < 14*2^54 */
freduce_degree(t);
freduce_coefficients(t);
/* |t[i]| < 2^26 */
memcpy(output, t, sizeof(limb) * 10);
}
/* Square a number: output = in**2
*
* output must be distinct from the input. The inputs are reduced coefficient
* form, the output is not.
*
* output[x] <= 14 * the largest product of the input limbs. */
static void fsquare_inner(limb *output, const limb *in) {
output[0] = ((limb) ((s32) in[0])) * ((s32) in[0]);
output[1] = 2 * ((limb) ((s32) in[0])) * ((s32) in[1]);
output[2] = 2 * (((limb) ((s32) in[1])) * ((s32) in[1]) +
((limb) ((s32) in[0])) * ((s32) in[2]));
output[3] = 2 * (((limb) ((s32) in[1])) * ((s32) in[2]) +
((limb) ((s32) in[0])) * ((s32) in[3]));
output[4] = ((limb) ((s32) in[2])) * ((s32) in[2]) +
4 * ((limb) ((s32) in[1])) * ((s32) in[3]) +
2 * ((limb) ((s32) in[0])) * ((s32) in[4]);
output[5] = 2 * (((limb) ((s32) in[2])) * ((s32) in[3]) +
((limb) ((s32) in[1])) * ((s32) in[4]) +
((limb) ((s32) in[0])) * ((s32) in[5]));
output[6] = 2 * (((limb) ((s32) in[3])) * ((s32) in[3]) +
((limb) ((s32) in[2])) * ((s32) in[4]) +
((limb) ((s32) in[0])) * ((s32) in[6]) +
2 * ((limb) ((s32) in[1])) * ((s32) in[5]));
output[7] = 2 * (((limb) ((s32) in[3])) * ((s32) in[4]) +
((limb) ((s32) in[2])) * ((s32) in[5]) +
((limb) ((s32) in[1])) * ((s32) in[6]) +
((limb) ((s32) in[0])) * ((s32) in[7]));
output[8] = ((limb) ((s32) in[4])) * ((s32) in[4]) +
2 * (((limb) ((s32) in[2])) * ((s32) in[6]) +
((limb) ((s32) in[0])) * ((s32) in[8]) +
2 * (((limb) ((s32) in[1])) * ((s32) in[7]) +
((limb) ((s32) in[3])) * ((s32) in[5])));
output[9] = 2 * (((limb) ((s32) in[4])) * ((s32) in[5]) +
((limb) ((s32) in[3])) * ((s32) in[6]) +
((limb) ((s32) in[2])) * ((s32) in[7]) +
((limb) ((s32) in[1])) * ((s32) in[8]) +
((limb) ((s32) in[0])) * ((s32) in[9]));
output[10] = 2 * (((limb) ((s32) in[5])) * ((s32) in[5]) +
((limb) ((s32) in[4])) * ((s32) in[6]) +
((limb) ((s32) in[2])) * ((s32) in[8]) +
2 * (((limb) ((s32) in[3])) * ((s32) in[7]) +
((limb) ((s32) in[1])) * ((s32) in[9])));
output[11] = 2 * (((limb) ((s32) in[5])) * ((s32) in[6]) +
((limb) ((s32) in[4])) * ((s32) in[7]) +
((limb) ((s32) in[3])) * ((s32) in[8]) +
((limb) ((s32) in[2])) * ((s32) in[9]));
output[12] = ((limb) ((s32) in[6])) * ((s32) in[6]) +
2 * (((limb) ((s32) in[4])) * ((s32) in[8]) +
2 * (((limb) ((s32) in[5])) * ((s32) in[7]) +
((limb) ((s32) in[3])) * ((s32) in[9])));
output[13] = 2 * (((limb) ((s32) in[6])) * ((s32) in[7]) +
((limb) ((s32) in[5])) * ((s32) in[8]) +
((limb) ((s32) in[4])) * ((s32) in[9]));
output[14] = 2 * (((limb) ((s32) in[7])) * ((s32) in[7]) +
((limb) ((s32) in[6])) * ((s32) in[8]) +
2 * ((limb) ((s32) in[5])) * ((s32) in[9]));
output[15] = 2 * (((limb) ((s32) in[7])) * ((s32) in[8]) +
((limb) ((s32) in[6])) * ((s32) in[9]));
output[16] = ((limb) ((s32) in[8])) * ((s32) in[8]) +
4 * ((limb) ((s32) in[7])) * ((s32) in[9]);
output[17] = 2 * ((limb) ((s32) in[8])) * ((s32) in[9]);
output[18] = 2 * ((limb) ((s32) in[9])) * ((s32) in[9]);
}
/* fsquare sets output = in^2.
*
* On entry: The |in| argument is in reduced coefficients form and |in[i]| <
* 2^27.
*
* On exit: The |output| argument is in reduced coefficients form (indeed, one
* need only provide storage for 10 limbs) and |out[i]| < 2^26. */
static void
fsquare(limb *output, const limb *in) {
limb t[19];
fsquare_inner(t, in);
/* |t[i]| < 14*2^54 because the largest product of two limbs will be <
* 2^(27+27) and fsquare_inner adds together, at most, 14 of those
* products. */
freduce_degree(t);
freduce_coefficients(t);
/* |t[i]| < 2^26 */
memcpy(output, t, sizeof(limb) * 10);
}
/* Take a little-endian, 32-byte number and expand it into polynomial form */
static void
fexpand(limb *output, const u8 *input) {
#define F(n,start,shift,mask) \
output[n] = ((((limb) input[start + 0]) | \
((limb) input[start + 1]) << 8 | \
((limb) input[start + 2]) << 16 | \
((limb) input[start + 3]) << 24) >> shift) & mask;
F(0, 0, 0, 0x3ffffff);
F(1, 3, 2, 0x1ffffff);
F(2, 6, 3, 0x3ffffff);
F(3, 9, 5, 0x1ffffff);
F(4, 12, 6, 0x3ffffff);
F(5, 16, 0, 0x1ffffff);
F(6, 19, 1, 0x3ffffff);
F(7, 22, 3, 0x1ffffff);
F(8, 25, 4, 0x3ffffff);
F(9, 28, 6, 0x1ffffff);
#undef F
}
#if (-32 >> 1) != -16
#error "This code only works when >> does sign-extension on negative numbers"
#endif
/* s32_eq returns 0xffffffff iff a == b and zero otherwise. */
static s32 s32_eq(s32 a, s32 b) {
a = ~(a ^ b);
a &= a << 16;
a &= a << 8;
a &= a << 4;
a &= a << 2;
a &= a << 1;
return a >> 31;
}
/* s32_gte returns 0xffffffff if a >= b and zero otherwise, where a and b are
* both non-negative. */
static s32 s32_gte(s32 a, s32 b) {
a -= b;
/* a >= 0 iff a >= b. */
return ~(a >> 31);
}
/* Take a fully reduced polynomial form number and contract it into a
* little-endian, 32-byte array.
*
* On entry: |input_limbs[i]| < 2^26 */
static void
fcontract(u8 *output, limb *input_limbs) {
int i;
int j;
s32 input[10];
s32 mask;
/* |input_limbs[i]| < 2^26, so it's valid to convert to an s32. */
for (i = 0; i < 10; i++) {
input[i] = input_limbs[i];
}
for (j = 0; j < 2; ++j) {
for (i = 0; i < 9; ++i) {
if ((i & 1) == 1) {
/* This calculation is a time-invariant way to make input[i]
* non-negative by borrowing from the next-larger limb. */
const s32 mask = input[i] >> 31;
const s32 carry = -((input[i] & mask) >> 25);
input[i] = input[i] + (carry << 25);
input[i+1] = input[i+1] - carry;
} else {
const s32 mask = input[i] >> 31;
const s32 carry = -((input[i] & mask) >> 26);
input[i] = input[i] + (carry << 26);
input[i+1] = input[i+1] - carry;
}
}
/* There's no greater limb for input[9] to borrow from, but we can multiply
* by 19 and borrow from input[0], which is valid mod 2^255-19. */
{
const s32 mask = input[9] >> 31;
const s32 carry = -((input[9] & mask) >> 25);
input[9] = input[9] + (carry << 25);
input[0] = input[0] - (carry * 19);
}
/* After the first iteration, input[1..9] are non-negative and fit within
* 25 or 26 bits, depending on position. However, input[0] may be
* negative. */
}
/* The first borrow-propagation pass above ended with every limb
except (possibly) input[0] non-negative.
If input[0] was negative after the first pass, then it was because of a
carry from input[9]. On entry, input[9] < 2^26 so the carry was, at most,
one, since (2**26-1) >> 25 = 1. Thus input[0] >= -19.
In the second pass, each limb is decreased by at most one. Thus the second
borrow-propagation pass could only have wrapped around to decrease
input[0] again if the first pass left input[0] negative *and* input[1]
through input[9] were all zero. In that case, input[1] is now 2^25 - 1,
and this last borrow-propagation step will leave input[1] non-negative. */
{
const s32 mask = input[0] >> 31;
const s32 carry = -((input[0] & mask) >> 26);
input[0] = input[0] + (carry << 26);
input[1] = input[1] - carry;
}
/* All input[i] are now non-negative. However, there might be values between
* 2^25 and 2^26 in a limb which is, nominally, 25 bits wide. */
for (j = 0; j < 2; j++) {
for (i = 0; i < 9; i++) {
if ((i & 1) == 1) {
const s32 carry = input[i] >> 25;
input[i] &= 0x1ffffff;
input[i+1] += carry;
} else {
const s32 carry = input[i] >> 26;
input[i] &= 0x3ffffff;
input[i+1] += carry;
}
}
{
const s32 carry = input[9] >> 25;
input[9] &= 0x1ffffff;
input[0] += 19*carry;
}
}
/* If the first carry-chain pass, just above, ended up with a carry from
* input[9], and that caused input[0] to be out-of-bounds, then input[0] was
* < 2^26 + 2*19, because the carry was, at most, two.
*
* If the second pass carried from input[9] again then input[0] is < 2*19 and
* the input[9] -> input[0] carry didn't push input[0] out of bounds. */
/* It still remains the case that input might be between 2^255-19 and 2^255.
* In this case, input[1..9] must take their maximum value and input[0] must
* be >= (2^255-19) & 0x3ffffff, which is 0x3ffffed. */
mask = s32_gte(input[0], 0x3ffffed);
for (i = 1; i < 10; i++) {
if ((i & 1) == 1) {
mask &= s32_eq(input[i], 0x1ffffff);
} else {
mask &= s32_eq(input[i], 0x3ffffff);
}
}
/* mask is either 0xffffffff (if input >= 2^255-19) and zero otherwise. Thus
* this conditionally subtracts 2^255-19. */
input[0] -= mask & 0x3ffffed;
for (i = 1; i < 10; i++) {
if ((i & 1) == 1) {
input[i] -= mask & 0x1ffffff;
} else {
input[i] -= mask & 0x3ffffff;
}
}
input[1] <<= 2;
input[2] <<= 3;
input[3] <<= 5;
input[4] <<= 6;
input[6] <<= 1;
input[7] <<= 3;
input[8] <<= 4;
input[9] <<= 6;
#define F(i, s) \
output[s+0] |= input[i] & 0xff; \
output[s+1] = (input[i] >> 8) & 0xff; \
output[s+2] = (input[i] >> 16) & 0xff; \
output[s+3] = (input[i] >> 24) & 0xff;
output[0] = 0;
output[16] = 0;
F(0,0);
F(1,3);
F(2,6);
F(3,9);
F(4,12);
F(5,16);
F(6,19);
F(7,22);
F(8,25);
F(9,28);
#undef F
}
/* Input: Q, Q', Q-Q'
* Output: 2Q, Q+Q'
*
* x2 z3: long form
* x3 z3: long form
* x z: short form, destroyed
* xprime zprime: short form, destroyed
* qmqp: short form, preserved
*
* On entry and exit, the absolute value of the limbs of all inputs and outputs
* are < 2^26. */
static void fmonty(limb *x2, limb *z2, /* output 2Q */
limb *x3, limb *z3, /* output Q + Q' */
limb *x, limb *z, /* input Q */
limb *xprime, limb *zprime, /* input Q' */
const limb *qmqp /* input Q - Q' */) {
limb origx[10], origxprime[10], zzz[19], xx[19], zz[19], xxprime[19],
zzprime[19], zzzprime[19], xxxprime[19];
memcpy(origx, x, 10 * sizeof(limb));
fsum(x, z);
/* |x[i]| < 2^27 */
fdifference(z, origx); /* does x - z */
/* |z[i]| < 2^27 */
memcpy(origxprime, xprime, sizeof(limb) * 10);
fsum(xprime, zprime);
/* |xprime[i]| < 2^27 */
fdifference(zprime, origxprime);
/* |zprime[i]| < 2^27 */
fproduct(xxprime, xprime, z);
/* |xxprime[i]| < 14*2^54: the largest product of two limbs will be <
* 2^(27+27) and fproduct adds together, at most, 14 of those products.
* (Approximating that to 2^58 doesn't work out.) */
fproduct(zzprime, x, zprime);
/* |zzprime[i]| < 14*2^54 */
freduce_degree(xxprime);
freduce_coefficients(xxprime);
/* |xxprime[i]| < 2^26 */
freduce_degree(zzprime);
freduce_coefficients(zzprime);
/* |zzprime[i]| < 2^26 */
memcpy(origxprime, xxprime, sizeof(limb) * 10);
fsum(xxprime, zzprime);
/* |xxprime[i]| < 2^27 */
fdifference(zzprime, origxprime);
/* |zzprime[i]| < 2^27 */
fsquare(xxxprime, xxprime);
/* |xxxprime[i]| < 2^26 */
fsquare(zzzprime, zzprime);
/* |zzzprime[i]| < 2^26 */
fproduct(zzprime, zzzprime, qmqp);
/* |zzprime[i]| < 14*2^52 */
freduce_degree(zzprime);
freduce_coefficients(zzprime);
/* |zzprime[i]| < 2^26 */
memcpy(x3, xxxprime, sizeof(limb) * 10);
memcpy(z3, zzprime, sizeof(limb) * 10);
fsquare(xx, x);
/* |xx[i]| < 2^26 */
fsquare(zz, z);
/* |zz[i]| < 2^26 */
fproduct(x2, xx, zz);
/* |x2[i]| < 14*2^52 */
freduce_degree(x2);
freduce_coefficients(x2);
/* |x2[i]| < 2^26 */
fdifference(zz, xx); // does zz = xx - zz
/* |zz[i]| < 2^27 */
memset(zzz + 10, 0, sizeof(limb) * 9);
fscalar_product(zzz, zz, 121665);
/* |zzz[i]| < 2^(27+17) */
/* No need to call freduce_degree here:
fscalar_product doesn't increase the degree of its input. */
freduce_coefficients(zzz);
/* |zzz[i]| < 2^26 */
fsum(zzz, xx);
/* |zzz[i]| < 2^27 */
fproduct(z2, zz, zzz);
/* |z2[i]| < 14*2^(26+27) */
freduce_degree(z2);
freduce_coefficients(z2);
/* |z2|i| < 2^26 */
}
/* Conditionally swap two reduced-form limb arrays if 'iswap' is 1, but leave
* them unchanged if 'iswap' is 0. Runs in data-invariant time to avoid
* side-channel attacks.
*
* NOTE that this function requires that 'iswap' be 1 or 0; other values give
* wrong results. Also, the two limb arrays must be in reduced-coefficient,
* reduced-degree form: the values in a[10..19] or b[10..19] aren't swapped,
* and all all values in a[0..9],b[0..9] must have magnitude less than
* INT32_MAX. */
static void
swap_conditional(limb a[19], limb b[19], limb iswap) {
unsigned i;
const s32 swap = (s32) -iswap;
for (i = 0; i < 10; ++i) {
const s32 x = swap & ( ((s32)a[i]) ^ ((s32)b[i]) );
a[i] = ((s32)a[i]) ^ x;
b[i] = ((s32)b[i]) ^ x;
}
}
/* Calculates nQ where Q is the x-coordinate of a point on the curve
*
* resultx/resultz: the x coordinate of the resulting curve point (short form)
* n: a little endian, 32-byte number
* q: a point of the curve (short form) */
static void
cmult(limb *resultx, limb *resultz, const u8 *n, const limb *q) {
limb a[19] = {0}, b[19] = {1}, c[19] = {1}, d[19] = {0};
limb *nqpqx = a, *nqpqz = b, *nqx = c, *nqz = d, *t;
limb e[19] = {0}, f[19] = {1}, g[19] = {0}, h[19] = {1};
limb *nqpqx2 = e, *nqpqz2 = f, *nqx2 = g, *nqz2 = h;
unsigned i, j;
memcpy(nqpqx, q, sizeof(limb) * 10);
for (i = 0; i < 32; ++i) {
u8 byte = n[31 - i];
for (j = 0; j < 8; ++j) {
const limb bit = byte >> 7;
swap_conditional(nqx, nqpqx, bit);
swap_conditional(nqz, nqpqz, bit);
fmonty(nqx2, nqz2,
nqpqx2, nqpqz2,
nqx, nqz,
nqpqx, nqpqz,
q);
swap_conditional(nqx2, nqpqx2, bit);
swap_conditional(nqz2, nqpqz2, bit);
t = nqx;
nqx = nqx2;
nqx2 = t;
t = nqz;
nqz = nqz2;
nqz2 = t;
t = nqpqx;
nqpqx = nqpqx2;
nqpqx2 = t;
t = nqpqz;
nqpqz = nqpqz2;
nqpqz2 = t;
byte <<= 1;
}
}
memcpy(resultx, nqx, sizeof(limb) * 10);
memcpy(resultz, nqz, sizeof(limb) * 10);
}
// -----------------------------------------------------------------------------
// Shamelessly copied from djb's code
// -----------------------------------------------------------------------------
static void
crecip(limb *out, const limb *z) {
limb z2[10];
limb z9[10];
limb z11[10];
limb z2_5_0[10];
limb z2_10_0[10];
limb z2_20_0[10];
limb z2_50_0[10];
limb z2_100_0[10];
limb t0[10];
limb t1[10];
int i;
/* 2 */ fsquare(z2,z);
/* 4 */ fsquare(t1,z2);
/* 8 */ fsquare(t0,t1);
/* 9 */ fmul(z9,t0,z);
/* 11 */ fmul(z11,z9,z2);
/* 22 */ fsquare(t0,z11);
/* 2^5 - 2^0 = 31 */ fmul(z2_5_0,t0,z9);
/* 2^6 - 2^1 */ fsquare(t0,z2_5_0);
/* 2^7 - 2^2 */ fsquare(t1,t0);
/* 2^8 - 2^3 */ fsquare(t0,t1);
/* 2^9 - 2^4 */ fsquare(t1,t0);
/* 2^10 - 2^5 */ fsquare(t0,t1);
/* 2^10 - 2^0 */ fmul(z2_10_0,t0,z2_5_0);
/* 2^11 - 2^1 */ fsquare(t0,z2_10_0);
/* 2^12 - 2^2 */ fsquare(t1,t0);
/* 2^20 - 2^10 */ for (i = 2;i < 10;i += 2) { fsquare(t0,t1); fsquare(t1,t0); }
/* 2^20 - 2^0 */ fmul(z2_20_0,t1,z2_10_0);
/* 2^21 - 2^1 */ fsquare(t0,z2_20_0);
/* 2^22 - 2^2 */ fsquare(t1,t0);
/* 2^40 - 2^20 */ for (i = 2;i < 20;i += 2) { fsquare(t0,t1); fsquare(t1,t0); }
/* 2^40 - 2^0 */ fmul(t0,t1,z2_20_0);
/* 2^41 - 2^1 */ fsquare(t1,t0);
/* 2^42 - 2^2 */ fsquare(t0,t1);
/* 2^50 - 2^10 */ for (i = 2;i < 10;i += 2) { fsquare(t1,t0); fsquare(t0,t1); }
/* 2^50 - 2^0 */ fmul(z2_50_0,t0,z2_10_0);
/* 2^51 - 2^1 */ fsquare(t0,z2_50_0);
/* 2^52 - 2^2 */ fsquare(t1,t0);
/* 2^100 - 2^50 */ for (i = 2;i < 50;i += 2) { fsquare(t0,t1); fsquare(t1,t0); }
/* 2^100 - 2^0 */ fmul(z2_100_0,t1,z2_50_0);
/* 2^101 - 2^1 */ fsquare(t1,z2_100_0);
/* 2^102 - 2^2 */ fsquare(t0,t1);
/* 2^200 - 2^100 */ for (i = 2;i < 100;i += 2) { fsquare(t1,t0); fsquare(t0,t1); }
/* 2^200 - 2^0 */ fmul(t1,t0,z2_100_0);
/* 2^201 - 2^1 */ fsquare(t0,t1);
/* 2^202 - 2^2 */ fsquare(t1,t0);
/* 2^250 - 2^50 */ for (i = 2;i < 50;i += 2) { fsquare(t0,t1); fsquare(t1,t0); }
/* 2^250 - 2^0 */ fmul(t0,t1,z2_50_0);
/* 2^251 - 2^1 */ fsquare(t1,t0);
/* 2^252 - 2^2 */ fsquare(t0,t1);
/* 2^253 - 2^3 */ fsquare(t1,t0);
/* 2^254 - 2^4 */ fsquare(t0,t1);
/* 2^255 - 2^5 */ fsquare(t1,t0);
/* 2^255 - 21 */ fmul(out,t1,z11);
}
int
curve25519_donna(u8 *mypublic, const u8 *secret, const u8 *basepoint) {
limb bp[10], x[10], z[11], zmone[10];
uint8_t e[32];
int i;
for (i = 0; i < 32; ++i) e[i] = secret[i];
e[0] &= 248;
e[31] &= 127;
e[31] |= 64;
fexpand(bp, basepoint);
cmult(x, z, e, bp);
crecip(zmone, z);
fmul(z, x, zmone);
fcontract(mypublic, z);
return 0;
}

1322
lib/crypt/ecc.c Normal file

File diff suppressed because it is too large Load Diff

90
lib/crypt/ecc.h Normal file
View File

@ -0,0 +1,90 @@
/* From https://github.com/jestan/easy-ecc */
#ifndef _EASY_ECC_H_
#define _EASY_ECC_H_
#include <stdint.h>
/* Curve selection options. */
#define secp128r1 16
#define secp192r1 24
#define secp256r1 32
#define secp384r1 48
#ifndef ECC_CURVE
#define ECC_CURVE secp256r1
#endif
#if (ECC_CURVE != secp128r1 && ECC_CURVE != secp192r1 && ECC_CURVE != secp256r1 && ECC_CURVE != secp384r1)
#error "Must define ECC_CURVE to one of the available curves"
#endif
#define ECC_BYTES ECC_CURVE
#ifdef __cplusplus
extern "C"
{
#endif
/* ecc_make_key() function.
Create a public/private key pair.
Outputs:
p_publicKey - Will be filled in with the public key.
p_privateKey - Will be filled in with the private key.
Returns 1 if the key pair was generated successfully, 0 if an error occurred.
*/
int ecc_make_key(uint8_t p_publicKey[ECC_BYTES+1], uint8_t p_privateKey[ECC_BYTES]);
/* ecdh_shared_secret() function.
Compute a shared secret given your secret key and someone else's public key.
Note: It is recommended that you hash the result of ecdh_shared_secret before using it for symmetric encryption or HMAC.
Inputs:
p_publicKey - The public key of the remote party.
p_privateKey - Your private key.
Outputs:
p_secret - Will be filled in with the shared secret value.
Returns 1 if the shared secret was generated successfully, 0 if an error occurred.
*/
int ecdh_shared_secret(const uint8_t p_publicKey[ECC_BYTES+1], const uint8_t p_privateKey[ECC_BYTES], uint8_t p_secret[ECC_BYTES]);
/* ecdsa_sign() function.
Generate an ECDSA signature for a given hash value.
Usage: Compute a hash of the data you wish to sign (SHA-2 is recommended) and pass it in to
this function along with your private key.
Inputs:
p_privateKey - Your private key.
p_hash - The message hash to sign.
Outputs:
p_signature - Will be filled in with the signature value.
Returns 1 if the signature generated successfully, 0 if an error occurred.
*/
int ecdsa_sign(const uint8_t p_privateKey[ECC_BYTES], const uint8_t p_hash[ECC_BYTES], uint8_t p_signature[ECC_BYTES*2]);
/* ecdsa_verify() function.
Verify an ECDSA signature.
Usage: Compute the hash of the signed data using the same hash as the signer and
pass it to this function along with the signer's public key and the signature values (r and s).
Inputs:
p_publicKey - The signer's public key
p_hash - The hash of the signed data.
p_signature - The signature value.
Returns 1 if the signature is valid, 0 if it is invalid.
*/
int ecdsa_verify(const uint8_t p_publicKey[ECC_BYTES+1], const uint8_t p_hash[ECC_BYTES], const uint8_t p_signature[ECC_BYTES*2]);
#ifdef __cplusplus
} /* end of extern "C" */
#endif
#endif /* _EASY_ECC_H_ */

View File

@ -29,6 +29,7 @@ libcrypt_sources = files('''
zuc.h
kasumi.h
ogs-kdf.h
ecc.h
ogs-aes.c
ogs-aes-cmac.c
@ -43,6 +44,9 @@ libcrypt_sources = files('''
ogs-kdf.c
ogs-base64.c
curve25519-donna.c
ecc.c
'''.split())
libcrypt_inc = include_directories('.')

View File

@ -15,7 +15,30 @@
*/
/*
* Copyright (C) 2019-2020 by Sukchan Lee <acetcom@gmail.com>
* Copyright (C) 2000-2012 Free Software Foundation, Inc.
* Copyright (C) 2017 Red Hat, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
/*
* Copyright (C) 2019-2022 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
@ -175,3 +198,254 @@ int ogs_base64_encode_binary(
*p++ = '\0';
return (int)(p - encoded);
}
/* copies data to result but removes newlines and <CR>
* returns the size of the data copied.
*
* It will fail with GNUTLS_E_BASE64_DECODING_ERROR if the
* end-result is the empty string.
*/
inline static int
cpydata(const uint8_t *data, int data_size, uint8_t **result, int *result_size)
{
int i, j;
*result = ogs_malloc(data_size + 1);
if (*result == NULL) {
ogs_error("ogs_malloc failed[%d]", data_size+1);
return OGS_ERROR;
}
for (j = i = 0; i < data_size; i++) {
if (data[i] == '\n' || data[i] == '\r' || data[i] == ' '
|| data[i] == '\t')
continue;
else if (data[i] == '-')
break;
(*result)[j] = data[i];
j++;
}
*result_size = j;
(*result)[j] = 0;
if (j==0) {
ogs_free(*result);
ogs_error("No Data");
return OGS_ERROR;
}
return j;
}
#define MEMSUB(x,y) ((ssize_t)((ptrdiff_t)x-(ptrdiff_t)y))
#define ENDSTR "-----"
int ogs_fbase64_decode(const char *header,
const uint8_t *data, size_t data_size, ogs_datum_t *result)
{
static const char top[] = "-----BEGIN ";
static const char bottom[] = "-----END ";
uint8_t *rdata, *kdata;
int rdata_size;
#define MAX_PEM_HEADER_LEN 128
char pem_header[MAX_PEM_HEADER_LEN];
uint8_t *bufcoded;
int bufcoded_len;
char *p, *last;
ogs_assert(header);
ogs_assert(data);
ogs_assert(data_size);
ogs_assert(result);
memset(result, 0, sizeof(*result));
p = pem_header;
last = pem_header + MAX_PEM_HEADER_LEN;
p = ogs_slprintf(p, last, "%s", top);
if (header != NULL)
p = ogs_slprintf(p, last, "%s", header);
rdata = memmem(data, data_size, pem_header, strlen(pem_header));
if (rdata == NULL) {
ogs_error("Cound not find [%s]", pem_header);
ogs_log_hexdump(OGS_LOG_ERROR, data, data_size);
return OGS_ERROR;
}
data_size -= MEMSUB(rdata, data);
if (data_size < 4 + strlen(bottom)) {
ogs_error("Not enough data (%d < 4 + %d)",
(int)data_size, (int)strlen(bottom));
ogs_log_hexdump(OGS_LOG_ERROR, data, data_size);
return OGS_ERROR;
}
kdata =
memmem(rdata + 1, data_size - 1, ENDSTR, sizeof(ENDSTR) - 1);
/* allow CR as well.
*/
if (kdata == NULL) {
ogs_error("Cound not find [%s]", ENDSTR);
ogs_log_hexdump(OGS_LOG_ERROR, data, data_size);
return OGS_ERROR;
}
data_size -= strlen(ENDSTR);
data_size -= MEMSUB(kdata, rdata);
rdata = kdata + strlen(ENDSTR);
/* position is now after the ---BEGIN--- headers */
kdata = memmem(rdata, data_size, bottom, strlen(bottom));
if (kdata == NULL) {
ogs_error("Cound not find [%s]", bottom);
ogs_log_hexdump(OGS_LOG_ERROR, data, data_size);
return OGS_ERROR;
}
/* position of kdata is before the ----END--- footer
*/
rdata_size = MEMSUB(kdata, rdata);
if (rdata_size < 4) {
ogs_error("Not enough data [%d]", rdata_size);
ogs_log_hexdump(OGS_LOG_ERROR, data, data_size);
return OGS_ERROR;
}
if (cpydata(rdata, rdata_size, &bufcoded, &bufcoded_len) == OGS_ERROR) {
ogs_error("cpydata() failed");
ogs_log_hexdump(OGS_LOG_ERROR, rdata, rdata_size);
return OGS_ERROR;
}
result->data = ogs_calloc(1, bufcoded_len);
if (result->data == NULL) {
ogs_error("ogs_calloc() failed [%d]", bufcoded_len);
ogs_free(bufcoded);
return OGS_ERROR;
}
result->size = ogs_base64_decode_binary(
result->data, (const char *)bufcoded);
if (result->size == 0) {
ogs_error("ogs_base64_decode_binary() failed");
ogs_log_hexdump(OGS_LOG_ERROR, bufcoded, bufcoded_len);
ogs_free(bufcoded);
return OGS_ERROR;
}
ogs_free(bufcoded);
return OGS_OK;
}
int ogs_pem_decode_curve25519_key(const char *filename, uint8_t *key)
{
int rv;
uint8_t buf[OGS_HUGE_LEN];
size_t bytes_read;
ogs_datum_t result;
#define CURVE25519_HEADER_LEN 16
const char *_header = "302e0201 00300506 032b656e 04220420";
uint8_t header[CURVE25519_HEADER_LEN];
ogs_assert(filename);
ogs_assert(key);
rv = ogs_file_read_full(filename, buf, OGS_HUGE_LEN, &bytes_read);
if (rv != OGS_OK) {
ogs_error("ogs_file_read_full[%s] failed", filename);
return OGS_ERROR;
}
rv = ogs_fbase64_decode("PRIVATE KEY", buf, bytes_read, &result);
if (rv != OGS_OK) {
ogs_error("ogs_fbase64_decode[%s] failed", filename);
ogs_log_hexdump(OGS_LOG_ERROR, result.data, result.size);
return OGS_ERROR;
}
rv = OGS_OK;
if (result.size != 48) {
ogs_error("Invalid size [%d]", (int)result.size);
rv = OGS_ERROR;
goto cleanup;
}
if (memcmp(ogs_hex_from_string(_header, header, sizeof(header)),
result.data, CURVE25519_HEADER_LEN) != 0) {
ogs_error("Invalid header [%d]", (int)result.size);
ogs_log_hexdump(OGS_LOG_FATAL, result.data, result.size);
rv = OGS_ERROR;
goto cleanup;
}
memcpy(key, result.data+CURVE25519_HEADER_LEN, OGS_ECCKEY_LEN);
cleanup:
if (result.data)
ogs_free(result.data);
return rv;
}
int ogs_pem_decode_secp256r1_key(const char *filename, uint8_t *key)
{
int rv;
uint8_t buf[OGS_HUGE_LEN];
size_t bytes_read;
ogs_datum_t result;
#define SECP256R1_HEADER_LEN 7
const char *_header = "30770201 010420";
uint8_t header[SECP256R1_HEADER_LEN];
ogs_assert(filename);
ogs_assert(key);
rv = ogs_file_read_full(filename, buf, OGS_HUGE_LEN, &bytes_read);
if (rv != OGS_OK) {
ogs_error("ogs_file_read_full[%s] failed", filename);
return OGS_ERROR;
}
rv = ogs_fbase64_decode("EC PRIVATE KEY", buf, bytes_read, &result);
if (rv != OGS_OK) {
ogs_error("ogs_fbase64_decode[%s] failed", filename);
ogs_log_hexdump(OGS_LOG_ERROR, result.data, result.size);
return OGS_ERROR;
}
rv = OGS_OK;
if (result.size != 121) {
ogs_error("Invalid size [%d]", (int)result.size);
rv = OGS_ERROR;
goto cleanup;
}
if (memcmp(ogs_hex_from_string(_header, header, sizeof(header)),
result.data, SECP256R1_HEADER_LEN) != 0) {
ogs_error("Invalid header [%d]", (int)result.size);
ogs_log_hexdump(OGS_LOG_FATAL, result.data, result.size);
rv = OGS_ERROR;
goto cleanup;
}
memcpy(key, result.data+SECP256R1_HEADER_LEN, OGS_ECCKEY_LEN);
cleanup:
if (result.data)
ogs_free(result.data);
return rv;
}

View File

@ -15,7 +15,29 @@
*/
/*
* Copyright (C) 2019-2020 by Sukchan Lee <acetcom@gmail.com>
* Copyright (C) 2000-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
/*
* Copyright (C) 2019-2022 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
@ -54,6 +76,12 @@ int ogs_base64_encode(
int ogs_base64_encode_binary(
char *encoded, const unsigned char *string, int len);
int ogs_fbase64_decode(const char *header,
const uint8_t *data, size_t data_size, ogs_datum_t *result);
int ogs_pem_decode_curve25519_key(const char *filename, uint8_t *key);
int ogs_pem_decode_secp256r1_key(const char *filename, uint8_t *key);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
* Copyright (C) 2019-2022 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
@ -35,6 +35,7 @@
#include "crypt/snow-3g.h"
#include "crypt/zuc.h"
#include "crypt/kasumi.h"
#include "crypt/ecc.h"
#include "crypt/ogs-kdf.h"
#include "crypt/ogs-base64.h"
@ -46,6 +47,7 @@ extern "C" {
#endif
#define OGS_KEY_LEN 16
#define OGS_IVEC_LEN 16
#define OGS_AMF_LEN 2
#define OGS_RAND_LEN 16
#define OGS_AUTN_LEN 16
@ -60,8 +62,14 @@ extern "C" {
#define OGS_HASH_MME_LEN 8
#define OGS_ECCKEY_LEN 32
#define OGS_MACTAG_LEN 8
#define OGS_KEYSTRLEN(x) ((x*2)+1)
int curve25519_donna(
uint8_t *mypublic, const uint8_t *secret, const uint8_t *basepoint);
#ifdef __cplusplus
}
#endif

View File

@ -262,6 +262,43 @@ void ogs_kdf_nh_gnb(uint8_t *kamf, uint8_t *sync_input, uint8_t *kgnb)
FC_FOR_NH_GNB_DERIVATION, param, kgnb);
}
/*
* TS33.501 Annex C.3.4.1 Profile A
* TS33.501 Annex C.3.4.2 Profile B
* ANSI-X9.63-KDF
*/
void ogs_kdf_ansi_x963(
uint8_t *z, size_t z_len, uint8_t *info, size_t info_len,
uint8_t *ek, uint8_t *icb, uint8_t *mk)
{
uint8_t input[ECC_BYTES+4+ECC_BYTES+1];
uint8_t output[OGS_KEY_LEN+OGS_IVEC_LEN+OGS_SHA256_DIGEST_SIZE];
uint32_t counter = 0;
size_t counter_len = sizeof(counter);
ogs_assert(z);
ogs_assert(info);
ogs_assert(ek);
ogs_assert(icb);
ogs_assert(mk);
ogs_assert((z_len+counter_len+info_len) <= (ECC_BYTES+4+ECC_BYTES+1));
memcpy(input, z, z_len);
counter = htobe32(1);
memcpy(input+z_len, &counter, counter_len);
memcpy(input+z_len+counter_len, info, info_len);
ogs_sha256(input, z_len+counter_len+info_len, output);
memcpy(ek, output, OGS_KEY_LEN);
memcpy(icb, output+OGS_KEY_LEN, OGS_IVEC_LEN);
counter = htobe32(2);
memcpy(input+z_len, &counter, counter_len);
ogs_sha256(input, z_len+counter_len+info_len, mk);
}
/* TS33.401 Annex A.2 KASME derivation function */
void ogs_auc_kasme(const uint8_t *ck, const uint8_t *ik,
const uint8_t *plmn_id, const uint8_t *sqn, const uint8_t *ak,

View File

@ -77,6 +77,15 @@ void ogs_kdf_kgnb_and_kn3iwf(uint8_t *kamf, uint32_t ul_count,
/* TS33.501 Annex A.10 NH derivation function */
void ogs_kdf_nh_gnb(uint8_t *kamf, uint8_t *sync_input, uint8_t *kgnb);
/*
* TS33.501 Annex C.3.4.1 Profile A
* TS33.501 Annex C.3.4.2 Profile B
* ANSI-X9.63-KDF
*/
void ogs_kdf_ansi_x963(
uint8_t *z, size_t z_len, uint8_t *info, size_t info_len,
uint8_t *ek, uint8_t *icb, uint8_t *mk);
/* TS33.401 Annex A.2 KASME derivation function */
void ogs_auc_kasme(const uint8_t *ck, const uint8_t *ik,
const uint8_t *plmn_id, const uint8_t *sqn, const uint8_t *ak,

View File

@ -80,20 +80,25 @@ int ogs_dbi_auth_info(char *supi, ogs_dbi_auth_info_t *auth_info)
if (!strcmp(key, "k") && BSON_ITER_HOLDS_UTF8(&inner_iter)) {
utf8 = (char *)bson_iter_utf8(&inner_iter, &length);
memcpy(auth_info->k, OGS_HEX(utf8, length, buf), OGS_KEY_LEN);
ogs_ascii_to_hex(utf8, length, buf, sizeof(buf));
memcpy(auth_info->k, buf, OGS_KEY_LEN);
} else if (!strcmp(key, "opc") && BSON_ITER_HOLDS_UTF8(&inner_iter)) {
utf8 = (char *)bson_iter_utf8(&inner_iter, &length);
auth_info->use_opc = 1;
memcpy(auth_info->opc, OGS_HEX(utf8, length, buf), OGS_KEY_LEN);
ogs_ascii_to_hex(utf8, length, buf, sizeof(buf));
memcpy(auth_info->opc, buf, OGS_KEY_LEN);
} else if (!strcmp(key, "op") && BSON_ITER_HOLDS_UTF8(&inner_iter)) {
utf8 = (char *)bson_iter_utf8(&inner_iter, &length);
memcpy(auth_info->op, OGS_HEX(utf8, length, buf), OGS_KEY_LEN);
ogs_ascii_to_hex(utf8, length, buf, sizeof(buf));
memcpy(auth_info->op, buf, OGS_KEY_LEN);
} else if (!strcmp(key, "amf") && BSON_ITER_HOLDS_UTF8(&inner_iter)) {
utf8 = (char *)bson_iter_utf8(&inner_iter, &length);
memcpy(auth_info->amf, OGS_HEX(utf8, length, buf), OGS_AMF_LEN);
ogs_ascii_to_hex(utf8, length, buf, sizeof(buf));
memcpy(auth_info->amf, buf, OGS_AMF_LEN);
} else if (!strcmp(key, "rand") && BSON_ITER_HOLDS_UTF8(&inner_iter)) {
utf8 = (char *)bson_iter_utf8(&inner_iter, &length);
memcpy(auth_info->rand, OGS_HEX(utf8, length, buf), OGS_RAND_LEN);
ogs_ascii_to_hex(utf8, length, buf, sizeof(buf));
memcpy(auth_info->rand, buf, OGS_RAND_LEN);
} else if (!strcmp(key, "sqn") && BSON_ITER_HOLDS_INT64(&inner_iter)) {
auth_info->sqn = bson_iter_int64(&inner_iter);
}

View File

@ -24,9 +24,12 @@ void ogs_nas_5gs_imsi_to_bcd(
{
ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci = NULL;
ogs_plmn_id_t plmn_id;
char tmp[OGS_MAX_IMSI_BCD_LEN+1];
char *p, *last;
uint8_t *scheme_output = NULL;
int scheme_output_size = 0;
char *scheme_output_bcd = NULL;
ogs_assert(mobile_identity);
ogs_assert(imsi_bcd);
@ -45,10 +48,19 @@ void ogs_nas_5gs_imsi_to_bcd(
p = ogs_slprintf(p, last, "%03d%03d",
ogs_plmn_id_mcc(&plmn_id), ogs_plmn_id_mnc(&plmn_id));
ogs_assert(mobile_identity->length > 8);
ogs_buffer_to_bcd(mobile_identity_suci->scheme_output,
mobile_identity->length - 8, tmp);
p = ogs_slprintf(p, last, "%s", tmp);
scheme_output =
(uint8_t *)mobile_identity->buffer +
OGS_NAS_5GS_MOBILE_IDENTITY_SUCI_MIN_SIZE;
scheme_output_size =
mobile_identity->length - OGS_NAS_5GS_MOBILE_IDENTITY_SUCI_MIN_SIZE;
ogs_assert(scheme_output_size);
scheme_output_bcd = ogs_calloc(1, scheme_output_size*2+1);
ogs_assert(scheme_output_bcd);
ogs_buffer_to_bcd(scheme_output, scheme_output_size, scheme_output_bcd);
p = ogs_slprintf(p, last, "%s", scheme_output_bcd);
ogs_free(scheme_output_bcd);
}
char *ogs_nas_5gs_suci_from_mobile_identity(
@ -56,10 +68,12 @@ char *ogs_nas_5gs_suci_from_mobile_identity(
{
ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci = NULL;
ogs_plmn_id_t plmn_id;
char tmp[OGS_NAS_MAX_SCHEME_OUTPUT_LEN*2+1];
char routing_indicator[5];
char *suci = NULL;
int scheme_output_len = 0;
uint8_t *scheme_output = NULL;
int scheme_output_size = 0;
char *scheme_output_string_or_bcd = NULL;
ogs_assert(mobile_identity);
@ -70,9 +84,9 @@ char *ogs_nas_5gs_suci_from_mobile_identity(
ogs_expect_or_return_val(mobile_identity_suci->h.supi_format ==
OGS_NAS_5GS_SUPI_FORMAT_IMSI, NULL);
ogs_expect_or_return_val(mobile_identity_suci->protection_scheme_id ==
OGS_NAS_5GS_NULL_SCHEME || mobile_identity_suci->protection_scheme_id ==
OGS_NAS_5GS_ECIES_SCHEME_PROFILE_A || mobile_identity_suci->protection_scheme_id ==
OGS_NAS_5GS_ECIES_SCHEME_PROFILE_B, NULL);
OGS_PROTECTION_SCHEME_NULL || mobile_identity_suci->protection_scheme_id ==
OGS_PROTECTION_SCHEME_PROFILE_A || mobile_identity_suci->protection_scheme_id ==
OGS_PROTECTION_SCHEME_PROFILE_B, NULL);
suci = ogs_msprintf("suci-%d-", mobile_identity_suci->h.supi_format);
ogs_expect_or_return_val(suci, NULL);
@ -116,26 +130,33 @@ char *ogs_nas_5gs_suci_from_mobile_identity(
routing_indicator[0] = '0';
}
scheme_output_len = mobile_identity->length - 8;
ogs_expect_or_return_val(scheme_output_len > 0, NULL);
ogs_expect_or_return_val(
scheme_output_len <= OGS_NAS_MAX_SCHEME_OUTPUT_LEN, NULL);
scheme_output =
(uint8_t *)mobile_identity->buffer +
OGS_NAS_5GS_MOBILE_IDENTITY_SUCI_MIN_SIZE;
scheme_output_size =
mobile_identity->length - OGS_NAS_5GS_MOBILE_IDENTITY_SUCI_MIN_SIZE;
ogs_assert(scheme_output_size);
scheme_output_string_or_bcd = ogs_calloc(1, scheme_output_size*2+1);
ogs_assert(scheme_output_string_or_bcd);
if (mobile_identity_suci->protection_scheme_id != OGS_NAS_5GS_NULL_SCHEME) {
ogs_hex_to_ascii(mobile_identity_suci->scheme_output,
scheme_output_len, tmp, sizeof(tmp));
if (mobile_identity_suci->protection_scheme_id !=
OGS_PROTECTION_SCHEME_NULL) {
ogs_hex_to_ascii(scheme_output, scheme_output_size,
scheme_output_string_or_bcd, scheme_output_size*2+1);
} else {
ogs_buffer_to_bcd(mobile_identity_suci->scheme_output,
scheme_output_len, tmp);
ogs_buffer_to_bcd(scheme_output, scheme_output_size,
scheme_output_string_or_bcd);
}
suci = ogs_mstrcatf(suci, "%s-%d-%d-%s",
routing_indicator,
mobile_identity_suci->protection_scheme_id,
mobile_identity_suci->home_network_pki_value,
tmp);
scheme_output_string_or_bcd);
ogs_expect(suci);
ogs_free(scheme_output_string_or_bcd);
return suci;
}

View File

@ -191,7 +191,6 @@ ED3(uint8_t type:4;,
/* 9.11.3.4 5GS mobile identity
* M LV-E 6-n */
#define OGS_NAS_MAX_SCHEME_OUTPUT_LEN 64
typedef struct ogs_nas_5gs_mobile_identity_header_s {
#define OGS_NAS_5GS_SUPI_FORMAT_IMSI 0
#define OGS_NAS_5GS_SUPI_FORMAT_NETWORK_SPECIFIC_IDENTIFIER 1
@ -199,6 +198,7 @@ ED3(uint8_t supi_format:4;,
uint8_t odd_even:1;,
uint8_t type:3;)
} __attribute__ ((packed)) ogs_nas_5gs_mobile_identity_header_t;
#define OGS_NAS_5GS_MOBILE_IDENTITY_SUCI_MIN_SIZE 8
typedef struct ogs_nas_5gs_mobile_identity_suci_s {
ogs_nas_5gs_mobile_identity_header_t h;
ogs_nas_plmn_id_t nas_plmn_id;
@ -207,12 +207,8 @@ typedef struct ogs_nas_5gs_mobile_identity_suci_s {
ED2(uint8_t routing_indicator4:4;,
uint8_t routing_indicator3:4;)
ED2(uint8_t spare3:4;,
#define OGS_NAS_5GS_NULL_SCHEME 0
#define OGS_NAS_5GS_ECIES_SCHEME_PROFILE_A 1
#define OGS_NAS_5GS_ECIES_SCHEME_PROFILE_B 2
uint8_t protection_scheme_id:4;)
uint8_t home_network_pki_value;
uint8_t scheme_output[OGS_NAS_MAX_SCHEME_OUTPUT_LEN];
} __attribute__ ((packed)) ogs_nas_5gs_mobile_identity_suci_t;
typedef struct ogs_nas_5gs_mobile_identity_guti_s {
ogs_nas_5gs_mobile_identity_header_t h;

View File

@ -143,7 +143,7 @@ ogs_amf_id_t *ogs_amf_id_from_string(ogs_amf_id_t *amf_id, const char *hex)
ogs_assert(amf_id);
ogs_assert(hex);
OGS_HEX(hex, strlen(hex), hexbuf);
ogs_hex_from_string(hex, hexbuf, sizeof(hexbuf));
amf_id->region = hexbuf[0];
amf_id->set1 = hexbuf[1];
@ -194,78 +194,6 @@ ogs_amf_id_t *ogs_amf_id_build(ogs_amf_id_t *amf_id,
return amf_id;
}
char *ogs_supi_from_suci(char *suci)
{
#define MAX_SUCI_TOKEN 16
char *array[MAX_SUCI_TOKEN];
char *p, *tmp;
int i;
char *supi = NULL;
ogs_assert(suci);
tmp = ogs_strdup(suci);
ogs_expect_or_return_val(tmp, NULL);
p = tmp;
i = 0;
while((array[i++] = strsep(&p, "-"))) {
/* Empty Body */
}
SWITCH(array[0])
CASE("suci")
SWITCH(array[1])
CASE("0") /* SUPI format : IMSI */
if (array[2] && array[3] && array[7])
supi = ogs_msprintf("imsi-%s%s%s",
array[2], array[3], array[7]);
break;
DEFAULT
ogs_error("Not implemented [%s]", array[1]);
break;
END
break;
DEFAULT
ogs_error("Not implemented [%s]", array[0]);
break;
END
ogs_free(tmp);
return supi;
}
char *ogs_supi_from_supi_or_suci(char *supi_or_suci)
{
char *type = NULL;
char *supi = NULL;
ogs_assert(supi_or_suci);
type = ogs_id_get_type(supi_or_suci);
if (!type) {
ogs_error("ogs_id_get_type[%s] failed", supi_or_suci);
goto cleanup;
}
SWITCH(type)
CASE("imsi")
supi = ogs_strdup(supi_or_suci);
ogs_expect(supi);
break;
CASE("suci")
supi = ogs_supi_from_suci(supi_or_suci);
ogs_expect(supi);
break;
DEFAULT
ogs_error("Not implemented [%s]", type);
break;
END
cleanup:
if (type)
ogs_free(type);
return supi;
}
char *ogs_id_get_type(char *str)
{
char *token, *p, *tmp;

View File

@ -58,6 +58,8 @@ extern "C" {
#define OGS_CHRGCHARS_LEN 2
#define OGS_MSIN_LEN 5
#define OGS_BCD_TO_BUFFER_LEN(x) (((x)+1)/2)
#define OGS_MAX_IMSI_BCD_LEN 15
#define OGS_MAX_IMSI_LEN \
@ -176,9 +178,11 @@ ogs_amf_id_t *ogs_amf_id_build(ogs_amf_id_t *amf_id,
uint8_t region, uint16_t set, uint8_t pointer);
/************************************
* SUPI/SUCI */
char *ogs_supi_from_suci(char *suci);
char *ogs_supi_from_supi_or_suci(char *supi_or_suci);
* 9.11.3.4 5GS mobile identity
* - Protection Scheme */
#define OGS_PROTECTION_SCHEME_NULL 0
#define OGS_PROTECTION_SCHEME_PROFILE_A 1
#define OGS_PROTECTION_SCHEME_PROFILE_B 2
/************************************
* SUPI/GPSI */
@ -781,6 +785,11 @@ int ogs_pcc_rule_install_flow_from_media(
int ogs_pcc_rule_update_qos_from_media(
ogs_pcc_rule_t *pcc_rule, ogs_media_component_t *media_component);
typedef struct ogs_datum_s {
unsigned char *data;
unsigned int size;
} ogs_datum_t;
#ifdef __cplusplus
}
#endif

View File

@ -115,6 +115,44 @@ ogs_sbi_context_t *ogs_sbi_self(void)
return &self;
}
bool ogs_app_tls_server_enabled(void)
{
if (self.tls.enabled == OGS_SBI_TLS_ENABLED_AUTO) {
if (self.tls.server.key && self.tls.server.cert)
return true;
else
return false;
} else if (self.tls.enabled == OGS_SBI_TLS_ENABLED_YES) {
ogs_assert(self.tls.server.key);
ogs_assert(self.tls.server.cert);
return true;
} else if (self.tls.enabled == OGS_SBI_TLS_ENABLED_NO) {
return false;
} else {
ogs_error("Unknown TLS enabled mode [%d]", self.tls.enabled);
return false;
}
}
bool ogs_app_tls_client_enabled(void)
{
if (self.tls.enabled == OGS_SBI_TLS_ENABLED_AUTO) {
if (self.tls.client.key && self.tls.client.cert)
return true;
else
return false;
} else if (self.tls.enabled == OGS_SBI_TLS_ENABLED_YES) {
ogs_assert(self.tls.client.key);
ogs_assert(self.tls.client.cert);
return true;
} else if (self.tls.enabled == OGS_SBI_TLS_ENABLED_NO) {
return false;
} else {
ogs_error("Unknown TLS enabled mode [%d]", self.tls.enabled);
return false;
}
}
static int ogs_sbi_context_prepare(void)
{
self.sbi_port = OGS_SBI_HTTP_PORT;
@ -123,6 +161,8 @@ static int ogs_sbi_context_prepare(void)
self.content_encoding = "gzip";
#endif
self.tls.enabled = OGS_SBI_TLS_ENABLED_AUTO;
return OGS_OK;
}
@ -130,7 +170,7 @@ static int ogs_sbi_context_validation(
const char *local, const char *nrf, const char *scp)
{
/* If SMF is only used in 4G EPC, no SBI interface is required. */
if (strcmp(local, "smf") != 0 &&
if (local && strcmp(local, "smf") != 0 &&
ogs_list_first(&self.server_list) == NULL) {
ogs_error("No %s.sbi: in '%s'", local, ogs_app()->file);
return OGS_ERROR;
@ -139,18 +179,19 @@ static int ogs_sbi_context_validation(
ogs_assert(context_initialized == 1);
switch (self.discovery_config.delegated) {
case OGS_SBI_DISCOVERY_DELEGATED_AUTO:
if (strcmp(local, "nrf") == 0) {
if (local && strcmp(local, "nrf") == 0) {
/* Skip NRF */
} else if (strcmp(local, "scp") == 0) {
} else if (local && strcmp(local, "scp") == 0) {
/* Skip SCP */
} else if (strcmp(local, "smf") == 0) {
} else if (local && strcmp(local, "smf") == 0) {
/* Skip SMF since SMF can run 4G */
} else {
if (NF_INSTANCE_CLIENT(self.nrf_instance) ||
NF_INSTANCE_CLIENT(self.scp_instance)) {
} else {
ogs_error("DELEGATED_AUTO - Both NRF and %s are unavailable",
strcmp(scp, "next_scp") == 0 ? "Next-hop SCP" : "SCP");
scp && strcmp(scp, "next_scp") == 0 ?
"Next-hop SCP" : "SCP");
return OGS_ERROR;
}
}
@ -158,7 +199,8 @@ static int ogs_sbi_context_validation(
case OGS_SBI_DISCOVERY_DELEGATED_YES:
if (NF_INSTANCE_CLIENT(self.scp_instance) == NULL) {
ogs_error("DELEGATED_YES - no %s available",
strcmp(scp, "next_scp") == 0 ? "Next-hop SCP" : "SCP");
scp && strcmp(scp, "next_scp") == 0 ?
"Next-hop SCP" : "SCP");
return OGS_ERROR;
}
break;
@ -174,6 +216,27 @@ static int ogs_sbi_context_validation(
ogs_assert_if_reached();
}
if (self.tls.enabled == OGS_SBI_TLS_ENABLED_YES) {
if (!self.tls.server.key) {
ogs_error("No Server Key");
return OGS_ERROR;
}
if (!self.tls.server.cert) {
ogs_error("No Server Certificate");
return OGS_ERROR;
}
if (!self.tls.client.key) {
ogs_error("No Client Key");
return OGS_ERROR;
}
if (!self.tls.client.cert) {
ogs_error("No Client Certificate");
return OGS_ERROR;
}
}
return OGS_OK;
}
@ -673,6 +736,141 @@ int ogs_sbi_context_parse_config(
YAML_SEQUENCE_NODE);
}
}
} else if (!strcmp(root_key, "tls")) {
ogs_yaml_iter_t tls_iter;
ogs_yaml_iter_recurse(&root_iter, &tls_iter);
while (ogs_yaml_iter_next(&tls_iter)) {
const char *tls_key = ogs_yaml_iter_key(&tls_iter);
ogs_assert(tls_key);
if (!strcmp(tls_key, "enabled")) {
const char *v = ogs_yaml_iter_value(&tls_iter);
if (!strcmp(v, "auto"))
self.tls.enabled = OGS_SBI_TLS_ENABLED_AUTO;
else if (!strcmp(v, "yes"))
self.tls.enabled = OGS_SBI_TLS_ENABLED_YES;
else if (!strcmp(v, "no"))
self.tls.enabled = OGS_SBI_TLS_ENABLED_NO;
else
ogs_warn("unknown 'tls.enabled' value `%s`", v);
} else if (!strcmp(tls_key, "server")) {
ogs_yaml_iter_t server_iter;
ogs_yaml_iter_recurse(&tls_iter, &server_iter);
while (ogs_yaml_iter_next(&server_iter)) {
const char *server_key =
ogs_yaml_iter_key(&server_iter);
ogs_assert(server_key);
if (!strcmp(server_key, "cacert")) {
self.tls.server.cacert =
ogs_yaml_iter_value(&server_iter);
} else if (!strcmp(server_key, "cert")) {
self.tls.server.cert =
ogs_yaml_iter_value(&server_iter);
} else if (!strcmp(server_key, "key")) {
self.tls.server.key =
ogs_yaml_iter_value(&server_iter);
} else
ogs_warn("unknown key `%s`", server_key);
}
} else if (!strcmp(tls_key, "client")) {
ogs_yaml_iter_t client_iter;
ogs_yaml_iter_recurse(&tls_iter, &client_iter);
while (ogs_yaml_iter_next(&client_iter)) {
const char *client_key =
ogs_yaml_iter_key(&client_iter);
ogs_assert(client_key);
if (!strcmp(client_key, "cacert")) {
self.tls.client.cacert =
ogs_yaml_iter_value(&client_iter);
} else if (!strcmp(client_key, "cert")) {
self.tls.client.cert =
ogs_yaml_iter_value(&client_iter);
} else if (!strcmp(client_key, "key")) {
self.tls.client.key =
ogs_yaml_iter_value(&client_iter);
} else
ogs_warn("unknown key `%s`", client_key);
}
} else
ogs_warn("unknown key `%s`", tls_key);
}
} else if (!strcmp(root_key, "hnet")) {
ogs_yaml_iter_t hnet_array, hnet_iter;
ogs_yaml_iter_recurse(&root_iter, &hnet_array);
do {
uint8_t id = 0, scheme = 0;
const char *filename = NULL;
if (ogs_yaml_iter_type(&hnet_array) ==
YAML_MAPPING_NODE) {
memcpy(&hnet_iter, &hnet_array,
sizeof(ogs_yaml_iter_t));
} else if (ogs_yaml_iter_type(&hnet_array) ==
YAML_SEQUENCE_NODE) {
if (!ogs_yaml_iter_next(&hnet_array))
break;
ogs_yaml_iter_recurse(&hnet_array,
&hnet_iter);
} else if (ogs_yaml_iter_type(&hnet_array) ==
YAML_SCALAR_NODE) {
break;
} else
ogs_assert_if_reached();
while (ogs_yaml_iter_next(&hnet_iter)) {
const char *hnet_key =
ogs_yaml_iter_key(&hnet_iter);
ogs_assert(hnet_key);
if (!strcmp(hnet_key, "id")) {
const char *v = ogs_yaml_iter_value(&hnet_iter);
if (v) {
if (atoi(v) >= 1 && atoi(v) <= 254) id = atoi(v);
}
} else if (!strcmp(hnet_key, "scheme")) {
const char *v = ogs_yaml_iter_value(&hnet_iter);
if (v) {
if (atoi(v) == 1 || atoi(v) == 2)
scheme = atoi(v);
}
} else if (!strcmp(hnet_key, "key")) {
filename = ogs_yaml_iter_value(&hnet_iter);
} else
ogs_warn("unknown key `%s`", hnet_key);
}
if (id >= OGS_HOME_NETWORK_PKI_VALUE_MIN &&
id <= OGS_HOME_NETWORK_PKI_VALUE_MAX &&
filename) {
if (scheme == OGS_PROTECTION_SCHEME_PROFILE_A) {
rv = ogs_pem_decode_curve25519_key(
filename, self.hnet[id].key);
if (rv == OGS_OK) {
self.hnet[id].avail = true;
self.hnet[id].scheme = scheme;
} else {
ogs_error(
"ogs_pem_decode_curve25519_key[%s] failed",
filename);
}
} else if (scheme == OGS_PROTECTION_SCHEME_PROFILE_B) {
rv = ogs_pem_decode_secp256r1_key(
filename, self.hnet[id].key);
if (rv == OGS_OK) {
self.hnet[id].avail = true;
self.hnet[id].scheme = scheme;
} else {
ogs_error(
"ogs_pem_decode_secp256r1_key[%s] failed",
filename);
}
} else
ogs_error("Invalid scheme [%d]", scheme);
} else
ogs_error("Invalid home network configuration "
"[id:%d, filename:%s]", id, filename);
} while (ogs_yaml_iter_type(&hnet_array) ==
YAML_SEQUENCE_NODE);
}
}

View File

@ -46,9 +46,33 @@ typedef struct ogs_sbi_discovery_config_s {
bool prefer_requester_nf_instance_id;
} ogs_sbi_discovery_config_t;
typedef enum {
OGS_SBI_TLS_ENABLED_AUTO = 0,
OGS_SBI_TLS_ENABLED_YES,
OGS_SBI_TLS_ENABLED_NO,
} ogs_sbi_tls_enabled_mode_e;
typedef struct ogs_sbi_context_s {
ogs_sbi_discovery_config_t discovery_config; /* SCP Discovery Delegated */
struct {
ogs_sbi_tls_enabled_mode_e enabled;
struct {
const char *cacert;
const char *cert;
const char *key;
} server, client;
} tls;
#define OGS_HOME_NETWORK_PKI_VALUE_MIN 1
#define OGS_HOME_NETWORK_PKI_VALUE_MAX 254
struct {
uint8_t avail;
uint8_t scheme;
uint8_t key[OGS_ECCKEY_LEN]; /* 32 bytes Private Key */
} hnet[OGS_HOME_NETWORK_PKI_VALUE_MAX+1]; /* PKI Value : 1 ~ 254 */
uint16_t sbi_port; /* SBI local port */
ogs_list_t server_list;

View File

@ -20,6 +20,255 @@
#include "ogs-sbi.h"
#include "yuarel.h"
static int parse_scheme_output(
char *_protection_scheme_id, char *_scheme_output,
ogs_datum_t *ecckey, ogs_datum_t *cipher_text, uint8_t *mactag)
{
uint8_t protection_scheme_id;
uint8_t scheme_output_size;
uint8_t *scheme_output = NULL;
uint8_t *p = NULL;
ogs_assert(_protection_scheme_id);
ogs_assert(_scheme_output);
ogs_assert(ecckey);
ogs_assert(mactag);
ogs_assert(cipher_text);
scheme_output_size = strlen(_scheme_output)/2;
if (scheme_output_size <= ((OGS_ECCKEY_LEN+1) + OGS_MACTAG_LEN)) {
ogs_error("Not enought length [%d]", (int)strlen(_scheme_output));
return OGS_ERROR;
}
scheme_output = ogs_calloc(1, scheme_output_size);
ogs_assert(scheme_output);
ogs_ascii_to_hex(_scheme_output, strlen(_scheme_output),
scheme_output, scheme_output_size);
protection_scheme_id = atoi(_protection_scheme_id);
if (protection_scheme_id == OGS_PROTECTION_SCHEME_PROFILE_A) {
ecckey->size = OGS_ECCKEY_LEN;
} else if (protection_scheme_id == OGS_PROTECTION_SCHEME_PROFILE_B) {
ecckey->size = OGS_ECCKEY_LEN+1;
} else {
ogs_free(scheme_output);
ogs_fatal("Invalid protection scheme id [%s]", _protection_scheme_id);
ogs_assert_if_reached();
return OGS_ERROR;
}
cipher_text->size = OGS_MSIN_LEN;
p = scheme_output;
ecckey->data = ogs_memdup(p, ecckey->size);
ogs_assert(ecckey->data);
p += ecckey->size;
cipher_text->data = ogs_memdup(p, cipher_text->size);
ogs_assert(cipher_text->data);
p += cipher_text->size;
memcpy(mactag, p, OGS_MACTAG_LEN);
ogs_free(scheme_output);
return OGS_OK;
}
char *ogs_supi_from_suci(char *suci)
{
#define MAX_SUCI_TOKEN 16
char *array[MAX_SUCI_TOKEN];
char *p, *tmp;
int i;
char *supi = NULL;
ogs_assert(suci);
tmp = ogs_strdup(suci);
ogs_expect_or_return_val(tmp, NULL);
p = tmp;
i = 0;
while((array[i++] = strsep(&p, "-"))) {
/* Empty Body */
}
SWITCH(array[0])
CASE("suci")
SWITCH(array[1])
CASE("0") /* SUPI format : IMSI */
if (array[2] && array[3] && array[5] && array[6] && array[7]) {
uint8_t protection_scheme_id = atoi(array[5]);
uint8_t home_network_pki_value = atoi(array[6]);
if (protection_scheme_id == OGS_PROTECTION_SCHEME_NULL) {
supi = ogs_msprintf("imsi-%s%s%s",
array[2], array[3], array[7]);
} else if (protection_scheme_id ==
OGS_PROTECTION_SCHEME_PROFILE_A ||
protection_scheme_id ==
OGS_PROTECTION_SCHEME_PROFILE_B) {
ogs_datum_t pubkey;
ogs_datum_t cipher_text;
ogs_datum_t plain_text;
char *plain_bcd;
uint8_t mactag1[OGS_MACTAG_LEN], mactag2[OGS_MACTAG_LEN];
uint8_t z[OGS_ECCKEY_LEN];
uint8_t ek[OGS_KEY_LEN];
uint8_t icb[OGS_IVEC_LEN];
uint8_t mk[OGS_SHA256_DIGEST_SIZE];
if (home_network_pki_value <
OGS_HOME_NETWORK_PKI_VALUE_MIN ||
home_network_pki_value >
OGS_HOME_NETWORK_PKI_VALUE_MAX) {
ogs_error("Invalid HNET PKI Value [%s]", array[6]);
break;
}
if (!ogs_sbi_self()->hnet[home_network_pki_value].avail) {
ogs_error("HNET PKI Value Not Avaiable [%s]", array[6]);
break;
}
if (ogs_sbi_self()->hnet[home_network_pki_value].scheme
!= protection_scheme_id) {
ogs_error("Scheme Not Matched [%d != %s]",
ogs_sbi_self()->hnet[protection_scheme_id].scheme,
array[5]);
break;
}
if (parse_scheme_output(
array[5], array[7],
&pubkey, &cipher_text, mactag1) != OGS_OK) {
ogs_error("parse_scheme_output[%s] failed", array[7]);
break;
}
if (protection_scheme_id ==
OGS_PROTECTION_SCHEME_PROFILE_A) {
curve25519_donna(z,
ogs_sbi_self()->hnet[home_network_pki_value].key,
pubkey.data);
} else if (protection_scheme_id ==
OGS_PROTECTION_SCHEME_PROFILE_B) {
if (ecdh_shared_secret(
pubkey.data,
ogs_sbi_self()->
hnet[home_network_pki_value].key,
z) != 1) {
ogs_error("ecdh_shared_secret() failed");
ogs_log_hexdump(OGS_LOG_ERROR,
pubkey.data, OGS_ECCKEY_LEN);
ogs_log_hexdump(OGS_LOG_ERROR,
ogs_sbi_self()->
hnet[home_network_pki_value].key,
OGS_ECCKEY_LEN);
goto cleanup;
}
} else
ogs_assert_if_reached();
ogs_kdf_ansi_x963(
z, OGS_ECCKEY_LEN, pubkey.data, pubkey.size,
ek, icb, mk);
ogs_hmac_sha256(
mk, OGS_SHA256_DIGEST_SIZE,
cipher_text.data, cipher_text.size,
mactag2, OGS_MACTAG_LEN);
if (memcmp(mactag1, mactag2, OGS_MACTAG_LEN) != 0) {
ogs_error("MAC-tag not matched");
ogs_log_hexdump(OGS_LOG_ERROR, mactag1, OGS_MACTAG_LEN);
ogs_log_hexdump(OGS_LOG_ERROR, mactag2, OGS_MACTAG_LEN);
goto cleanup;
}
plain_text.size = cipher_text.size;
plain_text.data = ogs_calloc(1, plain_text.size);
ogs_assert(plain_text.data);
ogs_aes_ctr128_encrypt(
ek, icb, cipher_text.data, cipher_text.size,
plain_text.data);
plain_bcd = ogs_calloc(1, plain_text.size*2+1);
ogs_assert(plain_bcd);
ogs_buffer_to_bcd(
plain_text.data, plain_text.size, plain_bcd);
supi = ogs_msprintf("imsi-%s%s%s",
array[2], array[3], plain_bcd);
ogs_assert(supi);
if (plain_text.data)
ogs_free(plain_text.data);
ogs_free(plain_bcd);
cleanup:
if (pubkey.data)
ogs_free(pubkey.data);
if (cipher_text.data)
ogs_free(cipher_text.data);
} else {
ogs_error("Invalid Protection Scheme [%s]", array[5]);
}
}
break;
DEFAULT
ogs_error("Not implemented [%s]", array[1]);
break;
END
break;
DEFAULT
ogs_error("Not implemented [%s]", array[0]);
break;
END
ogs_free(tmp);
return supi;
}
char *ogs_supi_from_supi_or_suci(char *supi_or_suci)
{
char *type = NULL;
char *supi = NULL;
ogs_assert(supi_or_suci);
type = ogs_id_get_type(supi_or_suci);
if (!type) {
ogs_error("ogs_id_get_type[%s] failed", supi_or_suci);
goto cleanup;
}
SWITCH(type)
CASE("imsi")
supi = ogs_strdup(supi_or_suci);
ogs_expect(supi);
break;
CASE("suci")
supi = ogs_supi_from_suci(supi_or_suci);
ogs_expect(supi);
break;
DEFAULT
ogs_error("Not implemented [%s]", type);
break;
END
cleanup:
if (type)
ogs_free(type);
return supi;
}
char *ogs_uridup(bool https, ogs_sockaddr_t *addr, ogs_sbi_header_t *h)
{
char buf[OGS_ADDRSTRLEN];

View File

@ -32,6 +32,9 @@ typedef struct ogs_sbi_server_s ogs_sbi_server_t;
typedef struct ogs_sbi_client_s ogs_sbi_client_t;
typedef struct ogs_sbi_header_s ogs_sbi_header_t;
char *ogs_supi_from_suci(char *suci);
char *ogs_supi_from_supi_or_suci(char *supi_or_suci);
char *ogs_uridup(bool https, ogs_sockaddr_t *addr, ogs_sbi_header_t *h);
char *ogs_sbi_server_uri(ogs_sbi_server_t *server, ogs_sbi_header_t *h);
char *ogs_sbi_client_apiroot(ogs_sbi_client_t *client);

View File

@ -202,10 +202,11 @@ static int server_start(ogs_sbi_server_t *server,
/* Create SSL CTX */
if (ogs_app_tls_server_enabled() == true) {
ogs_assert(ogs_app()->tls.server.key);
ogs_assert(ogs_app()->tls.server.cert);
ogs_assert(ogs_sbi_self()->tls.server.key);
ogs_assert(ogs_sbi_self()->tls.server.cert);
server->ssl_ctx = create_ssl_ctx(
ogs_app()->tls.server.key, ogs_app()->tls.server.cert);
ogs_sbi_self()->tls.server.key,
ogs_sbi_self()->tls.server.cert);
if (!server->ssl_ctx) {
ogs_error("Cannot create SSL CTX");
return OGS_ERROR;

View File

@ -148,7 +148,7 @@ message('\n'.join([
if cppcheck.found()
run_target('analyze-cppcheck',
command : [ 'misc/static_code_analyze.sh',
command : [ 'misc/static-code-analyze.sh',
meson.version().version_compare('>=0.55.0') ?
cppcheck.full_path() : cppcheck.path(),
meson.current_build_dir(),
@ -159,7 +159,7 @@ endif
if clangtidy.found()
run_target('analyze-clang-tidy',
command : [ 'misc/static_code_analyze.sh',
command : [ 'misc/static-code-analyze.sh',
meson.version().version_compare('>=0.55.0') ?
clangtidy.full_path() : clangtidy.path(),
meson.current_build_dir(),

23
misc/gen-hnkey.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
if [ $# -lt 1 -o $# -gt 2 ]
then
echo You must specify output directory : ./gen-hnkey.sh ../config/open5gs/hnet [numberOfKey]
exit;
fi
limit=3
if [ $# -eq 2 ]
then
limit=$2
fi
limit=$((limit * 2))
i=1; while [ $i -le $limit ]; do
openssl genpkey -algorithm X25519 -out $1/curve25519-$i.key
openssl ecparam -name prime256v1 -genkey -conv_form compressed -out $1/secp256r1-$(($i+1)).key
i=$(($i + 2))
done

View File

@ -2,7 +2,7 @@
if [ 1 -ne $# ]
then
echo You must specify output directory : ./make-certs.sh ../config/tls
echo You must specify output directory : ./make-certs.sh ../config/open5gs/tls
exit;
fi

View File

@ -1593,11 +1593,11 @@ amf_ue_t *amf_ue_find_by_message(ogs_nas_5gs_message_t *message)
(ogs_nas_5gs_mobile_identity_suci_t *)mobile_identity->buffer;
if (mobile_identity_suci->protection_scheme_id !=
OGS_NAS_5GS_NULL_SCHEME &&
OGS_PROTECTION_SCHEME_NULL &&
mobile_identity_suci->protection_scheme_id !=
OGS_NAS_5GS_ECIES_SCHEME_PROFILE_A &&
OGS_PROTECTION_SCHEME_PROFILE_A &&
mobile_identity_suci->protection_scheme_id !=
OGS_NAS_5GS_ECIES_SCHEME_PROFILE_B) {
OGS_PROTECTION_SCHEME_PROFILE_B) {
ogs_error("Invalid ProtectionSchemeID(%d) in SUCI",
mobile_identity_suci->protection_scheme_id);
return NULL;

View File

@ -136,11 +136,11 @@ ogs_nas_5gmm_cause_t gmm_handle_registration_request(amf_ue_t *amf_ue,
(ogs_nas_5gs_mobile_identity_suci_t *)mobile_identity->buffer;
if (mobile_identity_suci->protection_scheme_id !=
OGS_NAS_5GS_NULL_SCHEME &&
OGS_PROTECTION_SCHEME_NULL &&
mobile_identity_suci->protection_scheme_id !=
OGS_NAS_5GS_ECIES_SCHEME_PROFILE_A &&
OGS_PROTECTION_SCHEME_PROFILE_A &&
mobile_identity_suci->protection_scheme_id !=
OGS_NAS_5GS_ECIES_SCHEME_PROFILE_B) {
OGS_PROTECTION_SCHEME_PROFILE_B) {
ogs_error("Invalid ProtectionSchemeID(%d) in SUCI",
mobile_identity_suci->protection_scheme_id);
return OGS_5GMM_CAUSE_SEMANTICALLY_INCORRECT_MESSAGE;
@ -774,8 +774,12 @@ int gmm_handle_identity_response(amf_ue_t *amf_ue,
mobile_identity_suci =
(ogs_nas_5gs_mobile_identity_suci_t *)mobile_identity->buffer;
if (mobile_identity_suci->protection_scheme_id !=
OGS_NAS_5GS_NULL_SCHEME) {
ogs_error("Not implemented ProtectionSchemeID(%d) in SUCI",
OGS_PROTECTION_SCHEME_NULL &&
mobile_identity_suci->protection_scheme_id !=
OGS_PROTECTION_SCHEME_PROFILE_A &&
mobile_identity_suci->protection_scheme_id !=
OGS_PROTECTION_SCHEME_PROFILE_B) {
ogs_error("Invalid ProtectionSchemeID(%d) in SUCI",
mobile_identity_suci->protection_scheme_id);
return OGS_ERROR;
}

View File

@ -138,9 +138,10 @@ static int mme_s6a_subscription_data_from_avp(struct avp *avp,
ogs_assert(ret == 0);
if (avpch1) {
ret = fd_msg_avp_hdr(avpch1, &hdr);
memcpy(mme_ue->charging_characteristics,
OGS_HEX(hdr->avp_value->os.data, (int)hdr->avp_value->os.len, buf),
OGS_CHRGCHARS_LEN);
ogs_ascii_to_hex(
(char*)hdr->avp_value->os.data, (int)hdr->avp_value->os.len,
buf, sizeof(buf));
memcpy(mme_ue->charging_characteristics, buf, OGS_CHRGCHARS_LEN);
mme_ue->charging_characteristics_presence = true;
*subdatamask = (*subdatamask | OGS_DIAM_S6A_SUBDATA_CC);
}
@ -342,10 +343,12 @@ static int mme_s6a_subscription_data_from_avp(struct avp *avp,
ogs_assert(ret == 0);
if (avpch3) {
ret = fd_msg_avp_hdr(avpch3, &hdr);
ogs_ascii_to_hex(
(char*)hdr->avp_value->os.data,
(int)hdr->avp_value->os.len,
buf, sizeof(buf));
memcpy(session->charging_characteristics,
OGS_HEX(hdr->avp_value->os.data,
(int)hdr->avp_value->os.len, buf),
OGS_CHRGCHARS_LEN);
buf, OGS_CHRGCHARS_LEN);
session->charging_characteristics_presence = true;
} else {
memcpy(session->charging_characteristics,
@ -1701,12 +1704,13 @@ static int mme_ogs_diam_s6a_idr_cb( struct msg **msg, struct avp *avp,
memcpy(ida_ecgi,
ogs_nas_from_plmn_id(&ida_plmn_buf, &mme_ue->e_cgi.plmn_id), 3);
memcpy(ida_ecgi + 3,
OGS_HEX(ida_cell_id_hex, sizeof(ida_cell_id_hex), buf), 5);
ogs_hex_from_string(ida_cell_id_hex, buf, sizeof(buf)), 5);
ogs_snprintf(ida_tac_hex, sizeof(ida_tac_hex), "%04x", ida_tac);
memcpy(ida_tai,
ogs_nas_from_plmn_id(&ida_plmn_buf, &mme_ue->tai.plmn_id), 3);
memcpy(ida_tai + 3, OGS_HEX(ida_tac_hex, sizeof(ida_tac_hex), buf), 2);
memcpy(ida_tai + 3,
ogs_hex_from_string(ida_tac_hex, buf, sizeof(buf)), 2);
ida_age =
(ogs_time_now() - mme_ue->ue_location_timestamp) / 1000000 / 60;

View File

@ -46,15 +46,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x89;
mobile_identity_suci.scheme_output[1] = 0x67;
mobile_identity_suci.scheme_output[2] = 0x45;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0xf4;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "89674500f4");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x8d01b780;

View File

@ -112,6 +112,7 @@ void test_5gc_init(void)
ogs_log_install_domain(&__ogs_dbi_domain, "dbi", OGS_LOG_ERROR);
ogs_log_install_domain(&__ogs_nas_domain, "nas", OGS_LOG_ERROR);
ogs_log_install_domain(&__ogs_gtp_domain, "gtp", OGS_LOG_ERROR);
ogs_log_install_domain(&__ogs_sbi_domain, "sbi", OGS_LOG_ERROR);
ogs_sctp_init(ogs_app()->usrsctp.udp_port);
ogs_assert(ogs_dbi_init(ogs_app()->db_uri) == OGS_OK);

View File

@ -137,6 +137,7 @@ void test_app_init(void)
ogs_log_install_domain(&__ogs_dbi_domain, "dbi", OGS_LOG_ERROR);
ogs_log_install_domain(&__ogs_nas_domain, "nas", OGS_LOG_ERROR);
ogs_log_install_domain(&__ogs_gtp_domain, "gtp", OGS_LOG_ERROR);
ogs_log_install_domain(&__ogs_sbi_domain, "sbi", OGS_LOG_ERROR);
ogs_sctp_init(ogs_app()->usrsctp.udp_port);
ogs_assert(ogs_dbi_init(ogs_app()->db_uri) == OGS_OK);

View File

@ -49,15 +49,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1079baf0;

View File

@ -46,15 +46,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1079baf0;

View File

@ -49,15 +49,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1079baf0;
@ -476,15 +471,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1079baf0;
@ -895,15 +885,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x54f6401;
@ -1231,15 +1216,10 @@ static void test4_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x64010;

View File

@ -49,15 +49,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x54f6401;
@ -383,15 +378,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x54f6401;
@ -673,15 +663,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x54f6401;

View File

@ -51,15 +51,10 @@ static void issues_1431_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x00003c01;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x54f6401;
@ -316,7 +311,13 @@ static void test2_func(abts_case *tc, void *data)
tests1ap_recv(NULL, recvbuf);
for (i = 0; i < NUM_OF_TEST_UE; i++) {
uint64_t imsi_index;
const char *scheme_output[] = {
"0000000001",
"0000000002",
"0000000003",
"0000000004",
"0000000005",
};
/* Setup Test UE & Session Context */
memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));
@ -327,13 +328,11 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
imsi_index = i + 1;
ogs_uint64_to_buffer(imsi_index, 5, mobile_identity_suci.scheme_output);
test_ue[i] = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue[i] = test_ue_add_by_suci(
&mobile_identity_suci, scheme_output[i]);
ogs_assert(test_ue[i]);
test_ue[i]->e_cgi.cell_id = 0x54f6401;
@ -545,7 +544,13 @@ static void test3_func(abts_case *tc, void *data)
tests1ap_recv(NULL, recvbuf);
for (i = 0; i < NUM_OF_TEST_UE; i++) {
uint64_t imsi_index;
const char *scheme_output[] = {
"0000000001",
"0000000002",
"0000000003",
"0000000004",
"0000000005",
};
/* Setup Test UE & Session Context */
memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));
@ -556,13 +561,11 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
imsi_index = i + 1;
ogs_uint64_to_buffer(imsi_index, 5, mobile_identity_suci.scheme_output);
test_ue[i] = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue[i] = test_ue_add_by_suci(
&mobile_identity_suci, scheme_output[i]);
ogs_assert(test_ue[i]);
/* Multiple eNB-UE-S1AP-UD */

View File

@ -49,15 +49,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1079baf0;

View File

@ -46,15 +46,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1079baf0;
@ -214,15 +209,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x64010;
@ -499,15 +489,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x64010;

View File

@ -805,26 +805,44 @@ int test_context_parse_config(void)
return OGS_OK;
}
void test_ue_set_mobile_identity_suci(test_ue_t *test_ue,
static void test_ue_set_mobile_identity(test_ue_t *test_ue,
ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci,
uint16_t mobile_identity_suci_length)
const char *scheme_output_string)
{
ogs_nas_5gs_mobile_identity_t mobile_identity;
ogs_nas_5gs_mobile_identity_t *mobile_identity = NULL;
uint16_t scheme_output_size;
uint8_t *scheme_output = NULL;
ogs_assert(test_ue);
ogs_assert(mobile_identity_suci);
ogs_assert(mobile_identity_suci_length);
ogs_assert(scheme_output_string);
test_ue->mobile_identity_suci_length = mobile_identity_suci_length;
memcpy(&test_ue->mobile_identity_suci, mobile_identity_suci,
mobile_identity_suci_length);
scheme_output_size = strlen(scheme_output_string)/2;
scheme_output = ogs_calloc(1, scheme_output_size);
ogs_assert(scheme_output);
mobile_identity.length = test_ue->mobile_identity_suci_length;
mobile_identity.buffer = &test_ue->mobile_identity_suci;
scheme_output_size = ogs_ascii_to_hex(
scheme_output_string, strlen(scheme_output_string),
scheme_output, scheme_output_size);
ogs_assert(scheme_output_size);
mobile_identity = &test_ue->mobile_identity;
mobile_identity->length =
OGS_NAS_5GS_MOBILE_IDENTITY_SUCI_MIN_SIZE + scheme_output_size;
mobile_identity->buffer = ogs_calloc(1, mobile_identity->length);
ogs_assert(mobile_identity->buffer);
memcpy(mobile_identity->buffer,
mobile_identity_suci, OGS_NAS_5GS_MOBILE_IDENTITY_SUCI_MIN_SIZE);
memcpy((uint8_t *)mobile_identity->buffer +
OGS_NAS_5GS_MOBILE_IDENTITY_SUCI_MIN_SIZE,
scheme_output, scheme_output_size);
ogs_free(scheme_output);
if (test_ue->suci)
ogs_free(test_ue->suci);
test_ue->suci = ogs_nas_5gs_suci_from_mobile_identity(&mobile_identity);
test_ue->suci = ogs_nas_5gs_suci_from_mobile_identity(mobile_identity);
if (test_ue->supi)
ogs_free(test_ue->supi);
test_ue->supi = ogs_supi_from_suci(test_ue->suci);
@ -890,13 +908,13 @@ static void test_ue_set_mobile_identity_imsisv(test_ue_t *test_ue)
test_ue_t *test_ue_add_by_suci(
ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci,
uint16_t mobile_identity_suci_length)
const char *scheme_output)
{
int i, j;
test_ue_t *test_ue = NULL;
ogs_assert(mobile_identity_suci);
ogs_assert(mobile_identity_suci_length);
ogs_assert(scheme_output);
ogs_pool_alloc(&test_ue_pool, &test_ue);
ogs_assert(test_ue);
@ -944,8 +962,7 @@ test_ue_t *test_ue_add_by_suci(
}
}
test_ue_set_mobile_identity_suci(
test_ue, mobile_identity_suci, mobile_identity_suci_length);
test_ue_set_mobile_identity(test_ue, mobile_identity_suci, scheme_output);
test_ue_set_mobile_identity_imsi(test_ue);
test_ue_set_mobile_identity_imsisv(test_ue);
@ -961,6 +978,9 @@ void test_ue_remove(test_ue_t *test_ue)
ogs_list_remove(&self.test_ue_list, test_ue);
if (test_ue->mobile_identity.buffer)
ogs_free(test_ue->mobile_identity.buffer);
if (test_ue->suci)
ogs_free(test_ue->suci);
if (test_ue->supi)
@ -1216,8 +1236,10 @@ int test_db_insert_ue(test_ue_t *test_ue, bson_t *doc)
ogs_assert(test_ue);
ogs_assert(doc);
OGS_HEX(test_ue->k_string, strlen(test_ue->k_string), test_ue->k);
OGS_HEX(test_ue->opc_string, strlen(test_ue->opc_string), test_ue->opc);
ogs_hex_from_string(
test_ue->k_string, test_ue->k, sizeof(test_ue->k));
ogs_hex_from_string(
test_ue->opc_string, test_ue->opc, sizeof(test_ue->opc));
collection = mongoc_client_get_collection(
ogs_mongoc()->client, ogs_mongoc()->name, "subscribers");

View File

@ -297,7 +297,7 @@ typedef struct test_ue_s {
uint8_t imsi_buf[OGS_MAX_IMSI_LEN];
int imsi_len;
ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci;
ogs_nas_5gs_mobile_identity_t mobile_identity;
ogs_nas_mobile_identity_imeisv_t mobile_identity_imeisv;
bool mobile_identity_imeisv_presence;
uint16_t mobile_identity_suci_length;
@ -488,13 +488,9 @@ test_context_t *test_self(void);
int test_context_parse_config(void);
void test_ue_set_mobile_identity_suci(test_ue_t *test_ue,
ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci,
uint16_t mobile_identity_suci_length);
test_ue_t *test_ue_add_by_suci(
ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci,
uint16_t mobile_identity_suci_length);
const char *scheme_output);
void test_ue_remove(test_ue_t *test_ue);
void test_ue_remove_all(void);

View File

@ -295,8 +295,10 @@ ogs_pkbuf_t *testemm_build_authentication_response(test_ue_t *test_ue)
message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM;
message.emm.h.message_type = OGS_NAS_EPS_AUTHENTICATION_RESPONSE;
OGS_HEX(test_ue->k_string, strlen(test_ue->k_string), test_ue->k);
OGS_HEX(test_ue->opc_string, strlen(test_ue->opc_string), test_ue->opc);
ogs_hex_from_string(
test_ue->k_string, test_ue->k, sizeof(test_ue->k));
ogs_hex_from_string(
test_ue->opc_string, test_ue->opc, sizeof(test_ue->opc));
milenage_f2345(test_ue->opc, test_ue->k, test_ue->rand,
res, ck, ik, ak, NULL);
@ -346,8 +348,10 @@ ogs_pkbuf_t *testemm_build_authentication_failure(
authentication_failure->presencemask |=
OGS_NAS_EPS_AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_PRESENT;
OGS_HEX(test_ue->k_string, strlen(test_ue->k_string), test_ue->k);
OGS_HEX(test_ue->opc_string, strlen(test_ue->opc_string), test_ue->opc);
ogs_hex_from_string(
test_ue->k_string, test_ue->k, sizeof(test_ue->k));
ogs_hex_from_string(
test_ue->opc_string, test_ue->opc, sizeof(test_ue->opc));
milenage_f2345(test_ue->opc, test_ue->k, test_ue->rand,
NULL, NULL, NULL, NULL, ak);
@ -895,7 +899,7 @@ ogs_pkbuf_t *testemm_build_uplink_nas_transport(test_ue_t *test_ue)
message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM;
message.emm.h.message_type = OGS_NAS_EPS_UPLINK_NAS_TRANSPORT;
OGS_HEX(payload, strlen(payload), hexbuf);
ogs_hex_from_string(payload, hexbuf, sizeof(hexbuf));
nas_message_container->length = 106;
memcpy(nas_message_container->buffer,
hexbuf, nas_message_container->length);

View File

@ -87,9 +87,9 @@ ogs_pkbuf_t *testgmm_build_registration_request(
} else {
registration_request->mobile_identity.length =
test_ue->mobile_identity_suci_length;
test_ue->mobile_identity.length;
registration_request->mobile_identity.buffer =
&test_ue->mobile_identity_suci;
test_ue->mobile_identity.buffer;
}
if (test_ue->registration_request_param.uplink_data_status) {
@ -423,9 +423,9 @@ ogs_pkbuf_t *testgmm_build_de_registration_request(
&mobile_identity_guti;
} else {
deregistration_request_from_ue->mobile_identity.length =
test_ue->mobile_identity_suci_length;
test_ue->mobile_identity.length;
deregistration_request_from_ue->mobile_identity.buffer =
&test_ue->mobile_identity_suci;
test_ue->mobile_identity.buffer;
}
if (integrity_protected)
@ -449,9 +449,9 @@ ogs_pkbuf_t *testgmm_build_identity_response(test_ue_t *test_ue)
message.gmm.h.message_type = OGS_NAS_5GS_IDENTITY_RESPONSE;
identity_response->mobile_identity.length =
test_ue->mobile_identity_suci_length;
test_ue->mobile_identity.length;
identity_response->mobile_identity.buffer =
&test_ue->mobile_identity_suci;
test_ue->mobile_identity.buffer;
return ogs_nas_5gs_plain_encode(&message);
}

View File

@ -370,7 +370,7 @@ int test_gtpu_send_slacc_rs(ogs_socknode_t *node, test_bearer_t *bearer)
ogs_pkbuf_put(pkbuf, 200-OGS_GTPV1U_5GC_HEADER_LEN);
memset(pkbuf->data, 0, pkbuf->len);
OGS_HEX(payload, strlen(payload), tmp);
ogs_hex_from_string(payload, tmp, sizeof(tmp));
memcpy(pkbuf->data, tmp, payload_len);
ip6_h = pkbuf->data;
@ -439,7 +439,7 @@ int test_gtpu_send_slacc_rs_with_unspecified_source_address(
ogs_pkbuf_put(pkbuf, 200-OGS_GTPV1U_5GC_HEADER_LEN);
memset(pkbuf->data, 0, pkbuf->len);
OGS_HEX(payload, strlen(payload), tmp);
ogs_hex_from_string(payload, tmp, sizeof(tmp));
memcpy(pkbuf->data, tmp, payload_len);
ogs_pkbuf_trim(pkbuf, payload_len);

View File

@ -736,7 +736,7 @@ ogs_pkbuf_t *testngap_build_ue_radio_capability_info_indication(
asn_uint642INTEGER(AMF_UE_NGAP_ID, test_ue->amf_ue_ngap_id);
*RAN_UE_NGAP_ID = test_ue->ran_ue_ngap_id;
OGS_HEX(_capability_captured, strlen(_capability_captured), tmp),
ogs_hex_from_string(_capability_captured, tmp, sizeof(tmp));
UERadioCapability->size = 407;
UERadioCapability->buf = CALLOC(UERadioCapability->size, sizeof(uint8_t));
@ -1876,7 +1876,7 @@ ogs_pkbuf_t *testngap_build_handover_required(
SourceToTarget_TransparentContainer =
&ie->value.choice.SourceToTarget_TransparentContainer;
OGS_HEX(_container, strlen(_container), tmp),
ogs_hex_from_string(_container, tmp, sizeof(tmp));
SourceToTarget_TransparentContainer->size = 32;
SourceToTarget_TransparentContainer->buf =
@ -1992,7 +1992,7 @@ ogs_pkbuf_t *testngap_build_handover_request_ack(test_ue_t *test_ue)
TargetToSource_TransparentContainer =
&ie->value.choice.TargetToSource_TransparentContainer;
OGS_HEX(_container, strlen(_container), tmp),
ogs_hex_from_string(_container, tmp, sizeof(tmp));
TargetToSource_TransparentContainer->size = 4;
TargetToSource_TransparentContainer->buf =

View File

@ -456,7 +456,7 @@ ogs_pkbuf_t *tests1ap_build_ue_radio_capability_info_indication(
UERadioCapability = &ie->value.choice.UERadioCapability;
OGS_HEX(_capability_captured, strlen(_capability_captured), tmp),
ogs_hex_from_string(_capability_captured, tmp, sizeof(tmp));
UERadioCapability->size = 40;
UERadioCapability->buf = CALLOC(UERadioCapability->size, sizeof(uint8_t));
@ -1545,7 +1545,7 @@ ogs_pkbuf_t *test_s1ap_build_handover_required(
Source_ToTarget_TransparentContainer =
&ie->value.choice.Source_ToTarget_TransparentContainer;
OGS_HEX(_container, strlen(_container), tmp),
ogs_hex_from_string(_container, tmp, sizeof(tmp));
Source_ToTarget_TransparentContainer->size = 206;
Source_ToTarget_TransparentContainer->buf =
@ -1696,7 +1696,7 @@ ogs_pkbuf_t *test_s1ap_build_handover_request_ack(test_ue_t *test_ue)
&ie->value.choice.Target_ToSource_TransparentContainer;
ogs_s1ap_buffer_to_OCTET_STRING(
OGS_HEX(payload, strlen(payload), hexbuf), 132,
ogs_hex_from_string(payload, hexbuf, sizeof(hexbuf)), 132,
Target_ToSource_TransparentContainer);
return ogs_s1ap_encode(&pdu);
@ -2016,7 +2016,7 @@ ogs_pkbuf_t *test_s1ap_build_invalid_packet(int i)
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
ogs_hex_from_string(payload[i], hexbuf, sizeof(hexbuf)), len[i]);
return pkbuf;
}
@ -2060,7 +2060,7 @@ ogs_pkbuf_t *test_s1ap_build_enb_configuration_transfer(int i)
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
ogs_hex_from_string(payload[i], hexbuf, sizeof(hexbuf)), len[i]);
return pkbuf;
}

View File

@ -40,7 +40,7 @@ ogs_pkbuf_t *test_sgsap_location_update_accept(int i)
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
ogs_hex_from_string(payload[i], hexbuf, sizeof(hexbuf)), len[i]);
return pkbuf;
}
@ -64,7 +64,7 @@ ogs_pkbuf_t *test_sgsap_location_update_reject(int i)
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
ogs_hex_from_string(payload[i], hexbuf, sizeof(hexbuf)), len[i]);
return pkbuf;
}
@ -88,7 +88,7 @@ ogs_pkbuf_t *test_sgsap_imsi_detach_ack(int i)
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
ogs_hex_from_string(payload[i], hexbuf, sizeof(hexbuf)), len[i]);
return pkbuf;
}
@ -124,7 +124,7 @@ ogs_pkbuf_t *test_sgsap_paging_request(int i)
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
ogs_hex_from_string(payload[i], hexbuf, sizeof(hexbuf)), len[i]);
return pkbuf;
}
@ -148,7 +148,7 @@ ogs_pkbuf_t *test_sgsap_reset_indication(int i)
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
ogs_hex_from_string(payload[i], hexbuf, sizeof(hexbuf)), len[i]);
return pkbuf;
}
@ -172,7 +172,7 @@ ogs_pkbuf_t *test_sgsap_release_request(int i)
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
ogs_hex_from_string(payload[i], hexbuf, sizeof(hexbuf)), len[i]);
return pkbuf;
}
@ -193,7 +193,7 @@ ogs_pkbuf_t *test_sgsap_downlink_unitdata(int i)
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
ogs_hex_from_string(payload[i], hexbuf, sizeof(hexbuf)), len[i]);
return pkbuf;
}
@ -214,7 +214,7 @@ ogs_pkbuf_t *test_sgsap_mm_information_request(int i)
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
ogs_hex_from_string(payload[i], hexbuf, sizeof(hexbuf)), len[i]);
return pkbuf;
}

View File

@ -35,16 +35,20 @@ static void conv_test2(abts_case *tc, void *data)
char buffer[16];
ABTS_TRUE(tc, memcmp(k, OGS_HEX(K, strlen(K), buffer), 16) == 0);
ABTS_TRUE(tc, memcmp(k,
ogs_hex_from_string(K, buffer, sizeof(buffer)), 16) == 0);
ABTS_TRUE(tc, memcmp(op, OGS_HEX(OP, strlen(OP), buffer), 16) == 0);
ABTS_TRUE(tc, memcmp(op,
ogs_hex_from_string(OP, buffer, sizeof(buffer)), 16) == 0);
ABTS_TRUE(tc, memcmp(opc, OGS_HEX(OPc, strlen(OPc), buffer), 16) == 0);
ABTS_TRUE(tc, memcmp(opc,
ogs_hex_from_string(OPc, buffer, sizeof(buffer)), 16) == 0);
ABTS_TRUE(tc, memcmp(amf, OGS_HEX(AMF, strlen(AMF), buffer), 2) == 0);
ABTS_TRUE(tc, memcmp(amf,
ogs_hex_from_string(AMF, buffer, sizeof(buffer)), 2) == 0);
ABTS_TRUE(tc, memcmp(lower,
OGS_HEX(LOWER, strlen(LOWER), buffer), 4) == 0);
ogs_hex_from_string(LOWER, buffer, sizeof(buffer)), 4) == 0);
}
static void conv_test3(abts_case *tc, void *data)

View File

@ -817,7 +817,7 @@ static void test6_func(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, 182, req->len);
ABTS_TRUE(tc, memcmp(req->data,
OGS_HEX(TEST_TLV_BUILD_MSG, strlen(TEST_TLV_BUILD_MSG), testbuf),
ogs_hex_from_string(TEST_TLV_BUILD_MSG, testbuf, sizeof(testbuf)),
req->len) == 0);
/* Initialize message value structure */

View File

@ -24,6 +24,7 @@
abts_suite *test_aes(abts_suite *suite);
abts_suite *test_sha(abts_suite *suite);
abts_suite *test_base64(abts_suite *suite);
abts_suite *test_ecies(abts_suite *suite);
const struct testlist {
abts_suite *(*func)(abts_suite *suite);
@ -31,6 +32,7 @@ const struct testlist {
{test_aes},
{test_sha},
{test_base64},
{test_ecies},
{NULL},
};

View File

@ -63,11 +63,97 @@ static void base64_test1(abts_case *tc, void *data)
}
}
struct decode_tests_st {
const char *name;
uint8_t *raw;
unsigned raw_size;
const char *pem;
unsigned pem_size;
int res;
};
struct decode_tests_st decode_tests[] = {
{
.name = "dec-rnd1",
.pem = "-----BEGIN dec-rnd1-----\n"
"9ppGioRpeiiD2lLNYC85eA==\n"
"-----END rnd1-----\n",
.raw = "\xf6\x9a\x46\x8a\x84\x69\x7a\x28\x83\xda\x52\xcd\x60\x2f\x39\x78",
.raw_size = 16,
.res = OGS_OK
},
{
.name = "dec-rnd2",
.pem = "-----BEGIN dec-rnd2-----\n"
"LJ/7hUZ3TtPIz2dlc5+YvELe+Q==\n"
"-----END rnd2-----\n",
.raw = "\x2c\x9f\xfb\x85\x46\x77\x4e\xd3\xc8\xcf\x67\x65\x73\x9f\x98\xbc\x42\xde\xf9",
.raw_size = 19,
.res = OGS_OK
},
{
.name = "dec-extra-chars",
.pem = "-----BEGIN dec-extra-chars----- \n\n"
"\n\n LJ/7hUZ3TtPIz2dlc5+YvELe+Q== \n"
" -----END rnd2----- \n ",
.raw = "\x2c\x9f\xfb\x85\x46\x77\x4e\xd3\xc8\xcf\x67\x65\x73\x9f\x98\xbc\x42\xde\xf9",
.raw_size = 19,
.res = OGS_OK
},
#if 0
{
.name = "dec-invalid-header",
.pem = "-----BEGIN dec-xxx-----\n"
"LJ/7hUZ3TtPIz2dlc5+YvELe+Q==\n"
"-----END rnd2-----\n",
.raw = "\x2c\x9f\xfb\x85\x46\x77\x4e\xd3\xc8\xcf\x67\x65\x73\x9f\x98\xbc\x42\xde\xf9",
.raw_size = 19,
.res = OGS_ERROR
},
{
.name = "leak1",
.pem = "-----BEGIN leak1-----E-\x00\x00-----END ",
.pem_size = 34,
.raw = "",
.raw_size = 0,
.res = OGS_ERROR
},
#endif
};
static void base64_test2(abts_case *tc, void *data)
{
int i, rv;
ogs_datum_t result;
for (i = 0; i < sizeof(decode_tests)/sizeof(decode_tests[0]); i++) {
if (!decode_tests[i].pem_size)
decode_tests[i].pem_size = strlen(decode_tests[i].pem);
rv = ogs_fbase64_decode(
decode_tests[i].name,
(const uint8_t *)decode_tests[i].pem, decode_tests[i].pem_size,
&result);
ABTS_INT_EQUAL(tc, decode_tests[i].res, rv);
if (result.size) {
ABTS_INT_EQUAL(tc, decode_tests[i].raw_size, result.size);
ABTS_TRUE(tc,
memcmp(decode_tests[i].raw, result.data, result.size) == 0);
}
if (result.data)
ogs_free(result.data);
}
}
abts_suite *test_base64(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, base64_test1, NULL);
abts_run_test(suite, base64_test2, NULL);
return suite;
}

385
tests/crypt/ecies-test.c Normal file
View File

@ -0,0 +1,385 @@
/*
* Copyright (C) 2022 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ogs-crypt.h"
#include "core/abts.h"
static void ecies_profile_a(abts_case *tc, void *data)
{
const char *_e[] = {
"c53c22208b61860b06c62e5406a7b330c2b577aa5558981510d128247d38bd1d",
"c80949f13ebe61af4ebdbd293ea4f942696b9e815d7e8f0096bbf6ed7de62256",
"C53C22208B61860B06C62E5406A7B330C2B577AA5558981510D128247D38BD1D",
"BE9EFF3E9F22A4B42A3D236E7A6C500B3F2E7E0C7449988BA800D664BF4FCD97",
/* Private Key in curve25519-1.key */
"10c9c67e861a5625a1db8f684123896d9b3506199d3df1968e07b6c8448bb147",
/* Private Key in TS33.501 C4.3.1 */
"c80949f13ebe61af4ebdbd293ea4f942696b9e815d7e8f0096bbf6ed7de62256",
};
const char *_k[] = {
"b2e92f836055a255837debf850b528997ce0201cb82adfe4be1f587d07d8457d",
"5a8d38864820197c3394b92613b20b91633cbd897119273bf8e4a6f4eec0a650",
"977D8B2FDAA7B64AA700D04227D5B440630EA4EC50F9082273A26BB678C92222",
"5A8D38864820197C3394B92613B20B91633CBD897119273BF8e4A6f4EEC0A650",
/* Public Key in TS33.501 C4.3.1 */
"b2e92f836055a255837debf850b528997ce0201cb82adfe4be1f587d07d8457d",
/* Public Key in curve25519-1.key */
"e421686f6fb2d70e3fa28d940494095686c3179fef53514667a6ed106b8a7d3d",
};
const char *_ek[] = {
"028ddf890ec83cdf163947ce45f6ec1a0e3070ea5fe57e2b1f05139f3e82422a",
"028ddf890ec83cdf163947ce45f6ec1a0e3070ea5fe57e2b1f05139f3e82422a",
"511C1DF473BB88317F923501F8BA944FD3B667D25699DCB552DBCEF60BBDC56D",
"511C1DF473BB88317F923501F8BA944FD3B667D25699DCB552DBCEF60BBDC56D",
/* Share Key from curve25519-1.key + TS33.501 C4.3.1 */
"514bacfdc28039187eec8196339d3ef2665691cd13abcc2a5df15561d9348c60",
/* Share Key from curve25519-1.key + TS33.501 C4.3.1 */
"514bacfdc28039187eec8196339d3ef2665691cd13abcc2a5df15561d9348c60",
};
int i, num;
uint8_t e[OGS_ECCKEY_LEN];
uint8_t k[OGS_ECCKEY_LEN];
uint8_t ek[OGS_ECCKEY_LEN];
uint8_t tmp[OGS_ECCKEY_LEN];
num = 6;
for (i = 0; i < num; i++) {
curve25519_donna(ek,
ogs_hex_from_string(_e[i], e, sizeof(e)),
ogs_hex_from_string(_k[i], k, sizeof(k)));
ABTS_TRUE(tc, memcmp(ek,
ogs_hex_from_string(_ek[i], tmp, sizeof(tmp)), OGS_ECCKEY_LEN) == 0);
}
}
static void ecies_profile_b(abts_case *tc, void *data)
{
const char *_e[] = {
"F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA",
"99798858A1DC6A2C68637149A4B1DBFD1FDFF5ADDD62A2142F06699ED7602529",
"F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA",
"90A5898BD29FFA3F261E00E980067C70A2B1B992A21F5B4FEF6D4DF69FE804AD",
/* Private Key in secp256r1-2.key */
"74a9f918471f56f3befda5c51d738a3f94f5a52d4bc9db9799f5225fbccdde41",
/* Private Key in TS33.501 C4.4.1 */
"99798858A1DC6A2C68637149A4B1DBFD1FDFF5ADDD62A2142F06699ED7602529",
};
const char *_k[] = {
"039AAB8376597021E855679A9778EA0B67396E68C66DF32C0F41E9ACCA2DA9B9D1",
"0272DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD1",
"03759BB22C563D9F4A6B3C1419E543FC2F39D6823F02A9D71162B39399218B244B",
"0272DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD1",
/* Public Key in TS33.501 C4.4.1 */
"039AAB8376597021E855679A9778EA0B67396E68C66DF32C0F41E9ACCA2DA9B9D1",
/* Public Key in secp256r1-2.key */
"03adefcd1317d1ce8562ec25b91b4800120e1236d6e2661ea4235a84e3c85da244",
};
const char *_ek[] = {
"6C7E6518980025B982FBB2FF746E3C2E85A196D252099A7AD23EA7B4C0959CAE",
"6C7E6518980025B982FBB2FF746E3C2E85A196D252099A7AD23EA7B4C0959CAE",
"BC3529ED79541CF8C007CE9806330F4A5FF15064D7CF4B16943EF8F007597872",
"BC3529ED79541CF8C007CE9806330F4A5FF15064D7CF4B16943EF8F007597872",
/* Share Key from secp256r1-2.key + TS33.501 C4.4.1 */
"4072b8e3989b8695b35b99c923069508726fa3e65551aca1ec9560c501c190ce",
/* Share Key from secp256r1-2.key + TS33.501 C4.4.1 */
"4072b8e3989b8695b35b99c923069508726fa3e65551aca1ec9560c501c190ce",
};
uint8_t e[OGS_ECCKEY_LEN];
uint8_t k[OGS_ECCKEY_LEN+1];
uint8_t ek[OGS_ECCKEY_LEN];
uint8_t tmp[OGS_ECCKEY_LEN];
int i, r, num;
num = 6;
for (i = 0; i < num; i++) {
r = ecdh_shared_secret(
ogs_hex_from_string(_k[i], k, sizeof(k)),
ogs_hex_from_string(_e[i], e, sizeof(e)),
ek);
ABTS_INT_EQUAL(tc, 1, r);
ABTS_TRUE(tc, memcmp(ek,
ogs_hex_from_string(_ek[i], tmp, sizeof(tmp)), OGS_ECCKEY_LEN) == 0);
}
}
static void ansi_x963_kdf(abts_case *tc, void *data)
{
const char *_z[] = {
"028ddf890ec83cdf163947ce45f6ec1a0e3070ea5fe57e2b1f05139f3e82422a",
"511C1DF473BB88317F923501F8BA944FD3B667D25699DCB552DBCEF60BBDC56D",
"6C7E6518980025B982FBB2FF746E3C2E85A196D252099A7AD23EA7B4C0959CAE",
"BC3529ED79541CF8C007CE9806330F4A5FF15064D7CF4B16943EF8F007597872",
/* Share Key from curve25519-1.key + TS33.501 C4.3.1 */
"514bacfdc28039187eec8196339d3ef2665691cd13abcc2a5df15561d9348c60",
/* Share Key from secp256r1-2.key + TS33.501 C4.4.1 */
"4072b8e3989b8695b35b99c923069508726fa3e65551aca1ec9560c501c190ce",
};
const char *_info[] = {
"b2e92f836055a255837debf850b528997ce0201cb82adfe4be1f587d07d8457d",
"977D8B2FDAA7B64AA700D04227D5B440630EA4EC50F9082273A26BB678C92222",
"039AAB8376597021E855679A9778EA0B67396E68C66DF32C0F41E9ACCA2DA9B9D1",
"03759BB22C563D9F4A6B3C1419E543FC2F39D6823F02A9D71162B39399218B244B",
/* Public Key in TS33.501 C4.3.1 */
"b2e92f836055a255837debf850b528997ce0201cb82adfe4be1f587d07d8457d",
/* Public Key in TS33.501 C4.4.1 */
"039AAB8376597021E855679A9778EA0B67396E68C66DF32C0F41E9ACCA2DA9B9D1",
};
int info_len[] = {
32,
32,
33,
33,
32,
33,
};
const char *_ek[] = {
"2ba342cabd2b3b1e5e4e890da11b65f6",
"FE77B87D87F40428EDD71BCA69D79059",
"8A65C3AED80295C12BD55087E965702A",
"84F9A78995D39E6968047547ECC12C4F",
/* Enc Key from curve25519-1.key + TS33.501 C4.3.1 */
"6a898587f494ed58a1185b01207b6710",
/* Enc Key from secp256r1-2.key + TS33.501 C4.4.1 */
"a950bf5f8922b395f9b6bcf8ddfa48c2",
};
const char *_icb[] = {
"e2622cb0cdd08204e721c8ea9b95a7c6",
"cafa5287de2b20e3df1bd3a858da00ac",
"EF285B4061C3BAEE858AB6EC68487DAE",
"a1a6b7f89d422a733675996ebe781eb7",
/* ICB from curve25519-1.key + TS33.501 C4.3.1 */
"ebfc734de36bf03d5e94b9f9db800b32",
/* ICB from secp256r1-2.key + TS33.501 C4.4.1 */
"ff0b5323557bd5e2b1da731cd6ca1416",
};
const char *_mk[] = {
"d9846966fb7cf5fcf11266c5957dea60b83fff2b7c940690a4bfe57b1eb52bd2",
"D87B69F4FE8CD6B211264EA5E69F682F151A82252684CDB15A047E6EF0595028",
"A5EBAC0BC48D9CF7AE5CE39CD840AC6C761AEC04078FAB954D634F923E901C64",
"39D5517E965F8E1252B61345ED45226C5F1A8C69F03D6C91437591F0B8E48FA0",
/* MAC Key from curve25519-1.key + TS33.501 C4.3.1 */
"19045a963a79b4e397f2b81eb0258cbc0a64c9102aaf9e936d5c9f6d44fd8434",
/* MAC Key from secp256r1-2.key + TS33.501 C4.4.1 */
"96f5757bcdb3f4c33976afc96cf7883d3dd017feb3ac229fd813d535e23ed58f",
};
uint8_t z[OGS_ECCKEY_LEN];
uint8_t info[OGS_ECCKEY_LEN+1];
uint8_t ek[OGS_KEY_LEN];
uint8_t icb[OGS_IVEC_LEN];
uint8_t mk[OGS_SHA256_DIGEST_SIZE];
uint8_t tmp[OGS_SHA256_DIGEST_SIZE];
int i, num;
num = 6;
for (i = 0; i < num; i++) {
ogs_kdf_ansi_x963(
ogs_hex_from_string(_z[i], z, sizeof(z)), OGS_ECCKEY_LEN,
ogs_hex_from_string(_info[i], info, sizeof(info)), info_len[i],
ek, icb, mk);
ABTS_TRUE(tc, memcmp(ek,
ogs_hex_from_string(_ek[i], tmp, sizeof(tmp)), OGS_KEY_LEN) == 0);
ABTS_TRUE(tc, memcmp(icb,
ogs_hex_from_string(_icb[i], tmp, sizeof(tmp)), OGS_IVEC_LEN) == 0);
ABTS_TRUE(tc, memcmp(mk,
ogs_hex_from_string(_mk[i], tmp, sizeof(tmp)), OGS_SHA256_DIGEST_SIZE) == 0);
}
}
static void aes_128ctr(abts_case *tc, void *data)
{
const char *_ek[] = {
"2ba342cabd2b3b1e5e4e890da11b65f6",
"FE77B87D87F40428EDD71BCA69D79059",
"8A65C3AED80295C12BD55087E965702A",
"84F9A78995D39E6968047547ECC12C4F",
/* Enc Key from curve25519-1.key + TS33.501 C4.3.1 */
"6a898587f494ed58a1185b01207b6710",
/* Enc Key from secp256r1-2.key + TS33.501 C4.4.1 */
"a950bf5f8922b395f9b6bcf8ddfa48c2",
};
const char *_icb[] = {
"e2622cb0cdd08204e721c8ea9b95a7c6",
"cafa5287de2b20e3df1bd3a858da00ac",
"EF285B4061C3BAEE858AB6EC68487DAE",
"a1a6b7f89d422a733675996ebe781eb7",
/* ICB from curve25519-1.key + TS33.501 C4.3.1 */
"ebfc734de36bf03d5e94b9f9db800b32",
/* ICB from secp256r1-2.key + TS33.501 C4.4.1 */
"ff0b5323557bd5e2b1da731cd6ca1416",
};
const char *_plain[] = {
"00012080f6",
"766572796C6F6E67757365726E616D6531",
"00012080f6",
"766572796C6F6E67757365726E616D6531",
/* Plain-text from curve25519-1.key + TS33.501 C4.3.1 */
"00012080f6",
/* Plain-text from secp256r1-2.key + TS33.501 C4.4.1 */
"00012080f6",
};
const char *_cipher[] = {
"cb02352410",
"8E358A1582ADB15322C10E515141D2039A",
"46A33FC271",
"BE22D8B9F856A52ED381CD7EAF4CF2D525",
/* Ciphered-text from curve25519-1.key + TS33.501 C4.3.1 */
"7ee4435e19",
/* Ciphered-text from secp256r1-2.key + TS33.501 C4.4.1 */
"cdd22e3496",
};
int len[] = {
5,
17,
5,
17,
5,
5,
};
uint8_t ek[OGS_KEY_LEN];
uint8_t icb[OGS_IVEC_LEN];
uint8_t plain[17];
uint8_t cipher[17];
uint8_t tmp[17];
int i, num;
num = 6;
for (i = 0; i < num; i++) {
ogs_aes_ctr128_encrypt(
ogs_hex_from_string(_ek[i], ek, sizeof(ek)),
ogs_hex_from_string(_icb[i], icb, sizeof(icb)),
ogs_hex_from_string(_plain[i], plain, sizeof(plain)), len[i],
cipher);
ABTS_TRUE(tc, memcmp(cipher,
ogs_hex_from_string(_cipher[i], tmp, sizeof(tmp)), len[i]) == 0);
ogs_aes_ctr128_encrypt(
ogs_hex_from_string(_ek[i], ek, sizeof(ek)),
ogs_hex_from_string(_icb[i], icb, sizeof(icb)),
ogs_hex_from_string(_cipher[i], cipher, sizeof(cipher)), len[i],
plain);
ABTS_TRUE(tc, memcmp(plain,
ogs_hex_from_string(_plain[i], tmp, sizeof(tmp)), len[i]) == 0);
}
}
static void hmac_sha_256(abts_case *tc, void *data)
{
const char *_mk[] = {
"d9846966fb7cf5fcf11266c5957dea60b83fff2b7c940690a4bfe57b1eb52bd2",
"D87B69F4FE8CD6B211264EA5E69F682F151A82252684CDB15A047E6EF0595028",
"A5EBAC0BC48D9CF7AE5CE39CD840AC6C761AEC04078FAB954D634F923E901C64",
"39D5517E965F8E1252B61345ED45226C5F1A8C69F03D6C91437591F0B8E48FA0",
/* MAC Key from curve25519-1.key + TS33.501 C4.3.1 */
"19045a963a79b4e397f2b81eb0258cbc0a64c9102aaf9e936d5c9f6d44fd8434",
/* MAC Key from secp256r1-2.key + TS33.501 C4.4.1 */
"96f5757bcdb3f4c33976afc96cf7883d3dd017feb3ac229fd813d535e23ed58f",
};
const char *_cipher[] = {
"cb02352410",
"8E358A1582ADB15322C10E515141D2039A",
"46A33FC271",
"BE22D8B9F856A52ED381CD7EAF4CF2D525",
/* Ciphered-text from curve25519-1.key + TS33.501 C4.3.1 */
"7ee4435e19",
/* Ciphered-text from secp256r1-2.key + TS33.501 C4.4.1 */
"cdd22e3496",
};
const char *_mac_tag[] = {
"cddd9e730ef3fa87",
"12E1D7783A97F1AC",
"6AC7DAE96AA30A4D",
"3CDDC61A0A7882EB",
/* MAG-tag value from curve25519-1.key + TS33.501 C4.3.1 */
"78dc897bff24129c",
/* MAC-tag value secp256r1-2.key + TS33.501 C4.4.1 */
"5500e9242e65f58c",
};
int len[] = {
5,
17,
5,
17,
5,
5,
};
uint8_t mk[OGS_SHA256_DIGEST_SIZE];
uint8_t cipher[17];
uint8_t mac_tag[OGS_MACTAG_LEN];
uint8_t tmp[OGS_MACTAG_LEN];
int i, num;
num = 6;
for (i = 0; i < num; i++) {
ogs_hmac_sha256(
ogs_hex_from_string(_mk[i], mk, sizeof(mk)), OGS_SHA256_DIGEST_SIZE,
ogs_hex_from_string(_cipher[i], cipher, sizeof(cipher)), len[i],
mac_tag, OGS_MACTAG_LEN);
ABTS_TRUE(tc, memcmp(mac_tag,
ogs_hex_from_string(_mac_tag[i], tmp, sizeof(tmp)),
OGS_MACTAG_LEN) == 0);
}
}
abts_suite *test_ecies(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, ecies_profile_a, NULL);
abts_run_test(suite, ecies_profile_b, NULL);
abts_run_test(suite, ansi_x963_kdf, NULL);
abts_run_test(suite, aes_128ctr, NULL);
abts_run_test(suite, hmac_sha_256, NULL);
return suite;
}

View File

@ -19,6 +19,7 @@ testunit_crypt_sources = files('''
aes-test.c
sha-test.c
base64-test.c
ecies-test.c
abts-main.c
'''.split())

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x19b010;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x19b010;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x19b010;
@ -337,15 +332,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x19b010;
@ -537,15 +527,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x19b010;
@ -823,15 +808,10 @@ static void test4_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x19b010;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x19b010;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x19b010;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x19b010;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x19b010;

View File

@ -53,15 +53,10 @@ static void failure_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -456,15 +451,10 @@ static void direct_complete_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -1075,15 +1065,10 @@ static void direct_cancel_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -1494,15 +1479,10 @@ static void indirect_complete_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -2149,15 +2129,10 @@ static void indirect_cancel_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -53,15 +53,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -49,15 +49,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1234560;
@ -619,15 +614,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1234560;
@ -946,15 +936,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1234560;

View File

@ -46,15 +46,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x37;
mobile_identity_suci.scheme_output[1] = 0x46;
mobile_identity_suci.scheme_output[2] = 0;
mobile_identity_suci.scheme_output[3] = 0;
mobile_identity_suci.scheme_output[4] = 0x06;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1234560;

View File

@ -201,8 +201,10 @@ static void test_swx_send_mar(struct sess_state *sess_data)
uint64_t sqn_ms;
int i;
OGS_HEX(test_ue->k_string, strlen(test_ue->k_string), test_ue->k);
OGS_HEX(test_ue->opc_string, strlen(test_ue->opc_string), test_ue->opc);
ogs_hex_from_string(
test_ue->k_string, test_ue->k, sizeof(test_ue->k));
ogs_hex_from_string(
test_ue->opc_string, test_ue->opc, sizeof(test_ue->opc));
milenage_f2345(test_ue->opc, test_ue->k, test_ue->rand,
NULL, NULL, NULL, NULL, ak);

View File

@ -56,15 +56,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x10;
mobile_identity_suci.scheme_output[1] = 0x32;
mobile_identity_suci.scheme_output[2] = 0x54;
mobile_identity_suci.scheme_output[3] = 0x86;
mobile_identity_suci.scheme_output[4] = 0x91;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "1032548691");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1079baf;
@ -202,15 +197,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x10;
mobile_identity_suci.scheme_output[1] = 0x32;
mobile_identity_suci.scheme_output[2] = 0x54;
mobile_identity_suci.scheme_output[3] = 0x86;
mobile_identity_suci.scheme_output[4] = 0x91;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "1032548691");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1079baf;
@ -353,15 +343,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0x10;
mobile_identity_suci.scheme_output[1] = 0x32;
mobile_identity_suci.scheme_output[2] = 0x54;
mobile_identity_suci.scheme_output[3] = 0x86;
mobile_identity_suci.scheme_output[4] = 0x91;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "1032548691");
ogs_assert(test_ue);
test_ue->e_cgi.cell_id = 0x1079baf;

View File

@ -22,6 +22,7 @@
abts_suite *test_simple(abts_suite *suite);
abts_suite *test_guti(abts_suite *suite);
abts_suite *test_auth(abts_suite *suite);
abts_suite *test_ecc(abts_suite *suite);
abts_suite *test_idle(abts_suite *suite);
abts_suite *test_dereg(abts_suite *suite);
abts_suite *test_paging(abts_suite *suite);
@ -38,6 +39,7 @@ const struct testlist {
{test_simple},
{test_guti},
{test_auth},
{test_ecc},
{test_idle},
{test_dereg},
{test_paging},
@ -59,7 +61,9 @@ static void terminate(void)
test_child_terminate();
app_terminate();
ogs_sbi_context_final();
test_5gc_final();
ogs_app_terminate();
}
@ -69,8 +73,12 @@ static void initialize(const char *const argv[])
rv = ogs_app_initialize(NULL, NULL, argv);
ogs_assert(rv == OGS_OK);
test_5gc_init();
ogs_sbi_context_init();
ogs_assert(ogs_sbi_context_parse_config(NULL, "nrf", "scp") == OGS_OK);
rv = app_initialize(argv);
ogs_assert(rv == OGS_OK);
}

View File

@ -47,15 +47,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -412,15 +407,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -778,15 +768,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -294,15 +289,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -506,15 +496,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -958,15 +943,10 @@ static void test4_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -1257,15 +1237,10 @@ static void test5_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -0,0 +1,882 @@
/*
* Copyright (C) 2019,2020 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "test-common.h"
static void test1_func(abts_case *tc, void *data)
{
int rv;
ogs_socknode_t *ngap;
ogs_socknode_t *gtpu;
ogs_pkbuf_t *gmmbuf;
ogs_pkbuf_t *gsmbuf;
ogs_pkbuf_t *nasbuf;
ogs_pkbuf_t *sendbuf;
ogs_pkbuf_t *recvbuf;
ogs_ngap_message_t message;
int i;
ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci;
test_ue_t *test_ue = NULL;
test_sess_t *sess = NULL;
test_bearer_t *qos_flow = NULL;
bson_t *doc = NULL;
const char *scheme_output =
"b2e92f83 6055a255 837debf8 50b52899"
"7ce0201c b82adfe4 be1f587d 07d8457d"
"7ee4435e 1978dc89 7bff2412 9c";
/* Setup Test UE & Session Context */
memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));
mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI;
mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI;
mobile_identity_suci.routing_indicator1 = 0;
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id =
OGS_PROTECTION_SCHEME_PROFILE_A;
mobile_identity_suci.home_network_pki_value = 1;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, scheme_output);
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
test_ue->nas.registration.tsc = 0;
test_ue->nas.registration.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE;
test_ue->nas.registration.follow_on_request = 1;
test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL;
test_ue->k_string = "465b5ce8b199b49faa5f0a2ee238a6bc";
test_ue->opc_string = "e8ed289deba952e4283b54e88e6183ca";
/* gNB connects to AMF */
ngap = testngap_client(AF_INET);
ABTS_PTR_NOTNULL(tc, ngap);
/* gNB connects to UPF */
gtpu = test_gtpu_server(1, AF_INET);
ABTS_PTR_NOTNULL(tc, gtpu);
/* Send NG-Setup Reqeust */
sendbuf = testngap_build_ng_setup_request(0x4000, 22);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive NG-Setup Response */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/********** Insert Subscriber in Database */
doc = test_db_new_simple(test_ue);
ABTS_PTR_NOTNULL(tc, doc);
ABTS_INT_EQUAL(tc, OGS_OK, test_db_insert_ue(test_ue, doc));
/* Send Registration request */
gmmbuf = testgmm_build_registration_request(test_ue, NULL, false, false);
ABTS_PTR_NOTNULL(tc, gmmbuf);
test_ue->registration_request_param.gmm_capability = 1;
test_ue->registration_request_param.s1_ue_network_capability = 1;
test_ue->registration_request_param.requested_nssai = 1;
test_ue->registration_request_param.last_visited_registered_tai = 1;
test_ue->registration_request_param.ue_usage_setting = 1;
nasbuf = testgmm_build_registration_request(test_ue, NULL, false, false);
ABTS_PTR_NOTNULL(tc, nasbuf);
sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf,
NGAP_RRCEstablishmentCause_mo_Signalling, false, true);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Authentication request */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send Authentication response */
gmmbuf = testgmm_build_authentication_response(test_ue);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Security mode command */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send Security mode complete */
gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive InitialContextSetupRequest +
* Registration accept */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_InitialContextSetup,
test_ue->ngap_procedure_code);
/* Send UERadioCapabilityInfoIndication */
sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send InitialContextSetupResponse */
sendbuf = testngap_build_initial_context_setup_response(test_ue, false);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send Registration complete */
gmmbuf = testgmm_build_registration_complete(test_ue);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Configuration update command */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send De-registration request */
gmmbuf = testgmm_build_de_registration_request(test_ue, 1, true, false);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf,
NGAP_RRCEstablishmentCause_mo_Signalling, false, false);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive OLD UEContextReleaseCommand */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_UEContextRelease,
test_ue->ngap_procedure_code);
/* Send OLD UEContextReleaseComplete */
sendbuf = testngap_build_ue_context_release_complete(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive UEContextReleaseCommand */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_UEContextRelease,
test_ue->ngap_procedure_code);
/* Send UEContextReleaseComplete */
sendbuf = testngap_build_ue_context_release_complete(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
ogs_msleep(300);
/********** Remove Subscriber in Database */
ABTS_INT_EQUAL(tc, OGS_OK, test_db_remove_ue(test_ue));
/* gNB disonncect from UPF */
testgnb_gtpu_close(gtpu);
/* gNB disonncect from AMF */
testgnb_ngap_close(ngap);
/* Clear Test UE Context */
test_ue_remove(test_ue);
}
static void test2_func(abts_case *tc, void *data)
{
int rv;
ogs_socknode_t *ngap;
ogs_socknode_t *gtpu;
ogs_pkbuf_t *gmmbuf;
ogs_pkbuf_t *gsmbuf;
ogs_pkbuf_t *nasbuf;
ogs_pkbuf_t *sendbuf;
ogs_pkbuf_t *recvbuf;
ogs_ngap_message_t message;
int i;
ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci;
test_ue_t *test_ue = NULL;
test_sess_t *sess = NULL;
test_bearer_t *qos_flow = NULL;
bson_t *doc = NULL;
const char *scheme_output =
"b2e92f83 6055a255 837debf8 50b52899"
"7ce0201c b82adfe4 be1f587d 07d8457d"
"7ee4435e 1978dc89 7bff2412 9c";
/* Setup Test UE & Session Context */
memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));
mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI;
mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI;
mobile_identity_suci.routing_indicator1 = 0;
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id =
OGS_PROTECTION_SCHEME_PROFILE_A;
mobile_identity_suci.home_network_pki_value = 1;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, scheme_output);
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
test_ue->nas.registration.tsc = 0;
test_ue->nas.registration.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE;
test_ue->nas.registration.follow_on_request = 1;
test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL;
test_ue->k_string = "465b5ce8b199b49faa5f0a2ee238a6bc";
test_ue->opc_string = "e8ed289deba952e4283b54e88e6183ca";
/* gNB connects to AMF */
ngap = testngap_client(AF_INET);
ABTS_PTR_NOTNULL(tc, ngap);
/* gNB connects to UPF */
gtpu = test_gtpu_server(1, AF_INET);
ABTS_PTR_NOTNULL(tc, gtpu);
/* Send NG-Setup Reqeust */
sendbuf = testngap_build_ng_setup_request(0x4000, 22);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive NG-Setup Response */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/********** Insert Subscriber in Database */
doc = test_db_new_simple(test_ue);
ABTS_PTR_NOTNULL(tc, doc);
ABTS_INT_EQUAL(tc, OGS_OK, test_db_insert_ue(test_ue, doc));
/* Send Registration request */
test_ue->registration_request_param.guti = 1;
gmmbuf = testgmm_build_registration_request(test_ue, NULL, false, false);
ABTS_PTR_NOTNULL(tc, gmmbuf);
test_ue->registration_request_param.gmm_capability = 1;
test_ue->registration_request_param.s1_ue_network_capability = 1;
test_ue->registration_request_param.requested_nssai = 1;
test_ue->registration_request_param.last_visited_registered_tai = 1;
test_ue->registration_request_param.ue_usage_setting = 1;
nasbuf = testgmm_build_registration_request(test_ue, NULL, false, false);
ABTS_PTR_NOTNULL(tc, nasbuf);
sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf,
NGAP_RRCEstablishmentCause_mo_Signalling, false, true);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Identity request */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send Identity response */
gmmbuf = testgmm_build_identity_response(test_ue);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Authentication request */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send Authentication response */
gmmbuf = testgmm_build_authentication_response(test_ue);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Security mode command */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send Security mode complete */
gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive InitialContextSetupRequest +
* Registration accept */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_InitialContextSetup,
test_ue->ngap_procedure_code);
/* Send UERadioCapabilityInfoIndication */
sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send InitialContextSetupResponse */
sendbuf = testngap_build_initial_context_setup_response(test_ue, false);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send Registration complete */
gmmbuf = testgmm_build_registration_complete(test_ue);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Configuration update command */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send De-registration request */
gmmbuf = testgmm_build_de_registration_request(test_ue, 1, true, false);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf,
NGAP_RRCEstablishmentCause_mo_Signalling, false, false);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive OLD UEContextReleaseCommand */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_UEContextRelease,
test_ue->ngap_procedure_code);
/* Send OLD UEContextReleaseComplete */
sendbuf = testngap_build_ue_context_release_complete(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive UEContextReleaseCommand */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_UEContextRelease,
test_ue->ngap_procedure_code);
/* Send UEContextReleaseComplete */
sendbuf = testngap_build_ue_context_release_complete(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
ogs_msleep(300);
/********** Remove Subscriber in Database */
ABTS_INT_EQUAL(tc, OGS_OK, test_db_remove_ue(test_ue));
/* gNB disonncect from UPF */
testgnb_gtpu_close(gtpu);
/* gNB disonncect from AMF */
testgnb_ngap_close(ngap);
/* Clear Test UE Context */
test_ue_remove(test_ue);
}
static void test3_func(abts_case *tc, void *data)
{
int rv;
ogs_socknode_t *ngap;
ogs_socknode_t *gtpu;
ogs_pkbuf_t *gmmbuf;
ogs_pkbuf_t *gsmbuf;
ogs_pkbuf_t *nasbuf;
ogs_pkbuf_t *sendbuf;
ogs_pkbuf_t *recvbuf;
ogs_ngap_message_t message;
int i;
ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci;
test_ue_t *test_ue = NULL;
test_sess_t *sess = NULL;
test_bearer_t *qos_flow = NULL;
bson_t *doc = NULL;
const char *scheme_output =
"039AAB83 76597021 E855679A 9778EA0B"
"67396E68 C66DF32C 0F41E9AC CA2DA9B9" "D1"
"cdd22e34 96"
"5500e9242e65f58c";
/* Setup Test UE & Session Context */
memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));
mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI;
mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI;
mobile_identity_suci.routing_indicator1 = 0;
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id =
OGS_PROTECTION_SCHEME_PROFILE_B;
mobile_identity_suci.home_network_pki_value = 2;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, scheme_output);
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
test_ue->nas.registration.tsc = 0;
test_ue->nas.registration.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE;
test_ue->nas.registration.follow_on_request = 1;
test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL;
test_ue->k_string = "465b5ce8b199b49faa5f0a2ee238a6bc";
test_ue->opc_string = "e8ed289deba952e4283b54e88e6183ca";
/* gNB connects to AMF */
ngap = testngap_client(AF_INET);
ABTS_PTR_NOTNULL(tc, ngap);
/* gNB connects to UPF */
gtpu = test_gtpu_server(1, AF_INET);
ABTS_PTR_NOTNULL(tc, gtpu);
/* Send NG-Setup Reqeust */
sendbuf = testngap_build_ng_setup_request(0x4000, 22);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive NG-Setup Response */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/********** Insert Subscriber in Database */
doc = test_db_new_simple(test_ue);
ABTS_PTR_NOTNULL(tc, doc);
ABTS_INT_EQUAL(tc, OGS_OK, test_db_insert_ue(test_ue, doc));
/* Send Registration request */
gmmbuf = testgmm_build_registration_request(test_ue, NULL, false, false);
ABTS_PTR_NOTNULL(tc, gmmbuf);
test_ue->registration_request_param.gmm_capability = 1;
test_ue->registration_request_param.s1_ue_network_capability = 1;
test_ue->registration_request_param.requested_nssai = 1;
test_ue->registration_request_param.last_visited_registered_tai = 1;
test_ue->registration_request_param.ue_usage_setting = 1;
nasbuf = testgmm_build_registration_request(test_ue, NULL, false, false);
ABTS_PTR_NOTNULL(tc, nasbuf);
sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf,
NGAP_RRCEstablishmentCause_mo_Signalling, false, true);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Authentication request */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send Authentication response */
gmmbuf = testgmm_build_authentication_response(test_ue);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Security mode command */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send Security mode complete */
gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive InitialContextSetupRequest +
* Registration accept */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_InitialContextSetup,
test_ue->ngap_procedure_code);
/* Send UERadioCapabilityInfoIndication */
sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send InitialContextSetupResponse */
sendbuf = testngap_build_initial_context_setup_response(test_ue, false);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send Registration complete */
gmmbuf = testgmm_build_registration_complete(test_ue);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Configuration update command */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send De-registration request */
gmmbuf = testgmm_build_de_registration_request(test_ue, 1, true, false);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf,
NGAP_RRCEstablishmentCause_mo_Signalling, false, false);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive OLD UEContextReleaseCommand */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_UEContextRelease,
test_ue->ngap_procedure_code);
/* Send OLD UEContextReleaseComplete */
sendbuf = testngap_build_ue_context_release_complete(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive UEContextReleaseCommand */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_UEContextRelease,
test_ue->ngap_procedure_code);
/* Send UEContextReleaseComplete */
sendbuf = testngap_build_ue_context_release_complete(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
ogs_msleep(300);
/********** Remove Subscriber in Database */
ABTS_INT_EQUAL(tc, OGS_OK, test_db_remove_ue(test_ue));
/* gNB disonncect from UPF */
testgnb_gtpu_close(gtpu);
/* gNB disonncect from AMF */
testgnb_ngap_close(ngap);
/* Clear Test UE Context */
test_ue_remove(test_ue);
}
static void test4_func(abts_case *tc, void *data)
{
int rv;
ogs_socknode_t *ngap;
ogs_socknode_t *gtpu;
ogs_pkbuf_t *gmmbuf;
ogs_pkbuf_t *gsmbuf;
ogs_pkbuf_t *nasbuf;
ogs_pkbuf_t *sendbuf;
ogs_pkbuf_t *recvbuf;
ogs_ngap_message_t message;
int i;
ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci;
test_ue_t *test_ue = NULL;
test_sess_t *sess = NULL;
test_bearer_t *qos_flow = NULL;
bson_t *doc = NULL;
const char *scheme_output =
"039AAB83 76597021 E855679A 9778EA0B"
"67396E68 C66DF32C 0F41E9AC CA2DA9B9" "D1"
"cdd22e34 96"
"5500e9242e65f58c";
/* Setup Test UE & Session Context */
memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));
mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI;
mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI;
mobile_identity_suci.routing_indicator1 = 0;
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id =
OGS_PROTECTION_SCHEME_PROFILE_B;
mobile_identity_suci.home_network_pki_value = 2;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, scheme_output);
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
test_ue->nas.registration.tsc = 0;
test_ue->nas.registration.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE;
test_ue->nas.registration.follow_on_request = 1;
test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL;
test_ue->k_string = "465b5ce8b199b49faa5f0a2ee238a6bc";
test_ue->opc_string = "e8ed289deba952e4283b54e88e6183ca";
/* gNB connects to AMF */
ngap = testngap_client(AF_INET);
ABTS_PTR_NOTNULL(tc, ngap);
/* gNB connects to UPF */
gtpu = test_gtpu_server(1, AF_INET);
ABTS_PTR_NOTNULL(tc, gtpu);
/* Send NG-Setup Reqeust */
sendbuf = testngap_build_ng_setup_request(0x4000, 22);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive NG-Setup Response */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/********** Insert Subscriber in Database */
doc = test_db_new_simple(test_ue);
ABTS_PTR_NOTNULL(tc, doc);
ABTS_INT_EQUAL(tc, OGS_OK, test_db_insert_ue(test_ue, doc));
/* Send Registration request */
test_ue->registration_request_param.guti = 1;
gmmbuf = testgmm_build_registration_request(test_ue, NULL, false, false);
ABTS_PTR_NOTNULL(tc, gmmbuf);
test_ue->registration_request_param.gmm_capability = 1;
test_ue->registration_request_param.s1_ue_network_capability = 1;
test_ue->registration_request_param.requested_nssai = 1;
test_ue->registration_request_param.last_visited_registered_tai = 1;
test_ue->registration_request_param.ue_usage_setting = 1;
nasbuf = testgmm_build_registration_request(test_ue, NULL, false, false);
ABTS_PTR_NOTNULL(tc, nasbuf);
sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf,
NGAP_RRCEstablishmentCause_mo_Signalling, false, true);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Identity request */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send Identity response */
gmmbuf = testgmm_build_identity_response(test_ue);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Authentication request */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send Authentication response */
gmmbuf = testgmm_build_authentication_response(test_ue);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Security mode command */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send Security mode complete */
gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive InitialContextSetupRequest +
* Registration accept */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_InitialContextSetup,
test_ue->ngap_procedure_code);
/* Send UERadioCapabilityInfoIndication */
sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send InitialContextSetupResponse */
sendbuf = testngap_build_initial_context_setup_response(test_ue, false);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send Registration complete */
gmmbuf = testgmm_build_registration_complete(test_ue);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Configuration update command */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
/* Send De-registration request */
gmmbuf = testgmm_build_de_registration_request(test_ue, 1, true, false);
ABTS_PTR_NOTNULL(tc, gmmbuf);
sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf,
NGAP_RRCEstablishmentCause_mo_Signalling, false, false);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive OLD UEContextReleaseCommand */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_UEContextRelease,
test_ue->ngap_procedure_code);
/* Send OLD UEContextReleaseComplete */
sendbuf = testngap_build_ue_context_release_complete(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive UEContextReleaseCommand */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_UEContextRelease,
test_ue->ngap_procedure_code);
/* Send UEContextReleaseComplete */
sendbuf = testngap_build_ue_context_release_complete(test_ue);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
ogs_msleep(300);
/********** Remove Subscriber in Database */
ABTS_INT_EQUAL(tc, OGS_OK, test_db_remove_ue(test_ue));
/* gNB disonncect from UPF */
testgnb_gtpu_close(gtpu);
/* gNB disonncect from AMF */
testgnb_ngap_close(ngap);
/* Clear Test UE Context */
test_ue_remove(test_ue);
}
abts_suite *test_ecc(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, test1_func, NULL);
abts_run_test(suite, test2_func, NULL);
abts_run_test(suite, test3_func, NULL);
abts_run_test(suite, test4_func, NULL);
return suite;
}

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -528,15 +523,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -990,15 +980,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -315,7 +310,7 @@ static void test1_func(abts_case *tc, void *data)
#endif
/* INVALID SUCI */
test_ue->mobile_identity_suci.scheme_output[0] = 0x99;
((uint8_t *)(test_ue->mobile_identity.buffer))[9] = 0x99;
/* Send Identity response */
gmmbuf = testgmm_build_identity_response(test_ue);

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -444,15 +439,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -692,15 +682,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -1050,15 +1035,10 @@ static void test4_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -1503,15 +1483,10 @@ static void test5_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -1862,15 +1837,10 @@ static void test6_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -20,6 +20,7 @@ test5gc_registration_sources = files('''
simple-test.c
guti-test.c
auth-test.c
ecc-test.c
idle-test.c
dereg-test.c
paging-test.c

View File

@ -60,7 +60,13 @@ static void test1_func(abts_case *tc, void *data)
ABTS_PTR_NOTNULL(tc, recvbuf);
for (i = 0; i < NUM_OF_TEST_UE; i++) {
uint64_t imsi_index;
const char *scheme_output[] = {
"0000000001",
"0000000002",
"0000000003",
"0000000004",
"0000000005",
};
/* Setup Test UE & Session Context */
memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));
@ -71,18 +77,11 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
imsi_index = i + 1;
ogs_uint64_to_buffer(imsi_index, 5, mobile_identity_suci.scheme_output);
test_ue[i] = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue[i] = test_ue_add_by_suci(
&mobile_identity_suci, scheme_output[i]);
ogs_assert(test_ue[i]);
test_ue[i]->nr_cgi.cell_id = 0x40001;

View File

@ -48,15 +48,10 @@ static void cm_idle_paging_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -614,15 +609,10 @@ static void cm_connected_paging_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -959,15 +949,10 @@ static void cm_idle_error_indication_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -1306,15 +1291,10 @@ static void cm_connected_error_indication_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -1589,15 +1569,10 @@ static void vonr_qos_flow_test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -1989,15 +1964,10 @@ static void vonr_session_test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -2483,15 +2453,10 @@ static void registration_ue_context_test4_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -2877,15 +2842,10 @@ static void registration_idle_test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -360,15 +355,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -625,15 +615,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

View File

@ -48,15 +48,10 @@ static void test1_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -209,15 +204,10 @@ static void test2_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -509,15 +499,10 @@ static void test3_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -957,15 +942,10 @@ static void test4_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;
@ -1332,15 +1312,10 @@ static void test5_func(abts_case *tc, void *data)
mobile_identity_suci.routing_indicator2 = 0xf;
mobile_identity_suci.routing_indicator3 = 0xf;
mobile_identity_suci.routing_indicator4 = 0xf;
mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME;
mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
mobile_identity_suci.home_network_pki_value = 0;
mobile_identity_suci.scheme_output[0] = 0;
mobile_identity_suci.scheme_output[1] = 0;
mobile_identity_suci.scheme_output[2] = 0x20;
mobile_identity_suci.scheme_output[3] = 0x31;
mobile_identity_suci.scheme_output[4] = 0x90;
test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13);
test_ue = test_ue_add_by_suci(&mobile_identity_suci, "0000203190");
ogs_assert(test_ue);
test_ue->nr_cgi.cell_id = 0x40001;

Some files were not shown because too many files have changed in this diff Show More