1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-18 02:16:10 -05:00
v2fly/proxy/shadowsocks2022/kdf_blake3.go

32 lines
923 B
Go
Raw Normal View History

2023-11-03 16:10:11 -04:00
package shadowsocks2022
import (
"lukechampine.com/blake3"
2023-11-18 19:42:20 -05:00
"github.com/v2fly/v2ray-core/v5/common/buf"
2023-11-03 16:10:11 -04:00
)
func newBLAKE3KeyDerivation() *BLAKE3KeyDerivation {
return &BLAKE3KeyDerivation{}
}
2023-11-18 19:42:20 -05:00
type BLAKE3KeyDerivation struct{}
2023-11-03 16:10:11 -04:00
2023-11-18 19:42:20 -05:00
func (b BLAKE3KeyDerivation) GetSessionSubKey(effectivePsk, salt []byte, outKey []byte) error {
2023-11-03 16:10:11 -04:00
keyingMaterialBuffer := buf.New()
keyingMaterialBuffer.Write(effectivePsk)
2023-11-18 19:42:20 -05:00
keyingMaterialBuffer.Write(salt)
blake3.DeriveKey(outKey, "shadowsocks 2022 session subkey", keyingMaterialBuffer.Bytes())
2023-11-03 16:10:11 -04:00
keyingMaterialBuffer.Release()
return nil
}
2023-11-18 19:42:20 -05:00
func (b BLAKE3KeyDerivation) GetIdentitySubKey(effectivePsk, salt []byte, outKey []byte) error {
2023-11-03 16:10:11 -04:00
keyingMaterialBuffer := buf.New()
keyingMaterialBuffer.Write(effectivePsk)
2023-11-18 19:42:20 -05:00
keyingMaterialBuffer.Write(salt)
blake3.DeriveKey(outKey, "shadowsocks 2022 identity subkey", keyingMaterialBuffer.Bytes())
2023-11-03 16:10:11 -04:00
keyingMaterialBuffer.Release()
return nil
}