Harald Welte | e076ac0 | 2011-12-07 00:10:18 +0100 | [diff] [blame] | 1 | |
| 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 | |
| 10 | static void dump_auth_vec(struct osmo_auth_vector *vec) |
| 11 | { |
| 12 | printf("RAND:\t%s\n", osmo_hexdump(vec->rand, sizeof(vec->rand))); |
| 13 | |
| 14 | if (vec->auth_types & OSMO_AUTH_TYPE_UMTS) { |
| 15 | printf("AUTN:\t%s\n", osmo_hexdump(vec->autn, sizeof(vec->autn))); |
| 16 | printf("IK:\t%s\n", osmo_hexdump(vec->ik, sizeof(vec->ik))); |
| 17 | printf("CK:\t%s\n", osmo_hexdump(vec->ck, sizeof(vec->ck))); |
| 18 | printf("RES:\t%s\n", osmo_hexdump(vec->res, vec->res_len)); |
| 19 | } |
| 20 | |
| 21 | if (vec->auth_types & OSMO_AUTH_TYPE_GSM) { |
| 22 | printf("SRES:\t%s\n", osmo_hexdump(vec->sres, sizeof(vec->sres))); |
| 23 | printf("Kc:\t%s\n", osmo_hexdump(vec->kc, sizeof(vec->kc))); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | static struct osmo_sub_auth_data test_aud = { |
| 28 | .type = OSMO_AUTH_TYPE_UMTS, |
| 29 | .algo = OSMO_AUTH_ALG_MILENAGE, |
Harald Welte | aae2362 | 2011-12-07 11:35:02 +0100 | [diff] [blame] | 30 | .u.umts = { |
Harald Welte | e076ac0 | 2011-12-07 00:10:18 +0100 | [diff] [blame] | 31 | .opc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 32 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, |
| 33 | .k = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 34 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, |
| 35 | .amf = { 0x00, 0x00 }, |
Harald Welte | 57143a4 | 2011-12-07 03:12:44 +0100 | [diff] [blame] | 36 | .sqn = 0x22, |
Harald Welte | e076ac0 | 2011-12-07 00:10:18 +0100 | [diff] [blame] | 37 | }, |
| 38 | }; |
| 39 | |
Harald Welte | 042afe7 | 2012-03-21 08:19:47 +0100 | [diff] [blame] | 40 | static int opc_test(const struct osmo_sub_auth_data *aud) |
| 41 | { |
| 42 | int rc; |
| 43 | uint8_t opc[16]; |
| 44 | #if 0 |
| 45 | const uint8_t op[16] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 46 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; |
| 47 | #else |
| 48 | const uint8_t op[16] = { 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 }; |
| 49 | #endif |
| 50 | |
| 51 | rc = milenage_opc_gen(opc, aud->u.umts.k, op); |
| 52 | |
| 53 | printf("OP:\t%s\n", osmo_hexdump(op, sizeof(op))); |
| 54 | printf("OPC:\t%s\n", osmo_hexdump(opc, sizeof(opc))); |
| 55 | return rc; |
| 56 | } |
| 57 | |
Harald Welte | e076ac0 | 2011-12-07 00:10:18 +0100 | [diff] [blame] | 58 | int main(int argc, char **argv) |
| 59 | { |
| 60 | struct osmo_auth_vector _vec; |
| 61 | struct osmo_auth_vector *vec = &_vec; |
| 62 | uint8_t _rand[16]; |
| 63 | int rc; |
| 64 | |
| 65 | #if 0 |
| 66 | srand(time(NULL)); |
| 67 | *(uint32_t *)&_rand[0] = rand(); |
| 68 | *(uint32_t *)(&_rand[4]) = rand(); |
| 69 | *(uint32_t *)(&_rand[8]) = rand(); |
| 70 | *(uint32_t *)(&_rand[12]) = rand(); |
| 71 | #else |
| 72 | memset(_rand, 0, sizeof(_rand)); |
| 73 | #endif |
| 74 | memset(vec, 0, sizeof(*vec)); |
| 75 | |
| 76 | rc = osmo_auth_gen_vec(vec, &test_aud, _rand); |
| 77 | if (rc < 0) { |
| 78 | fprintf(stderr, "error generating auth vector\n"); |
| 79 | exit(1); |
| 80 | } |
| 81 | |
| 82 | dump_auth_vec(vec); |
| 83 | |
| 84 | const uint8_t auts[14] = { 0x87, 0x11, 0xa0, 0xec, 0x9e, 0x16, 0x37, 0xdf, |
| 85 | 0x17, 0xf8, 0x0b, 0x38, 0x4e, 0xe4 }; |
| 86 | |
| 87 | rc = osmo_auth_gen_vec_auts(vec, &test_aud, auts, _rand, _rand); |
| 88 | if (rc < 0) { |
| 89 | printf("AUTS failed\n"); |
| 90 | } else { |
Harald Welte | aae2362 | 2011-12-07 11:35:02 +0100 | [diff] [blame] | 91 | printf("AUTS success: SEQ.MS = %lu\n", test_aud.u.umts.sqn); |
Harald Welte | e076ac0 | 2011-12-07 00:10:18 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Harald Welte | 042afe7 | 2012-03-21 08:19:47 +0100 | [diff] [blame] | 94 | opc_test(&test_aud); |
| 95 | |
Harald Welte | e076ac0 | 2011-12-07 00:10:18 +0100 | [diff] [blame] | 96 | exit(0); |
| 97 | |
| 98 | } |