public void testKeyGen()
        {
            byte[] keyIn  = new byte[32];
            byte[] keyOut = null;

            keyIn[0] = 123;

            for (int count = 0; count < 1000; count++)
            {
                keyOut = curve25519.generatePublicKey(keyIn);
                Array.Copy(keyOut, 0, keyIn, 0, EXPECTED_LEN);
            }

            byte[] result2 = new byte[] {
                (byte)0xa2, (byte)0x3c, (byte)0x84, (byte)0x09, (byte)0xf2,
                (byte)0x93, (byte)0xb4, (byte)0x42, (byte)0x6a, (byte)0xf5,
                (byte)0xe5, (byte)0xe7, (byte)0xca, (byte)0xee, (byte)0x22,
                (byte)0xa0, (byte)0x01, (byte)0xc7, (byte)0x9a, (byte)0xca,
                (byte)0x1a, (byte)0xf2, (byte)0xea, (byte)0xcb, (byte)0x4d,
                (byte)0xdd, (byte)0xfa, (byte)0x05, (byte)0xf8, (byte)0xbc,
                (byte)0x7f, (byte)0x37
            };



            List <byte> keyOutList  = new List <byte>(keyOut);
            List <byte> result2List = new List <byte>(result2);

            CollectionAssert.AreEqual(result2, keyOut);
        }
Beispiel #2
0
        public void TestGenPublicKeyFromPrivateKey()
        {
            byte[] randomBuffer = GetRandomBuffer(EXPECTED_LEN);
            byte[] privKeyBytes = curve25519.generatePrivateKey(randomBuffer);

            byte[] publicKeyBytes = curve25519.generatePublicKey(privKeyBytes);
            Assert.IsNotNull(publicKeyBytes);
            Assert.AreEqual <int>(EXPECTED_LEN, publicKeyBytes.Length);

            bool allZero = true;

            //force fail to test this logic
            //publicKeyBytes = 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 public 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[] generatePublicKey(byte[] privateKey)
 {
     return(native.generatePublicKey(privateKey));
 }