| OLD | NEW |
| 1 /* | 1 /* |
| 2 * rand_gen.c | 2 * rand_gen.c |
| 3 * | 3 * |
| 4 * a random source (random number generator) | 4 * a random source (random number generator) |
| 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 30 matching lines...) Expand all Loading... |
| 41 * OF THE POSSIBILITY OF SUCH DAMAGE. | 41 * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 42 * | 42 * |
| 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 <unistd.h> /* for getopt() */ | 51 #include "getopt_s.h" |
| 52 #include "crypto_kernel.h" | 52 #include "crypto_kernel.h" |
| 53 | 53 |
| 54 /* | 54 /* |
| 55 * MAX_PRINT_STRING_LEN is defined in datatypes.h, and is the length | 55 * MAX_PRINT_STRING_LEN is defined in datatypes.h, and is the length |
| 56 * of the largest hexadecimal string that can be generated by the | 56 * of the largest hexadecimal string that can be generated by the |
| 57 * function octet_string_hex_string(). | 57 * function octet_string_hex_string(). |
| 58 */ | 58 */ |
| 59 | 59 |
| 60 #define BUF_LEN (MAX_PRINT_STRING_LEN/2) | 60 #define BUF_LEN (MAX_PRINT_STRING_LEN/2) |
| 61 | 61 |
| 62 void | 62 void |
| 63 usage(char *prog_name) { | 63 usage(char *prog_name) { |
| 64 printf("usage: %s -n <num_bytes> [-l][ -d debug_module ]*\n" | 64 printf("usage: %s -n <num_bytes> [-l][ -d debug_module ]*\n" |
| 65 " -n <num> output <num> random bytes, where <num>" | 65 " -n <num> output <num> random bytes, where <num>" |
| 66 " is between zero and %d\n" | 66 " is between zero and %d\n" |
| 67 " -l list the avaliable debug modules\n" | 67 " -l list the avaliable debug modules\n" |
| 68 " -d <mod> turn on debugging module <mod>\n", | 68 " -d <mod> turn on debugging module <mod>\n", |
| 69 prog_name, BUF_LEN); | 69 prog_name, BUF_LEN); |
| 70 exit(255); | 70 exit(255); |
| 71 } | 71 } |
| 72 | 72 |
| 73 int | 73 int |
| 74 main (int argc, char *argv[]) { | 74 main (int argc, char *argv[]) { |
| 75 extern char *optarg; | |
| 76 int q; | 75 int q; |
| 77 int num_octets = 0; | 76 int num_octets = 0; |
| 78 unsigned do_list_mods = 0; | 77 unsigned do_list_mods = 0; |
| 79 err_status_t status; | 78 err_status_t status; |
| 80 | 79 |
| 81 if (argc == 1) | 80 if (argc == 1) |
| 82 usage(argv[0]); | 81 usage(argv[0]); |
| 83 | 82 |
| 84 /* initialize kernel - we need to do this before anything else */ | 83 /* initialize kernel - we need to do this before anything else */ |
| 85 status = crypto_kernel_init(); | 84 status = crypto_kernel_init(); |
| 86 if (status) { | 85 if (status) { |
| 87 printf("error: crypto_kernel init failed\n"); | 86 printf("error: crypto_kernel init failed\n"); |
| 88 exit(1); | 87 exit(1); |
| 89 } | 88 } |
| 90 | 89 |
| 91 /* process input arguments */ | 90 /* process input arguments */ |
| 92 while (1) { | 91 while (1) { |
| 93 q = getopt(argc, argv, "ld:n:"); | 92 q = getopt_s(argc, argv, "ld:n:"); |
| 94 if (q == -1) | 93 if (q == -1) |
| 95 break; | 94 break; |
| 96 switch (q) { | 95 switch (q) { |
| 97 case 'd': | 96 case 'd': |
| 98 status = crypto_kernel_set_debug_module(optarg, 1); | 97 status = crypto_kernel_set_debug_module(optarg_s, 1); |
| 99 if (status) { | 98 if (status) { |
| 100 » printf("error: set debug module (%s) failed\n", optarg); | 99 » printf("error: set debug module (%s) failed\n", optarg_s); |
| 101 exit(1); | 100 exit(1); |
| 102 } | 101 } |
| 103 break; | 102 break; |
| 104 case 'l': | 103 case 'l': |
| 105 do_list_mods = 1; | 104 do_list_mods = 1; |
| 106 break; | 105 break; |
| 107 case 'n': | 106 case 'n': |
| 108 num_octets = atoi(optarg); | 107 num_octets = atoi(optarg_s); |
| 109 if (num_octets < 0 || num_octets > BUF_LEN) | 108 if (num_octets < 0 || num_octets > BUF_LEN) |
| 110 usage(argv[0]); | 109 usage(argv[0]); |
| 111 break; | 110 break; |
| 112 default: | 111 default: |
| 113 usage(argv[0]); | 112 usage(argv[0]); |
| 114 } | 113 } |
| 115 } | 114 } |
| 116 | 115 |
| 117 if (do_list_mods) { | 116 if (do_list_mods) { |
| 118 status = crypto_kernel_list_debug_modules(); | 117 status = crypto_kernel_list_debug_modules(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 135 | 134 |
| 136 status = crypto_kernel_shutdown(); | 135 status = crypto_kernel_shutdown(); |
| 137 if (status) { | 136 if (status) { |
| 138 printf("error: crypto_kernel shutdown failed\n"); | 137 printf("error: crypto_kernel shutdown failed\n"); |
| 139 exit(1); | 138 exit(1); |
| 140 } | 139 } |
| 141 | 140 |
| 142 return 0; | 141 return 0; |
| 143 } | 142 } |
| 144 | 143 |
| OLD | NEW |