github.com/imannamdari/v2ray-core/v5@v5.0.5/transport/internet/quic/config.go (about) 1 package quic 2 3 import ( 4 "crypto/aes" 5 "crypto/cipher" 6 "crypto/sha256" 7 8 "golang.org/x/crypto/chacha20poly1305" 9 10 "github.com/imannamdari/v2ray-core/v5/common" 11 "github.com/imannamdari/v2ray-core/v5/common/protocol" 12 "github.com/imannamdari/v2ray-core/v5/common/serial" 13 "github.com/imannamdari/v2ray-core/v5/transport/internet" 14 ) 15 16 func getAuth(config *Config) (cipher.AEAD, error) { 17 security := config.Security.GetSecurityType() 18 if security == protocol.SecurityType_NONE { 19 return nil, nil 20 } 21 22 salted := []byte(config.Key + "v2ray-quic-salt") 23 key := sha256.Sum256(salted) 24 25 if security == protocol.SecurityType_AES128_GCM { 26 block, err := aes.NewCipher(key[:16]) 27 common.Must(err) 28 return cipher.NewGCM(block) 29 } 30 31 if security == protocol.SecurityType_CHACHA20_POLY1305 { 32 return chacha20poly1305.New(key[:]) 33 } 34 35 return nil, newError("unsupported security type") 36 } 37 38 func getHeader(config *Config) (internet.PacketHeader, error) { 39 if config.Header == nil { 40 return nil, nil 41 } 42 43 msg, err := serial.GetInstanceOf(config.Header) 44 if err != nil { 45 return nil, err 46 } 47 48 return internet.CreatePacketHeader(msg) 49 }