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() { }