|
1 /* |
|
2 * Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * The original NIST Statistical Test Suite code is placed in public domain. |
|
16 * (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) |
|
17 * |
|
18 * This software was developed at the National Institute of Standards and Technology by |
|
19 * employees of the Federal Government in the course of their official duties. Pursuant |
|
20 * to title 17 Section 105 of the United States Code this software is not subject to |
|
21 * copyright protection and is in the public domain. The NIST Statistical Test Suite is |
|
22 * an experimental system. NIST assumes no responsibility whatsoever for its use by other |
|
23 * parties, and makes no guarantees, expressed or implied, about its quality, reliability, |
|
24 * or any other characteristic. We would appreciate acknowledgment if the software is used. |
|
25 */ |
|
26 |
|
27 #include "openc.h" |
|
28 #include "../include/externs.h" |
|
29 #include "../include/utilities.h" |
|
30 #include "../include/generators.h" |
|
31 #include "../include/genutils.h" |
|
32 |
|
33 const int KRandomByteCount = 1024; |
|
34 |
|
35 double |
|
36 lcg_rand(int N, double SEED, double* DUNIF, int NDIM) |
|
37 { |
|
38 int i; |
|
39 double DZ, DOVER, DZ1, DZ2, DOVER1, DOVER2; |
|
40 double DTWO31, DMDLS, DA1, DA2; |
|
41 |
|
42 DTWO31 = 2147483648.0; /* DTWO31=2**31 */ |
|
43 DMDLS = 2147483647.0; /* DMDLS=2**31-1 */ |
|
44 DA1 = 41160.0; /* DA1=950706376 MOD 2**16 */ |
|
45 DA2 = 950665216.0; /* DA2=950706376-DA1 */ |
|
46 |
|
47 DZ = SEED; |
|
48 if ( N > NDIM ) |
|
49 N = NDIM; |
|
50 for ( i=1; i<=N; i++ ) { |
|
51 DZ = floor(DZ); |
|
52 DZ1 = DZ*DA1; |
|
53 DZ2 = DZ*DA2; |
|
54 DOVER1 = floor(DZ1/DTWO31); |
|
55 DOVER2 = floor(DZ2/DTWO31); |
|
56 DZ1 = DZ1-DOVER1*DTWO31; |
|
57 DZ2 = DZ2-DOVER2*DTWO31; |
|
58 DZ = DZ1+DZ2+DOVER1+DOVER2; |
|
59 DOVER = floor(DZ/DMDLS); |
|
60 DZ = DZ-DOVER*DMDLS; |
|
61 DUNIF[i-1] = DZ/DMDLS; |
|
62 SEED = DZ; |
|
63 } |
|
64 |
|
65 return SEED; |
|
66 } |
|
67 |
|
68 void |
|
69 lcg() |
|
70 { |
|
71 double* DUNIF = NULL; |
|
72 double SEED; |
|
73 int i; |
|
74 unsigned bit; |
|
75 int num_0s, num_1s, v, bitsRead; |
|
76 |
|
77 SEED = 23482349.0; |
|
78 if ( ((epsilon = (BitSequence *) calloc(tp.n, sizeof(BitSequence))) == NULL) || |
|
79 ((DUNIF = (double*)calloc(tp.n, sizeof(double))) == NULL) ) { |
|
80 printf("Insufficient memory available.\n"); |
|
81 exit(1); |
|
82 } |
|
83 |
|
84 for ( v=0; v<tp.numOfBitStreams; v++ ) { |
|
85 num_0s = 0; |
|
86 num_1s = 0; |
|
87 bitsRead = 0; |
|
88 SEED = lcg_rand(tp.n, SEED, DUNIF, tp.n); |
|
89 for ( i=0; i<tp.n; i++ ) { |
|
90 if ( DUNIF[i] < 0.5 ) { |
|
91 bit = 0; |
|
92 num_0s++; |
|
93 } |
|
94 else { |
|
95 bit = 1; |
|
96 num_1s++; |
|
97 } |
|
98 bitsRead++; |
|
99 epsilon[i] = (BitSequence)bit; |
|
100 } |
|
101 fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
102 nist_test_suite(); |
|
103 } |
|
104 free(DUNIF); |
|
105 free(epsilon); |
|
106 } |
|
107 |
|
108 |
|
109 void |
|
110 quadRes1() |
|
111 { |
|
112 int k, num_0s, num_1s, bitsRead, done; |
|
113 BYTE p[64], g[64], x[128]; |
|
114 |
|
115 if ( ((epsilon = (BitSequence *)calloc(tp.n, sizeof(BitSequence))) == NULL) ) { |
|
116 printf("Insufficient memory available.\n"); |
|
117 exit(1); |
|
118 } |
|
119 ahtopb("987b6a6bf2c56a97291c445409920032499f9ee7ad128301b5d0254aa1a9633fdbd378d40149f1e23a13849f3d45992f5c4c6b7104099bc301f6005f9d8115e1", p, 64); |
|
120 ahtopb("3844506a9456c564b8b8538e0cc15aff46c95e69600f084f0657c2401b3c244734b62ea9bb95be4923b9b7e84eeaf1a224894ef0328d44bc3eb3e983644da3f5", g, 64); |
|
121 num_0s = 0; |
|
122 num_1s = 0; |
|
123 done = 0; |
|
124 bitsRead = 0; |
|
125 for ( k=0; k<tp.numOfBitStreams; k++ ) { |
|
126 num_0s = 0; |
|
127 num_1s = 0; |
|
128 done = 0; |
|
129 bitsRead = 0; |
|
130 do { |
|
131 memset(x, 0x00, 128); |
|
132 ModMult(x, g, 64, g, 64, p,64); |
|
133 memcpy(g, x+64, 64); |
|
134 done = convertToBits(g, 512, tp.n, &num_0s, &num_1s, &bitsRead); |
|
135 } while ( !done ); |
|
136 fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
137 nist_test_suite(); |
|
138 } |
|
139 free(epsilon); |
|
140 |
|
141 return; |
|
142 } |
|
143 |
|
144 void |
|
145 quadRes2() |
|
146 { |
|
147 BYTE g[64], x[129], t1[65]; |
|
148 BYTE One[1], Two, Three[1]; |
|
149 int k, num_0s, num_1s, bitsRead, done; |
|
150 |
|
151 if ( ((epsilon = (BitSequence *)calloc(tp.n, sizeof(BitSequence))) == NULL) ) { |
|
152 printf("Insufficient memory available.\n"); |
|
153 exit(1); |
|
154 } |
|
155 One[0] = 0x01; |
|
156 Two = 0x02; |
|
157 Three[0] = 0x03; |
|
158 |
|
159 ahtopb("7844506a9456c564b8b8538e0cc15aff46c95e69600f084f0657c2401b3c244734b62ea9bb95be4923b9b7e84eeaf1a224894ef0328d44bc3eb3e983644da3f5", g, 64); |
|
160 |
|
161 for( k=0; k<tp.numOfBitStreams; k++ ) { |
|
162 num_0s = 0; |
|
163 num_1s = 0; |
|
164 done = 0; |
|
165 bitsRead = 0; |
|
166 do { |
|
167 memset(t1, 0x00, 65); |
|
168 memset(x, 0x00, 129); |
|
169 smult(t1, Two, g, 64); /* 2x */ |
|
170 add(t1, 65, Three, 1); /* 2x+3 */ |
|
171 Mult(x, t1, 65, g, 64); /* x(2x+3) */ |
|
172 add(x, 129, One, 1); /* x(2x+3)+1 */ |
|
173 memcpy(g, x+65, 64); |
|
174 done = convertToBits(g, 512, tp.n, &num_0s, &num_1s, &bitsRead); |
|
175 } while ( !done) ; |
|
176 fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
177 nist_test_suite(); |
|
178 } |
|
179 free(epsilon); |
|
180 |
|
181 return; |
|
182 } |
|
183 |
|
184 void |
|
185 cubicRes() |
|
186 { |
|
187 BYTE g[64], tmp[128], x[192]; |
|
188 int k, num_0s, num_1s, bitsRead, done; |
|
189 |
|
190 if ( ((epsilon = (BitSequence *)calloc(tp.n, sizeof(BitSequence))) == NULL) ) { |
|
191 printf("Insufficient memory available.\n"); |
|
192 exit(1); |
|
193 } |
|
194 |
|
195 ahtopb("7844506a9456c564b8b8538e0cc15aff46c95e69600f084f0657c2401b3c244734b62ea9bb95be4923b9b7e84eeaf1a224894ef0328d44bc3eb3e983644da3f5", g, 64); |
|
196 |
|
197 for ( k=0; k<tp.numOfBitStreams; k++ ) { |
|
198 num_0s = 0; |
|
199 num_1s = 0; |
|
200 bitsRead = 0; |
|
201 done = 0; |
|
202 do { |
|
203 memset(tmp, 0x00, 128); |
|
204 memset(x, 0x00, 192); |
|
205 Mult(tmp, g, 64, g, 64); |
|
206 Mult(x, tmp, 128, g, 64); // Don't need to mod by 2^512, just take low 64 bytes |
|
207 memcpy(g, x+128, 64); |
|
208 done = convertToBits(g, 512, tp.n, &num_0s, &num_1s, &bitsRead); |
|
209 } while ( !done ); |
|
210 fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
211 nist_test_suite(); |
|
212 } |
|
213 free(epsilon); |
|
214 |
|
215 return; |
|
216 } |
|
217 |
|
218 void |
|
219 exclusiveOR() |
|
220 { |
|
221 int i, num_0s, num_1s, bitsRead; |
|
222 BYTE bit_sequence[127]; |
|
223 |
|
224 if ( ((epsilon = (BitSequence *)calloc(tp.n,sizeof(BitSequence))) == NULL) ) { |
|
225 printf("Insufficient memory available.\n"); |
|
226 exit(1); |
|
227 } |
|
228 |
|
229 memcpy(bit_sequence, "0001011011011001000101111001001010011011101101000100000010101111111010100100001010110110000000000100110000101110011111111100111", 127); |
|
230 num_0s = 0; |
|
231 num_1s = 0; |
|
232 bitsRead = 0; |
|
233 for (i=0; i<127; i++ ) { |
|
234 if ( bit_sequence[i] ) { |
|
235 epsilon[bitsRead] = 1; |
|
236 num_1s++; |
|
237 } |
|
238 else { |
|
239 epsilon[bitsRead] = 0; |
|
240 num_1s++; |
|
241 } |
|
242 bitsRead++; |
|
243 } |
|
244 for ( i=127; i<tp.n*tp.numOfBitStreams; i++ ) { |
|
245 if ( bit_sequence[(i-1)%127] != bit_sequence[(i-127)%127] ) { |
|
246 bit_sequence[i%127] = 1; |
|
247 epsilon[bitsRead] = 1; |
|
248 num_1s++; |
|
249 } |
|
250 else { |
|
251 bit_sequence[i%127] = 0; |
|
252 epsilon[bitsRead] = 0; |
|
253 num_0s++; |
|
254 } |
|
255 bitsRead++; |
|
256 if ( bitsRead == tp.n ) { |
|
257 fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
258 nist_test_suite(); |
|
259 num_0s = 0; |
|
260 num_1s = 0; |
|
261 bitsRead = 0; |
|
262 } |
|
263 } |
|
264 free(epsilon); |
|
265 |
|
266 return; |
|
267 } |
|
268 |
|
269 |
|
270 void |
|
271 modExp() |
|
272 { |
|
273 int k, num_0s, num_1s, bitsRead, done; |
|
274 BYTE p[64], g[64], x[192], y[20]; |
|
275 |
|
276 if ( (epsilon = (BitSequence *)calloc(tp.n, sizeof(BitSequence))) == NULL ) { |
|
277 printf("Insufficient memory available.\n"); |
|
278 exit(1); |
|
279 } |
|
280 ahtopb("7AB36982CE1ADF832019CDFEB2393CABDF0214EC", y, 20); |
|
281 ahtopb("987b6a6bf2c56a97291c445409920032499f9ee7ad128301b5d0254aa1a9633fdbd378d40149f1e23a13849f3d45992f5c4c6b7104099bc301f6005f9d8115e1", p, 64); |
|
282 ahtopb("3844506a9456c564b8b8538e0cc15aff46c95e69600f084f0657c2401b3c244734b62ea9bb95be4923b9b7e84eeaf1a224894ef0328d44bc3eb3e983644da3f5", g, 64); |
|
283 |
|
284 for ( k=0; k<tp.numOfBitStreams; k++ ) { |
|
285 num_0s = 0; |
|
286 num_1s = 0; |
|
287 bitsRead = 0; |
|
288 done = 0; |
|
289 do { |
|
290 memset(x, 0x00, 128); |
|
291 ModExp(x, g, 64, y, 20, p, 64); /* NOTE: g must be less than p */ |
|
292 done = convertToBits(x, 512, tp.n, &num_0s, &num_1s, &bitsRead); |
|
293 memcpy(y, x+44, 20); |
|
294 } while ( !done ); |
|
295 fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
296 nist_test_suite(); |
|
297 } |
|
298 free(epsilon); |
|
299 |
|
300 return; |
|
301 } |
|
302 |
|
303 void |
|
304 bbs() |
|
305 { |
|
306 int i, v, bitsRead; |
|
307 BYTE p[64], q[64], n[128], s[64], x[256]; |
|
308 int num_0s, num_1s; |
|
309 |
|
310 if ( (epsilon = (BitSequence*)calloc(tp.n, sizeof(BitSequence))) == NULL ) { |
|
311 printf("Insufficient memory available.\n"); |
|
312 exit(1); |
|
313 } |
|
314 ahtopb("E65097BAEC92E70478CAF4ED0ED94E1C94B154466BFB9EC9BE37B2B0FF8526C222B76E0E915017535AE8B9207250257D0A0C87C0DACEF78E17D1EF9DC44FD91F", p, 64); |
|
315 ahtopb("E029AEFCF8EA2C29D99CB53DD5FA9BC1D0176F5DF8D9110FD16EE21F32E37BA86FF42F00531AD5B8A43073182CC2E15F5C86E8DA059E346777C9A985F7D8A867", q, 64); |
|
316 memset(n, 0x00, 128); |
|
317 Mult(n, p, 64, q, 64); |
|
318 memset(s, 0x00, 64); |
|
319 ahtopb("10d6333cfac8e30e808d2192f7c0439480da79db9bbca1667d73be9a677ed31311f3b830937763837cb7b1b1dc75f14eea417f84d9625628750de99e7ef1e976", s, 64); |
|
320 memset(x, 0x00, 256); |
|
321 ModSqr(x, s, 64, n, 128); |
|
322 |
|
323 for ( v=0; v<tp.numOfBitStreams; v++ ) { |
|
324 num_0s = 0; |
|
325 num_1s = 0; |
|
326 bitsRead = 0; |
|
327 for ( i=0; i<tp.n; i++ ) { |
|
328 ModSqr(x, x, 128, n, 128); |
|
329 memcpy(x, x+128, 128); |
|
330 if ( (x[127] & 0x01) == 0 ) { |
|
331 num_0s++; |
|
332 epsilon[i] = 0; |
|
333 } |
|
334 else { |
|
335 num_1s++; |
|
336 epsilon[i] = 1; |
|
337 } |
|
338 bitsRead++; |
|
339 if ( (i % 50000) == 0 ) |
|
340 printf("\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
341 } |
|
342 |
|
343 fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
344 nist_test_suite(); |
|
345 } |
|
346 free(epsilon); |
|
347 } |
|
348 |
|
349 |
|
350 // The exponent, e, is set to 11 |
|
351 // This results in k = 837 and r = 187 |
|
352 void |
|
353 micali_schnorr() |
|
354 { |
|
355 long i, j; |
|
356 int k=837, num_0s, num_1s, bitsRead, done; |
|
357 BYTE p[64], q[64], n[128], e[1], X[128], Y[384], Tail[105]; |
|
358 |
|
359 if ( (epsilon = (BitSequence *)calloc(tp.n, sizeof(BitSequence))) == NULL ) { |
|
360 printf("Insufficient memory available.\n"); |
|
361 exit(1); |
|
362 } |
|
363 ahtopb("E65097BAEC92E70478CAF4ED0ED94E1C94B154466BFB9EC9BE37B2B0FF8526C222B76E0E915017535AE8B9207250257D0A0C87C0DACEF78E17D1EF9DC44FD91F", p, 64); |
|
364 ahtopb("E029AEFCF8EA2C29D99CB53DD5FA9BC1D0176F5DF8D9110FD16EE21F32E37BA86FF42F00531AD5B8A43073182CC2E15F5C86E8DA059E346777C9A985F7D8A867", q, 64); |
|
365 memset(n, 0x00, 128); |
|
366 Mult(n, p, 64, q, 64); |
|
367 e[0] = 0x0b; |
|
368 memset(X, 0x00, 128); |
|
369 ahtopb("237c5f791c2cfe47bfb16d2d54a0d60665b20904ec822a6", X+104, 24); |
|
370 |
|
371 for ( i=0; i<tp.numOfBitStreams; i++ ) { |
|
372 num_0s = 0; |
|
373 num_1s = 0; |
|
374 bitsRead = 0; |
|
375 do { |
|
376 ModExp(Y, X, 128, e, 1, n, 128); |
|
377 memcpy(Tail, Y+23, 105); |
|
378 for ( j=0; j<3; j++ ) |
|
379 bshl(Tail, 105); |
|
380 done = convertToBits(Tail, k, tp.n, &num_0s, &num_1s, &bitsRead); |
|
381 memset(X, 0x00, 128); |
|
382 memcpy(X+104, Y, 24); |
|
383 for ( j=0; j<5; j++ ) |
|
384 bshr(X+104, 24); |
|
385 } while ( !done ); |
|
386 |
|
387 fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
388 nist_test_suite(); |
|
389 } |
|
390 free(epsilon); |
|
391 } |
|
392 |
|
393 // Uses 160 bit Xkey and no XSeed (b=160) |
|
394 // This is the generic form of the generator found on the last page of the Change Notice for FIPS 186-2 |
|
395 void |
|
396 SHA1() |
|
397 { |
|
398 ULONG A, B, C, D, E, temp, Wbuff[16]; |
|
399 BYTE Xkey[20], G[20], M[64]; |
|
400 BYTE One[1] = { 0x01 }; |
|
401 int i, num_0s, num_1s, bitsRead; |
|
402 int done; |
|
403 ULONG tx[5] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }; |
|
404 |
|
405 if ( ((epsilon = (BitSequence *) calloc(tp.n,sizeof(BitSequence))) == NULL) ) { |
|
406 printf("Insufficient memory available.\n"); |
|
407 exit(1); |
|
408 } |
|
409 |
|
410 ahtopb("ec822a619d6ed5d9492218a7a4c5b15d57c61601", Xkey, 20); |
|
411 |
|
412 for ( i=0; i<tp.numOfBitStreams; i++ ) { |
|
413 num_0s = 0; |
|
414 num_1s = 0; |
|
415 bitsRead = 0; |
|
416 do { |
|
417 memcpy(M, Xkey, 20); |
|
418 memset(M+20, 0x00, 44); |
|
419 |
|
420 // Start: SHA Steps A-E |
|
421 A = tx[0]; |
|
422 B = tx[1]; |
|
423 C = tx[2]; |
|
424 D = tx[3]; |
|
425 E = tx[4]; |
|
426 |
|
427 memcpy((BYTE *)Wbuff, M, 64); |
|
428 #ifdef LITTLE_ENDIAN |
|
429 byteReverse(Wbuff, 20); |
|
430 #endif |
|
431 sub1Round1( 0 ); sub1Round1( 1 ); sub1Round1( 2 ); sub1Round1( 3 ); |
|
432 sub1Round1( 4 ); sub1Round1( 5 ); sub1Round1( 6 ); sub1Round1( 7 ); |
|
433 sub1Round1( 8 ); sub1Round1( 9 ); sub1Round1( 10 ); sub1Round1( 11 ); |
|
434 sub1Round1( 12 ); sub1Round1( 13 ); sub1Round1( 14 ); sub1Round1( 15 ); |
|
435 sub2Round1( 16 ); sub2Round1( 17 ); sub2Round1( 18 ); sub2Round1( 19 ); |
|
436 Round2( 20 ); Round2( 21 ); Round2( 22 ); Round2( 23 ); |
|
437 Round2( 24 ); Round2( 25 ); Round2( 26 ); Round2( 27 ); |
|
438 Round2( 28 ); Round2( 29 ); Round2( 30 ); Round2( 31 ); |
|
439 Round2( 32 ); Round2( 33 ); Round2( 34 ); Round2( 35 ); |
|
440 Round2( 36 ); Round2( 37 ); Round2( 38 ); Round2( 39 ); |
|
441 Round3( 40 ); Round3( 41 ); Round3( 42 ); Round3( 43 ); |
|
442 Round3( 44 ); Round3( 45 ); Round3( 46 ); Round3( 47 ); |
|
443 Round3( 48 ); Round3( 49 ); Round3( 50 ); Round3( 51 ); |
|
444 Round3( 52 ); Round3( 53 ); Round3( 54 ); Round3( 55 ); |
|
445 Round3( 56 ); Round3( 57 ); Round3( 58 ); Round3( 59 ); |
|
446 Round4( 60 ); Round4( 61 ); Round4( 62 ); Round4( 63 ); |
|
447 Round4( 64 ); Round4( 65 ); Round4( 66 ); Round4( 67 ); |
|
448 Round4( 68 ); Round4( 69 ); Round4( 70 ); Round4( 71 ); |
|
449 Round4( 72 ); Round4( 73 ); Round4( 74 ); Round4( 75 ); |
|
450 Round4( 76 ); Round4( 77 ); Round4( 78 ); Round4( 79 ); |
|
451 |
|
452 A += tx[0]; |
|
453 B += tx[1]; |
|
454 C += tx[2]; |
|
455 D += tx[3]; |
|
456 E += tx[4]; |
|
457 |
|
458 memcpy(G, (BYTE *)&A, 4); |
|
459 memcpy(G+4, (BYTE *)&B, 4); |
|
460 memcpy(G+8, (BYTE *)&C, 4); |
|
461 memcpy(G+12, (BYTE *)&D, 4); |
|
462 memcpy(G+16, (BYTE *)&E, 4); |
|
463 #ifdef LITTLE_ENDIAN |
|
464 byteReverse((ULONG *)G, 20); |
|
465 #endif |
|
466 // End: SHA Steps A-E |
|
467 |
|
468 done = convertToBits(G, 160, tp.n, &num_0s, &num_1s, &bitsRead); |
|
469 add(Xkey, 20, G, 20); |
|
470 add(Xkey, 20, One, 1); |
|
471 } while ( !done ); |
|
472 fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
473 nist_test_suite(); |
|
474 } |
|
475 free(epsilon); |
|
476 } |
|
477 |
|
478 void HASH_DRBG() |
|
479 { |
|
480 int done = 0; |
|
481 int num_0s = 0; |
|
482 int num_1s = 0; |
|
483 int bitsRead = 0; |
|
484 |
|
485 if ( ((epsilon = (BitSequence *) calloc(tp.n,sizeof(BitSequence))) == NULL) ) { |
|
486 printf("Insufficient memory available.\n"); |
|
487 exit(1); |
|
488 } |
|
489 |
|
490 TBuf8<KRandomByteCount> randBuffer(KRandomByteCount); |
|
491 |
|
492 for (int i = 0; i < tp.numOfBitStreams; ++i) |
|
493 { |
|
494 gConsole->Printf(_L("Starting test %d\n"), i+1); |
|
495 num_0s = 0; |
|
496 num_1s = 0; |
|
497 bitsRead = 0; |
|
498 done = 0; |
|
499 do |
|
500 { |
|
501 Math::Random(randBuffer); |
|
502 done = convertToBits(randBuffer.Ptr() , KRandomByteCount*8, tp.n, &num_0s, &num_1s, &bitsRead); |
|
503 } while ( !done ); |
|
504 fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); |
|
505 |
|
506 nist_test_suite(); |
|
507 } |
|
508 free(epsilon); |
|
509 } |
|
510 |