OLD | NEW |
| (Empty) |
1 /* | |
2 * Soak test the RNG for exhaustion failures | |
3 */ | |
4 | |
5 /* | |
6 * | |
7 * Copyright (c) 2001-2006, Cisco Systems, Inc. | |
8 * All rights reserved. | |
9 * | |
10 * Redistribution and use in source and binary forms, with or without | |
11 * modification, are permitted provided that the following conditions | |
12 * are met: | |
13 * | |
14 * Redistributions of source code must retain the above copyright | |
15 * notice, this list of conditions and the following disclaimer. | |
16 * | |
17 * Redistributions in binary form must reproduce the above | |
18 * copyright notice, this list of conditions and the following | |
19 * disclaimer in the documentation and/or other materials provided | |
20 * with the distribution. | |
21 * | |
22 * Neither the name of the Cisco Systems, Inc. nor the names of its | |
23 * contributors may be used to endorse or promote products derived | |
24 * from this software without specific prior written permission. | |
25 * | |
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
29 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
30 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
31 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
32 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
37 * OF THE POSSIBILITY OF SUCH DAMAGE. | |
38 * | |
39 */ | |
40 | |
41 #ifdef HAVE_CONFIG_H | |
42 #include <config.h> | |
43 #endif | |
44 | |
45 #include <stdio.h> /* for printf() */ | |
46 #include "getopt_s.h" | |
47 #include "crypto_kernel.h" | |
48 | |
49 #define BUF_LEN (MAX_PRINT_STRING_LEN/2) | |
50 | |
51 int main(int argc, char *argv[]) | |
52 { | |
53 int q; | |
54 int num_octets = 0; | |
55 err_status_t status; | |
56 uint32_t iterations = 0; | |
57 int print_values = 0; | |
58 | |
59 if (argc == 1) { | |
60 exit(255); | |
61 } | |
62 | |
63 status = crypto_kernel_init(); | |
64 if (status) { | |
65 printf("error: crypto_kernel init failed\n"); | |
66 exit(1); | |
67 } | |
68 | |
69 while (1) { | |
70 q = getopt_s(argc, argv, "pvn:"); | |
71 if (q == -1) { | |
72 break; | |
73 } | |
74 switch (q) { | |
75 case 'p': | |
76 print_values = 1; | |
77 break; | |
78 case 'n': | |
79 num_octets = atoi(optarg_s); | |
80 if (num_octets < 0 || num_octets > BUF_LEN) { | |
81 exit(255); | |
82 } | |
83 break; | |
84 case 'v': | |
85 num_octets = 30; | |
86 print_values = 0; | |
87 break; | |
88 default: | |
89 exit(255); | |
90 } | |
91 } | |
92 | |
93 if (num_octets > 0) { | |
94 while (iterations < 300000) { | |
95 uint8_t buffer[BUF_LEN]; | |
96 | |
97 status = crypto_get_random(buffer, num_octets); | |
98 if (status) { | |
99 printf("iteration %d error: failure in random source\n", iterati
ons); | |
100 exit(255); | |
101 } else if (print_values) { | |
102 printf("%s\n", octet_string_hex_string(buffer, num_octets)); | |
103 } | |
104 iterations++; | |
105 } | |
106 } | |
107 | |
108 status = crypto_kernel_shutdown(); | |
109 if (status) { | |
110 printf("error: crypto_kernel shutdown failed\n"); | |
111 exit(1); | |
112 } | |
113 | |
114 return 0; | |
115 } | |
116 | |
OLD | NEW |