-
+ 925D35158574838825AEE8B2269787E17FA2F3C3FC6BC6929EF573BBA3B1477F157FB9F162E627B13C5E60F02D6BEFCCCE395123FC061F8F2317173BD5CE8DC4eucrypt/smg_rsa/tests/tests.c(0 . 0)(1 . 46)
152 #include "smg_rsa.h"
153
154 #include <stdlib.h>
155 #include <time.h>
156
157 void err(char *msg)
158 {
159 fprintf(stderr, "%s\n", msg);
160 exit(1);
161 }
162
163 void time_entropy_source(int nruns, int noctets) {
164 unsigned char buffer[noctets];
165 int read, i;
166 struct timespec tstart, tend;
167 long int diff;
168
169 clock_gettime(CLOCK_MONOTONIC, &tstart);
170 for (i=0; i<nruns; i++) {
171 read = get_random_octets(noctets,buffer);
172 if (read != noctets)
173 err("Failed reading from entropy source!");
174 }
175 clock_gettime(CLOCK_MONOTONIC, &tend);
176
177 diff = tend.tv_sec-tstart.tv_sec;
178 double kbps = (nruns*noctets) / (diff*1000.0);
179 printf("ENTROPY source timing: %d kB in %ld seconds, at an average speed of %f kB/s over %d runs of %d octets each\n", nruns*noctets, diff, kbps, nruns, noctets);
180 }
181
182
183 int main(int ac, char **av)
184 {
185 int nruns;
186
187 if (ac<2) {
188 printf("Usage: %s number_of_runs\n", av[0]);
189 return -1;
190 }
191 nruns = atoi(av[1]);
192
193 printf("Timing entropy source...\n");
194 time_entropy_source(nruns,4096);
195
196 return 0;
197 }