aboutsummaryrefslogtreecommitdiff
path: root/bhash
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-05-01 01:55:17 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-05-01 01:55:17 +0200
commitc9c7ca1c6191844feaac28eaecdc684a2384537d (patch)
tree4a54fb5d40e525e8a41c7ef3cfcfb5f0c31e9e61 /bhash
parent762de8ec863f7a5a56867efbf77ea7cc0386135d (diff)
swap
Diffstat (limited to 'bhash')
-rw-r--r--bhash/bhash.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/bhash/bhash.go b/bhash/bhash.go
index a9369ab..3dc1ced 100644
--- a/bhash/bhash.go
+++ b/bhash/bhash.go
@@ -8,6 +8,7 @@ import (
"bytes"
"crypto/sha512"
"encoding/binary"
+ "io"
"golang.org/x/crypto/blowfish"
)
@@ -16,9 +17,17 @@ var (
magic = []byte("OxychromaticBlowfishSwatDynamite")
rounds = 64
words = blowfish.BlockSize
- hashSize = words * 4
+ hashSize = 4 * words
+ be = binary.BigEndian
+ le = binary.LittleEndian
)
+func swap(w io.Writer, data []byte) {
+ var u [2]uint32
+ binary.Read(bytes.NewReader(data), le, &u)
+ binary.Write(w, be, u)
+}
+
// Hash computes bcrypt hash
func Hash(pass, salt []byte) []byte {
c, err := blowfish.NewSaltedCipher(pass, salt)
@@ -39,9 +48,7 @@ func Hash(pass, salt []byte) []byte {
c.Encrypt(v, v)
}
// swap bytes and copy out
- var u [2]uint32
- binary.Read(bytes.NewReader(v), binary.BigEndian, &u)
- binary.Write(buf, binary.LittleEndian, u)
+ swap(buf, v)
}
return buf.Bytes()
}
@@ -61,7 +68,7 @@ func Pbkdf(pass, salt []byte, iter, keyLen int) []byte {
// first round, salt is salt
h.Reset()
h.Write(salt)
- binary.Write(h, binary.BigEndian, uint32(n))
+ binary.Write(h, be, uint32(n))
tmp := Hash(sha2pass, h.Sum(nil))
copy(out, tmp)