diff options
Diffstat (limited to 'src/revocation/gnunet-revocation-tvg.c')
-rw-r--r-- | src/revocation/gnunet-revocation-tvg.c | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/src/revocation/gnunet-revocation-tvg.c b/src/revocation/gnunet-revocation-tvg.c index cb5e31fcd..3ba5b56fa 100644 --- a/src/revocation/gnunet-revocation-tvg.c +++ b/src/revocation/gnunet-revocation-tvg.c | |||
@@ -29,15 +29,39 @@ | |||
29 | #include "gnunet_revocation_service.h" | 29 | #include "gnunet_revocation_service.h" |
30 | #include "gnunet_dnsparser_lib.h" | 30 | #include "gnunet_dnsparser_lib.h" |
31 | #include "gnunet_testing_lib.h" | 31 | #include "gnunet_testing_lib.h" |
32 | #include "revocation.h" | ||
32 | #include <inttypes.h> | 33 | #include <inttypes.h> |
33 | 34 | ||
34 | #define TEST_EPOCHS 2 | 35 | #define TEST_EPOCHS 2 |
35 | #define TEST_DIFFICULTY 5 | 36 | #define TEST_DIFFICULTY 5 |
36 | 37 | ||
38 | static char* d_pkey = | ||
39 | "6fea32c05af58bfa979553d188605fd57d8bf9cc263b78d5f7478c07b998ed70"; | ||
40 | |||
41 | int parsehex(char *src, char *dst, size_t dstlen, int invert) | ||
42 | { | ||
43 | char *line = src; | ||
44 | char *data = line; | ||
45 | int off; | ||
46 | int read_byte; | ||
47 | int data_len = 0; | ||
48 | |||
49 | while (sscanf(data, " %02x%n", &read_byte, &off) == 1) { | ||
50 | if (invert) | ||
51 | dst[dstlen - 1 - data_len++] = read_byte; | ||
52 | else | ||
53 | dst[data_len++] = read_byte; | ||
54 | data += off; | ||
55 | } | ||
56 | return data_len; | ||
57 | } | ||
58 | |||
59 | |||
37 | static void | 60 | static void |
38 | print_bytes (void *buf, | 61 | print_bytes_ (void *buf, |
39 | size_t buf_len, | 62 | size_t buf_len, |
40 | int fold) | 63 | int fold, |
64 | int in_be) | ||
41 | { | 65 | { |
42 | int i; | 66 | int i; |
43 | 67 | ||
@@ -45,11 +69,23 @@ print_bytes (void *buf, | |||
45 | { | 69 | { |
46 | if ((0 != i) && (0 != fold) && (i % fold == 0)) | 70 | if ((0 != i) && (0 != fold) && (i % fold == 0)) |
47 | printf ("\n"); | 71 | printf ("\n"); |
48 | printf ("%02x", ((unsigned char*) buf)[i]); | 72 | if (in_be) |
73 | printf ("%02x", ((unsigned char*) buf)[buf_len - 1 - i]); | ||
74 | else | ||
75 | printf ("%02x", ((unsigned char*) buf)[i]); | ||
49 | } | 76 | } |
50 | printf ("\n"); | 77 | printf ("\n"); |
51 | } | 78 | } |
52 | 79 | ||
80 | static void | ||
81 | print_bytes (void *buf, | ||
82 | size_t buf_len, | ||
83 | int fold) | ||
84 | { | ||
85 | print_bytes_ (buf, buf_len, fold, 0); | ||
86 | } | ||
87 | |||
88 | |||
53 | 89 | ||
54 | /** | 90 | /** |
55 | * Main function that will be run. | 91 | * Main function that will be run. |
@@ -74,16 +110,17 @@ run (void *cls, | |||
74 | 110 | ||
75 | id_priv.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA); | 111 | id_priv.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA); |
76 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); | 112 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); |
113 | parsehex(d_pkey,(char*)&id_priv.ecdsa_key, sizeof (id_priv.ecdsa_key), 1); | ||
77 | GNUNET_IDENTITY_key_get_public (&id_priv, | 114 | GNUNET_IDENTITY_key_get_public (&id_priv, |
78 | &id_pub); | 115 | &id_pub); |
79 | GNUNET_STRINGS_data_to_string (&id_pub, | 116 | GNUNET_STRINGS_data_to_string (&id_pub, |
80 | GNUNET_IDENTITY_key_get_length (&id_pub), | 117 | GNUNET_IDENTITY_key_get_length (&id_pub), |
81 | ztld, | 118 | ztld, |
82 | sizeof (ztld)); | 119 | sizeof (ztld)); |
83 | fprintf (stdout, "Zone private key (d, little-endian scalar, with ztype prepended):\n"); | 120 | fprintf (stdout, "Zone private key (d, big-endian scalar):\n"); |
84 | print_bytes (&id_priv, sizeof(id_priv), 8); | 121 | print_bytes_ (&id_priv.ecdsa_key, sizeof(id_priv.ecdsa_key), 8, 1); |
85 | fprintf (stdout, "\n"); | 122 | fprintf (stdout, "\n"); |
86 | fprintf (stdout, "Zone identifier (zid):\n"); | 123 | fprintf (stdout, "Zone identifier (ztype|zkey):\n"); |
87 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); | 124 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); |
88 | fprintf (stdout, "\n"); | 125 | fprintf (stdout, "\n"); |
89 | fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n"); | 126 | fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n"); |
@@ -104,6 +141,15 @@ run (void *cls, | |||
104 | { | 141 | { |
105 | pow_passes++; | 142 | pow_passes++; |
106 | } | 143 | } |
144 | struct GNUNET_REVOCATION_SignaturePurposePS *purp; | ||
145 | purp = REV_create_signature_message (pow); | ||
146 | fprintf (stdout, "Signed message:\n"); | ||
147 | print_bytes (purp, | ||
148 | ntohl (purp->purpose.size), | ||
149 | 8); | ||
150 | printf ("\n"); | ||
151 | GNUNET_free (purp); | ||
152 | |||
107 | exp = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | 153 | exp = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, |
108 | TEST_EPOCHS); | 154 | TEST_EPOCHS); |
109 | GNUNET_assert (GNUNET_OK == GNUNET_REVOCATION_check_pow (pow, | 155 | GNUNET_assert (GNUNET_OK == GNUNET_REVOCATION_check_pow (pow, |