aboutsummaryrefslogtreecommitdiff
path: root/bhash
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-14 09:53:27 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-14 09:53:27 +0200
commit77de5055b670b6b56d0dc091b4f90d626f76bfb6 (patch)
tree4e8c51e0435fd21023476be35869b0c31edd161e /bhash
parent636d7e91d4ff729e1f17011c61ee0ce99fec197e (diff)
...
Diffstat (limited to 'bhash')
-rw-r--r--bhash/bhash.go38
-rw-r--r--bhash/bhash_test.go9
2 files changed, 44 insertions, 3 deletions
diff --git a/bhash/bhash.go b/bhash/bhash.go
index 170855e..443a862 100644
--- a/bhash/bhash.go
+++ b/bhash/bhash.go
@@ -2,6 +2,8 @@ package bhash
import (
"bytes"
+ "crypto/sha512"
+ "log"
"golang.org/x/crypto/blowfish"
)
@@ -37,5 +39,39 @@ func Hash(pass, salt []byte) []byte {
return buf.Bytes()
}
-func Pbkdf() {
+func Pbkdf(pass, salt []byte, iter, keyLen int) []byte {
+ // collapse password
+ h := sha512.New()
+ h.Write(pass)
+ sha2pass := h.Sum(nil)
+
+ out := make([]byte, 32) // XXX
+
+ for count := 1; keyLen > 0; count++ {
+ countSalt := []byte{byte(count >> 24), byte(count >> 16), byte(count >> 8), byte(count)}
+ // first round salt is salt
+ h.Reset()
+ h.Write(salt)
+ h.Write(countSalt)
+ sha2salt := h.Sum(nil)
+ tmp := Hash(sha2pass, sha2salt)
+ copy(out, tmp)
+ log.Println(out)
+
+ for i := 1; i < iter; i++ {
+ h.Reset()
+ h.Write(tmp)
+ sha2salt = h.Sum(nil)
+ tmp = Hash(sha2pass, sha2salt)
+ log.Println(len(tmp), len(out))
+ for i := range out {
+ out[i] ^= tmp[i]
+ }
+ log.Println(out)
+ }
+
+ keyLen-- // XXX
+ }
+
+ return nil
}
diff --git a/bhash/bhash_test.go b/bhash/bhash_test.go
index c49f687..e3da3ef 100644
--- a/bhash/bhash_test.go
+++ b/bhash/bhash_test.go
@@ -25,9 +25,14 @@ func TestHashZero(t *testing.T) {
0x29, 0xbd, 0xe2, 0x0e, 0x23, 0x32, 0x9e, 0x77,
0x4d, 0x84, 0x22, 0xba, 0xc0, 0xa7, 0x92, 0x6c,
}
- zero := [32]byte{}
- res := Hash(zero[:], zero[:])
+ zero := make([]byte, 32)
+ res := Hash(zero, zero)
if !bytes.Equal(res, golden) {
t.Errorf("got %x, want %x", res, golden)
}
}
+
+func TestPbkdf(t *testing.T) {
+ zero := make([]byte, 32)
+ Pbkdf(zero, zero, 2, 2)
+}