aboutsummaryrefslogtreecommitdiff
path: root/bhash/bhash.go
diff options
context:
space:
mode:
Diffstat (limited to 'bhash/bhash.go')
-rw-r--r--bhash/bhash.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/bhash/bhash.go b/bhash/bhash.go
index 307d31d..ea3081c 100644
--- a/bhash/bhash.go
+++ b/bhash/bhash.go
@@ -8,9 +8,12 @@ import (
"golang.org/x/crypto/blowfish"
)
-var magic = []byte("OxychromaticBlowfishSwatDynamite")
-
-const rounds = 64
+var (
+ magic = []byte("OxychromaticBlowfishSwatDynamite")
+ rounds = 64
+ words = blowfish.BlockSize
+ hashSize = words * 4
+)
func Hash(pass, salt []byte) []byte {
c, err := blowfish.NewSaltedCipher(pass, salt)
@@ -24,10 +27,9 @@ func Hash(pass, salt []byte) []byte {
}
// encryption
buf := new(bytes.Buffer)
- blockSize := c.BlockSize()
- for n := 0; n < len(magic)/blockSize; n++ {
- b := make([]byte, blockSize)
- copy(b, magic[n*blockSize:(n+1)*blockSize])
+ for n := 0; n < len(magic)/words; n++ {
+ b := make([]byte, words)
+ copy(b, magic[n*words:(n+1)*words])
for i := 0; i < rounds; i++ {
c.Encrypt(b, b)
}
@@ -45,11 +47,9 @@ func Pbkdf(pass, salt []byte, iter, keyLen int) []byte {
h.Write(pass)
sha2pass := h.Sum(nil)
- hashLen := 4 * blowfish.BlockSize
- numBlocks := (keyLen + hashLen - 1) / hashLen
-
- out := make([]byte, hashLen)
- key := make([]byte, hashLen*numBlocks)
+ numBlocks := (keyLen + hashSize - 1) / hashSize
+ out := make([]byte, hashSize)
+ key := make([]byte, hashSize*numBlocks)
for n := 1; n <= numBlocks; n++ {
// first round, salt is salt