aboutsummaryrefslogtreecommitdiff
path: root/bhash/bhash.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-14 04:53:30 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-14 04:53:30 +0200
commit636d7e91d4ff729e1f17011c61ee0ce99fec197e (patch)
treecce94a6be044e269ffbc5e488685d72f9112bc9c /bhash/bhash.go
parentdffca582d57491e946582f2ac86e2c21ac5d6b74 (diff)
add bhash
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() {
+}