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); }
void example_crypto_sign() { Console.WriteLine("Example: example_crypto_sign()"); byte[] message = LibSalt.StringToByteArray("example"); ulong mlen = (ulong)message.Length; 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); Console.WriteLine("Public Key: " + LibSalt.ByteArrayToString(pk)); Console.WriteLine("Signed Message: " + LibSalt.ByteArrayToString(signed_message)); byte[] unsigned_message = new byte[mlen]; byte[] unsigned_message2 = new byte[mlen]; int success = LibSalt.crypto_sign_open(unsigned_message, signed_message, pk); int success2 = LibSalt.crypto_sign_open(unsigned_message2, signed_message, pk2); Console.WriteLine("Unsigned Message: " + LibSalt.ByteArrayToString(unsigned_message)); Console.WriteLine("Signature Verification for pk: " + LibSalt.ByteArrayToString(pk)); if (success == 0) { Console.WriteLine("Valid Signature"); } else { Console.WriteLine("Invalid signature"); } Console.WriteLine("Signature Verification for pk2: " + LibSalt.ByteArrayToString(pk2)); if (success2 == 0) { Console.WriteLine("Valid Signature"); } else { Console.WriteLine("Invalid signature"); } }