void test_crypto_sign_open() { Console.WriteLine("Testing crypto_sign_open() ....."); byte[] message = LibSalt.StringToByteArray("test"); ulong mlen = 4; byte[] pk = new byte[crypto_sign_PUBLICKEYBYTES]; byte[] sk = new byte[crypto_sign_SECRETKEYBYTES]; byte[] pk2 = new byte[crypto_sign_PUBLICKEYBYTES]; byte[] sk2 = new byte[crypto_sign_SECRETKEYBYTES]; LibSalt.crypto_sign_keypair(pk, sk); LibSalt.crypto_sign_keypair(pk2, sk2); ulong smlen = (ulong)LibSalt.crypto_sign_BYTES() + mlen; byte[] signed_message = new byte[smlen]; LibSalt.crypto_sign(signed_message, message, sk); byte[] unsigned_message = new byte[mlen]; int success = LibSalt.crypto_sign_open(unsigned_message, signed_message, pk); int success2 = LibSalt.crypto_sign_open(unsigned_message, signed_message, pk2); // Test for sucessful decoding signed message with correct private key UnitTest.ASSERT_EQUALS(success, 0); // Test for unsucessful decoding signed message with incorrect private key UnitTest.ASSERT_DIFFERS(success2, 0); }
public void test_crypto_sign_seed_keypair() { Console.WriteLine("Testing crypto_sign_seed_keypair() ....."); byte[] pk = new byte[crypto_sign_PUBLICKEYBYTES]; byte[] sk = new byte[crypto_sign_SECRETKEYBYTES]; byte[] pk2 = new byte[crypto_sign_PUBLICKEYBYTES]; byte[] sk2 = new byte[crypto_sign_SECRETKEYBYTES]; LibSalt.crypto_sign_seed_keypair(pk, sk, seed); LibSalt.crypto_sign_seed_keypair(pk2, sk2, seed); // Test for proper pk and sk array sizes UnitTest.ASSERT_EQUALS(pk.Length, crypto_sign_PUBLICKEYBYTES); UnitTest.ASSERT_EQUALS(sk.Length, crypto_sign_SECRETKEYBYTES); // Test for generating same pk/sk for same seed UnitTest.ASSERT_SAME_DATA(pk, pk2); UnitTest.ASSERT_SAME_DATA(sk, sk2); }
public void test_crypto_sign_keypair() { Console.WriteLine("Testing crypto_sign_keypair() ....."); byte[] pk = new byte[crypto_sign_PUBLICKEYBYTES]; byte[] sk = new byte[crypto_sign_SECRETKEYBYTES]; byte[] pk2 = new byte[crypto_sign_PUBLICKEYBYTES]; byte[] sk2 = new byte[crypto_sign_SECRETKEYBYTES]; LibSalt.crypto_sign_keypair(pk, sk); LibSalt.crypto_sign_keypair(pk2, sk2); // Test for proper pk and sk array sizes UnitTest.ASSERT_EQUALS(pk.Length, crypto_sign_PUBLICKEYBYTES); UnitTest.ASSERT_EQUALS(sk.Length, crypto_sign_SECRETKEYBYTES); // Test for generating different random pk/sk UnitTest.ASSERT_DIFFERENT_DATA(pk, pk2); UnitTest.ASSERT_DIFFERENT_DATA(sk, sk2); }