blob: 0223764a2b6c27a523882968dd1171bdfdb05402 [file] [log] [blame]
Harald Weltee076ac02011-12-07 00:10:18 +01001
2#include <stdlib.h>
3#include <stdio.h>
4#include <errno.h>
5#include <string.h>
6
7#include <osmocom/crypt/auth.h>
8#include <osmocom/core/utils.h>
9
Jacob Erlbeck73ae7a92013-10-08 12:04:42 +020010int milenage_opc_gen(uint8_t *opc, const uint8_t *k, const uint8_t *op);
11
Harald Weltee076ac02011-12-07 00:10:18 +010012static void dump_auth_vec(struct osmo_auth_vector *vec)
13{
14 printf("RAND:\t%s\n", osmo_hexdump(vec->rand, sizeof(vec->rand)));
15
16 if (vec->auth_types & OSMO_AUTH_TYPE_UMTS) {
17 printf("AUTN:\t%s\n", osmo_hexdump(vec->autn, sizeof(vec->autn)));
18 printf("IK:\t%s\n", osmo_hexdump(vec->ik, sizeof(vec->ik)));
19 printf("CK:\t%s\n", osmo_hexdump(vec->ck, sizeof(vec->ck)));
20 printf("RES:\t%s\n", osmo_hexdump(vec->res, vec->res_len));
21 }
22
23 if (vec->auth_types & OSMO_AUTH_TYPE_GSM) {
24 printf("SRES:\t%s\n", osmo_hexdump(vec->sres, sizeof(vec->sres)));
25 printf("Kc:\t%s\n", osmo_hexdump(vec->kc, sizeof(vec->kc)));
26 }
27}
28
29static struct osmo_sub_auth_data test_aud = {
30 .type = OSMO_AUTH_TYPE_UMTS,
31 .algo = OSMO_AUTH_ALG_MILENAGE,
Harald Welteaae23622011-12-07 11:35:02 +010032 .u.umts = {
Harald Weltee076ac02011-12-07 00:10:18 +010033 .opc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
35 .k = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
36 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
37 .amf = { 0x00, 0x00 },
Harald Welte57143a42011-12-07 03:12:44 +010038 .sqn = 0x22,
Harald Weltee076ac02011-12-07 00:10:18 +010039 },
40};
41
Harald Welte042afe72012-03-21 08:19:47 +010042static int opc_test(const struct osmo_sub_auth_data *aud)
43{
44 int rc;
45 uint8_t opc[16];
46#if 0
47 const uint8_t op[16] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
48 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };
49#else
50 const uint8_t op[16] = { 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 };
51#endif
52
53 rc = milenage_opc_gen(opc, aud->u.umts.k, op);
54
55 printf("OP:\t%s\n", osmo_hexdump(op, sizeof(op)));
56 printf("OPC:\t%s\n", osmo_hexdump(opc, sizeof(opc)));
57 return rc;
58}
59
Harald Weltee076ac02011-12-07 00:10:18 +010060int main(int argc, char **argv)
61{
62 struct osmo_auth_vector _vec;
63 struct osmo_auth_vector *vec = &_vec;
64 uint8_t _rand[16];
65 int rc;
66
67#if 0
68 srand(time(NULL));
69 *(uint32_t *)&_rand[0] = rand();
70 *(uint32_t *)(&_rand[4]) = rand();
71 *(uint32_t *)(&_rand[8]) = rand();
72 *(uint32_t *)(&_rand[12]) = rand();
73#else
74 memset(_rand, 0, sizeof(_rand));
75#endif
76 memset(vec, 0, sizeof(*vec));
77
78 rc = osmo_auth_gen_vec(vec, &test_aud, _rand);
79 if (rc < 0) {
80 fprintf(stderr, "error generating auth vector\n");
81 exit(1);
82 }
83
84 dump_auth_vec(vec);
85
86 const uint8_t auts[14] = { 0x87, 0x11, 0xa0, 0xec, 0x9e, 0x16, 0x37, 0xdf,
87 0x17, 0xf8, 0x0b, 0x38, 0x4e, 0xe4 };
88
89 rc = osmo_auth_gen_vec_auts(vec, &test_aud, auts, _rand, _rand);
90 if (rc < 0) {
91 printf("AUTS failed\n");
92 } else {
Jacob Erlbeck73ae7a92013-10-08 12:04:42 +020093 printf("AUTS success: SEQ.MS = %llu\n", (unsigned long long)test_aud.u.umts.sqn);
Harald Weltee076ac02011-12-07 00:10:18 +010094 }
95
Harald Welte042afe72012-03-21 08:19:47 +010096 opc_test(&test_aud);
97
Harald Weltee076ac02011-12-07 00:10:18 +010098 exit(0);
99
100}