public void testEcDh()
        {
            byte[] p = new byte[32];
            byte[] q = null;
            byte[] n = new byte[32];

            p[0] = 100;
            n[0] = 100;

            n = curve25519.generatePrivateKey(n);

            for (int count = 0; count < 1000; count++)
            {
                q = curve25519.calculateAgreement(n, p);
                Array.Copy(q, 0, p, 0, 32);
                q = curve25519.calculateAgreement(n, p);
                Array.Copy(q, 0, n, 0, 32);
                n = curve25519.generatePrivateKey(n);
            }

            byte[] result = new byte[] {
                (byte)0xce, (byte)0xb4, (byte)0x4e, (byte)0xd6, (byte)0x4a,
                (byte)0xd4, (byte)0xc2, (byte)0xb5, (byte)0x43, (byte)0x9d,
                (byte)0x25, (byte)0xde, (byte)0xb1, (byte)0x10, (byte)0xa8,
                (byte)0xd7, (byte)0x2e, (byte)0xb3, (byte)0xe3, (byte)0x8e,
                (byte)0xf4, (byte)0x8a, (byte)0x42, (byte)0x73, (byte)0xb1,
                (byte)0x1b, (byte)0x4b, (byte)0x13, (byte)0x8d, (byte)0x17,
                (byte)0xf9, (byte)0x34
            };

            List <byte> qList      = new List <byte>(q);
            List <byte> resultList = new List <byte>(result);

            CollectionAssert.AreEqual(resultList, qList);
        }
Beispiel #2
0
        public void TestGenPrivKeyFromRandom()
        {
            byte[] randomBuffer = GetRandomBuffer(EXPECTED_LEN);
            byte[] privKeyBytes = curve25519.generatePrivateKey(randomBuffer);
            Assert.IsNotNull(privKeyBytes);
            Assert.AreEqual(EXPECTED_LEN, privKeyBytes.Length,
                            "This implementation should produce 32 byte private keys.");

            bool allZero = true;

            //force fail to test this logic
            //privKeyBytes = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            foreach (byte b in privKeyBytes)
            {
                if (!allZero)
                {
                    break;                     //early
                }
                if (b.CompareTo(0) != 0)
                {
                    allZero = false;
                }
            }
            Assert.IsFalse(allZero, "A private key shouldn't be all zeroes.");
        }
		public void TestECPublicKeyEquals()
		{
			curve25519.Curve25519Native native = new curve25519.Curve25519Native();
			byte[] privKey = native.generatePrivateKey();
			byte[] pubKey = native.generatePublicKey(privKey);
			DjbECPublicKey key1 = new DjbECPublicKey(pubKey);

			byte[] pubKey2 = native.generatePublicKey(privKey);

			Assert.IsTrue(StructuralComparisons.StructuralEqualityComparer.Equals(
					pubKey, pubKey2));

			DjbECPublicKey key2 = new DjbECPublicKey(pubKey2);

			Assert.IsTrue(key1.Equals(key2));

			int hash1 = key1.GetHashCode();
			int hash2 = key2.GetHashCode();

			Assert.AreEqual<int>(hash1, hash2);
		}
Beispiel #4
0
        public void TestECPublicKeyEquals()
        {
            curve25519.Curve25519Native native = new curve25519.Curve25519Native();
            byte[]         privKey             = native.generatePrivateKey();
            byte[]         pubKey = native.generatePublicKey(privKey);
            DjbECPublicKey key1   = new DjbECPublicKey(pubKey);

            byte[] pubKey2 = native.generatePublicKey(privKey);

            Assert.IsTrue(StructuralComparisons.StructuralEqualityComparer.Equals(
                              pubKey, pubKey2));

            DjbECPublicKey key2 = new DjbECPublicKey(pubKey2);

            Assert.IsTrue(key1.Equals(key2));

            int hash1 = key1.GetHashCode();
            int hash2 = key2.GetHashCode();

            Assert.AreEqual <int>(hash1, hash2);
        }
 public byte[] generatePrivateKey(byte[] random)
 {
     return(native.generatePrivateKey(random));
 }