aboutsummaryrefslogtreecommitdiff
path: root/bhash
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-05-01 02:02:27 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-05-01 02:02:27 +0200
commitbf4f6005b433bf20394d5c6e3030c22885b36622 (patch)
tree4cc683b98105f8b1ffd675ab18c9b561c7681a73 /bhash
parentc9c7ca1c6191844feaac28eaecdc684a2384537d (diff)
const
Diffstat (limited to 'bhash')
-rw-r--r--bhash/bhash.go22
1 files changed, 7 insertions, 15 deletions
diff --git a/bhash/bhash.go b/bhash/bhash.go
index 3dc1ced..0c1d659 100644
--- a/bhash/bhash.go
+++ b/bhash/bhash.go
@@ -8,26 +8,17 @@ import (
"bytes"
"crypto/sha512"
"encoding/binary"
- "io"
"golang.org/x/crypto/blowfish"
)
-var (
- magic = []byte("OxychromaticBlowfishSwatDynamite")
+const (
+ magic = "OxychromaticBlowfishSwatDynamite"
rounds = 64
words = blowfish.BlockSize
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)
@@ -42,13 +33,14 @@ func Hash(pass, salt []byte) []byte {
// encryption
buf := new(bytes.Buffer)
for n := 0; n < len(magic)/words; n++ {
- v := make([]byte, words)
- copy(v, magic[n*words:(n+1)*words])
+ v := []byte(magic[n*words : (n+1)*words])
for i := 0; i < rounds; i++ {
c.Encrypt(v, v)
}
// swap bytes and copy out
- swap(buf, v)
+ var u [2]uint32
+ binary.Read(bytes.NewReader(v), binary.LittleEndian, &u)
+ binary.Write(buf, binary.BigEndian, u)
}
return buf.Bytes()
}
@@ -68,7 +60,7 @@ func Pbkdf(pass, salt []byte, iter, keyLen int) []byte {
// first round, salt is salt
h.Reset()
h.Write(salt)
- binary.Write(h, be, uint32(n))
+ binary.Write(h, binary.BigEndian, uint32(n))
tmp := Hash(sha2pass, h.Sum(nil))
copy(out, tmp)