From 870c6d65864ff8265c5e4863529df4a44f99e1b1 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Tue, 26 May 2020 10:50:23 +0200 Subject: test vectors in binary --- src/revocation/gnunet-revocation-tvg.c | 42 +++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'src/revocation/gnunet-revocation-tvg.c') diff --git a/src/revocation/gnunet-revocation-tvg.c b/src/revocation/gnunet-revocation-tvg.c index 2b850e436..b8f462b28 100644 --- a/src/revocation/gnunet-revocation-tvg.c +++ b/src/revocation/gnunet-revocation-tvg.c @@ -34,6 +34,22 @@ #define TEST_EPOCHS 2 #define TEST_DIFFICULTY 5 +static void +print_bytes (void *buf, + size_t buf_len, + int fold) +{ + int i; + + for (i = 0; i < buf_len; i++) + { + if ((0 != i) && (0 != fold) && (i%fold == 0)) + printf("\n"); + printf("%02x", ((unsigned char*)buf)[i]); + } + printf("\n"); +} + /** * Main function that will be run. * @@ -53,21 +69,16 @@ run (void *cls, struct GNUNET_REVOCATION_PowP pow; struct GNUNET_REVOCATION_PowCalculationHandle *ph; struct GNUNET_TIME_Relative exp; - char* data_enc; GNUNET_CRYPTO_ecdsa_key_create (&id_priv); GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv, &id_pub); - GNUNET_STRINGS_base64_encode (&id_priv, - sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), - &data_enc); - fprintf(stdout, "Zone private key (d):\n%s\n\n", data_enc); - GNUNET_free (data_enc); - GNUNET_STRINGS_base64_encode (&id_pub, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), - &data_enc); - fprintf(stdout, "Zone public key (zk):\n%s\n\n", data_enc); - GNUNET_free (data_enc); + fprintf(stdout, "Zone private key (d, little-endian scalar):\n"); + print_bytes (&id_priv, sizeof(id_priv), 0); + fprintf(stdout, "\n"); + fprintf(stdout, "Zone public key (zk):\n"); + print_bytes (&id_pub, sizeof(id_pub), 0); + fprintf(stdout, "\n"); memset (&pow, 0, sizeof (pow)); GNUNET_REVOCATION_pow_init (&id_priv, &pow); @@ -88,11 +99,10 @@ run (void *cls, GNUNET_assert (GNUNET_OK == GNUNET_REVOCATION_check_pow (&pow, TEST_DIFFICULTY, exp)); - GNUNET_STRINGS_base64_encode (&pow, - sizeof (struct GNUNET_REVOCATION_PowP), - &data_enc); - fprintf(stdout, "Proof:\n%s\n", data_enc); - GNUNET_free (data_enc); + fprintf(stdout, "Proof:\n"); + print_bytes (&pow, + sizeof (pow), + 8); } -- cgit v1.2.3