github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/proxy/vmess/aead/kdf.go (about)

     1  package aead
     2  
     3  import (
     4  	"crypto/hmac"
     5  	"crypto/sha256"
     6  	"hash"
     7  )
     8  
     9  func KDF(key []byte, path ...string) []byte {
    10  	hmacf := hmac.New(func() hash.Hash {
    11  		return sha256.New()
    12  	}, []byte(KDFSaltConst_VMessAEADKDF))
    13  
    14  	for _, v := range path {
    15  		hmacf = hmac.New(func() hash.Hash {
    16  			return hmacf
    17  		}, []byte(v))
    18  	}
    19  	hmacf.Write(key)
    20  	return hmacf.Sum(nil)
    21  }
    22  
    23  func KDF16(key []byte, path ...string) []byte {
    24  	r := KDF(key, path...)
    25  	return r[:16]
    26  }