gsm/auth: Add the XOR test algorithm

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
Sylvain Munaut 2014-02-06 14:00:13 +01:00
parent 9e76905c56
commit 01513720b0
6 changed files with 151 additions and 5 deletions

View File

@ -17,7 +17,7 @@ libosmogsm_la_SOURCES = a5.c rxlev_stat.c tlv_parser.c comp128.c comp128v23.c \
gsm0411_utils.c gsm0411_smc.c gsm0411_smr.c \
lapd_core.c lapdm.c \
auth_core.c auth_comp128v1.c auth_comp128v23.c \
auth_milenage.c milenage/aes-encblock.c \
auth_xor.c auth_milenage.c milenage/aes-encblock.c \
milenage/aes-internal.c milenage/aes-internal-enc.c \
milenage/milenage.c gan.c

51
src/gsm/auth_xor.c Normal file
View File

@ -0,0 +1,51 @@
/* GSM/GPRS/3G authentication core infrastructure */
/* (C) 2014 by Sylvain Munaut <tnt@246tNt.com>
*
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <osmocom/crypt/auth.h>
static int xor_gen_vec(struct osmo_auth_vector *vec,
struct osmo_sub_auth_data *aud,
const uint8_t *_rand)
{
int i;
for (i=0; i<4; i++)
vec->sres[i] = _rand[i] ^ aud->u.gsm.ki[i];
for (i=0; i<8; i++)
vec->kc[i] = _rand[i+4] ^ aud->u.gsm.ki[i+4];
vec->auth_types = OSMO_AUTH_TYPE_GSM;
return 0;
}
static struct osmo_auth_impl xor_alg = {
.algo = OSMO_AUTH_ALG_XOR,
.name = "XOR (libosmogsm built-in)",
.priority = 1000,
.gen_vec = &xor_gen_vec,
};
static __attribute__((constructor)) void on_dso_load_xor(void)
{
osmo_auth_register(&xor_alg);
}

View File

@ -7,7 +7,8 @@ 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 comp128/comp128_test utils/utils_test
vty/vty_test comp128/comp128_test utils/utils_test \
auth/gsm_test
if ENABLE_MSGFILE
check_PROGRAMS += msgfile/msgfile_test
@ -25,6 +26,9 @@ comp128_comp128_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/
auth_milenage_test_SOURCES = auth/milenage_test.c
auth_milenage_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
auth_gsm_test_SOURCES = auth/gsm_test.c
auth_gsm_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
bits_bitrev_test_SOURCES = bits/bitrev_test.c
bits_bitrev_test_LDADD = $(top_builddir)/src/libosmocore.la
@ -98,7 +102,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \
timer/timer_test.ok sms/sms_test.ok ussd/ussd_test.ok \
smscb/smscb_test.ok bits/bitrev_test.ok a5/a5_test.ok \
conv/conv_test.ok auth/milenage_test.ok \
conv/conv_test.ok auth/milenage_test.ok auth/gsm_test.ok \
lapd/lapd_test.ok gsm0408/gsm0408_test.ok \
gsm0808/gsm0808_test.ok gb/bssgp_fc_tests.err \
gb/bssgp_fc_tests.ok gb/bssgp_fc_tests.sh \

81
tests/auth/gsm_test.c Normal file
View File

@ -0,0 +1,81 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <osmocom/crypt/auth.h>
#include <osmocom/core/utils.h>
static const uint8_t test_ki[16] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
};
static const uint8_t test_rand[16] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
};
static struct {
enum osmo_auth_algo algo;
const uint8_t sres[4];
const uint8_t kc[8];
} test_results[] = {
{ OSMO_AUTH_ALG_COMP128v1,
{ 0x53, 0x51, 0x3e, 0xbd },
{ 0x13, 0xc2, 0x6b, 0x8f, 0x82, 0xab, 0x74, 0x00 },
},
{ OSMO_AUTH_ALG_COMP128v2,
{ 0x28, 0xe3, 0xcf, 0xa4 },
{ 0x8f, 0x0f, 0xf5, 0x68, 0x53, 0x3a, 0x54, 0x00 },
},
{ OSMO_AUTH_ALG_COMP128v3,
{ 0x28, 0xe3, 0xcf, 0xa4 },
{ 0x8f, 0x0f, 0xf5, 0x68, 0x53, 0x3a, 0x57, 0xb9 },
},
{ OSMO_AUTH_ALG_XOR,
{ 0x01, 0x32, 0x67, 0x54 },
{ 0xcd, 0xfe, 0xab, 0x98, 0x76, 0x45, 0x10, 0x23 },
},
{ OSMO_AUTH_ALG_NONE } /* Sentinel */
};
int main(int argc, char **argv)
{
struct osmo_auth_vector _vec, *vec = &_vec;
struct osmo_sub_auth_data _aud, *aud = &_aud;
int i, fail;
for (i=0; test_results[i].algo != OSMO_AUTH_ALG_NONE; i++)
{
if (!osmo_auth_supported(test_results[i].algo)) {
printf("UNSUPPORTED ALGO: %d\n", test_results[i].algo);
continue;
}
memset(aud, 0, sizeof(*aud));
memset(vec, 0, sizeof(*vec));
aud->type = OSMO_AUTH_TYPE_GSM;
aud->algo = test_results[i].algo;
memcpy(aud->u.gsm.ki, test_ki, 16);
osmo_auth_gen_vec(vec, aud, test_rand);
fail = 0;
fail |= memcmp(test_results[i].sres, vec->sres, 4);
fail |= memcmp(test_results[i].kc, vec->kc, 8);
printf("%s: %s\n", osmo_auth_alg_name(aud->algo), fail ? "FAIL" : "PASS");
if (fail) {
printf("SRES ref : %s\n", osmo_hexdump(test_results[i].sres, 4));
printf(" got : %s\n", osmo_hexdump(vec->sres, 4));
printf("Kc ref : %s\n", osmo_hexdump(test_results[i].kc, 8));
printf(" got : %s\n", osmo_hexdump(vec->kc, 8));
}
}
return 0;
}

4
tests/auth/gsm_test.ok Normal file
View File

@ -0,0 +1,4 @@
COMP128v1: PASS
COMP128v2: PASS
COMP128v3: PASS
XOR: PASS

View File

@ -48,12 +48,18 @@ cat $abs_srcdir/ussd/ussd_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/ussd/ussd_test], [0], [expout], [ignore])
AT_CLEANUP
AT_SETUP([auth])
AT_KEYWORDS([auth])
AT_SETUP([auth_milenage])
AT_KEYWORDS([auth_milenage])
cat $abs_srcdir/auth/milenage_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/auth/milenage_test], [0], [expout], [ignore])
AT_CLEANUP
AT_SETUP([auth_gsm])
AT_KEYWORDS([auth_gsm])
cat $abs_srcdir/auth/gsm_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/auth/gsm_test], [0], [expout], [ignore])
AT_CLEANUP
AT_SETUP([comp128])
AT_KEYWORDS([comp128])
cat $abs_srcdir/comp128/comp128_test.ok > expout