2 balloon -- Balloon password hashing function
3 Copyright (C) 2016 Sergey Matveev <stargrave@stargrave.org>
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.
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.
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/>.
28 func TestB(t *testing.T) {
29 f := func(passwd, salt []byte, s, t uint8) bool {
30 if len(passwd) == 0 || len(salt) == 0 {
33 B(sha256.New(), passwd, salt, int(s)%16+1, int(t)%16+1)
36 if err := quick.Check(f, nil); err != nil {
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 {
46 H(sha256.New, passwd, salt, int(s)%16+1, int(t)%16+1, int(p)%8+1)
49 if err := quick.Check(f, nil); err != nil {
54 func BenchmarkB(b *testing.B) {
55 passwd := make([]byte, 8)
57 salt := make([]byte, 8)
60 for i := 0; i < b.N; i++ {
61 B(sha256.New(), passwd, salt, 1<<10/sha256.New().Size(), 4)
65 func BenchmarkH(b *testing.B) {
66 passwd := make([]byte, 8)
68 salt := make([]byte, 8)
71 for i := 0; i < b.N; i++ {
72 H(sha256.New, passwd, salt, 1<<10/sha256.New().Size(), 4, 4)