aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-crypto-tvg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/gnunet-crypto-tvg.c')
-rw-r--r--src/util/gnunet-crypto-tvg.c124
1 files changed, 90 insertions, 34 deletions
diff --git a/src/util/gnunet-crypto-tvg.c b/src/util/gnunet-crypto-tvg.c
index 8949f427c..28e44e28b 100644
--- a/src/util/gnunet-crypto-tvg.c
+++ b/src/util/gnunet-crypto-tvg.c
@@ -128,6 +128,7 @@ d2j (json_t *vec,
128 json_object_set_new (vec, label, json); 128 json_object_set_new (vec, label, json);
129} 129}
130 130
131
131/** 132/**
132 * Add a number to a test vector. 133 * Add a number to a test vector.
133 * 134 *
@@ -138,8 +139,8 @@ d2j (json_t *vec,
138 */ 139 */
139static void 140static void
140uint2j (json_t *vec, 141uint2j (json_t *vec,
141 const char *label, 142 const char *label,
142 unsigned int num) 143 unsigned int num)
143{ 144{
144 json_t *json = json_integer (num); 145 json_t *json = json_integer (num);
145 146
@@ -154,7 +155,7 @@ expect_data_fixed (json_t *vec,
154 size_t expect_len) 155 size_t expect_len)
155{ 156{
156 const char *s = json_string_value (json_object_get (vec, name)); 157 const char *s = json_string_value (json_object_get (vec, name));
157 158
158 if (NULL == s) 159 if (NULL == s)
159 return GNUNET_NO; 160 return GNUNET_NO;
160 161
@@ -166,6 +167,7 @@ expect_data_fixed (json_t *vec,
166 return GNUNET_OK; 167 return GNUNET_OK;
167} 168}
168 169
170
169static int 171static int
170expect_data_dynamic (json_t *vec, 172expect_data_dynamic (json_t *vec,
171 const char *name, 173 const char *name,
@@ -173,6 +175,7 @@ expect_data_dynamic (json_t *vec,
173 size_t *ret_len) 175 size_t *ret_len)
174{ 176{
175 const char *s = json_string_value (json_object_get (vec, name)); 177 const char *s = json_string_value (json_object_get (vec, name));
178 char *tmp;
176 size_t len; 179 size_t len;
177 180
178 if (NULL == s) 181 if (NULL == s)
@@ -181,10 +184,14 @@ expect_data_dynamic (json_t *vec,
181 len = (strlen (s) * 5) / 8; 184 len = (strlen (s) * 5) / 8;
182 if (NULL != ret_len) 185 if (NULL != ret_len)
183 *ret_len = len; 186 *ret_len = len;
184 *data = GNUNET_malloc (len); 187 tmp = GNUNET_malloc (len);
185 188
186 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (s, strlen (s), *data, len)) 189 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (s, strlen (s), tmp, len))
190 {
191 GNUNET_free (tmp);
187 return GNUNET_NO; 192 return GNUNET_NO;
193 }
194 *data = tmp;
188 return GNUNET_OK; 195 return GNUNET_OK;
189} 196}
190 197
@@ -197,7 +204,7 @@ expect_data_dynamic (json_t *vec,
197 * 204 *
198 * @returns GNUNET_OK if the vector is okay 205 * @returns GNUNET_OK if the vector is okay
199 */ 206 */
200static int 207static int
201checkvec (const char *operation, 208checkvec (const char *operation,
202 json_t *vec) 209 json_t *vec)
203{ 210{
@@ -220,10 +227,11 @@ checkvec (const char *operation,
220 return GNUNET_SYSERR; 227 return GNUNET_SYSERR;
221 } 228 }
222 if (GNUNET_OK != expect_data_fixed (vec, 229 if (GNUNET_OK != expect_data_fixed (vec,
223 "output", 230 "output",
224 &hash_out, 231 &hash_out,
225 sizeof (hash_out))) 232 sizeof (hash_out)))
226 { 233 {
234 GNUNET_free (data);
227 GNUNET_break (0); 235 GNUNET_break (0);
228 return GNUNET_NO; 236 return GNUNET_NO;
229 } 237 }
@@ -232,9 +240,11 @@ checkvec (const char *operation,
232 240
233 if (0 != GNUNET_memcmp (&hc, &hash_out)) 241 if (0 != GNUNET_memcmp (&hc, &hash_out))
234 { 242 {
243 GNUNET_free (data);
235 GNUNET_break (0); 244 GNUNET_break (0);
236 return GNUNET_NO; 245 return GNUNET_NO;
237 } 246 }
247 GNUNET_free (data);
238 } 248 }
239 else if (0 == strcmp (operation, "ecc_ecdh")) 249 else if (0 == strcmp (operation, "ecc_ecdh"))
240 { 250 {
@@ -245,33 +255,33 @@ checkvec (const char *operation,
245 struct GNUNET_HashCode skm_comp; 255 struct GNUNET_HashCode skm_comp;
246 256
247 if (GNUNET_OK != expect_data_fixed (vec, 257 if (GNUNET_OK != expect_data_fixed (vec,
248 "priv1", 258 "priv1",
249 &priv1, 259 &priv1,
250 sizeof (priv1))) 260 sizeof (priv1)))
251 { 261 {
252 GNUNET_break (0); 262 GNUNET_break (0);
253 return GNUNET_NO; 263 return GNUNET_NO;
254 } 264 }
255 if (GNUNET_OK != expect_data_fixed (vec, 265 if (GNUNET_OK != expect_data_fixed (vec,
256 "priv2", 266 "priv2",
257 &priv2, 267 &priv2,
258 sizeof (priv2))) 268 sizeof (priv2)))
259 { 269 {
260 GNUNET_break (0); 270 GNUNET_break (0);
261 return GNUNET_NO; 271 return GNUNET_NO;
262 } 272 }
263 if (GNUNET_OK != expect_data_fixed (vec, 273 if (GNUNET_OK != expect_data_fixed (vec,
264 "pub1", 274 "pub1",
265 &pub1, 275 &pub1,
266 sizeof (pub1))) 276 sizeof (pub1)))
267 { 277 {
268 GNUNET_break (0); 278 GNUNET_break (0);
269 return GNUNET_NO; 279 return GNUNET_NO;
270 } 280 }
271 if (GNUNET_OK != expect_data_fixed (vec, 281 if (GNUNET_OK != expect_data_fixed (vec,
272 "skm", 282 "skm",
273 &skm, 283 &skm,
274 sizeof (skm))) 284 sizeof (skm)))
275 { 285 {
276 GNUNET_break (0); 286 GNUNET_break (0);
277 return GNUNET_NO; 287 return GNUNET_NO;
@@ -407,6 +417,8 @@ checkvec (const char *operation,
407 &ikm, 417 &ikm,
408 &ikm_len)) 418 &ikm_len))
409 { 419 {
420 GNUNET_free (out);
421 GNUNET_free (out_comp);
410 GNUNET_break (0); 422 GNUNET_break (0);
411 return GNUNET_SYSERR; 423 return GNUNET_SYSERR;
412 } 424 }
@@ -416,6 +428,9 @@ checkvec (const char *operation,
416 &salt, 428 &salt,
417 &salt_len)) 429 &salt_len))
418 { 430 {
431 GNUNET_free (out);
432 GNUNET_free (out_comp);
433 GNUNET_free (ikm);
419 GNUNET_break (0); 434 GNUNET_break (0);
420 return GNUNET_SYSERR; 435 return GNUNET_SYSERR;
421 } 436 }
@@ -425,6 +440,10 @@ checkvec (const char *operation,
425 &ctx, 440 &ctx,
426 &ctx_len)) 441 &ctx_len))
427 { 442 {
443 GNUNET_free (out);
444 GNUNET_free (out_comp);
445 GNUNET_free (ikm);
446 GNUNET_free (salt);
428 GNUNET_break (0); 447 GNUNET_break (0);
429 return GNUNET_SYSERR; 448 return GNUNET_SYSERR;
430 } 449 }
@@ -442,10 +461,19 @@ checkvec (const char *operation,
442 461
443 if (0 != memcmp (out, out_comp, out_len)) 462 if (0 != memcmp (out, out_comp, out_len))
444 { 463 {
464 GNUNET_free (out);
465 GNUNET_free (out_comp);
466 GNUNET_free (ikm);
467 GNUNET_free (salt);
468 GNUNET_free (ctx);
445 GNUNET_break (0); 469 GNUNET_break (0);
446 return GNUNET_NO; 470 return GNUNET_NO;
447 } 471 }
448 472 GNUNET_free (out);
473 GNUNET_free (out_comp);
474 GNUNET_free (ikm);
475 GNUNET_free (salt);
476 GNUNET_free (ctx);
449 } 477 }
450 else if (0 == strcmp (operation, "eddsa_ecdh")) 478 else if (0 == strcmp (operation, "eddsa_ecdh"))
451 { 479 {
@@ -562,6 +590,7 @@ checkvec (const char *operation,
562 &public_enc_data, 590 &public_enc_data,
563 &public_enc_len)) 591 &public_enc_len))
564 { 592 {
593 GNUNET_free (blinded_data);
565 GNUNET_break (0); 594 GNUNET_break (0);
566 return GNUNET_SYSERR; 595 return GNUNET_SYSERR;
567 } 596 }
@@ -571,6 +600,8 @@ checkvec (const char *operation,
571 &secret_enc_data, 600 &secret_enc_data,
572 &secret_enc_len)) 601 &secret_enc_len))
573 { 602 {
603 GNUNET_free (blinded_data);
604 GNUNET_free (public_enc_data);
574 GNUNET_break (0); 605 GNUNET_break (0);
575 return GNUNET_SYSERR; 606 return GNUNET_SYSERR;
576 } 607 }
@@ -580,6 +611,9 @@ checkvec (const char *operation,
580 &sig_enc_data, 611 &sig_enc_data,
581 &sig_enc_length)) 612 &sig_enc_length))
582 { 613 {
614 GNUNET_free (blinded_data);
615 GNUNET_free (public_enc_data);
616 GNUNET_free (secret_enc_data);
583 GNUNET_break (0); 617 GNUNET_break (0);
584 return GNUNET_SYSERR; 618 return GNUNET_SYSERR;
585 } 619 }
@@ -601,6 +635,11 @@ checkvec (const char *operation,
601 blinded_data_comp, 635 blinded_data_comp,
602 blinded_len)) ) 636 blinded_len)) )
603 { 637 {
638 GNUNET_free (blinded_data);
639 GNUNET_free (public_enc_data);
640 GNUNET_free (secret_enc_data);
641 GNUNET_free (sig_enc_data);
642 GNUNET_free (skey);
604 GNUNET_break (0); 643 GNUNET_break (0);
605 return GNUNET_NO; 644 return GNUNET_NO;
606 } 645 }
@@ -611,14 +650,27 @@ checkvec (const char *operation,
611 pkey)); 650 pkey));
612 public_enc_len = GNUNET_CRYPTO_rsa_public_key_encode (pkey, 651 public_enc_len = GNUNET_CRYPTO_rsa_public_key_encode (pkey,
613 &public_enc_data); 652 &public_enc_data);
614 sig_enc_length_comp = GNUNET_CRYPTO_rsa_signature_encode (sig, &sig_enc_data_comp); 653 sig_enc_length_comp = GNUNET_CRYPTO_rsa_signature_encode (sig,
654 &sig_enc_data_comp);
615 655
616 if ( (sig_enc_length != sig_enc_length_comp) || 656 if ( (sig_enc_length != sig_enc_length_comp) ||
617 (0 != memcmp (sig_enc_data, sig_enc_data_comp, sig_enc_length) )) 657 (0 != memcmp (sig_enc_data, sig_enc_data_comp, sig_enc_length) ))
618 { 658 {
659 GNUNET_free (blinded_sig);
660 GNUNET_free (blinded_data);
661 GNUNET_free (public_enc_data);
662 GNUNET_free (secret_enc_data);
663 GNUNET_free (sig_enc_data);
664 GNUNET_free (skey);
619 GNUNET_break (0); 665 GNUNET_break (0);
620 return GNUNET_NO; 666 return GNUNET_NO;
621 } 667 }
668 GNUNET_free (blinded_sig);
669 GNUNET_free (blinded_data);
670 GNUNET_free (public_enc_data);
671 GNUNET_free (secret_enc_data);
672 GNUNET_free (sig_enc_data);
673 GNUNET_free (skey);
622 } 674 }
623 else 675 else
624 { 676 {
@@ -629,6 +681,7 @@ checkvec (const char *operation,
629 return GNUNET_OK; 681 return GNUNET_OK;
630} 682}
631 683
684
632/** 685/**
633 * Check test vectors from stdin. 686 * Check test vectors from stdin.
634 * 687 *
@@ -656,7 +709,7 @@ check_vectors ()
656 return 1; 709 return 1;
657 } 710 }
658 vectors = json_object_get (vecfile, "vectors"); 711 vectors = json_object_get (vecfile, "vectors");
659 if (!json_is_array (vectors)) 712 if (! json_is_array (vectors))
660 { 713 {
661 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bad vectors\n"); 714 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bad vectors\n");
662 json_decref (vecfile); 715 json_decref (vecfile);
@@ -692,6 +745,7 @@ check_vectors ()
692 } 745 }
693} 746}
694 747
748
695/** 749/**
696 * Output test vectors. 750 * Output test vectors.
697 * 751 *
@@ -868,20 +922,20 @@ output_vectors ()
868 GNUNET_CRYPTO_ecdh_eddsa (&priv_ecdhe, &pub_eddsa, &key_material); 922 GNUNET_CRYPTO_ecdh_eddsa (&priv_ecdhe, &pub_eddsa, &key_material);
869 923
870 d2j (vec, "priv_ecdhe", 924 d2j (vec, "priv_ecdhe",
871 &priv_ecdhe, 925 &priv_ecdhe,
872 sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); 926 sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
873 d2j (vec, "pub_ecdhe", 927 d2j (vec, "pub_ecdhe",
874 &pub_ecdhe, 928 &pub_ecdhe,
875 sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); 929 sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
876 d2j (vec, "priv_eddsa", 930 d2j (vec, "priv_eddsa",
877 &priv_eddsa, 931 &priv_eddsa,
878 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); 932 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
879 d2j (vec, "pub_eddsa", 933 d2j (vec, "pub_eddsa",
880 &pub_eddsa, 934 &pub_eddsa,
881 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); 935 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
882 d2j (vec, "key_material", 936 d2j (vec, "key_material",
883 &key_material, 937 &key_material,
884 sizeof (struct GNUNET_HashCode)); 938 sizeof (struct GNUNET_HashCode));
885 } 939 }
886 940
887 { 941 {
@@ -968,6 +1022,7 @@ output_vectors ()
968 GNUNET_free (blinded_data); 1022 GNUNET_free (blinded_data);
969 GNUNET_free (sig_enc_data); 1023 GNUNET_free (sig_enc_data);
970 GNUNET_free (blinded_sig_enc_data); 1024 GNUNET_free (blinded_sig_enc_data);
1025 GNUNET_free (secret_enc_data);
971 } 1026 }
972 1027
973 json_dumpf (vecfile, stdout, JSON_INDENT (2)); 1028 json_dumpf (vecfile, stdout, JSON_INDENT (2));
@@ -977,6 +1032,7 @@ output_vectors ()
977 return 0; 1032 return 0;
978} 1033}
979 1034
1035
980/** 1036/**
981 * Main function that will be run. 1037 * Main function that will be run.
982 * 1038 *