nist_sp800_22

package
v0.0.0-...-c885e9f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const NONE uint64 = ^uint64(0)

Variables

View Source
var AperiodicTemplates [][][]uint8 = [][][]uint8{
	{
		{0, 1}, {1, 0}},
	{
		{0, 0, 1}, {0, 1, 1},
		{1, 0, 0}, {1, 1, 0},
	},
	{
		{0, 0, 0, 1}, {0, 0, 1, 1}, {0, 1, 1, 1},
		{1, 0, 0, 0}, {1, 1, 0, 0}, {1, 1, 1, 0},
	},
	{
		{0, 0, 0, 0, 1}, {0, 0, 0, 1, 1}, {0, 0, 1, 0, 1}, {0, 1, 0, 1, 1},
		{0, 0, 1, 1, 1}, {0, 1, 1, 1, 1}, {1, 1, 1, 0, 0}, {1, 1, 0, 1, 0},
		{1, 0, 1, 0, 0}, {1, 1, 0, 0, 0}, {1, 0, 0, 0, 0}, {1, 1, 1, 1, 0},
	},
	{
		{0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 1, 1}, {0, 0, 0, 1, 0, 1}, {0, 0, 0, 1, 1, 1}, {0, 0, 1, 0, 1, 1}, {0, 0, 1, 1, 0, 1}, {0, 0, 1, 1, 1, 1}, {0, 1, 0, 0, 1, 1}, {0, 1, 0, 1, 1, 1}, {0, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0}, {1, 0, 1, 0, 0, 0}, {1, 0, 1, 1, 0, 0}, {1, 1, 0, 0, 0, 0}, {1, 1, 0, 0, 1, 0}, {1, 1, 0, 1, 0, 0}, {1, 1, 1, 0, 0, 0}, {1, 1, 1, 0, 1, 0}, {1, 1, 1, 1, 0, 0}, {1, 1, 1, 1, 1, 0},
	},
	{
		{0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 1, 0, 1}, {0, 0, 0, 0, 1, 1, 1}, {0, 0, 0, 1, 0, 0, 1}, {0, 0, 0, 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 0, 0, 1, 0, 0, 0}, {1, 1, 0, 0, 1, 0, 1, 0}, {1, 1, 0, 1, 0, 0, 0, 0}, {1, 1, 0, 1, 0, 0, 1, 0}, {1, 1, 0, 1, 0, 1, 0, 0}, {1, 1, 0, 1, 1, 0, 0, 0}, {1, 1, 0, 1, 1, 0, 1, 0}, {1, 1, 0, 1, 1, 1, 0, 0}, {1, 1, 1, 0, 0, 0, 0, 0}, {1, 1, 1, 0, 0, 0, 1, 0}, {1, 1, 1, 0, 0, 1, 0, 0}, {1, 1, 1, 0, 0, 1, 1, 0}, {1, 1, 1, 0, 1, 0, 0, 0}, {1, 1, 1, 0, 1, 0, 1, 0}, {1, 1, 1, 0, 1, 1, 0, 0}, {1, 1, 1, 1, 0, 0, 0, 0}, {1, 1, 1, 1, 0, 0, 1, 0}, {1, 1, 1, 1, 0, 1, 0, 0}, {1, 1, 1, 1, 0, 1, 1, 0}, {1, 1, 1, 1, 1, 0, 0, 0}, {1, 1, 1, 1, 1, 0, 1, 0}, {1, 1, 1, 1, 1, 1, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 0},
	},
}

According to Page 72. I found the pattern that all data is odd number. It means, 1, 3, 5, ..., maximum-3, maximum-1

View Source
var CONSTANT_E []uint8
View Source
var CONSTANT_PI []uint8
View Source
var LEVEL float64 = 0.01 // for Decision Rule
View Source
var MACHEP float64 = 1.38777878078144567553e-17
View Source
var MAXLOG float64 = 7.09782712893383996732e2

Functions

func Amplitude

func Amplitude(real, imag []float64) []float64

func ApproximateEntropy

func ApproximateEntropy(m uint64, n uint64) (float64, bool, error)

Input Size Recommendation Choose m and n such that m < floor(log_2 (n))- 5.

func BerlekampMasseyAlgorithm

func BerlekampMasseyAlgorithm(s []uint8) uint64

TyeolRik's Implementation with Go-lang Handbook of Applied Cryptography, Page 201. 6.30 Algorithm Berlekamp-Massey algorithm

func BerlekampMasseyAlgorithmFromNIST

func BerlekampMasseyAlgorithmFromNIST(s []uint8) uint64

From NIST SP800-22, linearComplexity.c Handbook of Applied Cryptography, Page 201. 6.30 Algorithm Berlekamp-Massey algorithm

func BlockFrequency

func BlockFrequency(M uint64, n uint64) (float64, bool, error)

Input Size Recommendation The block size M should be selected such that M >= 20, M > 0.01n and N < 100. n >= 100

func CumulativeSums

func CumulativeSums(mode int, n uint64) (float64, bool, error)

param mode: A switch for applying the test either forward through the input sequence

mode = 0 : forward through the input sequence
mode = 1 : backward through the sequence

func CumulativeSums_All

func CumulativeSums_All() ([]float64, []bool, error)

func DFT

func DFT(X []float64) ([]float64, []float64)

Discrete Fourier Transform 3.6 Discrete Fourier Transform (Specral) Test, Page 68. Wiki definition // https://en.wikipedia.org/wiki/Discrete_Fourier_transform#Definition

func DecisionRule

func DecisionRule(_P_value float64, level float64) bool

func DecisionRule2

func DecisionRule2(_P_value1 float64, _P_value2 float64, level float64) bool

func DiscreteFourierTransform

func DiscreteFourierTransform(n uint64) (float64, bool, error)

func Frequency

func Frequency(n uint64) (float64, bool, error)

Param n is The length of the bit string.

func GetEpsilon

func GetEpsilon() []uint8

func GetLevel

func GetLevel() float64

func InputEpsilon

func InputEpsilon(_input []uint8)

func InputEpsilonAsString

func InputEpsilonAsString(_input string)

func InputEpsilonAsString_NonRevert

func InputEpsilonAsString_NonRevert(_input string)

func LinearComplexity

func LinearComplexity(M uint64, n uint64) (float64, bool, error)

Input Size Recommendation n >= 10^6, 500 <= M <= 5000, (n / M) >= 200

func LongestRunOfOnes

func LongestRunOfOnes(n uint64) (float64, bool, error)

Input Size Recommendation n >= 128

func Max

func Max(a uint64, b uint64) uint64

func Modulus

func Modulus(real, imag []float64) []float64

https://numpy.org/doc/stable/reference/generated/numpy.absolute.html For complex input, a + ib, the absolute value is Sqrt(a^2 + b^2)

func NonOverlappingTemplateMatching

func NonOverlappingTemplateMatching(B []uint8, eachBlockSize uint64) (float64, bool, error)

Input Size Recommendation Additionally, be sure that M > 0.01 * n and N=floor(n/M). Original Function in Official Document was func NonOverlappingTemplateMatching(m uint64, n uint64, eachBlockSize uint64) However, this parameter look slightly odd to Golang. So, I changed.

Variable B The m-bit template to be matched B is a string of ones and zeros (of length m) which is defined in a template library of non-periodic patterns contained within the test code.

func OverlappingTemplateMatching

func OverlappingTemplateMatching(B []uint8, eachBlockSize uint64) (float64, bool, error)

Input Size Recommendation NIST recommends m = 9 or m = 10, n >= 10^6 m should be chosen so that m ≈ log_2(M)

func Prepare_CONSTANT_E_asEpsilon

func Prepare_CONSTANT_E_asEpsilon() error

func Prepare_CONSTANT_PI_asEpsilon

func Prepare_CONSTANT_PI_asEpsilon() error

func PrettyPrint_Add

func PrettyPrint_Add(testName string, P_value float64, isRandom bool)

func PrettyPrint_Add_Array

func PrettyPrint_Add_Array(testName string, P_value []float64, isRandom []bool)

func PrettyPrint_Init

func PrettyPrint_Init()

func PrettyPrint_Render

func PrettyPrint_Render()

func RandomExcursions

func RandomExcursions(n uint64) ([]float64, []bool, error)

func RandomExcursionsVariant

func RandomExcursionsVariant(n uint64) ([]float64, []bool, error)

func Rank

func Rank(n uint64) (float64, bool, error)

func RankComputationOfBinaryMatrices

func RankComputationOfBinaryMatrices(matrix [][]uint8) uint64

According to NIST SP800-22 Revision 1a. Page. 123 F.1 Rank Computation of Binary Matrices

func Runs

func Runs(n uint64) (float64, bool, error)

Runs function returns "The total number of runs" across all n bits. the total number of zero runs + the total number of one-runs

func Serial

func Serial(m uint64, n uint64) ([]float64, []bool, error)

Input Size Recommendation Choose m and n such that m < floor(log_2 (n))- 2.

func SetEpsilon

func SetEpsilon(_input []uint8)

func SetLevel

func SetLevel(_level_between_0_and_1 float64)

func Uint_To_BitsArray

func Uint_To_BitsArray(input uint64) (bitArray []uint8)

func Uint_To_BitsArray_size_N

func Uint_To_BitsArray_size_N(input uint64, N uint64) (bitArray []uint8)

func Universal

func Universal(L uint64, Q uint64, n uint64) (float64, bool, error)

Input Size Recommendation n >= (Q + K)L 6 <= L <= 16, Q = 10 * 2^{L}, K =floor(n/L)- Q ≈ 1000 * 2^{L} The values of L, Q and n should be chosen as follows

func Universal_Recommended() (float64, bool, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL