(i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9);
i++)
{
- if (GNUNET_CRYPTO_hash_get_bit (target, i) !=
- GNUNET_CRYPTO_hash_get_bit (have, i))
+ if (GNUNET_CRYPTO_hash_get_bit_rtl (target, i) !=
+ GNUNET_CRYPTO_hash_get_bit_rtl (have, i))
lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10,
* last bit set will be 31 -- if
* i does not reach 512 first... */
fprintf (stdout,
"EXPIRATION: %"PRIu64"\n", rd->expiration_time);
fprintf (stdout,
- "DATA_SIZE: %"PRIu64"\n", rd->data_size);
+ "DATA_SIZE: %zu\n", rd->data_size);
fprintf (stdout,
"TYPE: %d\n", rd->record_type);
fprintf (stdout,
* Obtain a bit from a hashcode.
*
* @param code the `struct GNUNET_HashCode` to index bit-wise
- * @param bit index into the hashcode, [0...159]
+ * @param bit index into the hashcode, [0...159] where 0 is the leftmost bit
+ * (bytes in code interpreted big endian)
* @return Bit \a bit from hashcode \a code, -1 for invalid index
*/
int
-GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code,
- unsigned int bit);
+GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code,
+ unsigned int bit);
+
+
+/**
+ * Obtain a bit from a hashcode.
+ * @param code the GNUNET_CRYPTO_hash to index bit-wise
+ * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit
+ * (bytes in code interpreted little endian)
+ * @return Bit \a bit from hashcode \a code, -1 for invalid index
+ */
+int
+GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code,
+ unsigned int bit);
/**
unsigned int hash_count;
hash_count = 0;
- while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))
+ while (0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count))
hash_count++;
return hash_count;
}
{
unsigned int hash_count;
hash_count = 0;
- while ((0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)))
+ while ((0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count)))
hash_count++;
return hash_count;
}
/**
* Obtain a bit from a hashcode.
* @param code the GNUNET_CRYPTO_hash to index bit-wise
- * @param bit index into the hashcode, [0...511]
+ * @param bit index into the hashcode, [0...511] where 0 is the leftmost bit
+ * (bytes in code interpreted big endian)
* @return Bit \a bit from hashcode \a code, -1 for invalid index
*/
int
-GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, unsigned int
- bit)
+GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code,
+ unsigned int bit)
{
GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode));
return (((unsigned char *) code)[bit >> 3] & (128 >> (bit & 7))) > 0;
}
+/**
+ * Obtain a bit from a hashcode.
+ * @param code the GNUNET_CRYPTO_hash to index bit-wise
+ * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit
+ * (bytes in code interpreted little endian)
+ * @return Bit \a bit from hashcode \a code, -1 for invalid index
+ */
+int
+GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code,
+ unsigned int bit)
+{
+ GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode));
+ return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0;
+}
+
+
/**
* Determine how many low order bits match in two
unsigned int i;
for (i = 0; i < sizeof(struct GNUNET_HashCode) * 8; i++)
- if (GNUNET_CRYPTO_hash_get_bit (first, i) !=
- GNUNET_CRYPTO_hash_get_bit (second, i))
+ if (GNUNET_CRYPTO_hash_get_bit_rtl (first, i) !=
+ GNUNET_CRYPTO_hash_get_bit_rtl (second, i))
return i;
return sizeof(struct GNUNET_HashCode) * 8;
}
unsigned int hash_count;
hash_count = 0;
- while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))
+ while (0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count))
hash_count++;
return hash_count;
}
return 1;
if (1 != GNUNET_CRYPTO_hash_xorcmp (&h1, &h2, &h2))
return 1;
- memset (&d, 0xF0, sizeof(d));
- if (0 != GNUNET_CRYPTO_hash_get_bit (&d, 3))
+ memset (&d, 0x40, sizeof(d));
+ if (0 != GNUNET_CRYPTO_hash_get_bit_rtl (&d, 3))
return 1;
- if (1 != GNUNET_CRYPTO_hash_get_bit (&d, 6))
+ if (1 != GNUNET_CRYPTO_hash_get_bit_rtl (&d, 6))
+ return 1;
+ memset (&d, 0x02, sizeof(d));
+ if (0 != GNUNET_CRYPTO_hash_get_bit_ltr (&d, 3))
+ return 1;
+ if (1 != GNUNET_CRYPTO_hash_get_bit_ltr (&d, 6))
return 1;
memset (&d, 0, sizeof(d));
GNUNET_CRYPTO_hash_to_aes_key (&d, &skey, &iv);