Xray-core/transport/internet/quic/config.go

49 lines
1.0 KiB
Go
Raw Normal View History

2020-11-25 11:01:53 +00:00
package quic
import (
"crypto/aes"
"crypto/cipher"
"crypto/sha256"
2021-09-20 13:00:55 +00:00
"golang.org/x/crypto/chacha20poly1305"
2020-12-04 01:36:16 +00:00
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/transport/internet"
2020-11-25 11:01:53 +00:00
)
func getAuth(config *Config) (cipher.AEAD, error) {
security := config.Security.GetSecurityType()
if security == protocol.SecurityType_NONE {
return nil, nil
}
salted := []byte(config.Key + "xray-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
}
msg, err := config.Header.GetInstance()
if err != nil {
return nil, err
}
return internet.CreatePacketHeader(msg)
}