-
Notifications
You must be signed in to change notification settings - Fork 14
/
passphrase2pgp_test.go
64 lines (59 loc) · 1.52 KB
/
passphrase2pgp_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"bytes"
"testing"
)
func TestDecode(t *testing.T) {
table := []struct {
input string
want string
ok bool
}{
{"foo", "foo", true},
{"foo%25", "foo%", true},
{"a%3d0", "a=0", true},
{"%ff%00%0a", "\xff\x00\n", true},
{"%", "", false},
{"%0", "", false},
{"%xx", "", false},
}
for _, row := range table {
input := row.input
got, ok := pinentryDecode(input)
want := row.want
if string(got) != want || ok != row.ok {
t.Errorf("decode(%#v), got %#v/%v, want %#v/%v",
input, string(got), ok, want, row.ok)
}
}
}
func TestBcryptPBKDF(t *testing.T) {
const (
password = "hello\x00"
salt = "rocc is best cat"
rounds = 16
)
// Test vectors from OpenBSD's bcrypt_pbkdf()
table := [][]byte{
{
0xdb, 0xe3, 0x19, 0x10, 0xde, 0x3b, 0x69, 0x1d,
0x6b, 0x54, 0xe0, 0xb3, 0x29, 0xa1, 0x83, 0xd7,
0x7c, 0x71, 0xd8, 0xcf, 0xbe, 0x59, 0x96, 0xd7,
0x72, 0x8f, 0x58, 0x33, 0x09, 0xff, 0x5c, 0xec,
}, {
0xdb, 0x32, 0xe3, 0xe5, 0x19, 0x95, 0x10, 0xe0,
0xde, 0x1b, 0x3b, 0x43, 0x69, 0x01, 0x1d, 0xcc,
0x6b, 0x97, 0x54, 0xfd, 0xe0, 0x75, 0xb3, 0xb1,
0x29, 0x75, 0xa1, 0x13, 0x83, 0xa5, 0xd7, 0xbb,
0x7c, 0x1a, 0x71, 0xd4, 0xd8, 0x99, 0xcf, 0xaf,
0xbe, 0xc5, 0x59, 0xc3, 0x96, 0x3e, 0xd7, 0x57,
},
}
for _, want := range table {
got := bcryptPBKDF([]byte(password), []byte(salt), len(want), rounds)
if !bytes.Equal(got, want) {
t.Errorf("bcryptPBKDF(%#v, %#v, %d, %d), got %#v, want %#v",
password, salt, len(want), rounds, got, want)
}
}
}