1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
Backport of https://github.com/cisco/libsrtp/commit/84faa631a55235f6138cacda2e7f81980a43d13e
--- crypto/cipher/aes_gcm_ossl.c.orig 2017-08-01 11:57:38 UTC
+++ crypto/cipher/aes_gcm_ossl.c
@@ -85,8 +85,6 @@ extern cipher_type_t aes_gcm_256_openssl;
err_status_t aes_gcm_openssl_alloc (cipher_t **c, int key_len, int tlen)
{
aes_gcm_ctx_t *gcm;
- int tmp;
- uint8_t *allptr;
debug_print(mod_aes_gcm, "allocating cipher with key length %d", key_len);
debug_print(mod_aes_gcm, "allocating cipher with tag length %d", tlen);
@@ -105,16 +103,22 @@ err_status_t aes_gcm_openssl_alloc (cipher_t **c, int
}
/* allocate memory a cipher of type aes_gcm */
- tmp = sizeof(cipher_t) + sizeof(aes_gcm_ctx_t);
- allptr = crypto_alloc(tmp);
- if (allptr == NULL) {
+ *c = (cipher_t *)crypto_alloc(sizeof(cipher_t));
+ if (*c == NULL) {
return (err_status_alloc_fail);
}
+ memset(*c, 0x0, sizeof(cipher_t));
+ gcm = (aes_gcm_ctx_t *)crypto_alloc(sizeof(aes_gcm_ctx_t));
+ if (gcm == NULL) {
+ crypto_free(*c);
+ *c = NULL;
+ return (err_status_alloc_fail);
+ }
+ memset(gcm, 0x0, sizeof(aes_gcm_ctx_t));
+
/* set pointers */
- *c = (cipher_t*)allptr;
- (*c)->state = allptr + sizeof(cipher_t);
- gcm = (aes_gcm_ctx_t *)(*c)->state;
+ (*c)->state = gcm;
/* increment ref_count */
switch (key_len) {
@@ -122,15 +126,15 @@ err_status_t aes_gcm_openssl_alloc (cipher_t **c, int
(*c)->type = &aes_gcm_128_openssl;
(*c)->algorithm = AES_128_GCM;
aes_gcm_128_openssl.ref_count++;
- ((aes_gcm_ctx_t*)(*c)->state)->key_size = AES_128_KEYSIZE;
- ((aes_gcm_ctx_t*)(*c)->state)->tag_len = tlen;
+ gcm->key_size = AES_128_KEYSIZE;
+ gcm->tag_len = tlen;
break;
case AES_256_GCM_KEYSIZE_WSALT:
(*c)->type = &aes_gcm_256_openssl;
(*c)->algorithm = AES_256_GCM;
aes_gcm_256_openssl.ref_count++;
- ((aes_gcm_ctx_t*)(*c)->state)->key_size = AES_256_KEYSIZE;
- ((aes_gcm_ctx_t*)(*c)->state)->tag_len = tlen;
+ gcm->key_size = AES_256_KEYSIZE;
+ gcm->tag_len = tlen;
break;
}
@@ -164,10 +168,10 @@ err_status_t aes_gcm_openssl_dealloc (cipher_t *c)
return (err_status_dealloc_fail);
break;
}
+ /* zeroize the key material */
+ octet_string_set_to_zero((uint8_t*)ctx, sizeof(aes_gcm_ctx_t));
+ crypto_free(ctx);
}
-
- /* zeroize entire state*/
- octet_string_set_to_zero((uint8_t*)c, sizeof(cipher_t) + sizeof(aes_gcm_ctx_t));
/* free memory */
crypto_free(c);
--- crypto/cipher/aes_icm.c.orig 2017-08-01 11:57:38 UTC
+++ crypto/cipher/aes_icm.c
@@ -95,8 +95,7 @@ debug_module_t mod_aes_icm = {
err_status_t
aes_icm_alloc_ismacryp(cipher_t **c, int key_len, int forIsmacryp) {
extern cipher_type_t aes_icm;
- uint8_t *pointer;
- int tmp;
+ aes_icm_ctx_t *icm;
debug_print(mod_aes_icm,
"allocating cipher with key length %d", key_len);
@@ -114,13 +113,23 @@ aes_icm_alloc_ismacryp(cipher_t **c, int key_len, int
return err_status_bad_param;
/* allocate memory a cipher of type aes_icm */
- tmp = (sizeof(aes_icm_ctx_t) + sizeof(cipher_t));
- pointer = (uint8_t*)crypto_alloc(tmp);
- if (pointer == NULL)
+ *c = (cipher_t *)crypto_alloc(sizeof(cipher_t));
+ if (*c == NULL)
return err_status_alloc_fail;
+ memset(*c, 0x0, sizeof(cipher_t));
+
+ icm = (aes_icm_ctx_t *)crypto_alloc(sizeof(aes_icm_ctx_t));
+ if (icm == NULL) {
+ crypto_free(*c);
+ return err_status_alloc_fail;
+ }
+ memset(icm, 0x0, sizeof(aes_icm_ctx_t));
+
/* set pointers */
- *c = (cipher_t *)pointer;
+ (*c)->state = icm;
+ (*c)->type = &aes_icm;
+
switch (key_len) {
case 46:
(*c)->algorithm = AES_256_ICM;
@@ -132,13 +141,12 @@ aes_icm_alloc_ismacryp(cipher_t **c, int key_len, int
(*c)->algorithm = AES_128_ICM;
break;
}
- (*c)->type = &aes_icm;
- (*c)->state = pointer + sizeof(cipher_t);
/* increment ref_count */
aes_icm.ref_count++;
/* set key size */
+ icm->key_size = key_len;
(*c)->key_len = key_len;
return err_status_ok;
@@ -151,12 +159,20 @@ err_status_t aes_icm_alloc(cipher_t **c, int key_len,
err_status_t
aes_icm_dealloc(cipher_t *c) {
extern cipher_type_t aes_icm;
+ aes_icm_ctx_t *ctx;
- /* zeroize entire state*/
- octet_string_set_to_zero((uint8_t *)c,
- sizeof(aes_icm_ctx_t) + sizeof(cipher_t));
+ if (c == NULL) {
+ return err_status_bad_param;
+ }
- /* free memory */
+ ctx = (aes_icm_ctx_t *)c->state;
+ if (ctx) {
+ /* zeroize the key material */
+ octet_string_set_to_zero((uint8_t*)ctx, sizeof(aes_icm_ctx_t));
+ crypto_free(ctx);
+ }
+
+ /* free the cipher context */
crypto_free(c);
/* decrement ref_count */
--- crypto/cipher/aes_icm_ossl.c.orig 2017-08-01 11:57:38 UTC
+++ crypto/cipher/aes_icm_ossl.c
@@ -115,8 +115,6 @@ extern cipher_type_t aes_icm_256;
err_status_t aes_icm_openssl_alloc (cipher_t **c, int key_len, int tlen)
{
aes_icm_ctx_t *icm;
- int tmp;
- uint8_t *allptr;
debug_print(mod_aes_icm, "allocating cipher with key length %d", key_len);
@@ -132,16 +130,22 @@ err_status_t aes_icm_openssl_alloc (cipher_t **c, int
}
/* allocate memory a cipher of type aes_icm */
- tmp = sizeof(cipher_t) + sizeof(aes_icm_ctx_t);
- allptr = (uint8_t*)crypto_alloc(tmp);
- if (allptr == NULL) {
+ *c = (cipher_t *)crypto_alloc(sizeof(cipher_t));
+ if (*c == NULL) {
return err_status_alloc_fail;
}
+ memset(*c, 0x0, sizeof(cipher_t));
+ icm = (aes_icm_ctx_t *)crypto_alloc(sizeof(aes_icm_ctx_t));
+ if (icm == NULL) {
+ crypto_free(*c);
+ *c = NULL;
+ return err_status_alloc_fail;
+ }
+ memset(icm, 0x0, sizeof(aes_icm_ctx_t));
+
/* set pointers */
- *c = (cipher_t*)allptr;
- (*c)->state = allptr + sizeof(cipher_t);
- icm = (aes_icm_ctx_t*)(*c)->state;
+ (*c)->state = icm;
/* increment ref_count */
switch (key_len) {
@@ -149,21 +153,21 @@ err_status_t aes_icm_openssl_alloc (cipher_t **c, int
(*c)->algorithm = AES_128_ICM;
(*c)->type = &aes_icm;
aes_icm.ref_count++;
- ((aes_icm_ctx_t*)(*c)->state)->key_size = AES_128_KEYSIZE;
+ icm->key_size = AES_128_KEYSIZE;
break;
#ifndef SRTP_NO_AES192
case AES_192_KEYSIZE_WSALT:
(*c)->algorithm = AES_192_ICM;
(*c)->type = &aes_icm_192;
aes_icm_192.ref_count++;
- ((aes_icm_ctx_t*)(*c)->state)->key_size = AES_192_KEYSIZE;
+ icm->key_size = AES_192_KEYSIZE;
break;
#endif
case AES_256_KEYSIZE_WSALT:
(*c)->algorithm = AES_256_ICM;
(*c)->type = &aes_icm_256;
aes_icm_256.ref_count++;
- ((aes_icm_ctx_t*)(*c)->state)->key_size = AES_256_KEYSIZE;
+ icm->key_size = AES_256_KEYSIZE;
break;
}
@@ -209,11 +213,10 @@ err_status_t aes_icm_openssl_dealloc (cipher_t *c)
return err_status_dealloc_fail;
break;
}
+ /* zeroize the key material */
+ octet_string_set_to_zero((uint8_t*)ctx, sizeof(aes_icm_ctx_t));
+ crypto_free(ctx);
}
-
- /* zeroize entire state*/
- octet_string_set_to_zero((uint8_t*)c,
- sizeof(cipher_t) + sizeof(aes_icm_ctx_t));
/* free memory */
crypto_free(c);
--- crypto/cipher/null_cipher.c.orig 2017-08-01 11:57:38 UTC
+++ crypto/cipher/null_cipher.c
@@ -59,21 +59,21 @@ extern debug_module_t mod_cipher;
err_status_t
null_cipher_alloc(cipher_t **c, int key_len, int tlen) {
extern cipher_type_t null_cipher;
- uint8_t *pointer;
debug_print(mod_cipher,
"allocating cipher with key length %d", key_len);
/* allocate memory a cipher of type null_cipher */
- pointer = (uint8_t*)crypto_alloc(sizeof(null_cipher_ctx_t) + sizeof(cipher_t));
- if (pointer == NULL)
+ *c = (cipher_t *)crypto_alloc(sizeof(cipher_t));
+ if (*c == NULL)
return err_status_alloc_fail;
+ memset(*c, 0x0, sizeof(cipher_t));
+
/* set pointers */
- *c = (cipher_t *)pointer;
(*c)->algorithm = NULL_CIPHER;
(*c)->type = &null_cipher;
- (*c)->state = pointer + sizeof(cipher_t);
+ (*c)->state = 0x1; /* The null cipher does not maintain state */
/* set key size */
(*c)->key_len = key_len;
@@ -90,8 +90,7 @@ null_cipher_dealloc(cipher_t *c) {
extern cipher_type_t null_cipher;
/* zeroize entire state*/
- octet_string_set_to_zero((uint8_t *)c,
- sizeof(null_cipher_ctx_t) + sizeof(cipher_t));
+ octet_string_set_to_zero((uint8_t*)c, sizeof(cipher_t));
/* free memory of type null_cipher */
crypto_free(c);
--- crypto/test/cipher_driver.c.orig 2017-08-01 11:57:38 UTC
+++ crypto/test/cipher_driver.c
@@ -58,7 +58,6 @@
#else
#include "aes_icm.h"
#endif
-#include "null_cipher.h"
#define PRINT_DEBUG 0
|