diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2021-05-03 18:49:17 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2021-05-03 18:49:17 +0200 |
commit | d552acf5e7114f92d8251276ef76827a9db92257 (patch) | |
tree | 4b5ed54763b6acbd8292d52ef9fda9a789c56ec8 /src/gnsrecord | |
parent | 5bb2578678064ff4d537fcbc8d9a552a6779892d (diff) | |
download | gnunet-d552acf5e7114f92d8251276ef76827a9db92257.tar.gz gnunet-d552acf5e7114f92d8251276ef76827a9db92257.zip |
-add more tests for eddsa and gnsrecord
Diffstat (limited to 'src/gnsrecord')
-rw-r--r-- | src/gnsrecord/gnsrecord_crypto.c | 23 | ||||
-rw-r--r-- | src/gnsrecord/gnsrecord_misc.c | 2 | ||||
-rw-r--r-- | src/gnsrecord/test_gnsrecord_crypto.c | 22 |
3 files changed, 24 insertions, 23 deletions
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c index 289f0e885..7fe0c6953 100644 --- a/src/gnsrecord/gnsrecord_crypto.c +++ b/src/gnsrecord/gnsrecord_crypto.c | |||
@@ -396,11 +396,8 @@ block_create_eddsa (const struct GNUNET_CRYPTO_EddsaPrivateKey *key, | |||
396 | label, | 396 | label, |
397 | "gns", | 397 | "gns", |
398 | &dkey); | 398 | &dkey); |
399 | // FIXME: We may want a key_get_public_from_private_scalar function | 399 | GNUNET_CRYPTO_eddsa_key_get_public_from_scalar (&dkey, |
400 | struct GNUNET_CRYPTO_EddsaPublicKey test; | 400 | &edblock->derived_key); |
401 | crypto_scalarmult_ed25519_base_noclamp (test.q_y, | ||
402 | dkey.s); | ||
403 | edblock->derived_key = test; | ||
404 | derive_block_xsalsa_key (nonce, | 401 | derive_block_xsalsa_key (nonce, |
405 | skey, | 402 | skey, |
406 | label, | 403 | label, |
@@ -438,25 +435,21 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
438 | const struct GNUNET_GNSRECORD_Data *rd, | 435 | const struct GNUNET_GNSRECORD_Data *rd, |
439 | unsigned int rd_count) | 436 | unsigned int rd_count) |
440 | { | 437 | { |
441 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 438 | struct GNUNET_IDENTITY_PublicKey pkey; |
442 | struct GNUNET_CRYPTO_EddsaPublicKey edkey; | 439 | GNUNET_IDENTITY_key_get_public (key, |
443 | 440 | &pkey); | |
444 | switch (ntohl (key->type)) | 441 | switch (ntohl (key->type)) |
445 | { | 442 | { |
446 | case GNUNET_GNSRECORD_TYPE_PKEY: | 443 | case GNUNET_GNSRECORD_TYPE_PKEY: |
447 | GNUNET_CRYPTO_ecdsa_key_get_public (&key->ecdsa_key, | ||
448 | &pkey); | ||
449 | return block_create_ecdsa (&key->ecdsa_key, | 444 | return block_create_ecdsa (&key->ecdsa_key, |
450 | &pkey, | 445 | &pkey.ecdsa_key, |
451 | expire, | 446 | expire, |
452 | label, | 447 | label, |
453 | rd, | 448 | rd, |
454 | rd_count); | 449 | rd_count); |
455 | case GNUNET_GNSRECORD_TYPE_EDKEY: | 450 | case GNUNET_GNSRECORD_TYPE_EDKEY: |
456 | GNUNET_CRYPTO_eddsa_key_get_public (&key->eddsa_key, | ||
457 | &edkey); | ||
458 | return block_create_eddsa (&key->eddsa_key, | 451 | return block_create_eddsa (&key->eddsa_key, |
459 | &edkey, | 452 | &pkey.eddsa_key, |
460 | expire, | 453 | expire, |
461 | label, | 454 | label, |
462 | rd, | 455 | rd, |
@@ -930,7 +923,7 @@ GNUNET_GNSRECORD_query_from_public_key (const struct | |||
930 | GNUNET_CRYPTO_eddsa_public_key_derive (&pub->eddsa_key, | 923 | GNUNET_CRYPTO_eddsa_public_key_derive (&pub->eddsa_key, |
931 | label, | 924 | label, |
932 | "gns", | 925 | "gns", |
933 | &pd.eddsa_key); | 926 | &(pd.eddsa_key)); |
934 | GNUNET_CRYPTO_hash (&pd.eddsa_key, | 927 | GNUNET_CRYPTO_hash (&pd.eddsa_key, |
935 | sizeof (pd.eddsa_key), | 928 | sizeof (pd.eddsa_key), |
936 | query); | 929 | query); |
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c index 2fe315bd8..8d3a6421f 100644 --- a/src/gnsrecord/gnsrecord_misc.c +++ b/src/gnsrecord/gnsrecord_misc.c | |||
@@ -377,7 +377,7 @@ GNUNET_GNSRECORD_query_from_block (const struct GNUNET_GNSRECORD_Block *block, | |||
377 | switch (ntohl (block->type)) | 377 | switch (ntohl (block->type)) |
378 | { | 378 | { |
379 | case GNUNET_GNSRECORD_TYPE_PKEY: | 379 | case GNUNET_GNSRECORD_TYPE_PKEY: |
380 | GNUNET_CRYPTO_hash (&block->ecdsa_block.derived_key, | 380 | GNUNET_CRYPTO_hash (&(block->ecdsa_block.derived_key), |
381 | sizeof (block->ecdsa_block.derived_key), | 381 | sizeof (block->ecdsa_block.derived_key), |
382 | query); | 382 | query); |
383 | return GNUNET_OK; | 383 | return GNUNET_OK; |
diff --git a/src/gnsrecord/test_gnsrecord_crypto.c b/src/gnsrecord/test_gnsrecord_crypto.c index b9b2b5ba5..9e5a1aa7e 100644 --- a/src/gnsrecord/test_gnsrecord_crypto.c +++ b/src/gnsrecord/test_gnsrecord_crypto.c | |||
@@ -92,6 +92,7 @@ rd_decrypt_cb (void *cls, | |||
92 | res = 0; | 92 | res = 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | |||
95 | static void | 96 | static void |
96 | test_with_type (struct GNUNET_IDENTITY_PrivateKey *privkey) | 97 | test_with_type (struct GNUNET_IDENTITY_PrivateKey *privkey) |
97 | { | 98 | { |
@@ -99,6 +100,7 @@ test_with_type (struct GNUNET_IDENTITY_PrivateKey *privkey) | |||
99 | struct GNUNET_IDENTITY_PublicKey pubkey; | 100 | struct GNUNET_IDENTITY_PublicKey pubkey; |
100 | struct GNUNET_HashCode query_pub; | 101 | struct GNUNET_HashCode query_pub; |
101 | struct GNUNET_HashCode query_priv; | 102 | struct GNUNET_HashCode query_priv; |
103 | struct GNUNET_HashCode query_block; | ||
102 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get (); | 104 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get (); |
103 | 105 | ||
104 | 106 | ||
@@ -117,7 +119,7 @@ test_with_type (struct GNUNET_IDENTITY_PrivateKey *privkey) | |||
117 | &query_pub, | 119 | &query_pub, |
118 | sizeof(struct GNUNET_HashCode))); | 120 | sizeof(struct GNUNET_HashCode))); |
119 | /* create record */ | 121 | /* create record */ |
120 | s_name = "DUMMY.dummy.gnunet"; | 122 | s_name = "testlabel"; |
121 | s_rd = create_record (RECORDS); | 123 | s_rd = create_record (RECORDS); |
122 | 124 | ||
123 | /* Create block */ | 125 | /* Create block */ |
@@ -128,6 +130,13 @@ test_with_type (struct GNUNET_IDENTITY_PrivateKey *privkey) | |||
128 | s_rd, | 130 | s_rd, |
129 | RECORDS))); | 131 | RECORDS))); |
130 | GNUNET_assert (GNUNET_OK == | 132 | GNUNET_assert (GNUNET_OK == |
133 | GNUNET_GNSRECORD_query_from_block (block, | ||
134 | &query_block)); | ||
135 | GNUNET_assert (0 == memcmp (&query_pub, | ||
136 | &query_block, | ||
137 | sizeof(struct GNUNET_HashCode))); | ||
138 | |||
139 | GNUNET_assert (GNUNET_OK == | ||
131 | GNUNET_GNSRECORD_block_verify (block)); | 140 | GNUNET_GNSRECORD_block_verify (block)); |
132 | GNUNET_assert (GNUNET_OK == | 141 | GNUNET_assert (GNUNET_OK == |
133 | GNUNET_GNSRECORD_block_decrypt (block, | 142 | GNUNET_GNSRECORD_block_decrypt (block, |
@@ -139,7 +148,6 @@ test_with_type (struct GNUNET_IDENTITY_PrivateKey *privkey) | |||
139 | } | 148 | } |
140 | 149 | ||
141 | 150 | ||
142 | |||
143 | static void | 151 | static void |
144 | run (void *cls, | 152 | run (void *cls, |
145 | char *const *args, | 153 | char *const *args, |
@@ -158,17 +166,17 @@ run (void *cls, | |||
158 | test_with_type (&privkey); | 166 | test_with_type (&privkey); |
159 | end = GNUNET_TIME_absolute_get (); | 167 | end = GNUNET_TIME_absolute_get (); |
160 | printf ("Time: %llu ms\n", (unsigned long long) | 168 | printf ("Time: %llu ms\n", (unsigned long long) |
161 | GNUNET_TIME_absolute_get_difference (start, | 169 | GNUNET_TIME_absolute_get_difference (start, |
162 | end).rel_value_us); | 170 | end).rel_value_us); |
163 | 171 | ||
164 | privkey_ed.type = htonl (GNUNET_GNSRECORD_TYPE_EDKEY); | 172 | privkey_ed.type = htonl (GNUNET_GNSRECORD_TYPE_EDKEY); |
165 | GNUNET_CRYPTO_eddsa_key_create (&privkey_ed.eddsa_key); | 173 | GNUNET_CRYPTO_eddsa_key_create (&privkey_ed.eddsa_key); |
166 | start = GNUNET_TIME_absolute_get (); | 174 | start = GNUNET_TIME_absolute_get (); |
167 | test_with_type(&privkey_ed); | 175 | test_with_type (&privkey_ed); |
168 | end = GNUNET_TIME_absolute_get (); | 176 | end = GNUNET_TIME_absolute_get (); |
169 | printf ("Time: %llu ms\n", (unsigned long long) | 177 | printf ("Time: %llu ms\n", (unsigned long long) |
170 | GNUNET_TIME_absolute_get_difference (start, | 178 | GNUNET_TIME_absolute_get_difference (start, |
171 | end).rel_value_us); | 179 | end).rel_value_us); |
172 | 180 | ||
173 | 181 | ||
174 | } | 182 | } |