Example #1
0
func TestFindCharacteristic(t *testing.T) {
	M := matrix.GenerateRandom(rand.Reader, 8)

	A := matrix.GenerateRandom(rand.Reader, 8)
	AInv, _ := A.Invert()

	N, _ := DecomposeAffineEncoding(encoding.ComposedBytes{
		encoding.ByteLinear(A),
		encoding.ByteLinear(M),
		encoding.ByteLinear(AInv),
	})

	if FindCharacteristic(M) != FindCharacteristic(N) {
		t.Fatalf("FindCharacteristic was not invariant!\nM = %2.2x\nA = %2.2x\nN = %2.2x, ", M, A, N)
	}
}
Example #2
0
func BenchmarkFindCharacteristic(b *testing.B) {
	M := matrix.GenerateRandom(rand.Reader, 8)
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		FindCharacteristic(M)
	}
}
Example #3
0
func TestByteLinear(t *testing.T) {
	m := ByteLinear(matrix.GenerateRandom(rand.Reader, 8))

	for i := byte(0); i < 250; i++ {
		for j := byte(0); j < 250; j++ {
			if m.Decode(m.Encode(i)^m.Encode(j)) != i^j {
				t.Fatalf("Linear encoding didn't Encode/Decode correctly.")
			}
		}
	}
}
Example #4
0
func BenchmarkDecomposeAffineEncoding(b *testing.B) {
	aff := encoding.ByteAffine{
		encoding.ByteLinear(matrix.GenerateRandom(rand.Reader, 8)),
		0x60,
	}
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		DecomposeAffineEncoding(aff)
	}
}
Example #5
0
// Matrix takes a (private) seed and a (possibly public) label and produces a random non-singular 128x128 matrix.
func (rs *RandomSource) Matrix(label []byte, size int) matrix.Matrix {
	key := [16]byte{}
	copy(key[:], label)

	cached, ok := rs.matrixCache[key]

	if ok {
		return cached
	} else {
		rs.matrixCache[key] = matrix.GenerateRandom(rs.Stream(label), size)
		return rs.matrixCache[key]
	}
}