2 balloon -- Balloon password hashing function
3 Copyright (C) 2016-2021 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 the Free Software Foundation, version 3 of the License.
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.
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/>.
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(sha512.New(), passwd, salt, uint64(s)%16+1, uint64(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(sha512.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 sCost := uint64(1 << 10 / h.Size())
62 for i := 0; i < b.N; i++ {
63 B(h, passwd, salt, sCost, 4)
67 func BenchmarkH(b *testing.B) {
68 passwd := make([]byte, 8)
70 salt := make([]byte, 8)
72 sCost := 1 << 10 / sha512.New().Size()
74 for i := 0; i < b.N; i++ {
75 H(sha512.New, passwd, salt, sCost, 4, 4)