コード例 #1
0
        public void TestSha256()
        {
            byte[] secret = new byte[] {
                0x9b, 0xbe, 0x43, 0x6b, 0xa9, 0x40, 0xf0, 0x17,
                0xb1, 0x76, 0x52, 0x84, 0x9a, 0x71, 0xdb, 0x35
            };
            string label = "test label";
            byte[] seed = new byte[] {
                0xa0, 0xba, 0x9f, 0x93, 0x6c, 0xda, 0x31, 0x18,
                0x27, 0xa6, 0xf7, 0x96, 0xff, 0xd5, 0x19, 0x8c
            };
            byte[] output = new byte[] {
                0xe3, 0xf2, 0x29, 0xba, 0x72, 0x7b, 0xe1, 0x7b,
                0x8d, 0x12, 0x26, 0x20, 0x55, 0x7c, 0xd4, 0x53,
                0xc2, 0xaa, 0xb2, 0x1d, 0x07, 0xc3, 0xd4, 0x95,
                0x32, 0x9b, 0x52, 0xd4, 0xe6, 0x1e, 0xdb, 0x5a,
                0x6b, 0x30, 0x17, 0x91, 0xe9, 0x0d, 0x35, 0xc9,
                0xc9, 0xa4, 0x6b, 0x4e, 0x14, 0xba, 0xf9, 0xaf,
                0x0f, 0xa0, 0x22, 0xf7, 0x07, 0x7d, 0xef, 0x17,
                0xab, 0xfd, 0x37, 0x97, 0xc0, 0x56, 0x4b, 0xab,
                0x4f, 0xbc, 0x91, 0x66, 0x6e, 0x9d, 0xef, 0x9b,
                0x97, 0xfc, 0xe3, 0x4f, 0x79, 0x67, 0x89, 0xba,
                0xa4, 0x80, 0x82, 0xd1, 0x22, 0xee, 0x42, 0xc5,
                0xa7, 0x2e, 0x5a, 0x51, 0x10, 0xff, 0xf7, 0x01,
                0x87, 0x34, 0x7b, 0x66
            };

            PseudoRandomFunctionTLSGeneric prf = new PseudoRandomFunctionTLSGeneric("SHA256");
            byte[] ourOutput = prf.CreateDeriveBytes(secret, label, seed).GetBytes(output.Length);
            Assert.AreEqual(output, ourOutput);
        }
コード例 #2
0
        public void TestSha256()
        {
            byte[] secret = new byte[] {
                0x9b, 0xbe, 0x43, 0x6b, 0xa9, 0x40, 0xf0, 0x17,
                0xb1, 0x76, 0x52, 0x84, 0x9a, 0x71, 0xdb, 0x35
            };
            string label = "test label";

            byte[] seed = new byte[] {
                0xa0, 0xba, 0x9f, 0x93, 0x6c, 0xda, 0x31, 0x18,
                0x27, 0xa6, 0xf7, 0x96, 0xff, 0xd5, 0x19, 0x8c
            };
            byte[] output = new byte[] {
                0xe3, 0xf2, 0x29, 0xba, 0x72, 0x7b, 0xe1, 0x7b,
                0x8d, 0x12, 0x26, 0x20, 0x55, 0x7c, 0xd4, 0x53,
                0xc2, 0xaa, 0xb2, 0x1d, 0x07, 0xc3, 0xd4, 0x95,
                0x32, 0x9b, 0x52, 0xd4, 0xe6, 0x1e, 0xdb, 0x5a,
                0x6b, 0x30, 0x17, 0x91, 0xe9, 0x0d, 0x35, 0xc9,
                0xc9, 0xa4, 0x6b, 0x4e, 0x14, 0xba, 0xf9, 0xaf,
                0x0f, 0xa0, 0x22, 0xf7, 0x07, 0x7d, 0xef, 0x17,
                0xab, 0xfd, 0x37, 0x97, 0xc0, 0x56, 0x4b, 0xab,
                0x4f, 0xbc, 0x91, 0x66, 0x6e, 0x9d, 0xef, 0x9b,
                0x97, 0xfc, 0xe3, 0x4f, 0x79, 0x67, 0x89, 0xba,
                0xa4, 0x80, 0x82, 0xd1, 0x22, 0xee, 0x42, 0xc5,
                0xa7, 0x2e, 0x5a, 0x51, 0x10, 0xff, 0xf7, 0x01,
                0x87, 0x34, 0x7b, 0x66
            };

            PseudoRandomFunctionTLSGeneric prf = new PseudoRandomFunctionTLSGeneric("SHA256");

            byte[] ourOutput = prf.CreateDeriveBytes(secret, label, seed).GetBytes(output.Length);
            Assert.AreEqual(output, ourOutput);
        }
コード例 #3
0
        public void ClientVersionInvalidTest()
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            KeyExchangeAlgorithmRSA keyex = new KeyExchangeAlgorithmRSA();
            PseudoRandomFunctionTLSGeneric prf = new PseudoRandomFunctionTLSGeneric("SHA1");

            byte[] clientKeys = keyex.GetClientKeys(ProtocolVersion.TLS1_0, ProtocolVersion.TLS1_0, rsa);
            byte[] master1 = keyex.GetMasterSecret(prf, new byte[32]);
            keyex.ProcessClientKeys(ProtocolVersion.TLS1_0, ProtocolVersion.TLS1_2, new CertificatePrivateKey(keyex.CertificateKeyAlgorithm, rsa), clientKeys);
            byte[] master2 = keyex.GetMasterSecret(prf, new byte[32]);
            Assert.AreNotEqual (master1, master2);
        }
コード例 #4
0
        public void ClientVersionInvalidTest()
        {
            RSACryptoServiceProvider       rsa   = new RSACryptoServiceProvider();
            KeyExchangeAlgorithmRSA        keyex = new KeyExchangeAlgorithmRSA();
            PseudoRandomFunctionTLSGeneric prf   = new PseudoRandomFunctionTLSGeneric("SHA1");

            byte[] clientKeys = keyex.GetClientKeys(ProtocolVersion.TLS1_0, ProtocolVersion.TLS1_0, rsa);
            byte[] master1    = keyex.GetMasterSecret(prf, new byte[32]);
            keyex.ProcessClientKeys(ProtocolVersion.TLS1_0, ProtocolVersion.TLS1_2, new CertificatePrivateKey(keyex.CertificateKeyAlgorithm, rsa), clientKeys);
            byte[] master2 = keyex.GetMasterSecret(prf, new byte[32]);
            Assert.AreNotEqual(master1, master2);
        }
コード例 #5
0
        public void TestSha384v2()
        {
            byte[] secret = new byte[] {
                0x7A, 0xBF, 0xC4, 0x0A, 0x0C, 0x0E, 0x72, 0x52,
                0x96, 0x87, 0x71, 0x5F, 0x99, 0x80, 0xC8, 0x04,
                0xBE, 0x5C, 0xD6, 0x95, 0xA3, 0xCB, 0xD1, 0xD7,
                0xA0, 0x0D, 0xA6, 0x05, 0x30, 0x83, 0x11, 0x93,
                0x06, 0x9B, 0x8F, 0x4F, 0x6A, 0xD8, 0x74, 0x39,
                0xA7, 0xBE, 0x3B, 0xB3, 0x7B, 0x29, 0x24, 0x8C,
                0x3C, 0xBD, 0x8B, 0x8E, 0x0C, 0x57, 0x93, 0xF6,
                0x35, 0x11, 0x58, 0x52, 0xA3, 0x7E, 0x8E, 0xC6,
                0x1D, 0x70, 0xA2, 0x49, 0x7D, 0xD0, 0xDD, 0x60,
                0xA9, 0x20, 0x11, 0xC1, 0xCD, 0xCF, 0x8D, 0xC7,
                0xAC, 0x66, 0xE8, 0xC0, 0x15, 0x4D, 0xE5, 0x76,
                0x7E, 0x1E, 0xB3, 0xFF, 0x78, 0x99, 0x2E, 0x26,
                0x09, 0xCE, 0xC8, 0x43, 0xA1, 0x46, 0x0E, 0x71,
                0xCF, 0xF4, 0xF5, 0xEB, 0xBE, 0xFD, 0xF8, 0xF6,
                0x10, 0x91, 0xF3, 0x67, 0x8C, 0x12, 0xB8, 0xF9,
                0x72, 0x98, 0x61, 0x68, 0x59, 0x1D, 0x65, 0x5A
            };
            string label = "master secret";

            byte[] seed = new byte[] {
                0x4E, 0x79, 0xDE, 0x52, 0x25, 0xE4, 0xA5, 0xC0,
                0x37, 0xB1, 0x52, 0x40, 0x41, 0x30, 0x9E, 0x7D,
                0xE5, 0xD1, 0x06, 0x1A, 0x33, 0x7B, 0xFC, 0xCE,
                0x6B, 0x7F, 0xA7, 0x82, 0x9A, 0x5E, 0xC7, 0xFF,
                0x4E, 0x79, 0xE2, 0x02, 0x0F, 0x01, 0xD1, 0x77,
                0x88, 0x80, 0xCA, 0x52, 0x2F, 0xAC, 0x9F, 0x0A,
                0x6A, 0x6D, 0xEE, 0x5A, 0xB0, 0xB8, 0x45, 0x51,
                0xF7, 0xF0, 0x6D, 0xB9, 0x26, 0x78, 0x3D, 0xC7
            };
            byte[] output = new byte[] {
                0x69, 0xAE, 0xEA, 0x90, 0x22, 0xCE, 0xF8, 0x32,
                0xB1, 0xC0, 0x76, 0x33, 0x0F, 0x71, 0x96, 0x6A,
                0x64, 0x85, 0x86, 0x4D, 0x92, 0x09, 0x44, 0x06,
                0x0A, 0xB0, 0x27, 0x57, 0xC8, 0x5B, 0xD3, 0xC5,
                0xD4, 0x52, 0x9C, 0xE8, 0x44, 0xCC, 0x6C, 0xC0,
                0xC2, 0xC9, 0x5B, 0x49, 0x1D, 0xBC, 0xBC, 0x30
            };

            PseudoRandomFunctionTLSGeneric prf = new PseudoRandomFunctionTLSGeneric("SHA384");

            byte[] ourOutput = prf.CreateDeriveBytes(secret, label, seed).GetBytes(output.Length);
            Assert.AreEqual(output, ourOutput);
        }
コード例 #6
0
        public void TestVector()
        {
            byte[] encryptedKey =
            {
                0x00, 0x40, 0x51, 0x57, 0x5A, 0x26, 0x6D, 0xCC,
                0x65, 0x85, 0x55, 0xDE, 0x28, 0x01, 0x41, 0x62,
                0x13, 0x4F, 0x0A, 0xB4, 0xEF, 0x34, 0x99, 0x54,
                0x51, 0x9E, 0x4E, 0x6D, 0x21, 0x1B, 0xE9, 0x73,
                0x4C, 0xF8, 0x79, 0xF5, 0xBE, 0x71, 0x2D, 0x8F,
                0x22, 0xF7, 0x4E, 0x51, 0x49, 0x33, 0xD5, 0x0C,
                0x21, 0xC7, 0x17, 0xEE, 0x23, 0xA5, 0xD6, 0xA1,
                0x2C, 0x8D, 0xD2, 0x52, 0x5B, 0xE2, 0xC1, 0x10,
                0x8F, 0x14
            };
            string rsaKeys =
                "<RSAKeyValue>" +
                "<Modulus>nrum196jNc4CFruN2+6A/1S4XXdaYFDtuXuSVHUGfhINISX87ze7ASP4K4oq5qK8qux9wwndqB9ERD2ZuLBsfw==</Modulus>" +
                "<Exponent>EQ==</Exponent>" +
                "<P>/lOfBctf4yh0CwrxG1zJdQhjkLjq+ruy0uwJxiHolus=</P>" +
                "<Q>n8cEGYQH4J97W26zvq1xtXwKWDXpSDsPcSRijdYMw70=</Q>" +
                "<DP>wnwuT7mjrbWF6lOpUSjWSm/TqufCv7y17JZh07+TvrM=</DP>" +
                "<DQ>OGRbzMUv9Oz+XIFsnaagmmgDpqmdoQXJNv3IbkuMCNk=</DQ>" +
                "<InverseQ>xsbdvaSCbalm6wa8DtBMgOgWfbwPokwfnjQ1J0trre4=</InverseQ>" +
                "<D>QVxTwkydjqAe+k06aZ5xWhPTcce7zU6AARTDyGxsFcqIEb1qUN0pkAaWWE9dh+5pWyUQGyUhlFN4jc6kQE0HWQ==</D>" +
                "</RSAKeyValue>";

            byte[] masterSecret =
            {
                0xC9, 0xBC, 0x99, 0x08, 0xAA, 0x11, 0xFF, 0x63,
                0xBE, 0x01, 0xF4, 0x07, 0x0D, 0x37, 0x8E, 0xA0,
                0xE4, 0x1A, 0x30, 0x08, 0xAD, 0x08, 0xAC, 0xBA,
                0xEE, 0x37, 0xAA, 0xBD, 0x49, 0x28, 0x1C, 0xD6,
                0x7D, 0x2A, 0xBE, 0x55, 0x85, 0xA2, 0x30, 0x88,
                0xBE, 0xC9, 0xED, 0x76, 0x14, 0xDA, 0x6B, 0x1E
            };

            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);

            rsa.FromXmlString(rsaKeys);
            KeyExchangeAlgorithmRSA        keyex = new KeyExchangeAlgorithmRSA();
            PseudoRandomFunctionTLSGeneric prf   = new PseudoRandomFunctionTLSGeneric("SHA1");

            keyex.ProcessClientKeys(ProtocolVersion.TLS1_0, ProtocolVersion.TLS1_0, new CertificatePrivateKey(keyex.CertificateKeyAlgorithm, rsa), encryptedKey);
            byte[] master = keyex.GetMasterSecret(prf, new byte[32]);
            Assert.AreEqual(masterSecret, master);
        }
コード例 #7
0
        public void TestSha512()
        {
            byte[] secret = new byte[] {
                0xb0, 0x32, 0x35, 0x23, 0xc1, 0x85, 0x35, 0x99,
                0x58, 0x4d, 0x88, 0x56, 0x8b, 0xbb, 0x05, 0xeb
            };
            string label = "test label";

            byte[] seed = new byte[] {
                0xd4, 0x64, 0x0e, 0x12, 0xe4, 0xbc, 0xdb, 0xfb,
                0x43, 0x7f, 0x03, 0xe6, 0xae, 0x41, 0x8e, 0xe5
            };
            byte[] output = new byte[] {
                0x12, 0x61, 0xf5, 0x88, 0xc7, 0x98, 0xc5, 0xc2,
                0x01, 0xff, 0x03, 0x6e, 0x7a, 0x9c, 0xb5, 0xed,
                0xcd, 0x7f, 0xe3, 0xf9, 0x4c, 0x66, 0x9a, 0x12,
                0x2a, 0x46, 0x38, 0xd7, 0xd5, 0x08, 0xb2, 0x83,
                0x04, 0x2d, 0xf6, 0x78, 0x98, 0x75, 0xc7, 0x14,
                0x7e, 0x90, 0x6d, 0x86, 0x8b, 0xc7, 0x5c, 0x45,
                0xe2, 0x0e, 0xb4, 0x0c, 0x1c, 0xf4, 0xa1, 0x71,
                0x3b, 0x27, 0x37, 0x1f, 0x68, 0x43, 0x25, 0x92,
                0xf7, 0xdc, 0x8e, 0xa8, 0xef, 0x22, 0x3e, 0x12,
                0xea, 0x85, 0x07, 0x84, 0x13, 0x11, 0xbf, 0x68,
                0x65, 0x3d, 0x0c, 0xfc, 0x40, 0x56, 0xd8, 0x11,
                0xf0, 0x25, 0xc4, 0x5d, 0xdf, 0xa6, 0xe6, 0xfe,
                0xc7, 0x02, 0xf0, 0x54, 0xb4, 0x09, 0xd6, 0xf2,
                0x8d, 0xd0, 0xa3, 0x23, 0x3e, 0x49, 0x8d, 0xa4,
                0x1a, 0x3e, 0x75, 0xc5, 0x63, 0x0e, 0xed, 0xbe,
                0x22, 0xfe, 0x25, 0x4e, 0x33, 0xa1, 0xb0, 0xe9,
                0xf6, 0xb9, 0x82, 0x66, 0x75, 0xbe, 0xc7, 0xd0,
                0x1a, 0x84, 0x56, 0x58, 0xdc, 0x9c, 0x39, 0x75,
                0x45, 0x40, 0x1d, 0x40, 0xb9, 0xf4, 0x6c, 0x7a,
                0x40, 0x0e, 0xe1, 0xb8, 0xf8, 0x1c, 0xa0, 0xa6,
                0x0d, 0x1a, 0x39, 0x7a, 0x10, 0x28, 0xbf, 0xf5,
                0xd2, 0xef, 0x50, 0x66, 0x12, 0x68, 0x42, 0xfb,
                0x8d, 0xa4, 0x19, 0x76, 0x32, 0xbd, 0xb5, 0x4f,
                0xf6, 0x63, 0x3f, 0x86, 0xbb, 0xc8, 0x36, 0xe6,
                0x40, 0xd4, 0xd8, 0x98
            };

            PseudoRandomFunctionTLSGeneric prf = new PseudoRandomFunctionTLSGeneric("SHA512");

            byte[] ourOutput = prf.CreateDeriveBytes(secret, label, seed).GetBytes(output.Length);
            Assert.AreEqual(output, ourOutput);
        }
コード例 #8
0
        public void TestSha384()
        {
            byte[] secret = new byte[] {
                0xb8, 0x0b, 0x73, 0x3d, 0x6c, 0xee, 0xfc, 0xdc,
                0x71, 0x56, 0x6e, 0xa4, 0x8e, 0x55, 0x67, 0xdf
            };
            string label = "test label";

            byte[] seed = new byte[] {
                0xcd, 0x66, 0x5c, 0xf6, 0xa8, 0x44, 0x7d, 0xd6,
                0xff, 0x8b, 0x27, 0x55, 0x5e, 0xdb, 0x74, 0x65
            };
            byte[] output = new byte[] {
                0x7b, 0x0c, 0x18, 0xe9, 0xce, 0xd4, 0x10, 0xed,
                0x18, 0x04, 0xf2, 0xcf, 0xa3, 0x4a, 0x33, 0x6a,
                0x1c, 0x14, 0xdf, 0xfb, 0x49, 0x00, 0xbb, 0x5f,
                0xd7, 0x94, 0x21, 0x07, 0xe8, 0x1c, 0x83, 0xcd,
                0xe9, 0xca, 0x0f, 0xaa, 0x60, 0xbe, 0x9f, 0xe3,
                0x4f, 0x82, 0xb1, 0x23, 0x3c, 0x91, 0x46, 0xa0,
                0xe5, 0x34, 0xcb, 0x40, 0x0f, 0xed, 0x27, 0x00,
                0x88, 0x4f, 0x9d, 0xc2, 0x36, 0xf8, 0x0e, 0xdd,
                0x8b, 0xfa, 0x96, 0x11, 0x44, 0xc9, 0xe8, 0xd7,
                0x92, 0xec, 0xa7, 0x22, 0xa7, 0xb3, 0x2f, 0xc3,
                0xd4, 0x16, 0xd4, 0x73, 0xeb, 0xc2, 0xc5, 0xfd,
                0x4a, 0xbf, 0xda, 0xd0, 0x5d, 0x91, 0x84, 0x25,
                0x9b, 0x5b, 0xf8, 0xcd, 0x4d, 0x90, 0xfa, 0x0d,
                0x31, 0xe2, 0xde, 0xc4, 0x79, 0xe4, 0xf1, 0xa2,
                0x60, 0x66, 0xf2, 0xee, 0xa9, 0xa6, 0x92, 0x36,
                0xa3, 0xe5, 0x26, 0x55, 0xc9, 0xe9, 0xae, 0xe6,
                0x91, 0xc8, 0xf3, 0xa2, 0x68, 0x54, 0x30, 0x8d,
                0x5e, 0xaa, 0x3b, 0xe8, 0x5e, 0x09, 0x90, 0x70,
                0x3d, 0x73, 0xe5, 0x6f
            };

            PseudoRandomFunctionTLSGeneric prf = new PseudoRandomFunctionTLSGeneric("SHA384");

            byte[] ourOutput = prf.CreateDeriveBytes(secret, label, seed).GetBytes(output.Length);
            Assert.AreEqual(output, ourOutput);
        }
コード例 #9
0
        public void TestSha384()
        {
            byte[] secret = new byte[] {
                0xb8, 0x0b, 0x73, 0x3d, 0x6c, 0xee, 0xfc, 0xdc,
                0x71, 0x56, 0x6e, 0xa4, 0x8e, 0x55, 0x67, 0xdf
            };
            string label = "test label";
            byte[] seed = new byte[] {
                0xcd, 0x66, 0x5c, 0xf6, 0xa8, 0x44, 0x7d, 0xd6,
                0xff, 0x8b, 0x27, 0x55, 0x5e, 0xdb, 0x74, 0x65
            };
            byte[] output = new byte[] {
                0x7b, 0x0c, 0x18, 0xe9, 0xce, 0xd4, 0x10, 0xed,
                0x18, 0x04, 0xf2, 0xcf, 0xa3, 0x4a, 0x33, 0x6a,
                0x1c, 0x14, 0xdf, 0xfb, 0x49, 0x00, 0xbb, 0x5f,
                0xd7, 0x94, 0x21, 0x07, 0xe8, 0x1c, 0x83, 0xcd,
                0xe9, 0xca, 0x0f, 0xaa, 0x60, 0xbe, 0x9f, 0xe3,
                0x4f, 0x82, 0xb1, 0x23, 0x3c, 0x91, 0x46, 0xa0,
                0xe5, 0x34, 0xcb, 0x40, 0x0f, 0xed, 0x27, 0x00,
                0x88, 0x4f, 0x9d, 0xc2, 0x36, 0xf8, 0x0e, 0xdd,
                0x8b, 0xfa, 0x96, 0x11, 0x44, 0xc9, 0xe8, 0xd7,
                0x92, 0xec, 0xa7, 0x22, 0xa7, 0xb3, 0x2f, 0xc3,
                0xd4, 0x16, 0xd4, 0x73, 0xeb, 0xc2, 0xc5, 0xfd,
                0x4a, 0xbf, 0xda, 0xd0, 0x5d, 0x91, 0x84, 0x25,
                0x9b, 0x5b, 0xf8, 0xcd, 0x4d, 0x90, 0xfa, 0x0d,
                0x31, 0xe2, 0xde, 0xc4, 0x79, 0xe4, 0xf1, 0xa2,
                0x60, 0x66, 0xf2, 0xee, 0xa9, 0xa6, 0x92, 0x36,
                0xa3, 0xe5, 0x26, 0x55, 0xc9, 0xe9, 0xae, 0xe6,
                0x91, 0xc8, 0xf3, 0xa2, 0x68, 0x54, 0x30, 0x8d,
                0x5e, 0xaa, 0x3b, 0xe8, 0x5e, 0x09, 0x90, 0x70,
                0x3d, 0x73, 0xe5, 0x6f
            };

            PseudoRandomFunctionTLSGeneric prf = new PseudoRandomFunctionTLSGeneric("SHA384");
            byte[] ourOutput = prf.CreateDeriveBytes(secret, label, seed).GetBytes(output.Length);
            Assert.AreEqual(output, ourOutput);
        }
コード例 #10
0
        public void TestSha512()
        {
            byte[] secret = new byte[] {
                0xb0, 0x32, 0x35, 0x23, 0xc1, 0x85, 0x35, 0x99,
                0x58, 0x4d, 0x88, 0x56, 0x8b, 0xbb, 0x05, 0xeb
            };
            string label = "test label";
            byte[] seed = new byte[] {
                0xd4, 0x64, 0x0e, 0x12, 0xe4, 0xbc, 0xdb, 0xfb,
                0x43, 0x7f, 0x03, 0xe6, 0xae, 0x41, 0x8e, 0xe5
            };
            byte[] output = new byte[] {
                0x12, 0x61, 0xf5, 0x88, 0xc7, 0x98, 0xc5, 0xc2,
                0x01, 0xff, 0x03, 0x6e, 0x7a, 0x9c, 0xb5, 0xed,
                0xcd, 0x7f, 0xe3, 0xf9, 0x4c, 0x66, 0x9a, 0x12,
                0x2a, 0x46, 0x38, 0xd7, 0xd5, 0x08, 0xb2, 0x83,
                0x04, 0x2d, 0xf6, 0x78, 0x98, 0x75, 0xc7, 0x14,
                0x7e, 0x90, 0x6d, 0x86, 0x8b, 0xc7, 0x5c, 0x45,
                0xe2, 0x0e, 0xb4, 0x0c, 0x1c, 0xf4, 0xa1, 0x71,
                0x3b, 0x27, 0x37, 0x1f, 0x68, 0x43, 0x25, 0x92,
                0xf7, 0xdc, 0x8e, 0xa8, 0xef, 0x22, 0x3e, 0x12,
                0xea, 0x85, 0x07, 0x84, 0x13, 0x11, 0xbf, 0x68,
                0x65, 0x3d, 0x0c, 0xfc, 0x40, 0x56, 0xd8, 0x11,
                0xf0, 0x25, 0xc4, 0x5d, 0xdf, 0xa6, 0xe6, 0xfe,
                0xc7, 0x02, 0xf0, 0x54, 0xb4, 0x09, 0xd6, 0xf2,
                0x8d, 0xd0, 0xa3, 0x23, 0x3e, 0x49, 0x8d, 0xa4,
                0x1a, 0x3e, 0x75, 0xc5, 0x63, 0x0e, 0xed, 0xbe,
                0x22, 0xfe, 0x25, 0x4e, 0x33, 0xa1, 0xb0, 0xe9,
                0xf6, 0xb9, 0x82, 0x66, 0x75, 0xbe, 0xc7, 0xd0,
                0x1a, 0x84, 0x56, 0x58, 0xdc, 0x9c, 0x39, 0x75,
                0x45, 0x40, 0x1d, 0x40, 0xb9, 0xf4, 0x6c, 0x7a,
                0x40, 0x0e, 0xe1, 0xb8, 0xf8, 0x1c, 0xa0, 0xa6,
                0x0d, 0x1a, 0x39, 0x7a, 0x10, 0x28, 0xbf, 0xf5,
                0xd2, 0xef, 0x50, 0x66, 0x12, 0x68, 0x42, 0xfb,
                0x8d, 0xa4, 0x19, 0x76, 0x32, 0xbd, 0xb5, 0x4f,
                0xf6, 0x63, 0x3f, 0x86, 0xbb, 0xc8, 0x36, 0xe6,
                0x40, 0xd4, 0xd8, 0x98
            };

            PseudoRandomFunctionTLSGeneric prf = new PseudoRandomFunctionTLSGeneric("SHA512");
            byte[] ourOutput = prf.CreateDeriveBytes(secret, label, seed).GetBytes(output.Length);
            Assert.AreEqual(output, ourOutput);
        }
コード例 #11
0
        public void TestSha384v2()
        {
            byte[] secret = new byte[] {
                0x7A, 0xBF, 0xC4, 0x0A, 0x0C, 0x0E, 0x72, 0x52,
                0x96, 0x87, 0x71, 0x5F, 0x99, 0x80, 0xC8, 0x04,
                0xBE, 0x5C, 0xD6, 0x95, 0xA3, 0xCB, 0xD1, 0xD7,
                0xA0, 0x0D, 0xA6, 0x05, 0x30, 0x83, 0x11, 0x93,
                0x06, 0x9B, 0x8F, 0x4F, 0x6A, 0xD8, 0x74, 0x39,
                0xA7, 0xBE, 0x3B, 0xB3, 0x7B, 0x29, 0x24, 0x8C,
                0x3C, 0xBD, 0x8B, 0x8E, 0x0C, 0x57, 0x93, 0xF6,
                0x35, 0x11, 0x58, 0x52, 0xA3, 0x7E, 0x8E, 0xC6,
                0x1D, 0x70, 0xA2, 0x49, 0x7D, 0xD0, 0xDD, 0x60,
                0xA9, 0x20, 0x11, 0xC1, 0xCD, 0xCF, 0x8D, 0xC7,
                0xAC, 0x66, 0xE8, 0xC0, 0x15, 0x4D, 0xE5, 0x76,
                0x7E, 0x1E, 0xB3, 0xFF, 0x78, 0x99, 0x2E, 0x26,
                0x09, 0xCE, 0xC8, 0x43, 0xA1, 0x46, 0x0E, 0x71,
                0xCF, 0xF4, 0xF5, 0xEB, 0xBE, 0xFD, 0xF8, 0xF6,
                0x10, 0x91, 0xF3, 0x67, 0x8C, 0x12, 0xB8, 0xF9,
                0x72, 0x98, 0x61, 0x68, 0x59, 0x1D, 0x65, 0x5A
            };
            string label = "master secret";
            byte[] seed = new byte[] {
                0x4E, 0x79, 0xDE, 0x52, 0x25, 0xE4, 0xA5, 0xC0,
                0x37, 0xB1, 0x52, 0x40, 0x41, 0x30, 0x9E, 0x7D,
                0xE5, 0xD1, 0x06, 0x1A, 0x33, 0x7B, 0xFC, 0xCE,
                0x6B, 0x7F, 0xA7, 0x82, 0x9A, 0x5E, 0xC7, 0xFF,
                0x4E, 0x79, 0xE2, 0x02, 0x0F, 0x01, 0xD1, 0x77,
                0x88, 0x80, 0xCA, 0x52, 0x2F, 0xAC, 0x9F, 0x0A,
                0x6A, 0x6D, 0xEE, 0x5A, 0xB0, 0xB8, 0x45, 0x51,
                0xF7, 0xF0, 0x6D, 0xB9, 0x26, 0x78, 0x3D, 0xC7
            };
            byte[] output = new byte[] {
                0x69, 0xAE, 0xEA, 0x90, 0x22, 0xCE, 0xF8, 0x32,
                0xB1, 0xC0, 0x76, 0x33, 0x0F, 0x71, 0x96, 0x6A,
                0x64, 0x85, 0x86, 0x4D, 0x92, 0x09, 0x44, 0x06,
                0x0A, 0xB0, 0x27, 0x57, 0xC8, 0x5B, 0xD3, 0xC5,
                0xD4, 0x52, 0x9C, 0xE8, 0x44, 0xCC, 0x6C, 0xC0,
                0xC2, 0xC9, 0x5B, 0x49, 0x1D, 0xBC, 0xBC, 0x30
            };

            PseudoRandomFunctionTLSGeneric prf = new PseudoRandomFunctionTLSGeneric("SHA384");
            byte[] ourOutput = prf.CreateDeriveBytes(secret, label, seed).GetBytes(output.Length);
            Assert.AreEqual(output, ourOutput);
        }
コード例 #12
0
        public void TestVector()
        {
            byte[] encryptedKey = {
                0x00, 0x40, 0x51, 0x57, 0x5A, 0x26, 0x6D, 0xCC,
                0x65, 0x85, 0x55, 0xDE, 0x28, 0x01, 0x41, 0x62,
                0x13, 0x4F, 0x0A, 0xB4, 0xEF, 0x34, 0x99, 0x54,
                0x51, 0x9E, 0x4E, 0x6D, 0x21, 0x1B, 0xE9, 0x73,
                0x4C, 0xF8, 0x79, 0xF5, 0xBE, 0x71, 0x2D, 0x8F,
                0x22, 0xF7, 0x4E, 0x51, 0x49, 0x33, 0xD5, 0x0C,
                0x21, 0xC7, 0x17, 0xEE, 0x23, 0xA5, 0xD6, 0xA1,
                0x2C, 0x8D, 0xD2, 0x52, 0x5B, 0xE2, 0xC1, 0x10,
                0x8F, 0x14
            };
            string rsaKeys =
                "<RSAKeyValue>" +
                "<Modulus>nrum196jNc4CFruN2+6A/1S4XXdaYFDtuXuSVHUGfhINISX87ze7ASP4K4oq5qK8qux9wwndqB9ERD2ZuLBsfw==</Modulus>" +
                "<Exponent>EQ==</Exponent>" +
                "<P>/lOfBctf4yh0CwrxG1zJdQhjkLjq+ruy0uwJxiHolus=</P>" +
                "<Q>n8cEGYQH4J97W26zvq1xtXwKWDXpSDsPcSRijdYMw70=</Q>" +
                "<DP>wnwuT7mjrbWF6lOpUSjWSm/TqufCv7y17JZh07+TvrM=</DP>" +
                "<DQ>OGRbzMUv9Oz+XIFsnaagmmgDpqmdoQXJNv3IbkuMCNk=</DQ>" +
                "<InverseQ>xsbdvaSCbalm6wa8DtBMgOgWfbwPokwfnjQ1J0trre4=</InverseQ>" +
                "<D>QVxTwkydjqAe+k06aZ5xWhPTcce7zU6AARTDyGxsFcqIEb1qUN0pkAaWWE9dh+5pWyUQGyUhlFN4jc6kQE0HWQ==</D>" +
                "</RSAKeyValue>";
            byte[] masterSecret = {
                0xC9, 0xBC, 0x99, 0x08, 0xAA, 0x11, 0xFF, 0x63,
                0xBE, 0x01, 0xF4, 0x07, 0x0D, 0x37, 0x8E, 0xA0,
                0xE4, 0x1A, 0x30, 0x08, 0xAD, 0x08, 0xAC, 0xBA,
                0xEE, 0x37, 0xAA, 0xBD, 0x49, 0x28, 0x1C, 0xD6,
                0x7D, 0x2A, 0xBE, 0x55, 0x85, 0xA2, 0x30, 0x88,
                0xBE, 0xC9, 0xED, 0x76, 0x14, 0xDA, 0x6B, 0x1E
            };

            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);
            rsa.FromXmlString(rsaKeys);
            KeyExchangeAlgorithmRSA keyex = new KeyExchangeAlgorithmRSA();
            PseudoRandomFunctionTLSGeneric prf = new PseudoRandomFunctionTLSGeneric("SHA1");

            keyex.ProcessClientKeys(ProtocolVersion.TLS1_0, ProtocolVersion.TLS1_0, new CertificatePrivateKey(keyex.CertificateKeyAlgorithm, rsa), encryptedKey);
            byte[] master = keyex.GetMasterSecret(prf, new byte[32]);
            Assert.AreEqual (masterSecret, master);
        }