diff -r c1f20ce4abcf -r 3e88ff8f41d5 kerneltest/e32utils/nistsecurerng/src/assess.cpp --- a/kerneltest/e32utils/nistsecurerng/src/assess.cpp Tue Aug 31 16:34:26 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,419 +0,0 @@ -/* -* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -*/ - - -/* -------------------------------------------------------------------------- - Title : The NIST Statistical Test Suite - - Date : December 1999 - - Programmer : Juan Soto - - Summary : For use in the evaluation of the randomness of bitstreams - produced by cryptographic random number generators. - - Package : Version 1.0 - - Copyright : (c) 1999 by the National Institute Of Standards & Technology - - History : Version 1.0 by J. Soto, October 1999 - Revised by J. Soto, November 1999 - Revised by Larry Bassham, March 2008 - - Keywords : Pseudorandom Number Generator (PRNG), Randomness, Statistical - Tests, Complementary Error functions, Incomplete Gamma - Function, Random Walks, Rank, Fast Fourier Transform, - Template, Cryptographically Secure PRNG (CSPRNG), - Approximate Entropy (ApEn), Secure Hash Algorithm (SHA-1), - Blum-Blum-Shub (BBS) CSPRNG, Micali-Schnorr (MS) CSPRNG, - - Source : David Banks, Elaine Barker, James Dray, Allen Heckert, - Stefan Leigh, Mark Levenson, James Nechvatal, Andrew Rukhin, - Miles Smid, Juan Soto, Mark Vangel, and San Vo. - - Technical - Assistance : Larry Bassham, Ron Boisvert, James Filliben, Daniel Lozier, - and Bert Rust. - - Warning : Portability Issues. - - Limitation : Amount of memory allocated for workspace. - - Restrictions: Permission to use, copy, and modify this software without - fee is hereby granted, provided that this entire notice is - included in all copies of any software which is or includes - a copy or modification of this software and in all copies - of the supporting documentation for such software. - -------------------------------------------------------------------------- */ -//system include -#include -#include -#include - -// user include -#include "openc.h" -#include "../include/decls.h" -#include "../include/cephes.h" -#include "../include/utilities.h" -#include "../include/generators.h" - -typedef int (*CompareFnType)(const void*, const void*); - -void partitionResultFile(int numOfFiles, int numOfSequences, int option, int testNameID); -void postProcessResults(int option); -int cmp(const double *a, const double *b); -int computeMetrics(char *s, int test); - -int -StartNISTTest() -{ - int i; - int option = 10; /* TEMPLATE LENGTH/STREAM LENGTH/GENERATOR*/ - char *streamFile = NULL; /* STREAM FILENAME */ - - - tp.n = 1000000; // length of the individual bit stream(s) to be processed - tp.blockFrequencyBlockLength = 128; - tp.nonOverlappingTemplateBlockLength = 9; - tp.overlappingTemplateBlockLength = 9; - tp.approximateEntropyBlockLength = 10; - tp.serialBlockLength = 16; - tp.linearComplexitySequenceLength = 500; - tp.numOfBitStreams = 100; - chooseTests(); - fixParameters(); - openOutputStreams(option); - invokeTestSuite(option, streamFile); - fclose(freqfp); - for( i=1; i<=NUMOFTESTS; i++ ) { - if ( stats[i] != NULL ) - fclose(stats[i]); - if ( results[i] != NULL ) - fclose(results[i]); - } - if ( (testVector[0] == 1) || (testVector[TEST_CUSUM] == 1) ) - partitionResultFile(2, tp.numOfBitStreams, option, TEST_CUSUM); - if ( (testVector[0] == 1) || (testVector[TEST_NONPERIODIC] == 1) ) - partitionResultFile(MAXNUMOFTEMPLATES, tp.numOfBitStreams, option, TEST_NONPERIODIC); - if ( (testVector[0] == 1) || (testVector[TEST_RND_EXCURSION] == 1) ) - partitionResultFile(8, tp.numOfBitStreams, option, TEST_RND_EXCURSION); - if ( (testVector[0] == 1) || (testVector[TEST_RND_EXCURSION_VAR] == 1) ) - partitionResultFile(18, tp.numOfBitStreams, option, TEST_RND_EXCURSION_VAR); - if ( (testVector[0] == 1) || (testVector[TEST_SERIAL] == 1) ) - partitionResultFile(2, tp.numOfBitStreams, option, TEST_SERIAL); - fprintf(summary, "------------------------------------------------------------------------------\n"); - fprintf(summary, "RESULTS FOR THE UNIFORMITY OF P-VALUES AND THE PROPORTION OF PASSING SEQUENCES\n"); - fprintf(summary, "------------------------------------------------------------------------------\n"); - fprintf(summary, " C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 P-VALUE PROPORTION STATISTICAL TEST\n"); - fprintf(summary, "------------------------------------------------------------------------------\n"); - postProcessResults(option); - fclose(summary); - - return 1; - } - -void -partitionResultFile(int numOfFiles, int numOfSequences, int option, int testNameID) -{ - int i, k, m, j, start, end, num, numread; - float c; - FILE **fp = (FILE **)calloc(numOfFiles+1, sizeof(FILE *)); - int *results = (int *)calloc(numOfFiles, sizeof(int *)); - char *s[MAXFILESPERMITTEDFORPARTITION]; - char resultsDir[200]; - - for ( i=0; i 0.000000 ) - T[count++] = c; - } - - if ( (A = (double *)calloc(count, sizeof(double))) == NULL ) { - printf("Final Analysis Report aborted due to insufficient workspace\n"); - // Perform cleanup before returning - fclose(fp); - free(T); - return 0; - } - - for ( j=0; j