+ /* --- Do the FIPS test --- */
+
+ if (flags & f_fips) {
+ octet buf[FIPSTEST_BUFSZ];
+ unsigned rc;
+
+ r->ops->fill(r, buf, sizeof(buf));
+ rc = fipstest(buf);
+ if (rc & FIPSTEST_MONOBIT)
+ moan("failed monobit test");
+ if (rc & FIPSTEST_POKER)
+ moan("failed poker test");
+ if (rc & FIPSTEST_RUNS)
+ moan("failed runs test");
+ if (rc & FIPSTEST_LONGRUNS)
+ moan("failed long runs test");
+ if (!rc && (flags & f_progress))
+ puts("test passed");
+ return (rc ? EXIT_FAILURE : 0);
+ }
+
+ /* --- Do Maurer's test --- */
+
+ if (flags & f_maurer) {
+ octet buf[250 * 1024];
+ unsigned i;
+ unsigned rc = 0;
+ unsigned f = 0, jj = 0;
+ double maxz = 0;
+
+ static struct { double x; const char *sig; } sigtab[] = {
+ { 3.2905, "1e-3" },
+ { 3.0902, "2e-3" },
+ { 2.8070, "5e-3" },
+ { 2.5758, "1e-2" },
+ { 0 , 0 }
+ };
+
+ r->ops->fill(r, buf, sizeof(buf));
+ for (i = 5; i < 8; i++) {
+ double z = maurer(buf, sizeof(buf), i + 1);
+ double zz = fabs(z);
+ unsigned j;
+
+ for (j = 0; sigtab[j].sig; j++) {
+ if (zz > sigtab[j].x) {
+ if (zz > fabs(maxz)) {
+ maxz = z;
+ f = i + 1;
+ jj = j;
+ }
+ rc = EXIT_FAILURE;
+ moan("failed, bits = %u, sig = %s, Z_u = %g",
+ i + 1, sigtab[j].sig, z);
+ break;
+ }
+ }
+ if (flags & f_progress)
+ printf("bits = %u, Z_u = %g\n", i + 1, z);
+ }
+
+ return (rc);
+ }
+
+ /* --- Make sure we don't write to the terminal --- */
+