diff options
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 4 | ||||
-rw-r--r-- | src/gnsrecord/gnunet-gnsrecord-tvg.c | 2 | ||||
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 19 | ||||
-rw-r--r-- | src/nse/gnunet-service-nse.c | 2 | ||||
-rw-r--r-- | src/revocation/revocation_api.c | 13 | ||||
-rw-r--r-- | src/util/crypto_ecc.c | 10 | ||||
-rw-r--r-- | src/util/crypto_hash.c | 27 | ||||
-rw-r--r-- | src/util/crypto_pow.c | 21 | ||||
-rw-r--r-- | src/util/gnunet-scrypt.c | 2 | ||||
-rw-r--r-- | src/util/test_crypto_ecdsa.c | 9 | ||||
-rw-r--r-- | src/util/test_crypto_hash.c | 11 |
11 files changed, 85 insertions, 35 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index c251dfa12..fce69d3f6 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -927,8 +927,8 @@ get_distance (const struct GNUNET_HashCode *target, | |||
927 | (i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); | 927 | (i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); |
928 | i++) | 928 | i++) |
929 | { | 929 | { |
930 | if (GNUNET_CRYPTO_hash_get_bit (target, i) != | 930 | if (GNUNET_CRYPTO_hash_get_bit_rtl (target, i) != |
931 | GNUNET_CRYPTO_hash_get_bit (have, i)) | 931 | GNUNET_CRYPTO_hash_get_bit_rtl (have, i)) |
932 | lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10, | 932 | lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10, |
933 | * last bit set will be 31 -- if | 933 | * last bit set will be 31 -- if |
934 | * i does not reach 512 first... */ | 934 | * i does not reach 512 first... */ |
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c index cf815d629..862bd6f86 100644 --- a/src/gnsrecord/gnunet-gnsrecord-tvg.c +++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c | |||
@@ -47,7 +47,7 @@ print_record(const struct GNUNET_GNSRECORD_Data *rd) | |||
47 | fprintf (stdout, | 47 | fprintf (stdout, |
48 | "EXPIRATION: %"PRIu64"\n", rd->expiration_time); | 48 | "EXPIRATION: %"PRIu64"\n", rd->expiration_time); |
49 | fprintf (stdout, | 49 | fprintf (stdout, |
50 | "DATA_SIZE: %"PRIu64"\n", rd->data_size); | 50 | "DATA_SIZE: %zu\n", rd->data_size); |
51 | fprintf (stdout, | 51 | fprintf (stdout, |
52 | "TYPE: %d\n", rd->record_type); | 52 | "TYPE: %d\n", rd->record_type); |
53 | fprintf (stdout, | 53 | fprintf (stdout, |
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index a5a50e749..e880bd887 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -874,12 +874,25 @@ GNUNET_CRYPTO_hash_to_aes_key ( | |||
874 | * Obtain a bit from a hashcode. | 874 | * Obtain a bit from a hashcode. |
875 | * | 875 | * |
876 | * @param code the `struct GNUNET_HashCode` to index bit-wise | 876 | * @param code the `struct GNUNET_HashCode` to index bit-wise |
877 | * @param bit index into the hashcode, [0...159] | 877 | * @param bit index into the hashcode, [0...159] where 0 is the leftmost bit |
878 | * (bytes in code interpreted big endian) | ||
878 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | 879 | * @return Bit \a bit from hashcode \a code, -1 for invalid index |
879 | */ | 880 | */ |
880 | int | 881 | int |
881 | GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, | 882 | GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code, |
882 | unsigned int bit); | 883 | unsigned int bit); |
884 | |||
885 | |||
886 | /** | ||
887 | * Obtain a bit from a hashcode. | ||
888 | * @param code the GNUNET_CRYPTO_hash to index bit-wise | ||
889 | * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit | ||
890 | * (bytes in code interpreted little endian) | ||
891 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | ||
892 | */ | ||
893 | int | ||
894 | GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code, | ||
895 | unsigned int bit); | ||
883 | 896 | ||
884 | 897 | ||
885 | /** | 898 | /** |
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 411f533a5..461d55a7f 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -780,7 +780,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) | |||
780 | unsigned int hash_count; | 780 | unsigned int hash_count; |
781 | 781 | ||
782 | hash_count = 0; | 782 | hash_count = 0; |
783 | while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)) | 783 | while (0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count)) |
784 | hash_count++; | 784 | hash_count++; |
785 | return hash_count; | 785 | return hash_count; |
786 | } | 786 | } |
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c index 3789e6799..33c67d005 100644 --- a/src/revocation/revocation_api.c +++ b/src/revocation/revocation_api.c | |||
@@ -395,7 +395,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) | |||
395 | { | 395 | { |
396 | unsigned int hash_count; | 396 | unsigned int hash_count; |
397 | hash_count = 0; | 397 | hash_count = 0; |
398 | while ((0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))) | 398 | while ((0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count))) |
399 | hash_count++; | 399 | hash_count++; |
400 | return hash_count; | 400 | return hash_count; |
401 | } | 401 | } |
@@ -435,7 +435,6 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
435 | + sizeof (struct GNUNET_TIME_AbsoluteNBO) | 435 | + sizeof (struct GNUNET_TIME_AbsoluteNBO) |
436 | + sizeof (uint64_t)] GNUNET_ALIGN; | 436 | + sizeof (uint64_t)] GNUNET_ALIGN; |
437 | struct GNUNET_REVOCATION_SignaturePurposePS spurp; | 437 | struct GNUNET_REVOCATION_SignaturePurposePS spurp; |
438 | struct GNUNET_CRYPTO_HashAsciiEncoded h_str; | ||
439 | struct GNUNET_HashCode result; | 438 | struct GNUNET_HashCode result; |
440 | struct GNUNET_TIME_Absolute ts; | 439 | struct GNUNET_TIME_Absolute ts; |
441 | struct GNUNET_TIME_Absolute exp; | 440 | struct GNUNET_TIME_Absolute exp; |
@@ -493,11 +492,6 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
493 | "Score %u with %" PRIu64 " (#%u)\n", | 492 | "Score %u with %" PRIu64 " (#%u)\n", |
494 | tmp_score, pow_val, i); | 493 | tmp_score, pow_val, i); |
495 | 494 | ||
496 | GNUNET_CRYPTO_hash_to_enc (&result, | ||
497 | &h_str); | ||
498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
499 | "Hash: %s\n", (char*)&h_str); | ||
500 | |||
501 | score += tmp_score; | 495 | score += tmp_score; |
502 | 496 | ||
503 | } | 497 | } |
@@ -583,9 +577,14 @@ GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow, | |||
583 | unsigned int difficulty) | 577 | unsigned int difficulty) |
584 | { | 578 | { |
585 | struct GNUNET_REVOCATION_PowCalculationHandle *pc; | 579 | struct GNUNET_REVOCATION_PowCalculationHandle *pc; |
580 | struct GNUNET_TIME_Relative ttl; | ||
581 | |||
586 | 582 | ||
587 | pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle); | 583 | pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle); |
588 | pc->pow = pow; | 584 | pc->pow = pow; |
585 | ttl = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | ||
586 | epochs); | ||
587 | pc->pow->ttl = GNUNET_TIME_relative_hton (ttl); | ||
589 | pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 588 | pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
590 | UINT64_MAX); | 589 | UINT64_MAX); |
591 | pc->difficulty = difficulty; | 590 | pc->difficulty = difficulty; |
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 96d546185..e1608ae55 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c | |||
@@ -544,10 +544,18 @@ void | |||
544 | GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | 544 | GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) |
545 | { | 545 | { |
546 | BENCHMARK_START (eddsa_key_create); | 546 | BENCHMARK_START (eddsa_key_create); |
547 | /* | ||
548 | * We do not clamp for EdDSA, since all functions that use the private key do | ||
549 | * their own clamping (just like in libsodium). What we call "private key" | ||
550 | * here, actually corresponds to the seed in libsodium. | ||
551 | * | ||
552 | * (Contrast this to ECDSA, where functions using the private key can't clamp | ||
553 | * due to properties needed for GNS. That is a worse/unsafer API, but | ||
554 | * required for the GNS constructions to work.) | ||
555 | */ | ||
547 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, | 556 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, |
548 | pk, | 557 | pk, |
549 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); | 558 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); |
550 | // FIXME: should we not do the clamping here? Or is this done elsewhere? | ||
551 | BENCHMARK_END (eddsa_key_create); | 559 | BENCHMARK_END (eddsa_key_create); |
552 | } | 560 | } |
553 | 561 | ||
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index c41c419ff..622953476 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -244,18 +244,35 @@ GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode *hc, | |||
244 | /** | 244 | /** |
245 | * Obtain a bit from a hashcode. | 245 | * Obtain a bit from a hashcode. |
246 | * @param code the GNUNET_CRYPTO_hash to index bit-wise | 246 | * @param code the GNUNET_CRYPTO_hash to index bit-wise |
247 | * @param bit index into the hashcode, [0...511] | 247 | * @param bit index into the hashcode, [0...511] where 0 is the leftmost bit |
248 | * (bytes in code interpreted big endian) | ||
248 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | 249 | * @return Bit \a bit from hashcode \a code, -1 for invalid index |
249 | */ | 250 | */ |
250 | int | 251 | int |
251 | GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, unsigned int | 252 | GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code, |
252 | bit) | 253 | unsigned int bit) |
254 | { | ||
255 | GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode)); | ||
256 | return (((unsigned char *) code)[bit >> 3] & (128 >> (bit & 7))) > 0; | ||
257 | } | ||
258 | |||
259 | /** | ||
260 | * Obtain a bit from a hashcode. | ||
261 | * @param code the GNUNET_CRYPTO_hash to index bit-wise | ||
262 | * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit | ||
263 | * (bytes in code interpreted little endian) | ||
264 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | ||
265 | */ | ||
266 | int | ||
267 | GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code, | ||
268 | unsigned int bit) | ||
253 | { | 269 | { |
254 | GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode)); | 270 | GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode)); |
255 | return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0; | 271 | return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0; |
256 | } | 272 | } |
257 | 273 | ||
258 | 274 | ||
275 | |||
259 | /** | 276 | /** |
260 | * Determine how many low order bits match in two | 277 | * Determine how many low order bits match in two |
261 | * `struct GNUNET_HashCode`s. i.e. - 010011 and 011111 share | 278 | * `struct GNUNET_HashCode`s. i.e. - 010011 and 011111 share |
@@ -275,8 +292,8 @@ GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode *first, | |||
275 | unsigned int i; | 292 | unsigned int i; |
276 | 293 | ||
277 | for (i = 0; i < sizeof(struct GNUNET_HashCode) * 8; i++) | 294 | for (i = 0; i < sizeof(struct GNUNET_HashCode) * 8; i++) |
278 | if (GNUNET_CRYPTO_hash_get_bit (first, i) != | 295 | if (GNUNET_CRYPTO_hash_get_bit_rtl (first, i) != |
279 | GNUNET_CRYPTO_hash_get_bit (second, i)) | 296 | GNUNET_CRYPTO_hash_get_bit_rtl (second, i)) |
280 | return i; | 297 | return i; |
281 | return sizeof(struct GNUNET_HashCode) * 8; | 298 | return sizeof(struct GNUNET_HashCode) * 8; |
282 | } | 299 | } |
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c index 35511a130..6176afc33 100644 --- a/src/util/crypto_pow.c +++ b/src/util/crypto_pow.c | |||
@@ -43,17 +43,16 @@ GNUNET_CRYPTO_pow_hash (const char *salt, | |||
43 | size_t buf_len, | 43 | size_t buf_len, |
44 | struct GNUNET_HashCode *result) | 44 | struct GNUNET_HashCode *result) |
45 | { | 45 | { |
46 | GNUNET_break (ARGON2_OK == argon2d_hash_raw (3, /* iterations */ | 46 | GNUNET_break (ARGON2_OK == |
47 | 1024, /* memory (1 MiB) */ | 47 | argon2id_hash_raw (3, /* iterations */ |
48 | 1, /* threads */ | 48 | 1024, /* memory (1 MiB) */ |
49 | buf, | 49 | 1, /* threads */ |
50 | buf_len, | 50 | buf, |
51 | salt, | 51 | buf_len, |
52 | strlen (salt), | 52 | salt, |
53 | result, | 53 | strlen (salt), |
54 | sizeof (struct | 54 | result, |
55 | GNUNET_HashCode))); | 55 | sizeof (struct GNUNET_HashCode))); |
56 | |||
57 | } | 56 | } |
58 | 57 | ||
59 | 58 | ||
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c index 70ba48d82..9bb766595 100644 --- a/src/util/gnunet-scrypt.c +++ b/src/util/gnunet-scrypt.c | |||
@@ -79,7 +79,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) | |||
79 | unsigned int hash_count; | 79 | unsigned int hash_count; |
80 | 80 | ||
81 | hash_count = 0; | 81 | hash_count = 0; |
82 | while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)) | 82 | while (0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count)) |
83 | hash_count++; | 83 | hash_count++; |
84 | return hash_count; | 84 | return hash_count; |
85 | } | 85 | } |
diff --git a/src/util/test_crypto_ecdsa.c b/src/util/test_crypto_ecdsa.c index cfa236d6d..7908590a8 100644 --- a/src/util/test_crypto_ecdsa.c +++ b/src/util/test_crypto_ecdsa.c | |||
@@ -107,6 +107,7 @@ testDeriveSignVerify (void) | |||
107 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dpriv; | 107 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dpriv; |
108 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 108 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
109 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; | 109 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; |
110 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub2; | ||
110 | 111 | ||
111 | dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (&key, | 112 | dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (&key, |
112 | "test-derive", | 113 | "test-derive", |
@@ -117,9 +118,17 @@ testDeriveSignVerify (void) | |||
117 | "test-derive", | 118 | "test-derive", |
118 | "test-CTX", | 119 | "test-CTX", |
119 | &dpub); | 120 | &dpub); |
121 | GNUNET_CRYPTO_ecdsa_key_get_public (dpriv, &dpub2); | ||
120 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 122 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
121 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 123 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
122 | 124 | ||
125 | if (0 != GNUNET_memcmp (&dpub.q_y, &dpub2.q_y)) | ||
126 | { | ||
127 | fprintf (stderr, "%s", "key derivation failed\n"); | ||
128 | GNUNET_free (dpriv); | ||
129 | return GNUNET_SYSERR; | ||
130 | } | ||
131 | |||
123 | if (GNUNET_SYSERR == | 132 | if (GNUNET_SYSERR == |
124 | GNUNET_CRYPTO_ecdsa_sign_ (dpriv, | 133 | GNUNET_CRYPTO_ecdsa_sign_ (dpriv, |
125 | &purp, | 134 | &purp, |
diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c index 12e1324dd..d22e1f5d3 100644 --- a/src/util/test_crypto_hash.c +++ b/src/util/test_crypto_hash.c | |||
@@ -91,10 +91,15 @@ testArithmetic () | |||
91 | return 1; | 91 | return 1; |
92 | if (1 != GNUNET_CRYPTO_hash_xorcmp (&h1, &h2, &h2)) | 92 | if (1 != GNUNET_CRYPTO_hash_xorcmp (&h1, &h2, &h2)) |
93 | return 1; | 93 | return 1; |
94 | memset (&d, 0xF0, sizeof(d)); | 94 | memset (&d, 0x40, sizeof(d)); |
95 | if (0 != GNUNET_CRYPTO_hash_get_bit (&d, 3)) | 95 | if (0 != GNUNET_CRYPTO_hash_get_bit_rtl (&d, 3)) |
96 | return 1; | 96 | return 1; |
97 | if (1 != GNUNET_CRYPTO_hash_get_bit (&d, 6)) | 97 | if (1 != GNUNET_CRYPTO_hash_get_bit_rtl (&d, 6)) |
98 | return 1; | ||
99 | memset (&d, 0x02, sizeof(d)); | ||
100 | if (0 != GNUNET_CRYPTO_hash_get_bit_ltr (&d, 3)) | ||
101 | return 1; | ||
102 | if (1 != GNUNET_CRYPTO_hash_get_bit_ltr (&d, 6)) | ||
98 | return 1; | 103 | return 1; |
99 | memset (&d, 0, sizeof(d)); | 104 | memset (&d, 0, sizeof(d)); |
100 | GNUNET_CRYPTO_hash_to_aes_key (&d, &skey, &iv); | 105 | GNUNET_CRYPTO_hash_to_aes_key (&d, &skey, &iv); |