diff -r 95f71bcdcdb7 -r 657f875b013e kerneltest/e32utils/nistsecurerng/src/overlappingTemplateMatchings.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/overlappingTemplateMatchings.cpp Fri Jun 11 15:02:23 2010 +0300 @@ -0,0 +1,132 @@ +/* +* 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" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + O V E R L A P P I N G T E M P L A T E T E S T + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +double Pr(int u, double eta); + +void +OverlappingTemplateMatchings(int m, int n) +{ + int i, k, match; + double W_obs, eta, sum, chi2, p_value, lambda; + int M, N, j, K = 5; + unsigned int nu[6] = { 0, 0, 0, 0, 0, 0 }; + double pi[6] = { 0.143783, 0.139430, 0.137319, 0.124314, 0.106209, 0.348945 }; + BitSequence *sequence; + + M = 1032; + N = n/M; + + if ( (sequence = (BitSequence *) calloc(m, sizeof(BitSequence))) == NULL ) { + fprintf(stats[TEST_OVERLAPPING], "\t\t OVERLAPPING TEMPLATE OF ALL ONES TEST\n"); + fprintf(stats[TEST_OVERLAPPING], "\t\t---------------------------------------------\n"); + fprintf(stats[TEST_OVERLAPPING], "\t\tTEMPLATE DEFINITION: Insufficient memory, Overlapping Template Matchings test aborted!\n"); + } + else + for ( i=0; i=5 Chi^2 P-value Assignment\n"); + fprintf(stats[TEST_OVERLAPPING], "\t\t-----------------------------------------------\n"); + fprintf(stats[TEST_OVERLAPPING], "\t\t%3d %3d %3d %3d %3d %3d %f ", + nu[0], nu[1], nu[2], nu[3], nu[4], nu[5], chi2); + + if ( isNegative(p_value) || isGreaterThanOne(p_value) ) + fprintf(stats[TEST_OVERLAPPING], "WARNING: P_VALUE IS OUT OF RANGE.\n"); + + free(sequence); + fprintf(stats[TEST_OVERLAPPING], "%f %s\n\n", p_value, p_value < ALPHA ? "FAILURE" : "SUCCESS"); + fprintf(results[TEST_OVERLAPPING], "%f\n", p_value); +} + +double +Pr(int u, double eta) +{ + int l; + double sum, p; + + if ( u == 0 ) + p = exp(-eta); + else { + sum = 0.0; + for ( l=1; l<=u; l++ ) + sum += exp(-eta-u*log(2)+l*log(eta)-cephes_lgam(l+1)+cephes_lgam(u)-cephes_lgam(l)-cephes_lgam(u-l+1)); + p = sum; + } + return p; +}