Line data Source code
1 : /*
2 : * Unix SMB/CIFS implementation.
3 : *
4 : * Copyright (C) 2019 Guenther Deschner <gd@samba.org>
5 : *
6 : * This program is free software; you can redistribute it and/or modify
7 : * it under the terms of the GNU General Public License as published by
8 : * the Free Software Foundation; either version 3 of the License, or
9 : * (at your option) any later version.
10 : *
11 : * This program is distributed in the hope that it will be useful,
12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : * GNU General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU General Public License
17 : * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 : */
19 :
20 : #include <stdarg.h>
21 : #include <stddef.h>
22 : #include <stdint.h>
23 : #include <setjmp.h>
24 : #include <cmocka.h>
25 :
26 : #include "includes.h"
27 : #include "libcli/auth/libcli_auth.h"
28 :
29 : #include "lib/crypto/gnutls_helpers.h"
30 : #include <gnutls/gnutls.h>
31 : #include <gnutls/crypto.h>
32 :
33 10 : static void torture_gnutls_aes_128_cfb_flags(void **state,
34 : const DATA_BLOB session_key,
35 : const DATA_BLOB seq_num_initial,
36 : const DATA_BLOB confounder_initial,
37 : const DATA_BLOB confounder_expected,
38 : const DATA_BLOB clear_initial,
39 : const DATA_BLOB crypt_expected)
40 10 : {
41 10 : uint8_t confounder[8];
42 10 : DATA_BLOB io;
43 10 : gnutls_cipher_hd_t cipher_hnd = NULL;
44 10 : uint8_t sess_kf0[16] = {0};
45 10 : gnutls_datum_t key = {
46 : .data = sess_kf0,
47 : .size = sizeof(sess_kf0),
48 : };
49 10 : uint32_t iv_size =
50 10 : gnutls_cipher_get_iv_size(GNUTLS_CIPHER_AES_128_CFB8);
51 10 : uint8_t _iv[iv_size];
52 10 : gnutls_datum_t iv = {
53 : .data = _iv,
54 : .size = iv_size,
55 : };
56 10 : uint32_t i;
57 10 : int rc;
58 :
59 10 : assert_int_equal(session_key.length, 16);
60 10 : assert_int_equal(seq_num_initial.length, 8);
61 10 : assert_int_equal(confounder_initial.length, 8);
62 10 : assert_int_equal(confounder_expected.length, 8);
63 10 : assert_int_equal(clear_initial.length, crypt_expected.length);
64 :
65 10 : DEBUG(0,("checking buffer size: %d\n", (int)clear_initial.length));
66 :
67 10 : io = data_blob_dup_talloc(NULL, clear_initial);
68 10 : assert_non_null(io.data);
69 10 : assert_int_equal(io.length, clear_initial.length);
70 :
71 10 : memcpy(confounder, confounder_initial.data, 8);
72 :
73 10 : DEBUG(0,("confounder before crypt:\n"));
74 10 : dump_data(0, confounder, 8);
75 10 : DEBUG(0,("initial seq num:\n"));
76 10 : dump_data(0, seq_num_initial.data, 8);
77 10 : DEBUG(0,("io data before crypt:\n"));
78 10 : dump_data(0, io.data, io.length);
79 :
80 180 : for (i = 0; i < key.size; i++) {
81 160 : key.data[i] = session_key.data[i] ^ 0xf0;
82 : }
83 :
84 10 : ZERO_ARRAY(_iv);
85 :
86 10 : memcpy(iv.data + 0, seq_num_initial.data, 8);
87 10 : memcpy(iv.data + 8, seq_num_initial.data, 8);
88 :
89 10 : rc = gnutls_cipher_init(&cipher_hnd,
90 : GNUTLS_CIPHER_AES_128_CFB8,
91 : &key,
92 : &iv);
93 10 : assert_int_equal(rc, 0);
94 :
95 10 : rc = gnutls_cipher_encrypt(cipher_hnd,
96 : confounder,
97 : 8);
98 10 : assert_int_equal(rc, 0);
99 :
100 10 : rc = gnutls_cipher_encrypt(cipher_hnd,
101 : io.data,
102 : io.length);
103 10 : assert_int_equal(rc, 0);
104 :
105 10 : DEBUG(0,("confounder after crypt:\n"));
106 10 : dump_data(0, confounder, 8);
107 10 : DEBUG(0,("initial seq num:\n"));
108 10 : dump_data(0, seq_num_initial.data, 8);
109 10 : DEBUG(0,("io data after crypt:\n"));
110 10 : dump_data(0, io.data, io.length);
111 10 : assert_memory_equal(io.data, crypt_expected.data, crypt_expected.length);
112 10 : assert_memory_equal(confounder, confounder_expected.data, confounder_expected.length);
113 :
114 10 : rc = gnutls_cipher_decrypt(cipher_hnd,
115 : confounder,
116 : 8);
117 10 : assert_int_equal(rc, 0);
118 :
119 10 : rc = gnutls_cipher_decrypt(cipher_hnd,
120 : io.data,
121 : io.length);
122 10 : assert_int_equal(rc, 0);
123 10 : gnutls_cipher_deinit(cipher_hnd);
124 :
125 10 : DEBUG(0,("confounder after decrypt:\n"));
126 10 : dump_data(0, confounder, 8);
127 10 : DEBUG(0,("initial seq num:\n"));
128 10 : dump_data(0, seq_num_initial.data, 8);
129 10 : DEBUG(0,("io data after decrypt:\n"));
130 10 : dump_data(0, io.data, io.length);
131 10 : assert_memory_equal(io.data, clear_initial.data, clear_initial.length);
132 10 : assert_memory_equal(confounder, confounder_initial.data, confounder_initial.length);
133 10 : }
134 :
135 1 : static void torture_gnutls_aes_128_cfb(void **state)
136 : {
137 1 : const uint8_t _session_key[16] = {
138 : 0x8E, 0xE8, 0x27, 0x85, 0x83, 0x41, 0x3C, 0x8D,
139 : 0xC9, 0x54, 0x70, 0x75, 0x8E, 0xC9, 0x69, 0x91
140 : };
141 1 : const DATA_BLOB session_key = data_blob_const(_session_key, 16);
142 1 : const uint8_t _seq_num_initial[8] = {
143 : 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00
144 : };
145 1 : const DATA_BLOB seq_num_initial =
146 1 : data_blob_const(_seq_num_initial, 8);
147 1 : const uint8_t _confounder_initial[8] = {
148 : 0x6E, 0x09, 0x25, 0x94, 0x01, 0xA0, 0x09, 0x31
149 : };
150 1 : const DATA_BLOB confounder_initial =
151 1 : data_blob_const(_confounder_initial, 8);
152 1 : const uint8_t _confounder_expected[8] = {
153 : 0xCA, 0xFB, 0xAC, 0xFB, 0xA8, 0x26, 0x75, 0x2A
154 : };
155 1 : const DATA_BLOB confounder_expected =
156 1 : data_blob_const(_confounder_expected, 8);
157 1 : const uint8_t _clear_initial[] = {
158 : 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
159 : 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00,
160 : 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
161 : 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
162 : 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163 : 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164 : 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
165 : 0x8A, 0xE3, 0x13, 0x71, 0x02, 0xF4, 0x36, 0x71,
166 : 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00,
167 : 0x02, 0x40, 0x28, 0x00, 0x78, 0x57, 0x34, 0x12,
168 : 0x34, 0x12, 0xCD, 0xAB, 0xEF, 0x00, 0x01, 0x23,
169 : 0x45, 0x67, 0x89, 0xAB, 0x00, 0x00, 0x00, 0x00,
170 : 0x04, 0x5D, 0x88, 0x8A, 0xEB, 0x1C, 0xC9, 0x11,
171 : 0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60,
172 : 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173 : 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
174 : };
175 1 : const DATA_BLOB clear_initial = data_blob_const(_clear_initial,
176 : sizeof(_clear_initial));
177 1 : const uint8_t crypt_buffer[] = {
178 : 0xE2, 0xE5, 0xE3, 0x26, 0x45, 0xFB, 0xFC, 0xF3,
179 : 0x9C, 0x14, 0xDD, 0xE1, 0x39, 0x23, 0xE0, 0x55,
180 : 0xED, 0x8F, 0xF4, 0x92, 0xA1, 0xBD, 0xDC, 0x40,
181 : 0x58, 0x6F, 0xD2, 0x5B, 0xF9, 0xC9, 0xA3, 0x87,
182 : 0x46, 0x4B, 0x7F, 0xB2, 0x03, 0xD2, 0x35, 0x22,
183 : 0x3E, 0x70, 0x9F, 0x1E, 0x3F, 0x1F, 0xDB, 0x7D,
184 : 0x79, 0x88, 0x5A, 0x3D, 0xD3, 0x40, 0x1E, 0x69,
185 : 0xD7, 0xE2, 0x1D, 0x5A, 0xE9, 0x3B, 0xE1, 0xE2,
186 : 0x98, 0xFD, 0xCB, 0x3A, 0xF7, 0xB5, 0x1C, 0xF8,
187 : 0xCA, 0x02, 0x00, 0x99, 0x9F, 0x0C, 0x01, 0xE6,
188 : 0xD2, 0x00, 0xAF, 0xE0, 0x51, 0x88, 0x62, 0x50,
189 : 0xB7, 0xE8, 0x6D, 0x63, 0x4B, 0x97, 0x05, 0xC1,
190 : 0xD4, 0x83, 0x96, 0x29, 0x80, 0xAE, 0xD8, 0xA2,
191 : 0xED, 0xC9, 0x5D, 0x0D, 0x29, 0xFF, 0x2C, 0x23,
192 : 0x02, 0xFA, 0x3B, 0xEE, 0xE8, 0xBA, 0x06, 0x01,
193 : 0x95, 0xDF, 0x80, 0x76, 0x0B, 0x17, 0x0E, 0xD8
194 : };
195 1 : const DATA_BLOB crypt_expected = data_blob_const(crypt_buffer,
196 : sizeof(crypt_buffer));
197 1 : int buffer_sizes[] = {
198 : 0, 1, 3, 7, 8, 9, 15, 16, 17
199 : };
200 1 : int i;
201 :
202 1 : torture_gnutls_aes_128_cfb_flags(state,
203 : session_key,
204 : seq_num_initial,
205 : confounder_initial,
206 : confounder_expected,
207 : clear_initial,
208 : crypt_expected);
209 :
210 : /* repeat the test for varying buffer sizes */
211 :
212 11 : for (i = 0; i < ARRAY_SIZE(buffer_sizes); i++) {
213 9 : DATA_BLOB clear_initial_trunc =
214 9 : data_blob_const(clear_initial.data, buffer_sizes[i]);
215 9 : DATA_BLOB crypt_expected_trunc =
216 9 : data_blob_const(crypt_expected.data, buffer_sizes[i]);
217 9 : torture_gnutls_aes_128_cfb_flags(state,
218 : session_key,
219 : seq_num_initial,
220 : confounder_initial,
221 : confounder_expected,
222 : clear_initial_trunc,
223 : crypt_expected_trunc);
224 : }
225 1 : }
226 :
227 1 : static void torture_gnutls_des_crypt56(void **state)
228 : {
229 1 : static const uint8_t key[7] = {
230 : 0x69, 0x88, 0x96, 0x8E, 0xB5, 0x3A, 0x24
231 : };
232 1 : static const uint8_t clear[8] = {
233 : 0x3F, 0x49, 0x5B, 0x20, 0xA7, 0x84, 0xC2, 0x34
234 : };
235 1 : static const uint8_t crypt_expected[8] = {
236 : 0x54, 0x86, 0xCF, 0x51, 0x49, 0x3A, 0x53, 0x5B
237 : };
238 :
239 1 : uint8_t crypt[8];
240 1 : uint8_t decrypt[8];
241 1 : int rc;
242 :
243 1 : rc = des_crypt56_gnutls(crypt, clear, key, SAMBA_GNUTLS_ENCRYPT);
244 1 : assert_int_equal(rc, 0);
245 1 : assert_memory_equal(crypt, crypt_expected, 8);
246 :
247 1 : rc = des_crypt56_gnutls(decrypt, crypt, key, SAMBA_GNUTLS_DECRYPT);
248 1 : assert_int_equal(rc, 0);
249 1 : assert_memory_equal(decrypt, clear, 8);
250 1 : }
251 :
252 1 : static void torture_gnutls_E_P16(void **state)
253 : {
254 1 : static const uint8_t key[14] = {
255 : 0x98, 0xFD, 0xCB, 0x3A, 0xF7, 0xB5, 0x1C, 0xF8,
256 : 0x69, 0x88, 0x96, 0x8E, 0xB5, 0x3A
257 : };
258 1 : uint8_t buffer[16] = {
259 : 0x9C, 0x14, 0xDD, 0xE1, 0x39, 0x23, 0xE0, 0x55,
260 : 0x3F, 0x49, 0x5B, 0x20, 0xA7, 0x84, 0xC2, 0x34
261 : };
262 1 : static const uint8_t crypt_expected[16] = {
263 : 0x41, 0x4A, 0x7B, 0xEA, 0xAB, 0xBB, 0x95, 0xCE,
264 : 0x1D, 0xEA, 0xD9, 0xFF, 0xB0, 0xA9, 0xA4, 0x05
265 : };
266 :
267 1 : int rc;
268 :
269 1 : rc = E_P16(key, buffer);
270 1 : assert_int_equal(rc, 0);
271 1 : assert_memory_equal(buffer, crypt_expected, 16);
272 1 : }
273 :
274 1 : static void torture_gnutls_E_P24(void **state)
275 : {
276 1 : static const uint8_t key[21] = {
277 : 0xFB, 0x67, 0x99, 0xA4, 0x83, 0xF3, 0xD4, 0xED,
278 : 0x98, 0xFD, 0xCB, 0x3A, 0xF7, 0xB5, 0x1C, 0xF8,
279 : 0x69, 0x88, 0x96, 0x8E, 0x3A
280 : };
281 1 : const uint8_t c8[8] = {
282 : 0x44, 0xFB, 0xAC, 0xFB, 0x83, 0xB6, 0x75, 0x2A
283 : };
284 1 : static const uint8_t crypt_expected[24] = {
285 : 0x1A, 0x5E, 0x11, 0xA1, 0x59, 0xA9, 0x6B, 0x4E,
286 : 0x12, 0x5D, 0x81, 0x75, 0xA6, 0x62, 0x15, 0x6D,
287 : 0x5D, 0x20, 0x25, 0xC1, 0xA3, 0x92, 0xB3, 0x28
288 : };
289 :
290 1 : uint8_t crypt[24];
291 1 : int rc;
292 :
293 1 : rc = E_P24(key, c8, crypt);
294 1 : assert_int_equal(rc, 0);
295 1 : assert_memory_equal(crypt, crypt_expected, 24);
296 1 : }
297 :
298 1 : static void torture_gnutls_SMBOWFencrypt(void **state)
299 : {
300 1 : static const uint8_t password[16] = {
301 : 'M', 'y', 'p', 'a', 's', 's', 'w', 'o',
302 : 'r', 'd', 'i', 's', '1', '1', '1', '1'
303 : };
304 1 : const uint8_t c8[8] = {
305 : 0x79, 0x88, 0x5A, 0x3D, 0xD3, 0x40, 0x1E, 0x69
306 : };
307 1 : static const uint8_t crypt_expected[24] = {
308 : 0x3F, 0xE3, 0x53, 0x75, 0x81, 0xB4, 0xF0, 0xE7,
309 : 0x0C, 0xDE, 0xCD, 0xAE, 0x39, 0x1F, 0x14, 0xB4,
310 : 0xA4, 0x2B, 0x3E, 0x39, 0x16, 0xFD, 0x1D, 0x62
311 : };
312 :
313 1 : uint8_t crypt[24];
314 1 : int rc;
315 :
316 1 : rc = SMBOWFencrypt(password, c8, crypt);
317 1 : assert_int_equal(rc, 0);
318 1 : assert_memory_equal(crypt, crypt_expected, 24);
319 1 : }
320 :
321 1 : static void torture_gnutls_E_old_pw_hash(void **state)
322 : {
323 1 : static uint8_t key[14] = {
324 : 0x98, 0xFD, 0xCB, 0x3A, 0xF7, 0xB5, 0x1C, 0xF8,
325 : 0x69, 0x88, 0x96, 0x8E, 0xB5, 0x3A
326 : };
327 1 : uint8_t clear[16] = {
328 : 0x9C, 0x14, 0xDD, 0xE1, 0x39, 0x23, 0xE0, 0x55,
329 : 0x3F, 0x49, 0x5B, 0x20, 0xA7, 0x84, 0xC2, 0x34
330 : };
331 1 : static const uint8_t crypt_expected[16] = {
332 : 0x6A, 0xC7, 0x08, 0xCA, 0x2A, 0xC1, 0xAA, 0x64,
333 : 0x37, 0xEF, 0xBE, 0x58, 0xC2, 0x59, 0x33, 0xEC
334 : };
335 1 : uint8_t crypt[16];
336 1 : int rc;
337 :
338 1 : rc = E_old_pw_hash(key, clear, crypt);
339 1 : assert_int_equal(rc, 0);
340 1 : assert_memory_equal(crypt, crypt_expected, 16);
341 1 : }
342 :
343 1 : static void torture_gnutls_des_crypt128(void **state)
344 : {
345 1 : static uint8_t key[16] = {
346 : 0x98, 0xFD, 0xCB, 0x3A, 0xF7, 0xB5, 0x1C, 0xF8,
347 : 0xA9, 0x69, 0x88, 0x96, 0x8E, 0xB5, 0x3A, 0x24
348 : };
349 1 : static const uint8_t clear[8] = {
350 : 0x3F, 0x49, 0x5B, 0x20, 0xA7, 0x84, 0xC2, 0x34
351 : };
352 1 : static const uint8_t crypt_expected[8] = {
353 : 0x4C, 0xB4, 0x4B, 0xD3, 0xC8, 0xC1, 0xA5, 0x50
354 : };
355 :
356 1 : uint8_t crypt[8];
357 1 : int rc;
358 :
359 1 : rc = des_crypt128(crypt, clear, key);
360 1 : assert_int_equal(rc, 0);
361 1 : assert_memory_equal(crypt, crypt_expected, 8);
362 1 : }
363 :
364 1 : static void torture_gnutls_des_crypt112(void **state)
365 : {
366 1 : static uint8_t key[14] = {
367 : 0x98, 0xFD, 0xCB, 0x3A, 0xF7, 0xB5, 0x1C, 0xF8,
368 : 0x88, 0x96, 0x8E, 0xB5, 0x3A, 0x24
369 : };
370 1 : static const uint8_t clear[8] = {
371 : 0x2F, 0x49, 0x5B, 0x20, 0xD7, 0x84, 0xC2, 0x34
372 : };
373 1 : static const uint8_t crypt_expected[8] = {
374 : 0x87, 0x35, 0xFA, 0xA4, 0x5D, 0x7A, 0xA5, 0x05
375 : };
376 :
377 1 : uint8_t crypt[8];
378 1 : uint8_t decrypt[8];
379 1 : int rc;
380 :
381 1 : rc = des_crypt112(crypt, clear, key, SAMBA_GNUTLS_ENCRYPT);
382 1 : assert_int_equal(rc, 0);
383 1 : assert_memory_equal(crypt, crypt_expected, 8);
384 :
385 1 : rc = des_crypt112(decrypt, crypt, key, SAMBA_GNUTLS_DECRYPT);
386 1 : assert_int_equal(rc, 0);
387 1 : assert_memory_equal(decrypt, clear, 8);
388 1 : }
389 :
390 1 : static void torture_gnutls_des_crypt112_16(void **state)
391 : {
392 1 : static uint8_t key[14] = {
393 : 0x1E, 0x38, 0x27, 0x5B, 0x3B, 0xB8, 0x67, 0xEB,
394 : 0x88, 0x96, 0x8E, 0xB5, 0x3A, 0x24
395 : };
396 1 : static const uint8_t clear[16] = {
397 : 0x02, 0xFA, 0x3B, 0xEE, 0xE8, 0xBA, 0x06, 0x01,
398 : 0xFB, 0x67, 0x99, 0xA4, 0x83, 0xF3, 0xD4, 0xED
399 : };
400 1 : static const uint8_t crypt_expected[16] = {
401 : 0x3C, 0x10, 0x37, 0x67, 0x96, 0x95, 0xF7, 0x96,
402 : 0xAA, 0x03, 0xB9, 0xEA, 0xD6, 0xB3, 0xC3, 0x2D
403 : };
404 :
405 1 : uint8_t crypt[16];
406 1 : uint8_t decrypt[16];
407 1 : int rc;
408 :
409 1 : rc = des_crypt112_16(crypt, clear, key, SAMBA_GNUTLS_ENCRYPT);
410 1 : assert_int_equal(rc, 0);
411 1 : assert_memory_equal(crypt, crypt_expected, 16);
412 :
413 1 : rc = des_crypt112_16(decrypt, crypt, key, SAMBA_GNUTLS_DECRYPT);
414 1 : assert_int_equal(rc, 0);
415 1 : assert_memory_equal(decrypt, clear, 16);
416 1 : }
417 :
418 1 : static void torture_gnutls_sam_rid_crypt(void **state)
419 : {
420 1 : static const uint8_t clear[16] = {
421 : 0x02, 0xFA, 0x3B, 0xEE, 0xE8, 0xBA, 0x06, 0x01,
422 : 0x3F, 0x49, 0x5B, 0x20, 0xA7, 0x84, 0xC2, 0x34
423 : };
424 1 : static const uint8_t crypt_expected[16] = {
425 : 0x1E, 0x38, 0x27, 0x5B, 0x3B, 0xB8, 0x67, 0xEB,
426 : 0xFB, 0x67, 0x99, 0xA4, 0x83, 0xF3, 0xD4, 0xED
427 : };
428 :
429 1 : uint8_t crypt[16];
430 1 : uint8_t decrypt[16];
431 1 : int rid = 500;
432 1 : int rc;
433 :
434 1 : rc = sam_rid_crypt(rid, clear, crypt, SAMBA_GNUTLS_ENCRYPT);
435 1 : assert_int_equal(rc, 0);
436 1 : assert_memory_equal(crypt, crypt_expected, 16);
437 :
438 1 : rc = sam_rid_crypt(rid, crypt, decrypt, SAMBA_GNUTLS_DECRYPT);
439 1 : assert_int_equal(rc, 0);
440 1 : assert_memory_equal(decrypt, clear, 16);
441 1 : }
442 :
443 1 : static void torture_gnutls_SMBsesskeygen_lm_sess_key(void **state)
444 : {
445 1 : static const uint8_t lm_hash[16] = {
446 : 0xFB, 0x67, 0x99, 0xA4, 0x83, 0xF3, 0xD4, 0xED,
447 : 0x9C, 0x14, 0xDD, 0xE1, 0x39, 0x23, 0xE0, 0x55
448 : };
449 1 : static const uint8_t lm_resp[24] = {
450 : 0x02, 0xFA, 0x3B, 0xEE, 0xE8, 0xBA, 0x06, 0x01,
451 : 0x02, 0xFA, 0x3B, 0xEE, 0xE8, 0xBA, 0x06, 0x01,
452 : 0x1E, 0x38, 0x27, 0x5B, 0x3B, 0xB8, 0x67, 0xEB
453 : };
454 1 : static const uint8_t crypt_expected[16] = {
455 : 0x52, 0x8D, 0xB2, 0xD3, 0x89, 0x83, 0xFB, 0x9C,
456 : 0x96, 0x45, 0x15, 0x4B, 0xC3, 0xF5, 0xD5, 0x7F
457 : };
458 :
459 1 : uint8_t crypt_sess_key[16];
460 1 : NTSTATUS status;
461 :
462 1 : status = SMBsesskeygen_lm_sess_key(lm_hash, lm_resp, crypt_sess_key);
463 1 : assert_true(NT_STATUS_IS_OK(status));
464 1 : assert_memory_equal(crypt_sess_key, crypt_expected, 16);
465 1 : }
466 :
467 1 : static void torture_gnutls_sess_crypt_blob(void **state)
468 : {
469 1 : static uint8_t _key[16] = {
470 : 0x1E, 0x38, 0x27, 0x5B, 0x3B, 0xB8, 0x67, 0xEB,
471 : 0xFA, 0xEE, 0xE8, 0xBA, 0x06, 0x01, 0x2D, 0x95
472 : };
473 1 : DATA_BLOB key = data_blob_const(_key, 16);
474 1 : static const uint8_t _clear[24] = {
475 : 0x98, 0xFD, 0xCB, 0x3A, 0xF7, 0xB5, 0x1C, 0xF8,
476 : 0x02, 0xFA, 0x3B, 0xEE, 0xE8, 0xBA, 0x06, 0x01,
477 : 0x3F, 0x49, 0x5B, 0x20, 0xA7, 0x84, 0xC2, 0x34
478 : };
479 1 : DATA_BLOB clear = data_blob_const(_clear, 24);
480 1 : static const uint8_t crypt_expected[24] = {
481 : 0x2B, 0xDD, 0x3B, 0xFA, 0x48, 0xC9, 0x63, 0x56,
482 : 0xAE, 0x8B, 0x3E, 0xCF, 0xEF, 0xDF, 0x7A, 0x42,
483 : 0xB3, 0x00, 0x71, 0x7F, 0x5D, 0x1D, 0xE4, 0x70
484 : };
485 1 : DATA_BLOB crypt = data_blob(NULL, 24);
486 1 : DATA_BLOB decrypt = data_blob(NULL, 24);
487 1 : int rc;
488 :
489 1 : rc = sess_crypt_blob(&crypt, &clear, &key, SAMBA_GNUTLS_ENCRYPT);
490 1 : assert_int_equal(rc, 0);
491 1 : assert_memory_equal(crypt.data, crypt_expected, 24);
492 :
493 1 : rc = sess_crypt_blob(&decrypt, &crypt, &key, SAMBA_GNUTLS_DECRYPT);
494 1 : assert_int_equal(rc, 0);
495 1 : assert_memory_equal(decrypt.data, clear.data, 24);
496 1 : }
497 :
498 1 : int main(int argc, char *argv[])
499 : {
500 1 : int rc;
501 1 : const struct CMUnitTest tests[] = {
502 : cmocka_unit_test(torture_gnutls_aes_128_cfb),
503 : cmocka_unit_test(torture_gnutls_des_crypt56),
504 : cmocka_unit_test(torture_gnutls_E_P16),
505 : cmocka_unit_test(torture_gnutls_E_P24),
506 : cmocka_unit_test(torture_gnutls_SMBOWFencrypt),
507 : cmocka_unit_test(torture_gnutls_E_old_pw_hash),
508 : cmocka_unit_test(torture_gnutls_des_crypt128),
509 : cmocka_unit_test(torture_gnutls_des_crypt112),
510 : cmocka_unit_test(torture_gnutls_des_crypt112_16),
511 : cmocka_unit_test(torture_gnutls_sam_rid_crypt),
512 : cmocka_unit_test(torture_gnutls_SMBsesskeygen_lm_sess_key),
513 : cmocka_unit_test(torture_gnutls_sess_crypt_blob),
514 : };
515 :
516 1 : if (argc == 2) {
517 0 : cmocka_set_test_filter(argv[1]);
518 : }
519 1 : cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
520 :
521 1 : rc = cmocka_run_group_tests(tests, NULL, NULL);
522 :
523 1 : return rc;
524 : }
|