OLD | NEW |
1 /* | 1 /* |
2 * cipher_driver.c | 2 * cipher_driver.c |
3 * | 3 * |
4 * A driver for the generic cipher type | 4 * A driver for the generic cipher type |
5 * | 5 * |
6 * David A. McGrew | 6 * David A. McGrew |
7 * Cisco Systems, Inc. | 7 * Cisco Systems, Inc. |
8 */ | 8 */ |
9 | 9 |
10 /* | 10 /* |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 * | 43 * |
44 */ | 44 */ |
45 | 45 |
46 #ifdef HAVE_CONFIG_H | 46 #ifdef HAVE_CONFIG_H |
47 #include <config.h> | 47 #include <config.h> |
48 #endif | 48 #endif |
49 | 49 |
50 #include <stdio.h> /* for printf() */ | 50 #include <stdio.h> /* for printf() */ |
51 #include <stdlib.h> /* for rand() */ | 51 #include <stdlib.h> /* for rand() */ |
52 #include <string.h> /* for memset() */ | 52 #include <string.h> /* for memset() */ |
53 #include <unistd.h> /* for getopt() */ | 53 #include "getopt_s.h" |
54 #include "cipher.h" | 54 #include "cipher.h" |
55 #ifdef OPENSSL | 55 #ifdef OPENSSL |
56 #include "aes_icm_ossl.h" | 56 #include "aes_icm_ossl.h" |
57 #include "aes_gcm_ossl.h" | 57 #include "aes_gcm_ossl.h" |
58 #else | 58 #else |
59 #include "aes_icm.h" | 59 #include "aes_icm.h" |
60 #endif | 60 #endif |
61 #include "null_cipher.h" | 61 #include "null_cipher.h" |
62 | 62 |
63 #define PRINT_DEBUG 0 | 63 #define PRINT_DEBUG 0 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | 146 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, |
147 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, | 147 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, |
148 }; | 148 }; |
149 int q; | 149 int q; |
150 unsigned do_timing_test = 0; | 150 unsigned do_timing_test = 0; |
151 unsigned do_validation = 0; | 151 unsigned do_validation = 0; |
152 unsigned do_array_timing_test = 0; | 152 unsigned do_array_timing_test = 0; |
153 | 153 |
154 /* process input arguments */ | 154 /* process input arguments */ |
155 while (1) { | 155 while (1) { |
156 q = getopt(argc, argv, "tva"); | 156 q = getopt_s(argc, argv, "tva"); |
157 if (q == -1) | 157 if (q == -1) |
158 break; | 158 break; |
159 switch (q) { | 159 switch (q) { |
160 case 't': | 160 case 't': |
161 do_timing_test = 1; | 161 do_timing_test = 1; |
162 break; | 162 break; |
163 case 'v': | 163 case 'v': |
164 do_validation = 1; | 164 do_validation = 1; |
165 break; | 165 break; |
166 case 'a': | 166 case 'a': |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 366 |
367 return err_status_ok; | 367 return err_status_ok; |
368 } | 368 } |
369 | 369 |
370 /* | 370 /* |
371 * cipher_driver_test_buffering(ct) tests the cipher's output | 371 * cipher_driver_test_buffering(ct) tests the cipher's output |
372 * buffering for correctness by checking the consistency of succesive | 372 * buffering for correctness by checking the consistency of succesive |
373 * calls | 373 * calls |
374 */ | 374 */ |
375 | 375 |
| 376 #define INITIAL_BUFLEN 1024 |
376 err_status_t | 377 err_status_t |
377 cipher_driver_test_buffering(cipher_t *c) { | 378 cipher_driver_test_buffering(cipher_t *c) { |
378 int i, j, num_trials = 1000; | 379 int i, j, num_trials = 1000; |
379 unsigned len, buflen = 1024; | 380 unsigned len, buflen = INITIAL_BUFLEN; |
380 uint8_t buffer0[buflen], buffer1[buflen], *current, *end; | 381 uint8_t buffer0[INITIAL_BUFLEN], buffer1[INITIAL_BUFLEN], *current, *end; |
381 uint8_t idx[16] = { | 382 uint8_t idx[16] = { |
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34 | 384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34 |
384 }; | 385 }; |
385 err_status_t status; | 386 err_status_t status; |
386 | 387 |
387 printf("testing output buffering for cipher %s...", | 388 printf("testing output buffering for cipher %s...", |
388 c->type->description); | 389 c->type->description); |
389 | 390 |
390 for (i=0; i < num_trials; i++) { | 391 for (i=0; i < num_trials; i++) { |
391 | 392 |
392 /* set buffers to zero */ | 393 /* set buffers to zero */ |
393 for (j=0; j < buflen; j++) | 394 for (j=0; j < (int) buflen; j++) { |
394 buffer0[j] = buffer1[j] = 0; | 395 buffer0[j] = buffer1[j] = 0; |
| 396 } |
395 | 397 |
396 /* initialize cipher */ | 398 /* initialize cipher */ |
397 status = cipher_set_iv(c, idx, direction_encrypt); | 399 status = cipher_set_iv(c, idx, direction_encrypt); |
398 if (status) | 400 if (status) |
399 return status; | 401 return status; |
400 | 402 |
401 /* generate 'reference' value by encrypting all at once */ | 403 /* generate 'reference' value by encrypting all at once */ |
402 status = cipher_encrypt(c, buffer0, &buflen); | 404 status = cipher_encrypt(c, buffer0, &buflen); |
403 if (status) | 405 if (status) |
404 return status; | 406 return status; |
(...skipping 21 matching lines...) Expand all Loading... |
426 | 428 |
427 /* advance pointer into buffer1 to reflect encryption */ | 429 /* advance pointer into buffer1 to reflect encryption */ |
428 current += len; | 430 current += len; |
429 | 431 |
430 /* if buffer1 is all encrypted, break out of loop */ | 432 /* if buffer1 is all encrypted, break out of loop */ |
431 if (current == end) | 433 if (current == end) |
432 break; | 434 break; |
433 } | 435 } |
434 | 436 |
435 /* compare buffers */ | 437 /* compare buffers */ |
436 for (j=0; j < buflen; j++) | 438 for (j=0; j < (int) buflen; j++) { |
437 if (buffer0[j] != buffer1[j]) { | 439 if (buffer0[j] != buffer1[j]) { |
438 #if PRINT_DEBUG | 440 #if PRINT_DEBUG |
439 printf("test case %d failed at byte %d\n", i, j); | 441 printf("test case %d failed at byte %d\n", i, j); |
440 printf("computed: %s\n", octet_string_hex_string(buffer1, buflen)); | 442 printf("computed: %s\n", octet_string_hex_string(buffer1, buflen)); |
441 printf("expected: %s\n", octet_string_hex_string(buffer0, buflen)); | 443 printf("expected: %s\n", octet_string_hex_string(buffer0, buflen)); |
442 #endif | 444 #endif |
443 return err_status_algo_fail; | 445 return err_status_algo_fail; |
444 } | 446 } |
| 447 } |
445 } | 448 } |
446 | 449 |
447 printf("passed\n"); | 450 printf("passed\n"); |
448 | 451 |
449 return err_status_ok; | 452 return err_status_ok; |
450 } | 453 } |
451 | 454 |
452 | 455 |
453 /* | 456 /* |
454 * The function cipher_test_throughput_array() tests the effect of CPU | 457 * The function cipher_test_throughput_array() tests the effect of CPU |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 status); | 613 status); |
611 return status; | 614 return status; |
612 } | 615 } |
613 | 616 |
614 cipher_array_test_throughput(ca, num_cipher); | 617 cipher_array_test_throughput(ca, num_cipher); |
615 | 618 |
616 cipher_array_delete(ca, num_cipher); | 619 cipher_array_delete(ca, num_cipher); |
617 | 620 |
618 return err_status_ok; | 621 return err_status_ok; |
619 } | 622 } |
OLD | NEW |