github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/proxy/shadowsocks2022/kdf_blake3.go (about) 1 package shadowsocks2022 2 3 import ( 4 "lukechampine.com/blake3" 5 6 "github.com/v2fly/v2ray-core/v5/common/buf" 7 ) 8 9 func newBLAKE3KeyDerivation() *BLAKE3KeyDerivation { 10 return &BLAKE3KeyDerivation{} 11 } 12 13 type BLAKE3KeyDerivation struct{} 14 15 func (b BLAKE3KeyDerivation) GetSessionSubKey(effectivePsk, salt []byte, outKey []byte) error { 16 keyingMaterialBuffer := buf.New() 17 keyingMaterialBuffer.Write(effectivePsk) 18 keyingMaterialBuffer.Write(salt) 19 blake3.DeriveKey(outKey, "shadowsocks 2022 session subkey", keyingMaterialBuffer.Bytes()) 20 keyingMaterialBuffer.Release() 21 return nil 22 } 23 24 func (b BLAKE3KeyDerivation) GetIdentitySubKey(effectivePsk, salt []byte, outKey []byte) error { 25 keyingMaterialBuffer := buf.New() 26 keyingMaterialBuffer.Write(effectivePsk) 27 keyingMaterialBuffer.Write(salt) 28 blake3.DeriveKey(outKey, "shadowsocks 2022 identity subkey", keyingMaterialBuffer.Bytes()) 29 keyingMaterialBuffer.Release() 30 return nil 31 }