From 861d6822cf0617551fcfd5bd1e16b08e8664c6f7 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 15 Apr 2017 02:52:29 +0200 Subject: cleanup --- bhash/bhash.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'bhash') 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 -- cgit v1.2.3