diff -r 345b1ca54e88 -r 039a3e647356 kerneltest/e32utils/nistsecurerng/src/universal.cpp --- a/kerneltest/e32utils/nistsecurerng/src/universal.cpp Wed Sep 15 13:42:27 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +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/cephes.h" - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - U N I V E R S A L T E S T - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -void -Universal(int n) -{ - int i, j, p, L, Q, K; - double arg, sqrt2, sigma, phi, sum, p_value, c; - long *T, decRep; - double expected_value[17] = { 0, 0, 0, 0, 0, 0, 5.2177052, 6.1962507, 7.1836656, - 8.1764248, 9.1723243, 10.170032, 11.168765, - 12.168070, 13.167693, 14.167488, 15.167379 }; - double variance[17] = { 0, 0, 0, 0, 0, 0, 2.954, 3.125, 3.238, 3.311, 3.356, 3.384, - 3.401, 3.410, 3.416, 3.419, 3.421 }; - - /* * * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * THE FOLLOWING REDEFINES L, SHOULD THE CONDITION: n >= 1010*2^L*L * - * NOT BE MET, FOR THE BLOCK LENGTH L. * - * * * * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - L = 5; - if ( n >= 387840 ) L = 6; - if ( n >= 904960 ) L = 7; - if ( n >= 2068480 ) L = 8; - if ( n >= 4654080 ) L = 9; - if ( n >= 10342400 ) L = 10; - if ( n >= 22753280 ) L = 11; - if ( n >= 49643520 ) L = 12; - if ( n >= 107560960 ) L = 13; - if ( n >= 231669760 ) L = 14; - if ( n >= 496435200 ) L = 15; - if ( n >= 1059061760 ) L = 16; - - Q = 10*(int)pow(2, L); - K = (int) (floor(n/L) - (double)Q); /* BLOCKS TO TEST */ - - p = (int)pow(2, L); - if ( (L < 6) || (L > 16) || ((double)Q < 10*pow(2, L)) || - ((T = (long *)calloc(p, sizeof(long))) == NULL) ) { - fprintf(stats[TEST_UNIVERSAL], "\t\tUNIVERSAL STATISTICAL TEST\n"); - fprintf(stats[TEST_UNIVERSAL], "\t\t---------------------------------------------\n"); - fprintf(stats[TEST_UNIVERSAL], "\t\tERROR: L IS OUT OF RANGE.\n"); - fprintf(stats[TEST_UNIVERSAL], "\t\t-OR- : Q IS LESS THAN %f.\n", 10*pow(2, L)); - fprintf(stats[TEST_UNIVERSAL], "\t\t-OR- : Unable to allocate T.\n"); - return; - } - - /* COMPUTE THE EXPECTED: Formula 16, in Marsaglia's Paper */ - c = 0.7 - 0.8/(double)L + (4 + 32/(double)L)*pow(K, -3/(double)L)/15; - sigma = c * sqrt(variance[L]/(double)K); - sqrt2 = sqrt(2); - sum = 0.0; - for ( i=0; i