Debian Codegraph @

debian/patches/backport/05-Fix-incorrect-HMac-Chaining-further-checking-needed.patch

raw
1 From: Shelikhoo <[email protected]>
2 Date: Mon, 22 Feb 2021 13:20:36 +0000
3 Subject: Fix incorrect HMac Chaining, further checking needed
4
5 (cherry picked from commit 0024c6e028768d8516bdee11be9834b2617ff00c)
6
7 Closes: #1009818
8 ---
9 proxy/vmess/aead/kdf.go | 20 +++++++++++++++-----
10 1 file changed, 15 insertions(+), 5 deletions(-)
11
12 diff --git a/proxy/vmess/aead/kdf.go b/proxy/vmess/aead/kdf.go
13 index ebcea0a..5fc4ac5 100644
14 --- a/proxy/vmess/aead/kdf.go
15 +++ b/proxy/vmess/aead/kdf.go
16 @@ -7,17 +7,27 @@ import (
17 )
18
19 func KDF(key []byte, path ...string) []byte {
20 - hmacf := hmac.New(sha256.New, []byte(KDFSaltConstVMessAEADKDF))
21 -
22 + hmacCreator := &hMacCreator{value: []byte(KDFSaltConstVMessAEADKDF)}
23 for _, v := range path {
24 - hmacf = hmac.New(func() hash.Hash {
25 - return hmacf
26 - }, []byte(v))
27 + hmacCreator = &hMacCreator{value: []byte(v), parent: hmacCreator}
28 }
29 + hmacf := hmacCreator.Create()
30 hmacf.Write(key)
31 return hmacf.Sum(nil)
32 }
33
34 +type hMacCreator struct {
35 + parent *hMacCreator
36 + value []byte
37 +}
38 +
39 +func (h *hMacCreator) Create() hash.Hash {
40 + if h.parent == nil {
41 + return hmac.New(sha256.New, h.value)
42 + }
43 + return hmac.New(h.parent.Create, h.value)
44 +}
45 +
46 func KDF16(key []byte, path ...string) []byte {
47 r := KDF(key, path...)
48 return r[:16]