diff -r 345b1ca54e88 -r 039a3e647356 kerneltest/e32utils/nistsecurerng/src/generators.cpp --- a/kerneltest/e32utils/nistsecurerng/src/generators.cpp Wed Sep 15 13:42:27 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,510 +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: -* The original NIST Statistical Test Suite code is placed in public domain. -* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) -* -* This software was developed at the National Institute of Standards and Technology by -* employees of the Federal Government in the course of their official duties. Pursuant -* to title 17 Section 105 of the United States Code this software is not subject to -* copyright protection and is in the public domain. The NIST Statistical Test Suite is -* an experimental system. NIST assumes no responsibility whatsoever for its use by other -* parties, and makes no guarantees, expressed or implied, about its quality, reliability, -* or any other characteristic. We would appreciate acknowledgment if the software is used. -*/ - -#include "openc.h" -#include "../include/externs.h" -#include "../include/utilities.h" -#include "../include/generators.h" -#include "../include/genutils.h" - -const int KRandomByteCount = 1024; - -double -lcg_rand(int N, double SEED, double* DUNIF, int NDIM) -{ - int i; - double DZ, DOVER, DZ1, DZ2, DOVER1, DOVER2; - double DTWO31, DMDLS, DA1, DA2; - - DTWO31 = 2147483648.0; /* DTWO31=2**31 */ - DMDLS = 2147483647.0; /* DMDLS=2**31-1 */ - DA1 = 41160.0; /* DA1=950706376 MOD 2**16 */ - DA2 = 950665216.0; /* DA2=950706376-DA1 */ - - DZ = SEED; - if ( N > NDIM ) - N = NDIM; - for ( i=1; i<=N; i++ ) { - DZ = floor(DZ); - DZ1 = DZ*DA1; - DZ2 = DZ*DA2; - DOVER1 = floor(DZ1/DTWO31); - DOVER2 = floor(DZ2/DTWO31); - DZ1 = DZ1-DOVER1*DTWO31; - DZ2 = DZ2-DOVER2*DTWO31; - DZ = DZ1+DZ2+DOVER1+DOVER2; - DOVER = floor(DZ/DMDLS); - DZ = DZ-DOVER*DMDLS; - DUNIF[i-1] = DZ/DMDLS; - SEED = DZ; - } - - return SEED; -} - -void -lcg() -{ - double* DUNIF = NULL; - double SEED; - int i; - unsigned bit; - int num_0s, num_1s, v, bitsRead; - - SEED = 23482349.0; - if ( ((epsilon = (BitSequence *) calloc(tp.n, sizeof(BitSequence))) == NULL) || - ((DUNIF = (double*)calloc(tp.n, sizeof(double))) == NULL) ) { - printf("Insufficient memory available.\n"); - exit(1); - } - - for ( v=0; v randBuffer(KRandomByteCount); - - for (int i = 0; i < tp.numOfBitStreams; ++i) - { - gConsole->Printf(_L("Starting test %d\n"), i+1); - num_0s = 0; - num_1s = 0; - bitsRead = 0; - done = 0; - do - { - Math::Random(randBuffer); - done = convertToBits(randBuffer.Ptr() , KRandomByteCount*8, tp.n, &num_0s, &num_1s, &bitsRead); - } while ( !done ); - fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); - - nist_test_suite(); - } - free(epsilon); - } -