blob: 37f47c3956a3aee9686830774c9fb6acb812d749 [file] [log] [blame]
Neels Hofmeyr6b883f72017-01-31 16:40:28 +01001/* gen_ts_55_205_test_sets/main_template.c: Template to generate test code
2 * from 3GPP TS 55.205 test sets */
3
4/* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
5 *
6 * All Rights Reserved
7 *
8 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#include <stdio.h>
26#include <string.h>
27#include <inttypes.h>
28
29#include <osmocom/core/application.h>
30#include <osmocom/core/utils.h>
31#include <osmocom/core/logging.h>
32
33#include <osmocom/crypt/auth.h>
34
35#include "logging.h"
36#include "auc.h"
37
38#define comment_start() fprintf(stderr, "\n===== %s\n", __func__);
39#define comment_end() fprintf(stderr, "===== %s: SUCCESS\n\n", __func__);
40
41#define VERBOSE_ASSERT(val, expect_op, fmt) \
42 do { \
43 fprintf(stderr, #val " == " fmt "\n", (val)); \
44 OSMO_ASSERT((val) expect_op); \
45 } while (0);
46
47char *vec_str(const struct osmo_auth_vector *vec)
48{
49 static char buf[1024];
50 char *pos = buf;
51 char *end = buf + sizeof(buf);
52
53#define append(what) \
54 if (pos >= end) \
55 return buf; \
56 pos += snprintf(pos, sizeof(buf) - (pos - buf), \
57 " " #what ": %s\n", \
58 osmo_hexdump_nospc((void*)&vec->what, sizeof(vec->what)))
59
60 append(rand);
61 append(ck);
62 append(ik);
63 append(res);
64 append(kc);
65 append(sres);
66#undef append
67
68 return buf;
69}
70
71#define VEC_IS(vec, expect) do { \
72 char *_is = vec_str(vec); \
Neels Hofmeyr6b883f72017-01-31 16:40:28 +010073 if (strcmp(_is, expect)) { \
74 fprintf(stderr, "MISMATCH! expected ==\n%s\n", \
75 expect); \
76 char *a = _is; \
77 char *b = expect; \
78 for (; *a && *b; a++, b++) { \
79 if (*a != *b) { \
80 while (a > _is && *(a-1) != '\n') a--; \
81 fprintf(stderr, "mismatch at %d:\n" \
82 "%s", (int)(a - _is), a); \
83 break; \
84 } \
85 } \
86 OSMO_ASSERT(false); \
Neels Hofmeyr8d97d342017-02-21 22:46:35 +010087 } else \
88 fprintf(stderr, "vector matches expectations\n"); \
Neels Hofmeyr6b883f72017-01-31 16:40:28 +010089 } while (0)
90
91uint8_t fake_rand[16] = { 0 };
92
93int rand_get(uint8_t *rand, unsigned int len)
94{
95 OSMO_ASSERT(len <= sizeof(fake_rand));
96 memcpy(rand, fake_rand, len);
97 return len;
98}
99
100FUNCTIONS
101
102int main()
103{
104 printf("3GPP TS 55.205 Test Sets\n");
105 osmo_init_logging(&hlr_log_info);
106 log_set_print_filename(osmo_stderr_target, 0);
107 log_set_print_timestamp(osmo_stderr_target, 0);
108 log_set_use_color(osmo_stderr_target, 0);
109 log_set_print_category(osmo_stderr_target, 1);
Neels Hofmeyr6eb231e2017-10-27 03:35:45 +0200110 log_parse_category_mask(osmo_stderr_target, "DMAIN,1:DDB,1:DAUC,1");
Neels Hofmeyr6b883f72017-01-31 16:40:28 +0100111
112FUNCTION_CALLS
113
114 printf("Done\n");
115 return 0;
116}