k, op, opc, amf is added

This commit is contained in:
Sukchan Lee 2017-03-02 14:18:24 +09:00
parent 713d786f0c
commit 604817869f
5 changed files with 61 additions and 13 deletions

View File

@ -81,6 +81,8 @@ extern "C" {
CORE_DECLARE(status_t) core_generate_random_bytes(
unsigned char *buf, int length);
CORE_DECLARE(void *) core_ascii_to_hex(char *in, int len, char *out);
/** @} */
#ifdef __cplusplus

View File

@ -20,7 +20,7 @@ libcore_la_SOURCES = \
nodist_libcore_la_SOURCES = \
debug.c fsm.c msgq.c ringbuf.c timer.c tlv.c \
aes.c aes_cmac.c sha1.c sha1_hmac.c sha2.c sha2_hmac.c
aes.c aes_cmac.c sha1.c sha1_hmac.c sha2.c sha2_hmac.c misc.c
libcore_la_DEPENDENCIES = \
$(top_srcdir)/lib/core/src/@OSDIR@/libcore@OSDIR@.la

15
lib/core/src/misc.c Normal file
View File

@ -0,0 +1,15 @@
#include "core_errno.h"
void *core_ascii_to_hex(char *in, int len, char *out)
{
int i, j, high, low;
for (i = 0, j = 0; i < len; i+=2, j+=1)
{
high = in[i] > '9' ? in[i] - 'A' + 10 : in[i] - '0';
low = in[i+1] > '9' ? in[i+1] - 'A' + 10 : in[i+1] - '0';
out[j] = (high << 4) | low;
}
return out;
}

View File

@ -9,11 +9,36 @@ static void misc_test1(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, CORE_OK, core_generate_random_bytes(c, sizeof c));
}
static void misc_test2(abts_case *tc, void *data)
{
#define K "465B5CE8B199B49FAA5F0A2EE238A6BC"
#define OP "5F1D289C5D354D0A140C2548F5F3E3BA"
#define OPc "E8ED289DEBA952E4283B54E88E6183CA"
#define AMF "8000"
c_uint8_t k[16] = "\x46\x5B\x5C\xE8\xB1\x99\xB4\x9F\xAA\x5F\x0A\x2E\xE2\x38\xA6\xBC";
c_uint8_t op[16] = "\x5F\x1D\x28\x9C\x5D\x35\x4D\x0A\x14\x0C\x25\x48\xF5\xF3\xE3\xBA";
c_uint8_t opc[16] = "\xE8\xED\x28\x9D\xEB\xA9\x52\xE4\x28\x3B\x54\xE8\x8E\x61\x83\xCA";
c_uint8_t amf[2] = { 0x80, 0x00 };
char buffer[16];
ABTS_TRUE(tc, memcmp(k, core_ascii_to_hex(K, strlen(K), buffer), 16) == 0);
ABTS_TRUE(tc, memcmp(op, core_ascii_to_hex(OP, strlen(OP), buffer), 16) == 0);
ABTS_TRUE(tc, memcmp(opc,
core_ascii_to_hex(OPc, strlen(OPc), buffer), 16) == 0);
ABTS_TRUE(tc, memcmp(amf,
core_ascii_to_hex(AMF, strlen(AMF), buffer), 2) == 0);
}
abts_suite *testmisc(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, misc_test1, NULL);
abts_run_test(suite, misc_test2, NULL);
return suite;
}

View File

@ -2,6 +2,7 @@
#include "core_debug.h"
#include "core_pool.h"
#include "core_lib.h"
#include "hss_ctx.h"
#include "s6a_app.h"
@ -111,11 +112,12 @@ int hss_init(void)
/* FIXME : this is a sample UE for testing */
{
ue_ctx_t *ue;
char buffer[MAX_KEY_LEN];
char k[16] = "\x46\x5B\x5C\xE8\xB1\x99\xB4\x9F\xAA\x5F\x0A\x2E\xE2\x38\xA6\xBC";
char op[16] = "\x5F\x1D\x28\x9C\x5D\x35\x4D\x0A\x14\x0C\x25\x48\xF5\xF3\xE3\xBA";
char opc[16] = "\xE8\xED\x28\x9D\xEB\xA9\x52\xE4\x28\x3B\x54\xE8\x8E\x61\x83\xCA";
char amf[2] = { 0x80, 0x00 };
#define K "465B5CE8B199B49FAA5F0A2EE238A6BC"
#define OP "5F1D289C5D354D0A140C2548F5F3E3BA"
#define OPc "E8ED289DEBA952E4283B54E88E6183CA"
#define AMF "8000"
ue = hss_ue_ctx_add();
d_assert(ue, return -1, "UE context add failed");
@ -124,10 +126,12 @@ int hss_init(void)
strcpy((char*)ue->imsi, UE1_IMSI);
ue->imsi_len = strlen(UE1_IMSI);
memcpy(ue->k, k, MAX_KEY_LEN);
memcpy(ue->op, op, MAX_KEY_LEN);
memcpy(ue->opc, opc, MAX_KEY_LEN);
memcpy(ue->amf, amf, MAX_AMF_LEN);
memcpy(ue->k, core_ascii_to_hex(K, strlen(K), buffer), MAX_KEY_LEN);
memcpy(ue->op, core_ascii_to_hex(OP, strlen(OP), buffer), MAX_KEY_LEN);
memcpy(ue->opc,
core_ascii_to_hex(OPc, strlen(OPc), buffer), MAX_KEY_LEN);
memcpy(ue->amf,
core_ascii_to_hex(AMF, strlen(AMF), buffer), MAX_KEY_LEN);
ue = hss_ue_ctx_add();
d_assert(ue, return -1, "UE context add failed");
@ -136,10 +140,12 @@ int hss_init(void)
strcpy((char*)ue->imsi, UE2_IMSI);
ue->imsi_len = strlen(UE2_IMSI);
memcpy(ue->k, k, MAX_KEY_LEN);
memcpy(ue->op, op, MAX_KEY_LEN);
memcpy(ue->opc, opc, MAX_KEY_LEN);
memcpy(ue->amf, amf, MAX_AMF_LEN);
memcpy(ue->k, core_ascii_to_hex(K, strlen(K), buffer), MAX_KEY_LEN);
memcpy(ue->op, core_ascii_to_hex(OP, strlen(OP), buffer), MAX_KEY_LEN);
memcpy(ue->opc,
core_ascii_to_hex(OPc, strlen(OPc), buffer), MAX_KEY_LEN);
memcpy(ue->amf,
core_ascii_to_hex(AMF, strlen(AMF), buffer), MAX_KEY_LEN);
}
memset(&data, 0, sizeof(data));