]> Cypherpunks.ru repositories - balloon.git/blob - balloon_test.go
Unify copyright comment format
[balloon.git] / balloon_test.go
1 /*
2 balloon -- Balloon password hashing function
3 Copyright (C) 2016-2022 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 Lesser General Public License as
7 the Free Software Foundation, version 3 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program.  If not, see
16 <http://www.gnu.org/licenses/>.
17 */
18
19 package balloon
20
21 import (
22         "crypto/rand"
23         "crypto/sha512"
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(sha512.New(), passwd, salt, uint64(s)%16+1, uint64(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(sha512.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         h := sha512.New()
60         sCost := uint64(1 << 10 / h.Size())
61         b.ResetTimer()
62         for i := 0; i < b.N; i++ {
63                 B(h, passwd, salt, sCost, 4)
64         }
65 }
66
67 func BenchmarkH(b *testing.B) {
68         passwd := make([]byte, 8)
69         rand.Read(passwd)
70         salt := make([]byte, 8)
71         rand.Read(salt)
72         sCost := 1 << 10 / sha512.New().Size()
73         b.ResetTimer()
74         for i := 0; i < b.N; i++ {
75                 H(sha512.New, passwd, salt, sCost, 4, 4)
76         }
77 }