-
-
Save copie/5b64854ed7c31dcd2c96846e140f8d39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hmac | |
import hashlib | |
uuid = bytearray([150, 200, 146, 76, 182, 30, 17, 235, 133, 41, 2, 66, 172, 19, 0, 3]) | |
print(uuid.hex()) | |
hmacf = hmac.HMAC("VMess AEAD KDF".encode(), digestmod = hashlib.sha256) | |
hmacf = hmac.HMAC("AES Auth ID Encryption".encode(), digestmod = lambda : hmacf) | |
hmacf.update(uuid) | |
print(hmacf.hexdigest()) | |
# output | |
# 96c8924cb61e11eb85290242ac130003 | |
# 82ce2cf920a0dbddefe1abe6110619077e5653561fce26ec8c0e3b5aae2997bc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/hmac" | |
"crypto/sha256" | |
"encoding/hex" | |
"fmt" | |
"hash" | |
) | |
const ( | |
kdfSaltConstAuthIDEncryptionKey = "AES Auth ID Encryption" | |
kdfSaltConstVMessAEADKDF = "VMess AEAD KDF" | |
) | |
type hash2 struct { | |
hash.Hash | |
} | |
func KDF(key []byte, path ...string) []byte { | |
fmt.Println(hex.EncodeToString(key)) | |
hmacf := hmac.New(sha256.New, []byte(kdfSaltConstVMessAEADKDF)) | |
for _, v := range path { | |
first := true | |
hmacf = hmac.New(func() hash.Hash { | |
if first { | |
first = false | |
return hash2{hmacf} | |
} | |
return hmacf | |
}, []byte(v)) | |
} | |
hmacf.Write(key) | |
return hmacf.Sum(nil) | |
} | |
func main() { | |
x := KDF([]byte{150, 200, 146, 76, 182, 30, 17, 235, 133, 41, 2, 66, 172, 19, 0, 3}, | |
kdfSaltConstAuthIDEncryptionKey) | |
fmt.Println(hex.EncodeToString(x)) | |
} | |
// output | |
// 96c8924cb61e11eb85290242ac130003 | |
// 97eaf3b2dc29b026f4253337f1728c5e12f4e79a9e4f8e1bc86d2015f86a26ca | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment