コード例 #1
0
ファイル: ECMQVTest.cs プロジェクト: kazuki/opencrypto.net
		public void Test_Random ()
		{
			ECDomainNames name = ECDomainNames.secp256r1;
			for (int i = 0; i < 10; i ++) {
				ECMQV ecmqv1 = new ECMQV (name);
				ECMQV ecmqv2 = new ECMQV (name);
				int keyDataLen = 20;

				byte[] key1 = ecmqv1.PerformKeyAgreement (ecmqv2.Parameters.KeyPair1.PublicKey, ecmqv2.Parameters.KeyPair2.PublicKey, keyDataLen);
				byte[] key2 = ecmqv2.PerformKeyAgreement (ecmqv1.Parameters.KeyPair1.PublicKey, ecmqv1.Parameters.KeyPair2.PublicKey, keyDataLen);
				Assert.AreEqual (key1, key2);
			}
		}
コード例 #2
0
ファイル: ECMQVTest.cs プロジェクト: kazuki/opencrypto.net
		public void Test_Random_with_SharedInfo ()
		{
			ECDomainNames name = ECDomainNames.secp256r1;
			for (int i = 0; i < 10; i++) {
				ECMQV ecmqv1 = new ECMQV (name);
				ECMQV ecmqv2 = new ECMQV (name);
				int keyDataLen = 20;

				byte[] sharedInfo = RNG.GetBytes (RNG.GetBytes (1)[0] + 1);
				ecmqv1.SharedInfo = sharedInfo;
				ecmqv2.SharedInfo = sharedInfo;

				byte[] key1 = ecmqv1.PerformKeyAgreement (ecmqv2.Parameters.KeyPair1.PublicKey, ecmqv2.Parameters.KeyPair2.PublicKey, keyDataLen);
				byte[] key2 = ecmqv2.PerformKeyAgreement (ecmqv1.Parameters.KeyPair1.PublicKey, ecmqv1.Parameters.KeyPair2.PublicKey, keyDataLen);
				Assert.AreEqual (key1, key2);
			}
		}
コード例 #3
0
ファイル: ECMQVTest.cs プロジェクト: kazuki/opencrypto.net
		public void Test_MQV ()
		{
			ECDomainNames name = ECDomainNames.secp160r1;
			ECMQV ecmqv1 = new ECMQV (name);
			ECMQV ecmqv2 = new ECMQV (name);
			int keyDataLen = 20;
			int keyBytes = 20;

			ecmqv1.Parameters.KeyPair1.PrivateKey = Number.Parse ("971761939728640320549601132085879836204587084162", 10).ToByteArray (keyBytes, false);
			ecmqv1.Parameters.KeyPair2.PrivateKey = Number.Parse ("117720748206090884214100397070943062470184499100", 10).ToByteArray (keyBytes, false);
			ecmqv2.Parameters.KeyPair1.PrivateKey = Number.Parse ("399525573676508631577122671218044116107572676710", 10).ToByteArray (keyBytes, false);
			ecmqv2.Parameters.KeyPair2.PrivateKey = Number.Parse ("141325380784931851783969312377642205317371311134", 10).ToByteArray (keyBytes, false);

			byte[] key1 = ecmqv1.PerformKeyAgreement (ecmqv2.Parameters.KeyPair1.PublicKey, ecmqv2.Parameters.KeyPair2.PublicKey, keyDataLen);
			byte[] key2 = ecmqv2.PerformKeyAgreement (ecmqv1.Parameters.KeyPair1.PublicKey, ecmqv1.Parameters.KeyPair2.PublicKey, keyDataLen);

			Assert.AreEqual (key1, key2, "#1");
			Assert.AreEqual (key1, Number.Parse ("C06763F8C3D2452C1CC5D29BD61918FB485063F6", 16).ToByteArray (keyDataLen, false), "#2");
		}