github.com/EagleQL/Xray-core@v1.4.3/proxy/vmess/aead/kdf.go (about) 1 package aead 2 3 import ( 4 "crypto/hmac" 5 "crypto/sha256" 6 "hash" 7 ) 8 9 type hash2 struct { 10 hash.Hash 11 } 12 13 func KDF(key []byte, path ...string) []byte { 14 hmacf := hmac.New(sha256.New, []byte(KDFSaltConstVMessAEADKDF)) 15 16 for _, v := range path { 17 first := true 18 hmacf = hmac.New(func() hash.Hash { 19 if first { 20 first = false 21 return hash2{hmacf} 22 } 23 return hmacf 24 }, []byte(v)) 25 } 26 hmacf.Write(key) 27 return hmacf.Sum(nil) 28 } 29 30 func KDF16(key []byte, path ...string) []byte { 31 r := KDF(key, path...) 32 return r[:16] 33 }