X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/44d4e7aac663215fc910ea39bcc84a404afcdb2c..cc3ca08f22460b15423bb88632f3a12741b19003:/fipstest.c diff --git a/fipstest.c b/fipstest.c index cdfcc05..4563882 100644 --- a/fipstest.c +++ b/fipstest.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: fipstest.c,v 1.1 2000/06/17 10:55:38 mdw Exp $ + * $Id: fipstest.c,v 1.4 2004/04/08 01:36:15 mdw Exp $ * - * FIPS 140-1 randomness tests + * FIPS140 randomness tests * * (c) 2000 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,26 +15,18 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: fipstest.c,v $ - * Revision 1.1 2000/06/17 10:55:38 mdw - * FIPS 140-1 random generator test. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -68,7 +60,7 @@ static unsigned monobit(const octet *p) } } - if (9654 >= n1 || n1 >= 10346) + if (9725 >= n1 || n1 >= 10275) return (FIPSTEST_MONOBIT); return (0); } @@ -83,7 +75,7 @@ static unsigned monobit(const octet *p) * divided into 4-bit nibbles %$x_i$%. If * %$f(x) = \sum_{x_i = x} 1$% is the frequency of each nibble, * then the test is passed if - * %$1.03 < 16/5000 \sum_i f(i)^2 - 5000 < 57.4$%. + * %$2.16 < 16/5000 \sum_i f(i)^2 - 5000 < 46.17$%. */ static unsigned poker(const octet *p) @@ -109,9 +101,9 @@ static unsigned poker(const octet *p) for (i = 0; i < 16; i++) q += f[i] * f[i]; q <<= 4; - q -= 5000 * 5000; + q -= 5000ul * 5000ul; - if (5150 >= q || q >= 287000) + if (10800 >= q || q >= 230850) return (FIPSTEST_POKER); return (0); } @@ -133,7 +125,7 @@ static unsigned runs(const octet *p) unsigned i, j; unsigned r = 0; unsigned bb = 0; - unsigned f[2][6] = { 0 }; + unsigned f[2][6] = { { 0 } }; /* --- Count the run lengths --- */ @@ -157,8 +149,8 @@ static unsigned runs(const octet *p) } } } - - if (r >= 34) + + if (r >= 26) rc |= FIPSTEST_LONGRUNS; if (r > 6) r = 6; @@ -166,21 +158,15 @@ static unsigned runs(const octet *p) /* --- Check the results --- */ - if (2267 > f[0][0] || f[0][0] > 2733 || - 2267 > f[1][0] || f[1][0] > 2733 || - 1079 > f[0][1] || f[0][1] > 1421 || - 1079 > f[1][1] || f[1][1] > 1421 || - 502 > f[0][2] || f[0][2] > 748 || - 502 > f[1][2] || f[1][2] > 748 || - 223 > f[0][3] || f[0][3] > 402 || - 223 > f[1][3] || f[1][3] > 402 || - 90 > f[0][4] || f[0][4] > 223 || - 90 > f[1][4] || f[1][4] > 223 || - 90 > f[0][5] || f[0][5] > 223 || - 90 > f[1][5] || f[1][5] > 223) + if (2343 > f[0][0] || f[0][0] > 2657 || 2343 > f[1][0] || f[1][0] > 2657 || + 1135 > f[0][1] || f[0][1] > 1365 || 1135 > f[1][1] || f[1][1] > 1365 || + 542 > f[0][2] || f[0][2] > 708 || 542 > f[1][2] || f[1][2] > 708 || + 251 > f[0][3] || f[0][3] > 373 || 251 > f[1][3] || f[1][3] > 373 || + 111 > f[0][4] || f[0][4] > 201 || 111 > f[1][4] || f[1][4] > 201 || + 111 > f[0][5] || f[0][5] > 201 || 111 > f[1][5] || f[1][5] > 201) rc |= FIPSTEST_RUNS; - return (rc); + return (rc); } /* --- @fipstest@ --- * @@ -190,7 +176,7 @@ static unsigned runs(const octet *p) * * Returns: Zero if OK, or a bitmask of failed tests. * - * Use: Performs the FIPS 140-1 randomness tests on a block of data. + * Use: Performs the FIPS140 randomness tests on a block of data. */ unsigned fipstest(const octet *p)