aboutsummaryrefslogtreecommitdiff
path: root/bhash/bhash.go
diff options
context:
space:
mode:
Diffstat (limited to 'bhash/bhash.go')
-rw-r--r--bhash/bhash.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/bhash/bhash.go b/bhash/bhash.go
new file mode 100644
index 0000000..170855e
--- /dev/null
+++ b/bhash/bhash.go
@@ -0,0 +1,41 @@
+package bhash
+
+import (
+ "bytes"
+
+ "golang.org/x/crypto/blowfish"
+)
+
+var magic = []byte("OxychromaticBlowfishSwatDynamite")
+
+const rounds = 64
+
+func Hash(pass, salt []byte) []byte {
+ c, err := blowfish.NewSaltedCipher(pass, salt)
+ if err != nil {
+ panic(err)
+ }
+ // key expansion
+ for i := 0; i < rounds; i++ {
+ blowfish.ExpandKey(salt, c)
+ blowfish.ExpandKey(pass, c)
+ }
+ // encryption
+ buf := new(bytes.Buffer)
+ bSz := c.BlockSize()
+ for n := 0; n < len(magic)/bSz; n++ {
+ b := make([]byte, bSz)
+ copy(b, magic[n*bSz:(n+1)*bSz])
+ for i := 0; i < rounds; i++ {
+ c.Encrypt(b, b)
+ }
+ // copy out
+ b[0], b[1], b[2], b[3] = b[3], b[2], b[1], b[0]
+ b[4], b[5], b[6], b[7] = b[7], b[6], b[5], b[4]
+ buf.Write(b)
+ }
+ return buf.Bytes()
+}
+
+func Pbkdf() {
+}