]> Cypherpunks.ru repositories - balloon.git/blob - balloon_test.go
Initial revision
[balloon.git] / balloon_test.go
1 /*
2 balloon -- Balloon password hashing function
3 Copyright (C) 2016 Sergey Matveev <stargrave@stargrave.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package balloon
20
21 import (
22         "crypto/rand"
23         "crypto/sha256"
24         "testing"
25         "testing/quick"
26 )
27
28 func TestB(t *testing.T) {
29         f := func(passwd, salt []byte, s, t uint8) bool {
30                 if len(passwd) == 0 || len(salt) == 0 {
31                         return true
32                 }
33                 B(sha256.New(), passwd, salt, int(s)%16+1, int(t)%16+1)
34                 return true
35         }
36         if err := quick.Check(f, nil); err != nil {
37                 t.Error(err)
38         }
39 }
40
41 func TestH(t *testing.T) {
42         f := func(passwd, salt []byte, s, t, p uint8) bool {
43                 if len(passwd) == 0 || len(salt) == 0 {
44                         return true
45                 }
46                 H(sha256.New, passwd, salt, int(s)%16+1, int(t)%16+1, int(p)%8+1)
47                 return true
48         }
49         if err := quick.Check(f, nil); err != nil {
50                 t.Error(err)
51         }
52 }
53
54 func BenchmarkB(b *testing.B) {
55         passwd := make([]byte, 8)
56         rand.Read(passwd)
57         salt := make([]byte, 8)
58         rand.Read(salt)
59         b.ResetTimer()
60         for i := 0; i < b.N; i++ {
61                 B(sha256.New(), passwd, salt, 1<<10/sha256.New().Size(), 4)
62         }
63 }
64
65 func BenchmarkH(b *testing.B) {
66         passwd := make([]byte, 8)
67         rand.Read(passwd)
68         salt := make([]byte, 8)
69         rand.Read(salt)
70         b.ResetTimer()
71         for i := 0; i < b.N; i++ {
72                 H(sha256.New, passwd, salt, 1<<10/sha256.New().Size(), 4, 4)
73         }
74 }