aboutsummaryrefslogtreecommitdiff
path: root/bhash/bhash.go
diff options
context:
space:
mode:
Diffstat (limited to 'bhash/bhash.go')
-rw-r--r--bhash/bhash.go38
1 files changed, 37 insertions, 1 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
}