blob: 14436f19373561886045f8be5e1fae0b2400a2e7 [file] [log] [blame]
Sylvain Munaut810c3342011-11-17 20:33:19 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <stdint.h>
4#include <string.h>
5
6#include <osmocom/core/bits.h>
7#include <osmocom/core/utils.h>
8#include <osmocom/gsm/a5.h>
9
10static const uint8_t key[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
11static const uint32_t fn = 123456;
12static const uint8_t dl[] = {
13 /* A5/0 */
14 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
15 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
16
17 /* A5/1 */
18 0xcb, 0xa2, 0x55, 0x76, 0x17, 0x5d, 0x3b, 0x1c,
19 0x7b, 0x2f, 0x29, 0xa8, 0xc1, 0xb6, 0x00,
20
21 /* A5/2 */
22 0x45, 0x9c, 0x88, 0xc3, 0x82, 0xb7, 0xff, 0xb3,
23 0x98, 0xd2, 0xf9, 0x6e, 0x0f, 0x14, 0x80,
24};
25static const uint8_t ul[] = {
26 /* A5/0 */
27 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
28 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29
30 /* A5/1 */
31 0xd9, 0x03, 0x5e, 0x0f, 0x2a, 0xec, 0x13, 0x9a,
32 0x05, 0xd4, 0xa8, 0x7b, 0xb1, 0x64, 0x80,
33
34 /* A5/2 */
35 0xf0, 0x3a, 0xac, 0xde, 0xe3, 0x5b, 0x5e, 0x65,
36 0x80, 0xba, 0xab, 0xc0, 0x59, 0x26, 0x40,
37};
38
39static const char *
40binstr(ubit_t *d, int n)
41{
42 static char str[256];
43 int i;
44
45 for (i=0; i<n; i++)
46 str[i] = d[i] ? '1' : '0';
47
48 str[i] = '\0';
49
50 return str;
51}
52
53int main(int argc, char **argv)
54{
55 ubit_t exp[114];
56 ubit_t out[114];
57 int n, i;
58
59 for (n=0; n<3; n++) {
60 /* "Randomize" */
61 for (i=0; i<114; i++)
62 out[i] = i & 1;
63
64 /* DL */
65 osmo_pbit2ubit(exp, &dl[15*n], 114);
66
67 osmo_a5(n, key, fn, out, NULL);
68
69 printf("A5/%d - DL: %s", n, binstr(out, 114));
70
71 if (!memcmp(exp, out, 114))
72 printf(" => OK\n");
73 else {
74 printf(" => BAD\n");
75 printf(" Expected: %s", binstr(out, 114));
76 fprintf(stderr, "[!] A5/%d DL failed", n);
77 exit(1);
78 }
79
80 /* UL */
81 osmo_pbit2ubit(exp, &ul[15*n], 114);
82
83 osmo_a5(n, key, fn, NULL, out);
84
85 printf("A5/%d - UL: %s", n, binstr(out, 114));
86
87 if (!memcmp(exp, out, 114))
88 printf(" => OK\n");
89 else {
90 printf(" => BAD\n");
91 printf(" Expected: %s", binstr(out, 114));
92 fprintf(stderr, "[!] A5/%d UL failed", n);
93 exit(1);
94 }
95 }
96
97 return 0;
98}