encryptiontest

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package encryptiontest provides support for testing encryption and associated key management.

Index

Constants

View Source
const MinDataSize = 20000

MinDataSize is a suggested minimum data size for the runstest to be meaingfully and reliably used.

Variables

View Source
var (
	// TestKey is the key used in tests.
	TestKey = []byte("0123456789abcdef")
	// TestID is the ID used in tests.
	TestID = []byte("0123456789abcdef")

	// BadID will generate an error if passed to NewBlock.
	BadID = []byte(strings.Repeat("0", 16))
	// FailGenKey will generate an error when GenerateKey is called.
	FailGenKey = []byte(strings.Repeat("1", 16))
	// FailNewGCMKey will generate an error when NewGCM is called.
	FailNewGCMKey = []byte(strings.Repeat("2", 16))
)

Functions

func ExpectedRuns

func ExpectedRuns(n1, n2 int) float64

ExpectedRuns returns the approximation for the number of expected runs when n1 and n2 are the number of positive/negative values in a sample. expeted runs = 2 * n1 * n2 / n1 + n2 n1 and n2 must be >= 10.

func IsRandom

func IsRandom(buf []byte, significance Significance) bool

IsRandom uses the runstest to determine if the supplied data is random at the requested significance level. Note, that, the test is expected to fail (at the rate implied by the sigfnificance level) even if the data is random. Hence any user of this test should take that into account; the RunAtSignificanceLevel function in this package is provided as a convenience for doing so.

func IsTestStatisticRandom

func IsTestStatisticRandom(t float64, significance Significance) bool

IsTestStatisticRandom returns true if the suipplied test statistic value meets the criteria defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35d.htm for being random at the requested significance level. Also see: http://influentialpoints.com/Training/runs_tests-principles-properties-assumptions.htm and note the assumptions:

  • In its usual form, the test is not sensitive to departures from randomness for run lengths of two.
  • The runs test has the wrong type error rate if used to evaluate the independence of errors in time-series regression models.

func Median

func Median(data []byte) byte

Median returns the median value of the supplied byte slice.

func MedianRuns

func MedianRuns(data []byte) (above, below, runs int)

MedianRuns returns the number of runs in the supplied byte slice where a run is defined as a sequence of consecutive positive (> median) or negative (< median) values. Median values are ignored.

func RunAtSignificanceLevel

func RunAtSignificanceLevel(significance Significance, fn func(s Significance) bool) (failed int, expectedFailures int, iterations int, success bool)

RunAtSignificanceLevel runs the supplied function sufficient times to measure the false positive rate for the requested significance level. The supplied function should return the success of the test being measured. returns true if the function meets the requested significance level.

func RunsTestStatistic

func RunsTestStatistic(runs, n1, n2 int) float64

RunsTestStatistic calculates the 'runs test' stastistic as per: http://www.itl.nist.gov/div898/handbook/eda/section3/eda35d.htm and other sources.

func Variance

func Variance(n1, n2 int) float64

Variance returns the approximation to the standard deviation of the number of runs where n1 and n2 are the number of positive/negative values in a sample. variance = 2 * n1 * n2 * (2 * n1 * n2 − n1 − n2)

-------------------------------------
     (n1 + n2)^2 * (n1 + n2 − 1)

n1 and n2 must be >= 10

Types

type FakeAESRegistry

type FakeAESRegistry struct {
	Key []byte
}

FakeAESRegistry represents a fake aes-128 (16-byte key) registry with hmac-sha512 for use with tests.

func NewFakeAESRegistry

func NewFakeAESRegistry() *FakeAESRegistry

NewFakeAESRegistry returns a new FakeAESRegistry

func (*FakeAESRegistry) BlockSize

func (fr *FakeAESRegistry) BlockSize() int

BlockSize implements encryted.KeyRegistry.

func (*FakeAESRegistry) GenerateKey

func (fr *FakeAESRegistry) GenerateKey() (ID []byte, err error)

GenerateKey implements encrypted.KeyRegistry.

func (*FakeAESRegistry) HMACSize

func (fr *FakeAESRegistry) HMACSize() int

HMACSize implements encryted.KeyRegistry.

func (*FakeAESRegistry) NewBlock

func (fr *FakeAESRegistry) NewBlock(ID []byte, opts ...interface{}) (hmacHash hash.Hash, block cipher.Block, err error)

NewBlock implements encryted.KeyRegistry.

func (*FakeAESRegistry) NewGCM

func (fr *FakeAESRegistry) NewGCM(block cipher.Block, opts ...interface{}) (aead cipher.AEAD, err error)

NewGCM implements encryted.KeyRegistry.

type Significance

type Significance float64

Significance represents the statistical significance level acceptable for a given test. Note that the significance level represents the chance of a false positive, so choosing the .2% level implies a .2% change of a false positive.

const (
	// PointTwoPercent represents a 0.2% significance level.
	PointTwoPercent Significance = 0.999
	// OnePercent represents a 1% significance level.
	OnePercent Significance = 0.995
	// FivePercent represents a 5% significance level.
	FivePercent Significance = 0.975
)

func (Significance) String

func (s Significance) String() string

Jump to

Keyboard shortcuts

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