diff options
Diffstat (limited to 'src/util/crypto_hash.c')
-rw-r--r-- | src/util/crypto_hash.c | 27 |
1 files changed, 22 insertions, 5 deletions
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 | */ |
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) |
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 | */ | ||
266 | int | ||
267 | GNUNET_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 | } |