mirror of https://gerrit.osmocom.org/libosmocore
Refactor COMP128v23 implementation and add test suit
This commit is contained in:
parent
56cc60dc20
commit
4f0abc0e3e
|
@ -62,6 +62,7 @@ tests/ussd/ussd_test
|
|||
tests/smscb/smscb_test
|
||||
tests/bits/bitrev_test
|
||||
tests/a5/a5_test
|
||||
tests/comp128/comp128_test
|
||||
tests/auth/milenage_test
|
||||
tests/conv/conv_test
|
||||
tests/lapd/lapd_test
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
* Performs the COMP128 version 2 and 3 algorithm (used as A3/A8)
|
||||
* ki : uint8_t [16]
|
||||
* srand : uint8_t [16]
|
||||
* version : uint8_t (2 or 3)
|
||||
* sres : uint8_t [4]
|
||||
* kc : uint8_t [8]
|
||||
* returns 1 if not version 2 or 3 specified
|
||||
*/
|
||||
int comp128v23(const uint8_t *ki, const uint8_t *rand, uint8_t version, uint8_t *sres, uint8_t *kc);
|
||||
int comp128v2(const uint8_t *ki, const uint8_t *rand, uint8_t *sres, uint8_t *kc);
|
||||
int comp128v3(const uint8_t *ki, const uint8_t *rand, uint8_t *sres, uint8_t *kc);
|
||||
|
||||
#endif /* __COMP128V23_H__ */
|
||||
|
|
|
@ -31,7 +31,7 @@ static int c128v2_gen_vec(struct osmo_auth_vector *vec,
|
|||
struct osmo_sub_auth_data *aud,
|
||||
const uint8_t *_rand)
|
||||
{
|
||||
comp128v23(aud->u.gsm.ki, _rand, 2, vec->sres, vec->kc);
|
||||
comp128v2(aud->u.gsm.ki, _rand, vec->sres, vec->kc);
|
||||
vec->auth_types = OSMO_AUTH_TYPE_GSM;
|
||||
|
||||
return 0;
|
||||
|
@ -48,7 +48,7 @@ static int c128v3_gen_vec(struct osmo_auth_vector *vec,
|
|||
struct osmo_sub_auth_data *aud,
|
||||
const uint8_t *_rand)
|
||||
{
|
||||
comp128v23(aud->u.gsm.ki, _rand, 3, vec->sres, vec->kc);
|
||||
comp128v3(aud->u.gsm.ki, _rand, vec->sres, vec->kc);
|
||||
vec->auth_types = OSMO_AUTH_TYPE_GSM;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -64,21 +64,17 @@ static const uint8_t table0[256] = {
|
|||
218, 160, 187, 106, 35, 87, 105, 96, 145, 199, 159, 12, 121, 103, 112
|
||||
};
|
||||
|
||||
#define RAND_SIZE 16
|
||||
#define KI_SIZE 16
|
||||
#define SRES_SIZE 4
|
||||
#define KC_SIZE 8
|
||||
|
||||
static void
|
||||
_comp128v23_internal(uint8_t *output, const uint8_t *kxor, const uint8_t *rand)
|
||||
{
|
||||
uint8_t temp[RAND_SIZE];
|
||||
uint8_t km_rm[RAND_SIZE+KI_SIZE];
|
||||
uint8_t temp[16];
|
||||
uint8_t km_rm[32];
|
||||
uint8_t i,j,k,z;
|
||||
|
||||
memset(temp,0,sizeof(temp)/sizeof(uint8_t));
|
||||
memcpy(km_rm,rand,RAND_SIZE);
|
||||
memcpy(km_rm+RAND_SIZE,kxor,KI_SIZE);
|
||||
memset(temp, 0, sizeof(temp));
|
||||
memcpy(km_rm, rand, 16);
|
||||
memcpy(km_rm + 16, kxor, 16);
|
||||
|
||||
for (i=0; i<5; i++) {
|
||||
for (z=0; z<16; z++) {
|
||||
|
@ -106,21 +102,18 @@ _comp128v23_internal(uint8_t *output, const uint8_t *kxor, const uint8_t *rand)
|
|||
}
|
||||
|
||||
int
|
||||
comp128v23(const uint8_t *ki, const uint8_t *rand, uint8_t version, uint8_t *sres, uint8_t *kc)
|
||||
comp128v3(const uint8_t *ki, const uint8_t *rand, uint8_t *sres, uint8_t *kc)
|
||||
{
|
||||
uint8_t k_mix[KI_SIZE];
|
||||
uint8_t rand_mix[RAND_SIZE];
|
||||
uint8_t katyvasz[KI_SIZE];
|
||||
uint8_t output[KI_SIZE];
|
||||
uint8_t i,s;
|
||||
uint8_t k_mix[16];
|
||||
uint8_t rand_mix[16];
|
||||
uint8_t katyvasz[16];
|
||||
uint8_t output[16];
|
||||
uint8_t i;
|
||||
|
||||
if (!(version==2 || version==3))
|
||||
return 1;
|
||||
|
||||
memset(k_mix,0,sizeof(k_mix)/sizeof(uint8_t));
|
||||
memset(rand_mix,0,sizeof(rand_mix)/sizeof(uint8_t));
|
||||
memset(katyvasz,0,sizeof(katyvasz)/sizeof(uint8_t));
|
||||
memset(output,0,sizeof(output)/sizeof(uint8_t));
|
||||
memset(k_mix, 0, sizeof(k_mix));
|
||||
memset(rand_mix, 0, sizeof(rand_mix));
|
||||
memset(katyvasz, 0, sizeof(katyvasz));
|
||||
memset(output, 0, sizeof(output));
|
||||
|
||||
for (i=0; i<8; i++) {
|
||||
k_mix[i] = ki[15 - i];
|
||||
|
@ -144,23 +137,21 @@ comp128v23(const uint8_t *ki, const uint8_t *rand, uint8_t version, uint8_t *sre
|
|||
output[i] = rand_mix[15-i];
|
||||
}
|
||||
|
||||
if (version==2) {
|
||||
output[15] = 0;
|
||||
output[14] = 4*(output[14]>>2);
|
||||
}
|
||||
|
||||
s = 8;
|
||||
i = 0;
|
||||
while (i<4) {
|
||||
output[s+i-4] = output[s+i];
|
||||
output[s+i] = output[s+i+4];
|
||||
i++;
|
||||
}
|
||||
memmove(output + 4, output + 8, 8); /* ignore bytes 4..7 */
|
||||
|
||||
/* the algorithm uses 16 bytes until this point, but only 12 bytes are effective
|
||||
* also 12 bytes coming out from the SIM card */
|
||||
memcpy(sres,output,SRES_SIZE*sizeof(uint8_t));
|
||||
memcpy(kc,&output[SRES_SIZE],KC_SIZE*sizeof(uint8_t));
|
||||
memcpy(sres, output, 4);
|
||||
memcpy(kc, output + 4, 8);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
comp128v2(const uint8_t *ki, const uint8_t *rand, uint8_t *sres, uint8_t *kc)
|
||||
{
|
||||
int r = comp128v3(ki, rand, sres, kc);
|
||||
kc[7] = 0; /* 10 last bits of Kc forced to 0 */
|
||||
kc[6] &= 0xfc;
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \
|
|||
gb/bssgp_fc_test gb/gprs_ns_test \
|
||||
logging/logging_test fr/fr_test \
|
||||
loggingrb/loggingrb_test strrb/strrb_test \
|
||||
vty/vty_test
|
||||
vty/vty_test comp128/comp128_test
|
||||
|
||||
if ENABLE_MSGFILE
|
||||
check_PROGRAMS += msgfile/msgfile_test
|
||||
|
@ -16,6 +16,9 @@ endif
|
|||
a5_a5_test_SOURCES = a5/a5_test.c
|
||||
a5_a5_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
|
||||
|
||||
comp128_comp128_test_SOURCES = comp128/comp128_test.c
|
||||
comp128_comp128_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
|
||||
|
||||
auth_milenage_test_SOURCES = auth/milenage_test.c
|
||||
auth_milenage_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
|
||||
|
||||
|
@ -101,7 +104,7 @@ EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \
|
|||
logging/logging_test.ok logging/logging_test.err \
|
||||
fr/fr_test.ok loggingrb/logging_test.ok \
|
||||
loggingrb/logging_test.err strrb/strrb_test.ok \
|
||||
vty/vty_test.ok
|
||||
vty/vty_test.ok comp128/comp128_test.ok
|
||||
|
||||
DISTCLEANFILES = atconfig
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -54,6 +54,12 @@ cat $abs_srcdir/auth/milenage_test.ok > expout
|
|||
AT_CHECK([$abs_top_builddir/tests/auth/milenage_test], [0], [expout], [ignore])
|
||||
AT_CLEANUP
|
||||
|
||||
AT_SETUP([comp128])
|
||||
AT_KEYWORDS([comp128])
|
||||
cat $abs_srcdir/comp128/comp128_test.ok > expout
|
||||
AT_CHECK([$abs_top_builddir/tests/comp128/comp128_test], [0], [expout])
|
||||
AT_CLEANUP
|
||||
|
||||
AT_SETUP([lapd])
|
||||
AT_KEYWORDS([lapd])
|
||||
cat $abs_srcdir/lapd/lapd_test.ok > expout
|
||||
|
|
Loading…
Reference in New Issue