mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-27 12:35:39 +08:00
33a6579a3a
* Refactor ssr stream cipher to expose iv and key References: https://github.com/Dreamacro/go-shadowsocks2 https://github.com/sh4d0wfiend/go-shadowsocksr2 * Implement ssr obfs Reference: https://github.com/mzz2017/shadowsocksR * Implement ssr protocol References: https://github.com/mzz2017/shadowsocksR https://github.com/shadowsocksRb/shadowsocksr-libev https://github.com/shadowsocksr-backup/shadowsocksr
34 lines
521 B
Go
34 lines
521 B
Go
package tools
|
|
|
|
import (
|
|
"crypto/hmac"
|
|
"crypto/md5"
|
|
"crypto/sha1"
|
|
)
|
|
|
|
const HmacSHA1Len = 10
|
|
|
|
func HmacMD5(key, data []byte) []byte {
|
|
hmacMD5 := hmac.New(md5.New, key)
|
|
hmacMD5.Write(data)
|
|
return hmacMD5.Sum(nil)[:16]
|
|
}
|
|
|
|
func HmacSHA1(key, data []byte) []byte {
|
|
hmacSHA1 := hmac.New(sha1.New, key)
|
|
hmacSHA1.Write(data)
|
|
return hmacSHA1.Sum(nil)[:20]
|
|
}
|
|
|
|
func MD5Sum(b []byte) []byte {
|
|
h := md5.New()
|
|
h.Write(b)
|
|
return h.Sum(nil)
|
|
}
|
|
|
|
func SHA1Sum(b []byte) []byte {
|
|
h := sha1.New()
|
|
h.Write(b)
|
|
return h.Sum(nil)
|
|
}
|