2 balloon -- Balloon password hashing function
3 Copyright (C) 2016-2017 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 Lesser General Public License as
7 published by the Free Software Foundation, either version 3 of the
8 License, or (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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this program. If not, see
17 <http://www.gnu.org/licenses/>.
29 func TestB(t *testing.T) {
30 f := func(passwd, salt []byte, s, t uint8) bool {
31 if len(passwd) == 0 || len(salt) == 0 {
34 B(sha256.New(), passwd, salt, int(s)%16+1, int(t)%16+1)
37 if err := quick.Check(f, nil); err != nil {
42 func TestH(t *testing.T) {
43 f := func(passwd, salt []byte, s, t, p uint8) bool {
44 if len(passwd) == 0 || len(salt) == 0 {
47 H(sha256.New, passwd, salt, int(s)%16+1, int(t)%16+1, int(p)%8+1)
50 if err := quick.Check(f, nil); err != nil {
55 func BenchmarkB(b *testing.B) {
56 passwd := make([]byte, 8)
58 salt := make([]byte, 8)
61 for i := 0; i < b.N; i++ {
62 B(sha256.New(), passwd, salt, 1<<10/sha256.New().Size(), 4)
66 func BenchmarkH(b *testing.B) {
67 passwd := make([]byte, 8)
69 salt := make([]byte, 8)
72 for i := 0; i < b.N; i++ {
73 H(sha256.New, passwd, salt, 1<<10/sha256.New().Size(), 4, 4)