public void Test_fcontract()
        {
            long [] input = new long[] {
                0x0000000001212121,
                0x0000000000484848,
                0x0000000000242424,
                0x0000000001090909,
                0x0000000000848484,
                0x0000000001212121,
                0x0000000000909090,
                0x0000000000242424,
                0x0000000002121212,
                0x0000000000848484
            };
            byte[] output = new byte[32];

            Curve25519Donna.fcontract(output, input);

            byte[] expected_key = new byte[] {
                0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
                0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21
            };

            for (int i = 0; i < 32; i++)
            {
                Assert.AreEqual <long>(expected_key[i], output[i]);
            }
        }
 public void Test_fexpand()
 {
     long [] output    = new long[19];
     byte[]  input_key = new byte[] {
         0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
         0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21
     };
     Curve25519Donna.fexpand(output, input_key);
     long[] expected = new long[] {
         0x0000000001212121,
         0x0000000000484848,
         0x0000000000242424,
         0x0000000001090909,
         0x0000000000848484,
         0x0000000001212121,
         0x0000000000909090,
         0x0000000000242424,
         0x0000000002121212,
         0x0000000000848484
     };
     for (int i = 0; i < 10; i++)
     {
         Assert.AreEqual <long>(expected[i], output[i]);
     }
 }
        public void Test_s32_eq()
        {
            int same      = Curve25519Donna.s32_eq(11, 11);
            int different = Curve25519Donna.s32_eq(13, 32);

            Assert.AreEqual <int>(0, different);
            Assert.AreEqual <int>(-1, same); //0xFFFFFFFF
        }
        public void Test_s32_gte()
        {
            int bigger = Curve25519Donna.s32_gte(3, 2);
            int same   = Curve25519Donna.s32_gte(5000, 5000);
            int less   = Curve25519Donna.s32_gte(4999, 10001);

            Assert.AreEqual <int>(-1, bigger);
            Assert.AreEqual <int>(-1, same);
            Assert.AreEqual <int>(0, less);
        }
        public void Test_swap_conditional()
        {
            long[] incrementing = new long[19];
            for (int i = 0; i < 19; i++)
            {
                incrementing[i] = i + 1;
            }
            long[] decrementing = new long[19];
            int    j            = 19;

            for (int i = 0; i < 19; i++)
            {
                decrementing[i] = j;
                j--;
            }
            long[] inc = (long[])incrementing.Clone();
            long[] dec = (long[])decrementing.Clone();

            //First-run, don't swap (iswap = 0)
            Curve25519Donna.swap_conditional(inc, dec, 0);

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual <long>(i + 1, inc[i]);
            }
            j = 19;
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual <long>(j, dec[i]);
                j--;
            }

            //Now swap (iswap = 1)
            Curve25519Donna.swap_conditional(inc, dec, 1);

            //First 10 places of each should have swapped, making this nicely symmetrical output
            long [] inc_expected = new long[] {
                19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
            };
            long[] dec_expected = new long[] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
            };

            for (int i = 0; i < 19; i++)
            {
                Assert.AreEqual <long>(inc_expected[i], inc[i]);
            }
            for (int i = 0; i < 19; i++)
            {
                Assert.AreEqual <long>(dec_expected[i], dec[i]);
            }
        }
 public override byte[] calculateAgreement(byte[] ourPrivate, byte[] theirPublic)
 {
     byte[] sharedKeyAgreement = new byte[32];
     Curve25519Donna.curve25519_donna(sharedKeyAgreement, ourPrivate, theirPublic);
     return(sharedKeyAgreement);
 }
 public override byte[] generatePublicKey(byte[] privateKey)
 {
     byte[] publicKey = new byte[32];
     Curve25519Donna.curve25519_donna(publicKey, privateKey, basepoint);
     return(publicKey);
 }