1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/transport/internet/quic/config.go

50 lines
1.1 KiB
Go
Raw Normal View History

2018-11-21 16:02:19 -05:00
package quic
import (
"crypto/aes"
"crypto/cipher"
"crypto/sha256"
"golang.org/x/crypto/chacha20poly1305"
2021-02-16 15:31:50 -05:00
"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/protocol"
"github.com/v2fly/v2ray-core/v5/common/serial"
"github.com/v2fly/v2ray-core/v5/transport/internet"
2018-11-21 16:02:19 -05:00
)
func getAuth(config *Config) (cipher.AEAD, error) {
security := config.Security.GetSecurityType()
if security == protocol.SecurityType_NONE {
return nil, nil
}
salted := []byte(config.Key + "v2ray-quic-salt")
key := sha256.Sum256(salted)
if security == protocol.SecurityType_AES128_GCM {
block, err := aes.NewCipher(key[:16])
common.Must(err)
return cipher.NewGCM(block)
}
if security == protocol.SecurityType_CHACHA20_POLY1305 {
return chacha20poly1305.New(key[:])
}
return nil, newError("unsupported security type")
}
func getHeader(config *Config) (internet.PacketHeader, error) {
if config.Header == nil {
return nil, nil
}
2021-06-19 09:36:54 -04:00
msg, err := serial.GetInstanceOf(config.Header)
2018-11-21 16:02:19 -05:00
if err != nil {
return nil, err
}
return internet.CreatePacketHeader(msg)
}