Browse Source

Add bc xchacha20-ietf-poly1305

Drop NaCl
pull/3006/head
Bruce Wayne 4 years ago
parent
commit
f738fda7ca
No known key found for this signature in database GPG Key ID: 6D396097F05051BF
2 changed files with 4 additions and 62 deletions
  1. +4
    -1
      Shadowsocks.Net/Crypto/AEAD/AEADBouncyCastleCrypto.cs
  2. +0
    -61
      Shadowsocks.Net/Crypto/AEAD/AEADNaClCrypto.cs

+ 4
- 1
Shadowsocks.Net/Crypto/AEAD/AEADBouncyCastleCrypto.cs View File

@@ -1,6 +1,7 @@
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Parameters;
using Shadowsocks.Net.Crypto.Extensions;
using System;
using System.Collections.Generic;

@@ -16,6 +17,7 @@ namespace Shadowsocks.Net.Crypto.AEAD
{
CipherFamily.AesGcm => new GcmBlockCipher(new AesEngine()),
CipherFamily.Chacha20Poly1305 => new ChaCha20Poly1305(),
CipherFamily.XChacha20Poly1305 => new XChaCha20Poly1305(),
_ => throw new NotSupportedException(),
};
}
@@ -27,6 +29,7 @@ namespace Shadowsocks.Net.Crypto.AEAD
{"aes-192-gcm", new CipherInfo("aes-192-gcm", 24, 24, 12, 16, CipherFamily.AesGcm)},
{"aes-256-gcm", new CipherInfo("aes-256-gcm", 32, 32, 12, 16, CipherFamily.AesGcm)},
{"chacha20-ietf-poly1305", new CipherInfo("chacha20-ietf-poly1305",32, 32, 12, 16, CipherFamily.Chacha20Poly1305)},
{"xchacha20-ietf-poly1305", new CipherInfo("xchacha20-ietf-poly1305",32, 32, 24, 16, CipherFamily.XChacha20Poly1305)},
};

protected override Dictionary<string, CipherInfo> GetCiphers()


+ 0
- 61
Shadowsocks.Net/Crypto/AEAD/AEADNaClCrypto.cs View File

@@ -1,61 +0,0 @@
using NaCl.Core;
using NaCl.Core.Base;
using System;
using System.Collections.Generic;

namespace Shadowsocks.Net.Crypto.AEAD
{
public class AEADNaClCrypto : AEADCrypto
{

SnufflePoly1305 enc;
public AEADNaClCrypto(string method, string password) : base(method, password)
{
}

#region Cipher Info
private static readonly Dictionary<string, CipherInfo> _ciphers = new Dictionary<string, CipherInfo>
{
{"chacha20-ietf-poly1305", new CipherInfo("chacha20-ietf-poly1305",32, 32, 12, 16, CipherFamily.Chacha20Poly1305)},
{"xchacha20-ietf-poly1305", new CipherInfo("xchacha20-ietf-poly1305",32, 32, 24, 16, CipherFamily.XChacha20Poly1305)},
};

protected override Dictionary<string, CipherInfo> GetCiphers()
{
return _ciphers;
}

public static Dictionary<string, CipherInfo> SupportedCiphers()
{
return _ciphers;
}
#endregion

public override void InitCipher(byte[] salt, bool isEncrypt)
{
base.InitCipher(salt, isEncrypt);
enc = cipherFamily switch
{
CipherFamily.XChacha20Poly1305 => new XChaCha20Poly1305(sessionKey),
_ => new ChaCha20Poly1305(sessionKey),
};
}

public override int CipherEncrypt(ReadOnlySpan<byte> plain, Span<byte> cipher)
{
//byte[] ct = enc.Encrypt(plain, null, nonce);
//ct.CopyTo(cipher);
//return ct.Length;

throw new NotImplementedException();
}

public override int CipherDecrypt(Span<byte> plain, ReadOnlySpan<byte> cipher)
{
//byte[] pt = enc.Decrypt(cipher, null, nonce);
//pt.CopyTo(plain);
//return pt.Length;
throw new NotImplementedException();
}
}
}

Loading…
Cancel
Save