Пример #1
0
    public void test_crypto_sign()
    {
        Console.WriteLine("Testing crypto_sign() .....");

        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() + (ulong)mlen;

        byte[] signed_message  = new byte[smlen];
        byte[] signed_message2 = new byte[smlen];

        LibSalt.crypto_sign(signed_message, message, sk);
        LibSalt.crypto_sign(signed_message2, message, sk);

        // Test for proper signed message
        UnitTest.ASSERT_SAME_DATA(signed_message, signed_message2);
    }
Пример #2
0
    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);
    }
Пример #3
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");
        }
    }
Пример #4
0
    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);
    }
Пример #5
0
    public void example_crypto_sign_keypair()
    {
        Console.WriteLine("Example: 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);

        Console.WriteLine("Keypair One: ");
        Console.WriteLine("pk: " + LibSalt.ByteArrayToString(pk));
        Console.WriteLine("sk: " + LibSalt.ByteArrayToString(sk));

        Console.WriteLine("Keypair Two: ");
        Console.WriteLine("pk: " + LibSalt.ByteArrayToString(pk2));
        Console.WriteLine("sk: " + LibSalt.ByteArrayToString(sk2));
        Console.WriteLine();
    }