Exemplo n.º 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);
    }
Exemplo n.º 2
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);
    }
Exemplo n.º 3
0
    public void test_randombytes_buf_deterministic()
    {
        Console.WriteLine("Testing randombytes_buf_deterministic() .....");

        int size = 16;

        byte[] buf  = new byte[size];
        byte[] buf2 = new byte[size];
        byte[] buf3 = new byte[size];
        LibSalt.randombytes_buf_deterministic(buf, seed);
        LibSalt.randombytes_buf_deterministic(buf2, seed);
        LibSalt.randombytes_buf_deterministic(buf3, seed2);

        // Test for generating same randombyte arrays with same seeds
        UnitTest.ASSERT_SAME_DATA(buf, buf2);

        // Test for generating different randombyte arrays with different seeds
        UnitTest.ASSERT_DIFFERENT_DATA(buf, buf3);
        UnitTest.ASSERT_DIFFERENT_DATA(buf2, buf3);
    }