diff -r 95f71bcdcdb7 -r 657f875b013e kerneltest/e32utils/nistsecurerng/src/linearComplexity.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/linearComplexity.cpp Fri Jun 11 15:02:23 2010 +0300 @@ -0,0 +1,153 @@ +/* +* 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/cephes.h" + +void +LinearComplexity(int M, int n) +{ + int i, ii, j, d, N, L, m, N_, sign, K = 6; + double p_value, T_, mean, nu[7], chi2; + double pi[7] = { 0.01047, 0.03125, 0.12500, 0.50000, 0.25000, 0.06250, 0.020833 }; + BitSequence* T = NULL; + BitSequence* P = NULL; + BitSequence* B_ = NULL; + BitSequence* C = NULL; + + N = (int)floor(n/M); + if ( ((B_ = (BitSequence *) calloc(M, sizeof(BitSequence))) == NULL) || + ((C = (BitSequence *) calloc(M, sizeof(BitSequence))) == NULL) || + ((P = (BitSequence *) calloc(M, sizeof(BitSequence))) == NULL) || + ((T = (BitSequence *) calloc(M, sizeof(BitSequence))) == NULL) ) { + printf("Insufficient Memory for Work Space:: Linear Complexity Test\n"); + if ( B_!= NULL ) + free(B_); + if ( C != NULL ) + free(C); + if ( P != NULL ) + free(P); + if ( T != NULL ) + free(T); + return; + } + + + fprintf(stats[TEST_LINEARCOMPLEXITY], "-----------------------------------------------------\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "\tL I N E A R C O M P L E X I T Y\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "-----------------------------------------------------\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "\tM (substring length) = %d\n", M); + fprintf(stats[TEST_LINEARCOMPLEXITY], "\tN (number of substrings) = %d\n", N); + fprintf(stats[TEST_LINEARCOMPLEXITY], "-----------------------------------------------------\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], " F R E Q U E N C Y \n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "-----------------------------------------------------\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], " C0 C1 C2 C3 C4 C5 C6 CHI2 P-value\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "-----------------------------------------------------\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "\tNote: %d bits were discarded!\n", n%M); + + for ( i=0; i -2.5 && T_ <= -1.5 ) + nu[1]++; + else if ( T_ > -1.5 && T_ <= -0.5 ) + nu[2]++; + else if ( T_ > -0.5 && T_ <= 0.5 ) + nu[3]++; + else if ( T_ > 0.5 && T_ <= 1.5 ) + nu[4]++; + else if ( T_ > 1.5 && T_ <= 2.5 ) + nu[5]++; + else + nu[6]++; + } + chi2 = 0.00; + for ( i=0; i