annotate smswrap/ota-smswrap-sjs1.c @ 4:c2de42994e57

ota-smspp-envelope utility written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Feb 2021 23:41:46 +0000
parents 8dfa3bfaa9c1
children
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 */
3
8dfa3bfaa9c1 Sysmocom 2DES keys don't have correct parity
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
46 for (n = 0; n < 2; n++)
8dfa3bfaa9c1 Sysmocom 2DES keys don't have correct parity
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
47 DES_set_key_unchecked(keybin + n, sched + n);
2
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 read_payload()
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 int rc;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 unsigned maxlen;
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 maxlen = MAX_PAYLOAD_LEN;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (padding_mode)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 maxlen -= 8;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 rc = read_hex_from_stdin(payload_data, maxlen);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (rc < 0)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 exit(1); /* error msg already printed */
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 payload_len = rc;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 compute_pad_length()
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 unsigned ciph_len, rem;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 ciph_len = payload_len + 14;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 rem = ciph_len & 7;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!rem && !padding_mode)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 padding_len = 0;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 else
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 padding_len = 8 - 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
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 compute_signature()
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 u_char plainbuf[MAX_SIGBUF], cipher_out[MAX_SIGBUF];
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 unsigned ciphlen;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 DES_cblock ivec;
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 plainbuf[0] = 0;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 plainbuf[1] = payload_len + padding_len + 8 + 8 + 6;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 bcopy(part_head, plainbuf + 2, 8);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 bcopy(part_cnt, plainbuf + 10, 6);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 bcopy(payload_data, plainbuf + 16, payload_len + padding_len);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 bzero(plainbuf + 16 + payload_len + padding_len, 6);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 ciphlen = payload_len + padding_len + 16 + 6;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 bzero(&ivec, sizeof ivec);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 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
91 &keysched_kid[1], &ivec, DES_ENCRYPT);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 bcopy(cipher_out + ciphlen - 8, signature, 8);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 encrypt_message()
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 u_char plainbuf[MAX_CIPHERTEXT];
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 DES_cblock ivec;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 bcopy(part_cnt, plainbuf, 6);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 bcopy(signature, plainbuf + 6, 8);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 bcopy(payload_data, plainbuf + 14, payload_len + padding_len);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 ciphertext_len = payload_len + padding_len + 14;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 bzero(&ivec, sizeof ivec);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 DES_ede2_cbc_encrypt(plainbuf, ciphertext, ciphertext_len,
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 &keysched_kic[0], &keysched_kic[1], &ivec,
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 DES_ENCRYPT);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 emit_hex_bytes(bytes, len)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 u_char *bytes;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 unsigned len;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 u_char *dp;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 unsigned n;
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 dp = bytes;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 for (n = 0; n < len; n++)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 printf("%02X", *dp++);
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
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 main(argc, argv)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 char **argv;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 if (argc < 3 || argc > 4) {
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 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
127 exit(1);
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 process_key_arg(argv[1], keysched_kic, "KIC2");
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 process_key_arg(argv[2], keysched_kid, "KID2");
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 if (argc > 3)
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 padding_mode = atoi(argv[3]);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 else
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 padding_mode = 0;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 read_payload();
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 compute_pad_length();
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 part_cnt[5] = padding_len;
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 compute_signature();
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 encrypt_message();
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 /* emit output! */
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 printf("027000%04X", ciphertext_len + 8);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 emit_hex_bytes(part_head, 8);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 emit_hex_bytes(ciphertext, ciphertext_len);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 putchar('\n');
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 exit(0);
d5e9af482548 ota-smswrap-sjs1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 }