aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c4
-rw-r--r--src/gnsrecord/gnunet-gnsrecord-tvg.c2
-rw-r--r--src/include/gnunet_crypto_lib.h19
-rw-r--r--src/nse/gnunet-service-nse.c2
-rw-r--r--src/revocation/revocation_api.c2
-rw-r--r--src/util/crypto_hash.c27
-rw-r--r--src/util/gnunet-scrypt.c2
-rw-r--r--src/util/test_crypto_hash.c11
8 files changed, 52 insertions, 17 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 */
880int 881int
881GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, 882GNUNET_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 */
893int
894GNUNET_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 2ae8e2df9..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}
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 4982ba404..622953476 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -244,17 +244,34 @@ 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 */
250int 251int
251GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, unsigned int 252GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code,
252 bit) 253 unsigned int bit)
253{ 254{
254 GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode)); 255 GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode));
255 return (((unsigned char *) code)[bit >> 3] & (128 >> (bit & 7))) > 0; 256 return (((unsigned char *) code)[bit >> 3] & (128 >> (bit & 7))) > 0;
256} 257}
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 */
266int
267GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code,
268 unsigned int bit)
269{
270 GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode));
271 return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0;
272}
273
274
258 275
259/** 276/**
260 * Determine how many low order bits match in two 277 * Determine how many low order bits match in two
@@ -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/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_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);