annotate smswrap/ota-smswrap-sjs1.c @ 2:d5e9af482548

ota-smswrap-sjs1 program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Feb 2021 22:21:29 +0000
parents
children 8dfa3bfaa9c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This utility will read a string of RFM APDU commands from stdin
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * and wrap this OTA command block into an SMS-PP User Data element
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * as appropriate for sysmoUSIM-SJS1 version of SIM RFM, including
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * the necessary cryptographic checksum and ciphering.
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 *
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * The two command line arguments are KIC2 and KID2 secret keys
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * for the target SIM, the payload to be wrapped is supplied on stdin.
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 */
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <sys/types.h>
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <openssl/des.h>
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdio.h>
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <stdlib.h>
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <string.h>
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <strings.h>
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #define MAX_PAYLOAD_LEN 106
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #define MAX_SIGBUF (MAX_PAYLOAD_LEN + 16 + 6)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #define MAX_CIPHERTEXT (MAX_PAYLOAD_LEN + 14)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 u_char payload_data[MAX_PAYLOAD_LEN];
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 unsigned payload_len, padding_len;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 int padding_mode;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 DES_key_schedule keysched_kic[2], keysched_kid[2];
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 u_char part_head[8] = {0x15, 0x06, 0x01, 0x25, 0x25, 0xB0, 0x00, 0x10};
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 u_char part_cnt[6], signature[8];
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 u_char ciphertext[MAX_CIPHERTEXT];
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 unsigned ciphertext_len;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 process_key_arg(arg, sched, name)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 char *arg, *name;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 DES_key_schedule *sched;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 DES_cblock keybin[2];
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 int rc;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 unsigned n;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 rc = decode_hex_data_from_string(arg, keybin, 16, 16);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (rc < 0)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1); /* error msg already printed */
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 for (n = 0; n < 2; n++) {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 rc = DES_set_key_checked(keybin + n, sched + n);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (rc < 0) {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr,
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 "bad %s argument: DES_set_key_checked() returned %d on part %u\n",
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 name, rc, n);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 exit(1);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 read_payload()
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 int rc;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 unsigned maxlen;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 maxlen = MAX_PAYLOAD_LEN;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (padding_mode)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 maxlen -= 8;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 rc = read_hex_from_stdin(payload_data, maxlen);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (rc < 0)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 exit(1); /* error msg already printed */
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 payload_len = rc;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 compute_pad_length()
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 unsigned ciph_len, rem;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 ciph_len = payload_len + 14;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 rem = ciph_len & 7;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 if (!rem && !padding_mode)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 padding_len = 0;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 else
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 padding_len = 8 - rem;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 compute_signature()
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 u_char plainbuf[MAX_SIGBUF], cipher_out[MAX_SIGBUF];
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 unsigned ciphlen;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 DES_cblock ivec;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 plainbuf[0] = 0;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 plainbuf[1] = payload_len + padding_len + 8 + 8 + 6;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 bcopy(part_head, plainbuf + 2, 8);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 bcopy(part_cnt, plainbuf + 10, 6);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 bcopy(payload_data, plainbuf + 16, payload_len + padding_len);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 bzero(plainbuf + 16 + payload_len + padding_len, 6);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 ciphlen = payload_len + padding_len + 16 + 6;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 bzero(&ivec, sizeof ivec);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 DES_ede2_cbc_encrypt(plainbuf, cipher_out, ciphlen, &keysched_kid[0],
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 &keysched_kid[1], &ivec, DES_ENCRYPT);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 bcopy(cipher_out + ciphlen - 8, signature, 8);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 encrypt_message()
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 u_char plainbuf[MAX_CIPHERTEXT];
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 DES_cblock ivec;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 bcopy(part_cnt, plainbuf, 6);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 bcopy(signature, plainbuf + 6, 8);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 bcopy(payload_data, plainbuf + 14, payload_len + padding_len);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 ciphertext_len = payload_len + padding_len + 14;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 bzero(&ivec, sizeof ivec);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 DES_ede2_cbc_encrypt(plainbuf, ciphertext, ciphertext_len,
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 &keysched_kic[0], &keysched_kic[1], &ivec,
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 DES_ENCRYPT);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 emit_hex_bytes(bytes, len)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 u_char *bytes;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 unsigned len;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 u_char *dp;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 unsigned n;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 dp = bytes;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 for (n = 0; n < len; n++)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 printf("%02X", *dp++);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 main(argc, argv)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 char **argv;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 if (argc < 3 || argc > 4) {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 fprintf(stderr, "usage: %s KIC2-hex KID2-hex\n", argv[0]);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 exit(1);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 process_key_arg(argv[1], keysched_kic, "KIC2");
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 process_key_arg(argv[2], keysched_kid, "KID2");
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 if (argc > 3)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 padding_mode = atoi(argv[3]);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 else
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 padding_mode = 0;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 read_payload();
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 compute_pad_length();
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 part_cnt[5] = padding_len;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 compute_signature();
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 encrypt_message();
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 /* emit output! */
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 printf("027000%04X", ciphertext_len + 8);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 emit_hex_bytes(part_head, 8);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 emit_hex_bytes(ciphertext, ciphertext_len);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 putchar('\n');
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 exit(0);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }