update it

This commit is contained in:
Sukchan Lee 2017-03-03 22:05:05 +09:00
parent 4dc2571ed2
commit b489fa4b46
4 changed files with 28 additions and 11 deletions

View File

@ -88,7 +88,8 @@ 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);
CORE_DECLARE(void *) core_uint64_to_buffer(c_uint64_t num, c_uint8_t *array);
CORE_DECLARE(void *) core_int_to_buffer(c_uint64_t num,
c_uint8_t *buffer, int size);
/** @} */

View File

@ -14,11 +14,11 @@ void *core_ascii_to_hex(char *in, int len, char *out)
return out;
}
void *core_uint64_to_buffer(c_uint64_t num, c_uint8_t *buffer)
void *core_int_to_buffer(c_uint64_t num, c_uint8_t *buffer, int size)
{
int i;
for (i = 0; i < 8; i++)
buffer[i] = (num >> (8-1-i) * 8) & 0xff;
for (i = 0; i < size; i++)
buffer[i] = (num >> ((size-1-i) * 8)) & 0xff;
return buffer;
}

View File

@ -35,11 +35,27 @@ static void misc_test2(abts_case *tc, void *data)
static void misc_test3(abts_case *tc, void *data)
{
c_uint64_t num = 0x0123456789abcdef;
c_uint8_t buf[8];
c_uint8_t tmp[8] = "\x01\x23\x45\x67\x89\xab\xcd\xef";
#define MAX_SIZE 8
c_uint8_t tmp[MAX_SIZE] = "\x01\x23\x45\x67\x89\xab\xcd\xef";
c_uint8_t buf[MAX_SIZE];
c_uint64_t num;
ABTS_TRUE(tc, memcmp(tmp, core_uint64_to_buffer(num, buf), 8) == 0);
num = 0x0123456789abcdef;
ABTS_TRUE(tc, memcmp(tmp, core_int_to_buffer(num, buf, 8), 8) == 0);
num = 0x0123456789abcd;
ABTS_TRUE(tc, memcmp(tmp, core_int_to_buffer(num, buf, 7), 7) == 0);
num = 0x0123456789ab;
ABTS_TRUE(tc, memcmp(tmp, core_int_to_buffer(num, buf, 6), 6) == 0);
num = 0x0123456789;
ABTS_TRUE(tc, memcmp(tmp, core_int_to_buffer(num, buf, 5), 5) == 0);
num = 0x01234567;
ABTS_TRUE(tc, memcmp(tmp, core_int_to_buffer(num, buf, 4), 4) == 0);
num = 0x012345;
ABTS_TRUE(tc, memcmp(tmp, core_int_to_buffer(num, buf, 3), 3) == 0);
num = 0x0123;
ABTS_TRUE(tc, memcmp(tmp, core_int_to_buffer(num, buf, 2), 2) == 0);
num = 0x01;
ABTS_TRUE(tc, memcmp(tmp, core_int_to_buffer(num, buf, 1), 1) == 0);
}
abts_suite *testmisc(abts_suite *suite)

View File

@ -38,7 +38,7 @@ static int hss_air_cb( struct msg **msg, struct avp *avp,
union avp_value val;
ue_ctx_t *ue = NULL;
c_uint8_t buffer[8];
c_uint8_t sqn[MAX_SQN_LEN];
c_uint8_t autn[MAX_KEY_LEN];
c_uint8_t ik[MAX_KEY_LEN];
c_uint8_t ck[MAX_KEY_LEN];
@ -75,9 +75,9 @@ static int hss_air_cb( struct msg **msg, struct avp *avp,
core_generate_random_bytes(ue->rand, MAX_KEY_LEN);
milenage_opc(ue->k, ue->op, ue->opc);
milenage_generate(ue->opc, ue->amf, ue->k,
core_uint64_to_buffer(ue->sqn, buffer), ue->rand,
core_int_to_buffer(ue->sqn, sqn, MAX_SQN_LEN), ue->rand,
autn, ik, ck, ak, xres, &xres_len);
derive_kasme(ck, ik, hdr->avp_value->os.data, buffer, ak, kasme);
derive_kasme(ck, ik, hdr->avp_value->os.data, sqn, ak, kasme);
ue->sqn = (ue->sqn + 32) & 0x7ffffffffff;