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