Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing/nist-sts: porting NIST-Statistical-Test-Suite #1875

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ Make.dep
.dirlinks
.vscode
.DS_Store
testing/nist-sts/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 530b8e0d0f9ea68f1dd977caddc76fbe4a2c66b8 Mon Sep 17 00:00:00 2001
From: makejian <[email protected]>
Date: Wed, 19 Apr 2023 22:57:44 +0800
Subject: [PATCH 1/2] Solve the memory out of bounds problem in sts

Signed-off-by: makejian <[email protected]>
Change-Id: I28a132a793603205e25e5925de3e51ff2c44873b
---
sts/src/discreteFourierTransform.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git nist-sts/sts/src/discreteFourierTransform.c nist-sts/sts/src/discreteFourierTransform.c
index 61b52c2..96b4bb7 100644
--- nist-sts/sts/src/discreteFourierTransform.c
+++ nist-sts/sts/src/discreteFourierTransform.c
@@ -38,7 +38,7 @@ DiscreteFourierTransform(int n)

m[0] = sqrt(X[0]*X[0]); /* COMPUTE MAGNITUDE */

- for ( i=0; i<n/2; i++ )
+ for ( i=0; i<n/2-1; i++ )
m[i+1] = sqrt(pow(X[2*i+1],2)+pow(X[2*i+2],2));
count = 0; /* CONFIDENCE INTERVAL */
upperBound = sqrt(2.995732274*n);
--
2.40.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
From a5e672bb9b4f672d3541d76aac40206cf0fdb714 Mon Sep 17 00:00:00 2001
From: makejian <[email protected]>
Date: Tue, 16 May 2023 21:23:20 +0800
Subject: [PATCH 2/2] Fix bug that crash in running a single test after running all
tests

double free same memory
Signed-off-by: makejian <[email protected]>
Change-Id: Ie56dabd6d6eae93c0b066ced6148ea362f1c6085
---
sts/src/assess.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git nist-sts/sts/src/assess.c nist-sts/sts/src/assess.c
index cf41d4f..3aa5800 100644
--- nist-sts/sts/src/assess.c
+++ nist-sts/sts/src/assess.c
@@ -84,10 +84,14 @@ main(int argc, char *argv[])
invokeTestSuite(option, streamFile);
fclose(freqfp);
for( i=1; i<=NUMOFTESTS; i++ ) {
- if ( stats[i] != NULL )
+ if ( stats[i] != NULL ) {
fclose(stats[i]);
- if ( results[i] != NULL )
+ stats[i] = NULL;
+ }
+ if ( results[i] != NULL ) {
fclose(results[i]);
+ results[i] = NULL;
+ }
}
if ( (testVector[0] == 1) || (testVector[TEST_CUSUM] == 1) )
partitionResultFile(2, tp.numOfBitStreams, option, TEST_CUSUM);
--
2.40.0

30 changes: 30 additions & 0 deletions testing/nist-sts/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config TESTING_NIST_STS
tristate "NIST Statistical Test Suite"
default n
---help---
https://csrc.nist.gov/projects/random-bit-generation/documentation-and-software

if TESTING_NIST_STS

config TESTING_NIST_STS_PROGNAME
string "Program name"
default "nist_sts"

config TESTING_NIST_STS_PRIORITY
int "nist_sts task priority"
default 100

config TESTING_NIST_STS_STACKSIZE
int "nist_sts stack size"
default 8192

config TESTING_NIST_STS_VERSION
string "nist_sts version"
default "2_1_2"

endif
23 changes: 23 additions & 0 deletions testing/nist-sts/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
############################################################################
# apps/testing/nist-sts/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

ifneq ($(CONFIG_TESTING_NIST_STS),)
CONFIGURED_APPS += $(APPDIR)/testing/nist-sts
endif
63 changes: 63 additions & 0 deletions testing/nist-sts/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
############################################################################
# apps/testing/nist-sts/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

include $(APPDIR)/Make.defs

PROGNAME = $(CONFIG_TESTING_NIST_STS_PROGNAME)
PRIORITY = $(CONFIG_TESTING_NIST_STS_PRIORITY)
STACKSIZE = $(CONFIG_TESTING_NIST_STS_STACKSIZE)
MODULE = $(CONFIG_TESTING_NIST_STS)

NIST_URL ?= "https://csrc.nist.gov/CSRC/media/Projects/Random-Bit-Generation/documents/"

NIST_UNPACKNAME = nist-sts
NIST_PACKNAME = sts-2.1.2
NIST_ZIP = sts-2_1_2.zip
UNPACK ?= unzip -q -o

$(NIST_ZIP):
@echo "Downloading: $(NIST_ZIP)"
$(Q) $(call DOWNLOAD,$(NIST_URL),$(NIST_ZIP))

$(NIST_UNPACKNAME): $(NIST_ZIP)
@echo "Unpacking: $(NIST_ZIP) -> $(NIST_UNPACKNAME)"
$(Q) $(UNPACK) $(NIST_ZIP)
$(Q) mv $(NIST_PACKNAME) $(NIST_UNPACKNAME)
$(Q) mv $(NIST_UNPACKNAME)/$(NIST_PACKNAME) $(NIST_UNPACKNAME)/sts
$(Q) echo "Patching $(NIST_UNPACKNAME)"
$(Q) patch -p1 -d $(NIST_UNPACKNAME) < 0001-Solve-the-memory-out-of-bounds-problem-in-sts.patch
$(Q) patch -p1 -d $(NIST_UNPACKNAME) < 0002-Fix-bug-that-crash-in-running-a-single-test-after-ru.patch
$(Q) touch $(NIST_UNPACKNAME)

MAINSRC = nist-sts/sts/src/assess.c
CSRCS = $(shell find nist-sts/sts/src -name "*.c" ! -name "assess.c")
CFLAGS += -Wno-misleading-indentation -Wno-unused-but-set-variable \
-Wno-strict-prototypes -Wno-undef -Wno-shadow -Wno-unused-variable

# Download and unpack tarball if no git repo found
ifeq ($(wildcard $(NIST_UNPACKNAME)/.git),)
context:: $(NIST_UNPACKNAME)

distclean::
$(call DELDIR, $(NIST_UNPACKNAME))
$(call DELFILE, $(NIST_ZIP))
endif

include $(APPDIR)/Application.mk
Loading