mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 01:08:33 +00:00
Add xchacha20-ietf-poly1305 for Shadowsocks
This commit is contained in:
parent
3fe61ed4a2
commit
238bd5d050
5 changed files with 52 additions and 23 deletions
|
@ -77,6 +77,12 @@ func createChaCha20Poly1305(key []byte) cipher.AEAD {
|
|||
return ChaChaPoly1305
|
||||
}
|
||||
|
||||
func createXChaCha20Poly1305(key []byte) cipher.AEAD {
|
||||
XChaChaPoly1305, err := chacha20poly1305.NewX(key)
|
||||
common.Must(err)
|
||||
return XChaChaPoly1305
|
||||
}
|
||||
|
||||
func (a *Account) getCipher() (Cipher, error) {
|
||||
switch a.CipherType {
|
||||
case CipherType_AES_128_GCM:
|
||||
|
@ -97,6 +103,12 @@ func (a *Account) getCipher() (Cipher, error) {
|
|||
IVBytes: 32,
|
||||
AEADAuthCreator: createChaCha20Poly1305,
|
||||
}, nil
|
||||
case CipherType_XCHACHA20_POLY1305:
|
||||
return &AEADCipher{
|
||||
KeyBytes: 32,
|
||||
IVBytes: 32,
|
||||
AEADAuthCreator: createXChaCha20Poly1305,
|
||||
}, nil
|
||||
case CipherType_NONE:
|
||||
return NoneCipher{}, nil
|
||||
default:
|
||||
|
@ -152,11 +164,12 @@ func (c *AEADCipher) IVSize() int32 {
|
|||
}
|
||||
|
||||
func (c *AEADCipher) createAuthenticator(key []byte, iv []byte) *crypto.AEADAuthenticator {
|
||||
nonce := crypto.GenerateInitialAEADNonce()
|
||||
subkey := make([]byte, c.KeyBytes)
|
||||
hkdfSHA1(key, iv, subkey)
|
||||
aead := c.AEADAuthCreator(subkey)
|
||||
nonce := crypto.GenerateAEADNonceWithSize(aead.NonceSize())
|
||||
return &crypto.AEADAuthenticator{
|
||||
AEAD: c.AEADAuthCreator(subkey),
|
||||
AEAD: aead,
|
||||
NonceGenerator: nonce,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue