GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
+ by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
#define ITER 25
+static int
+testCorrectKey ()
+{
+ const char *want = "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000";
+ GNUNET_HashCode in;
+ struct GNUNET_CRYPTO_RsaPrivateKey *hostkey;
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
+ int i;
+ char out[3];
+
+ fprintf (stderr, "Testing KBlock key correctness");
+ GNUNET_CRYPTO_hash ("X", strlen ("X"), &in);
+ hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
+ if (hostkey == NULL)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey);
+ GNUNET_CRYPTO_rsa_key_free (hostkey);
+#if 0
+ for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++)
+ printf("%02x", ((unsigned char*) &pkey)[i]);
+ printf ("\n");
+#endif
+ for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++)
+ {
+ snprintf(out, sizeof (out), "%02x", ((unsigned char*) &pkey)[i]);
+ if (0 != strncmp (out, &want[i*2], 2))
+ {
+ fprintf (stderr,
+ " Failed! Wanted %.2s but got %2s at %d\n",
+ &want[i*2],
+ out, i);
+ return GNUNET_SYSERR;
+ }
+ }
+ fprintf (stderr, " OK\n");
+ return GNUNET_OK;
+}
+
+
static int
testMultiKey (const char *word)
{
printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n",
ITER,
(unsigned long long)
- GNUNET_TIME_absolute_get_duration (start).value, ok);
+ GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
if (ok == 0)
return GNUNET_OK;
else
printf ("%d RSA sign/verify operations %llums\n",
ITER,
(unsigned long long)
- GNUNET_TIME_absolute_get_duration (start).value);
+ GNUNET_TIME_absolute_get_duration (start).rel_value);
return ok;
}
struct GNUNET_CRYPTO_RsaPrivateKey *hostkey;
GNUNET_log_setup ("test-crypto-ksk", "WARNING", NULL);
+ if (GNUNET_OK != testCorrectKey ())
+ failureCount++;
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &in);
hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
if (hostkey == NULL)
printf ("\nGNUNET_CRYPTO_rsa_key_create_from_hash failed!\n");
return 1;
}
-
if (GNUNET_OK != testMultiKey ("foo"))
failureCount++;
if (GNUNET_OK != testMultiKey ("bar"))