Beispiel #1
0
    public void Test(string keyHex, int originSize, string hex, string hex2)
    {
        var key = keyHex.FromHex();

        Test(new BcRC4Crypto(key), originSize, hex, hex2);
        Test(StreamCryptoCreate.Rc4(key), originSize, hex, hex2);
    }
        protected override void InitCipher(byte[] iv, bool isEncrypt)
        {
            base.InitCipher(iv, isEncrypt);
            _crypto?.Dispose();

            if (cipherFamily == CipherFamily.Rc4Md5)
            {
                Span <byte> temp    = stackalloc byte[keyLen + ivLen];
                var         realKey = new byte[MD5Length];
                key.CopyTo(temp);
                iv.CopyTo(temp.Slice(keyLen));
                MD5Utils.Fast440(temp, realKey);

                _crypto = StreamCryptoCreate.Rc4(realKey);
                return;
            }

            _crypto = cipherFamily switch
            {
                CipherFamily.AesCfb => StreamCryptoCreate.AesCfb(isEncrypt, key, iv),
                CipherFamily.Chacha20 => StreamCryptoCreate.ChaCha20(key, iv),
                CipherFamily.Rc4 => StreamCryptoCreate.Rc4(key),
                _ => throw new NotSupportedException()
            };
        }
Beispiel #3
0
        public void Test(string keyHex, string ivHex, string hex, string hex2)
        {
            var key = keyHex.FromHex();
            var iv  = ivHex.FromHex();

            Test(StreamCryptoCreate.AesCtr(key, iv), hex, hex2);
        }
Beispiel #4
0
    public void Test(string keyHex, string ivHex, string i1, string o1, string i2, string o2)
    {
        var key = keyHex.FromHex();
        var iv  = ivHex.FromHex();

        Test(new BcXSalsa20Crypto(key, iv), i1, o1, i2, o2);
        Test(new XSalsa20CryptoX86(key, iv), i1, o1, i2, o2);
        Test(new XSalsa20CryptoSF(key, iv), i1, o1, i2, o2);
        Test(StreamCryptoCreate.XSalsa20(key, iv), i1, o1, i2, o2);
    }
Beispiel #5
0
        public void TestCounter0(string keyHex, string ivHex, string hex, string hex2)
        {
            var key = keyHex.FromHex();
            var iv  = ivHex.FromHex();

            TestCounter0(new BcXChaCha20Crypto(key, iv), hex, hex2);
            TestCounter0(new XChaCha20CryptoSF(key, iv), hex, hex2);
            TestCounter0(new XChaCha20CryptoX86(key, iv), hex, hex2);
            TestCounter0(StreamCryptoCreate.XChaCha20(key, iv), hex, hex2);
        }
Beispiel #6
0
        public void Test(string keyHex, string ivHex, string hex0, string hex1, string hex2, string hex3)
        {
            var key = keyHex.FromHex();
            var iv  = ivHex.FromHex();

            Test(new BcSalsa20Crypto(key, iv), hex0, hex1, hex2, hex3);
            Test(new Salsa20CryptoSF(key, iv), hex0, hex1, hex2, hex3);
            Test(new Salsa20CryptoX86(key, iv), hex0, hex1, hex2, hex3);
            Test(StreamCryptoCreate.Salsa20(key, iv), hex0, hex1, hex2, hex3);
        }
Beispiel #7
0
        public void Test(string keyHex, string ivHex, string hex, string hex2)
        {
            var key = keyHex.FromHex();
            var iv  = ivHex.FromHex();

            Test(new BcAESCFBStreamCrypto(true, key, iv), hex, hex2);
            Test(new BcAESCFBStreamCrypto(false, key, iv), hex2, hex);
            Test(StreamCryptoCreate.AesCfb(true, key, iv), hex, hex2);
            Test(StreamCryptoCreate.AesCfb(false, key, iv), hex2, hex);
        }
Beispiel #8
0
    public ChaCha20Poly1305Crypto(ReadOnlySpan <byte> key)
    {
        if (key.Length < KeySize)
        {
            throw new ArgumentException(@"Key length must be 32 bytes.", nameof(key));
        }

        _chacha20 = StreamCryptoCreate.ChaCha20(key);

        _buffer = ArrayPool <byte> .Shared.Rent(32);
    }
Beispiel #9
0
 public void SM4CTR()
 {
     Test(StreamCryptoCreate.Sm4Ctr(_randomKey16, _randomIv16), _randombytes.Span);
 }
Beispiel #10
0
 public void AESCTR()
 {
     Test(StreamCryptoCreate.AesCtr(_randomKey16, _randomIv16), _randombytes.Span);
 }
 protected override IStreamCrypto CreateCrypto(bool isEncrypt, ReadOnlySpan <byte> key, ReadOnlySpan <byte> iv)
 {
     return(StreamCryptoCreate.AesCfb(isEncrypt, key, iv));
 }
Beispiel #12
0
 public void AESCFB()
 {
     Test(StreamCryptoCreate.AesCfb(true, _randomKey16, _randomIv16), _randombytes.Span);
 }
Beispiel #13
0
 protected override IStreamCrypto CreateCrypto(bool isEncrypt, ReadOnlySpan <byte> key, ReadOnlySpan <byte> iv)
 {
     return(StreamCryptoCreate.ChaCha20Original(key, iv));
 }
Beispiel #14
0
 public void RC4()
 {
     Test(StreamCryptoCreate.Rc4(_randomKey), _randombytes.Span);
 }
Beispiel #15
0
 protected override IStreamCrypto CreateCrypto(bool isEncrypt, ReadOnlySpan <byte> key, ReadOnlySpan <byte> iv)
 {
     return(StreamCryptoCreate.Rc4(key));
 }