update it

This commit is contained in:
Sukchan Lee 2017-03-06 22:47:39 +09:00
parent 6fc3d16f7a
commit 118e7eb84d
11 changed files with 67 additions and 26 deletions

View File

@ -3,10 +3,10 @@
noinst_LTLIBRARIES = lib3gpp.la
lib3gpp_la_SOURCES = \
3gpp_common.h plmn_id.h key_derive.h
3gpp_common.h plmn_id.h
nodist_lib3gpp_la_SOURCES = \
plmn_id.c key_derive.c
plmn_id.c
AM_CPPFLAGS = \
-I$(top_srcdir)/lib/core/include

View File

@ -1,10 +0,0 @@
#ifndef __3GPP_KDF_H__
#define __3GPP_KDF_H__
#include "core.h"
void key_derive_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
const c_uint8_t plmn_id[3], const c_uint8_t *sqn, const c_uint8_t *ak,
c_uint8_t *kasme);
#endif /* __3GPP_KDF_H__ */

View File

@ -3,10 +3,10 @@
noinst_LTLIBRARIES = libhss.la
libhss_la_SOURCES = \
milenage.h context.h
milenage.h kdf.h context.h
nodist_libhss_la_SOURCES = \
milenage.c init.c context.c
milenage.c kdf.c init.c context.c
libhss_la_DEPENDENCIES = \
$(top_srcdir)/lib/core/src/libcore.la \

View File

@ -4,7 +4,7 @@
#include "core_lib.h"
#include "core_sha2.h"
#include "key_derive.h"
#include "kdf.h"
#include "milenage.h"
#include "context.h"
@ -74,7 +74,7 @@ static int hss_air_cb( struct msg **msg, struct avp *avp,
milenage_generate(ue->opc, ue->amf, ue->k,
core_uint64_to_buffer(ue->sqn, MAX_SQN_LEN, sqn), ue->rand,
autn, ik, ck, ak, xres, &xres_len);
key_derive_kasme(ck, ik, hdr->avp_value->os.data, sqn, ak, kasme);
hss_kdf_kasme(ck, ik, hdr->avp_value->os.data, sqn, ak, kasme);
ue->sqn = (ue->sqn + 32) & 0x7ffffffffff;

View File

@ -1,9 +1,10 @@
#define TRACE_MODULE _3gpp_kdf
#define TRACE_MODULE _hss_kdf
#include "core_debug.h"
#include "core_sha2_hmac.h"
void key_derive_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
#define FC_VALUE 0x10
void hss_kdf_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
const c_uint8_t plmn_id[3], const c_uint8_t *sqn, const c_uint8_t *ak,
c_uint8_t *kasme)
{
@ -14,14 +15,13 @@ void key_derive_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
memcpy(&k[0], ck, 16);
memcpy(&k[16], ik, 16);
s[0] = 0x10;
s[0] = FC_VALUE;
memcpy(&s[1], plmn_id, 3);
s[4] = 0x00;
s[5] = 0x03;
for (i = 0; i < 6; i++)
s[6+i] = sqn[i] ^ ak[i];
s[12] = 0x00;
s[13] = 0x06;

10
src/hss/kdf.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __HSS_KDF_H__
#define __HSS_KDF_H__
#include "core.h"
void hss_kdf_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
const c_uint8_t plmn_id[3], const c_uint8_t *sqn, const c_uint8_t *ak,
c_uint8_t *kasme);
#endif /* __HSS_KDF_H__ */

View File

@ -3,12 +3,14 @@
noinst_LTLIBRARIES = libmme.la
libmme_la_SOURCES = \
kdf.h \
event.h context.h \
s1ap_build.h s1ap_conv.h s1ap_path.h \
nas_conv.h \
sm.h s6a_sm.h
nodist_libmme_la_SOURCES = \
kdf.c \
init.c event.c context.c \
s1ap_build.c s1ap_conv.c s1ap_path.c \
nas_conv.c \

View File

@ -1,5 +1,5 @@
#ifndef __CONTEXT_H__
#define __CONTEXT_H__
#ifndef __MME_CTX_H__
#define __MME_CTX_H__
#include "core_list.h"
#include "core_errno.h"
@ -128,4 +128,4 @@ CORE_DECLARE(rab_ctx_t*) mme_ctx_rab_next(rab_ctx_t *ue);
}
#endif /* __cplusplus */
#endif /* !__CONTEXT_H__ */
#endif /* __MME_CTX_H__ */

25
src/mme/kdf.c Normal file
View File

@ -0,0 +1,25 @@
#define TRACE_MODULE _mme_kdf
#include "core_sha2_hmac.h"
#define FC_VALUE 0x15
void mme_kdf_nas(c_uint8_t algorithm_type_distinguishers,
c_uint8_t algorithm_identity, c_uint8_t *kasme, c_uint8_t *knas)
{
c_uint8_t s[7];
c_uint8_t out[32];
s[0] = FC_VALUE;
s[1] = algorithm_type_distinguishers;
s[2] = 0x00;
s[3] = 0x01;
s[1] = algorithm_identity;
s[2] = 0x00;
s[3] = 0x01;
hmac_sha256(kasme, 32, s, 7, out, 32);
memcpy(knas, out+16, 16);
}

14
src/mme/kdf.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef __MME_KDF_H__
#define __MME_KDF_H__
#include "core.h"
#include "nas_ies.h"
#define MME_KDF_NAS_ENC_ALG 0x01
#define MME_KDF_NAS_INT_ALG 0x02
void mme_kdf_nas(c_uint8_t algorithm_type_distinguishers,
c_uint8_t algorithm_identity, c_uint8_t *kasme, c_uint8_t *knas);
#endif /* __MME_KDF_H__ */

View File

@ -3,7 +3,7 @@
#include "core_sha2_hmac.h"
#include "milenage.h"
#include "key_derive.h"
#include "hss/kdf.h"
#include "testutil.h"
@ -107,7 +107,7 @@ static void security_test3(abts_case *tc, void *data)
c_uint8_t kasme[32];
c_uint8_t tmp[32];
key_derive_kasme(
hss_kdf_kasme(
core_ascii_to_hex(_ck, strlen(_ck), ck),
core_ascii_to_hex(_ik, strlen(_ik), ik),
core_ascii_to_hex(_plmn_id, strlen(_plmn_id), plmn_id),