aboutsummaryrefslogtreecommitdiff
path: root/bhash
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-15 02:52:29 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-15 02:52:29 +0200
commit861d6822cf0617551fcfd5bd1e16b08e8664c6f7 (patch)
tree2f6c8455ff0668b37cf1015ddb4dcda60d2d7c92 /bhash
parent03637ede32a1152c32eb7d87eb9b1638a037ab91 (diff)
cleanup
Diffstat (limited to 'bhash')
-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