1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 type TestConstantTimeCompareStruct
struct {
17 var testConstandTimeCompareData
= []TestConstantTimeCompareStruct
{
18 {[]byte{}, []byte{}, 1},
19 {[]byte{0x11}, []byte{0x11}, 1},
20 {[]byte{0x12}, []byte{0x11}, 0},
23 func TestConstantTimeCompare(t
*testing
.T
) {
24 for i
, test
:= range testConstandTimeCompareData
{
25 if r
:= ConstantTimeCompare(test
.a
, test
.b
); r
!= test
.out
{
26 t
.Errorf("#%d bad result (got %x, want %x)", i
, r
, test
.out
)
31 type TestConstantTimeByteEqStruct
struct {
36 var testConstandTimeByteEqData
= []TestConstantTimeByteEqStruct
{
44 func byteEq(a
, b
uint8) int {
51 func TestConstantTimeByteEq(t
*testing
.T
) {
52 for i
, test
:= range testConstandTimeByteEqData
{
53 if r
:= ConstantTimeByteEq(test
.a
, test
.b
); r
!= test
.out
{
54 t
.Errorf("#%d bad result (got %x, want %x)", i
, r
, test
.out
)
57 err
:= quick
.CheckEqual(ConstantTimeByteEq
, byteEq
, nil)
63 func eq(a
, b
int32) int {
70 func TestConstantTimeEq(t
*testing
.T
) {
71 err
:= quick
.CheckEqual(ConstantTimeEq
, eq
, nil)
77 func makeCopy(v
int, x
, y
[]byte) []byte {
89 func constantTimeCopyWrapper(v
int, x
, y
[]byte) []byte {
96 ConstantTimeCopy(v
, x
, y
)
100 func TestConstantTimeCopy(t
*testing
.T
) {
101 err
:= quick
.CheckEqual(constantTimeCopyWrapper
, makeCopy
, nil)