Ejemplo n.º 1
0
    public void RC4_TestVector_IETF()
    {
        byte[] keyStream = ArrayPool <byte> .Shared.Rent(8192);

        Array.Clear(keyStream); // ArrayPool buffers are not zeroed

        // echo -n "Internet Engineering Task Force" | sha256sum
        using var rc4 = new RC4(Convert.FromHexString("1ada31d5cf688221c109163908ebe51debb46227c6cc8b37641910833222772a"));
        rc4.Process(keyStream);

        AssertKeyStreamEqual(keyStream, 0, "dd5bcb0018e922d494759d7c395d02d3");
        AssertKeyStreamEqual(keyStream, 16, "c8446f8f77abf737685353eb89a1c9eb");
        AssertKeyStreamEqual(keyStream, 240, "af3e30f9c095045938151575c3fb9098");
        AssertKeyStreamEqual(keyStream, 256, "f8cb6274db99b80b1d2012a98ed48f0e");
        AssertKeyStreamEqual(keyStream, 496, "25c3005a1cb85de076259839ab7198ab");
        AssertKeyStreamEqual(keyStream, 512, "9dcbc183e8cb994b727b75be3180769c");
        AssertKeyStreamEqual(keyStream, 752, "a1d3078dfa9169503ed9d4491dee4eb2");
        AssertKeyStreamEqual(keyStream, 768, "8514a5495858096f596e4bcd66b10665");
        AssertKeyStreamEqual(keyStream, 1008, "5f40d59ec1b03b33738efa60b2255d31");
        AssertKeyStreamEqual(keyStream, 1024, "3477c7f764a41baceff90bf14f92b7cc");
        AssertKeyStreamEqual(keyStream, 1520, "ac4e95368d99b9eb78b8da8f81ffa795");
        AssertKeyStreamEqual(keyStream, 1536, "8c3c13f8c2388bb73f38576e65b7c446");
        AssertKeyStreamEqual(keyStream, 2032, "13c4b9c1dfb66579eddd8a280b9f7316");
        AssertKeyStreamEqual(keyStream, 2048, "ddd27820550126698efaadc64b64f66e");
        AssertKeyStreamEqual(keyStream, 3056, "f08f2e66d28ed143f3a237cf9de73559");
        AssertKeyStreamEqual(keyStream, 3072, "9ea36c525531b880ba124334f57b0b70");
        AssertKeyStreamEqual(keyStream, 4080, "d5a39e3dfcc50280bac4a6b5aa0dca7d");
        AssertKeyStreamEqual(keyStream, 4096, "370b1c1fe655916d97fd0d47ca1d72b8");

        ArrayPool <byte> .Shared.Return(keyStream);
    }
Ejemplo n.º 2
0
    public void RC4_TestVector_0x0102030405()
    {
        byte[] keyStream = ArrayPool <byte> .Shared.Rent(8192);

        Array.Clear(keyStream); // ArrayPool buffers are not zeroed

        using var rc4 = new RC4(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 });
        rc4.Process(keyStream);

        AssertKeyStreamEqual(keyStream, 0, "b2396305f03dc027ccc3524a0a1118a8");
        AssertKeyStreamEqual(keyStream, 16, "6982944f18fc82d589c403a47a0d0919");
        AssertKeyStreamEqual(keyStream, 240, "28cb1132c96ce286421dcaadb8b69eae");
        AssertKeyStreamEqual(keyStream, 256, "1cfcf62b03eddb641d77dfcf7f8d8c93");
        AssertKeyStreamEqual(keyStream, 496, "42b7d0cdd918a8a33dd51781c81f4041");
        AssertKeyStreamEqual(keyStream, 512, "6459844432a7da923cfb3eb4980661f6");
        AssertKeyStreamEqual(keyStream, 752, "ec10327bde2beefd18f9277680457e22");
        AssertKeyStreamEqual(keyStream, 768, "eb62638d4f0ba1fe9fca20e05bf8ff2b");
        AssertKeyStreamEqual(keyStream, 1008, "45129048e6a0ed0b56b490338f078da5");
        AssertKeyStreamEqual(keyStream, 1024, "30abbcc7c20b01609f23ee2d5f6bb7df");
        AssertKeyStreamEqual(keyStream, 1520, "3294f744d8f9790507e70f62e5bbceea");
        AssertKeyStreamEqual(keyStream, 1536, "d8729db41882259bee4f825325f5a130");
        AssertKeyStreamEqual(keyStream, 2032, "1eb14a0c13b3bf47fa2a0ba93ad45b8b");
        AssertKeyStreamEqual(keyStream, 2048, "cc582f8ba9f265e2b1be9112e975d2d7");
        AssertKeyStreamEqual(keyStream, 3056, "f2e30f9bd102ecbf75aaade9bc35c43c");
        AssertKeyStreamEqual(keyStream, 3072, "ec0e11c479dc329dc8da7968fe965681");
        AssertKeyStreamEqual(keyStream, 4080, "068326a2118416d21f9d04b2cd1ca050");
        AssertKeyStreamEqual(keyStream, 4096, "ff25b58995996707e51fbdf08b34d875");

        ArrayPool <byte> .Shared.Return(keyStream);
    }
Ejemplo n.º 3
0
        protected override byte[] ProcessOutgoingData(byte[] data)
        {
            if (RC4Initialized)
            {
                return(rc4Out.Process(data));
            }

            return(data);
        }
Ejemplo n.º 4
0
        protected override byte[] ProcessIncomingData(byte[] data)
        {
            if (RC4Initialized)
            {
                return(rc4In.Process(data));
            }

            return(data);
        }