Hunter0x7c7
2022-08-11 b8230139fb40edea387617b6accd8371e37eda58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package quic
 
import (
    "crypto/aes"
    "crypto/cipher"
    "crypto/sha256"
 
    "golang.org/x/crypto/chacha20poly1305"
 
    "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"
)
 
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
    }
 
    msg, err := serial.GetInstanceOf(config.Header)
    if err != nil {
        return nil, err
    }
 
    return internet.CreatePacketHeader(msg)
}