-
Notifications
You must be signed in to change notification settings - Fork 4
/
md5_test.go
49 lines (38 loc) · 976 Bytes
/
md5_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"bytes"
"crypto/md5"
"reflect"
"testing"
)
func TestNonleakyMd5(t *testing.T) {
var (
data = []byte("gopher gopher gopher")
orig = md5.Sum(data)
nlmd5 = NewNonleakyMd5()
nonleaky = make([]byte, nlmd5.Size())
)
nlmd5.Write(data)
nlmd5.Sum(nonleaky)
t.Logf("expected %x", orig)
t.Logf(" got %x", nonleaky)
if !bytes.Equal(nonleaky, orig[:]) {
t.Fatalf("mismatch between crypt.md5.Sum() and NonleakyMd5.Sum()")
}
t.Logf("before nlmd5.Reset():\n%v", nlmd5.hash_value.Interface())
nlmd5.Reset()
t.Logf("after nlmd5.Reset():\n%v", nlmd5.hash_value.Interface())
for _, b := range nlmd5.field_x() {
if b != 0 {
t.Fatal("NonleakyMd5.raw.x not correctly cleaned")
}
}
for _, b := range _MD5_PADDING[1:] {
if b != 0 {
t.Fatal("NonleakyMd5.tmp not correctly cleaned")
}
}
if !reflect.DeepEqual(nlmd5.Hash, md5.New()) {
t.Fatal("reflect.DeepEqual complaints about nlmd5.Hash != md5.New()")
}
}