mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-06-07 08:13:35 -04:00
Fix incorrect HMac Chaining, further checking needed
This commit is contained in:
parent
efb963237c
commit
0024c6e028
@ -7,16 +7,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func KDF(key []byte, path ...string) []byte {
|
func KDF(key []byte, path ...string) []byte {
|
||||||
var hmacf hash.Hash
|
hmacCreator := &hMacCreator{value: []byte(KDFSaltConstVMessAEADKDF)}
|
||||||
for _, v := range path {
|
for _, v := range path {
|
||||||
hmacf = hmac.New(func() hash.Hash {
|
hmacCreator = &hMacCreator{value: []byte(v), parent: hmacCreator}
|
||||||
return hmac.New(sha256.New, []byte(KDFSaltConstVMessAEADKDF))
|
|
||||||
}, []byte(v))
|
|
||||||
}
|
}
|
||||||
|
hmacf := hmacCreator.Create()
|
||||||
hmacf.Write(key)
|
hmacf.Write(key)
|
||||||
return hmacf.Sum(nil)
|
return hmacf.Sum(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type hMacCreator struct {
|
||||||
|
parent *hMacCreator
|
||||||
|
value []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *hMacCreator) Create() hash.Hash {
|
||||||
|
if h.parent == nil {
|
||||||
|
return hmac.New(sha256.New, h.value)
|
||||||
|
}
|
||||||
|
return hmac.New(h.parent.Create, h.value)
|
||||||
|
}
|
||||||
|
|
||||||
func KDF16(key []byte, path ...string) []byte {
|
func KDF16(key []byte, path ...string) []byte {
|
||||||
r := KDF(key, path...)
|
r := KDF(key, path...)
|
||||||
return r[:16]
|
return r[:16]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user