aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-01-02 13:10:25 +0100
committerChristian Grothoff <christian@grothoff.org>2022-01-02 13:10:25 +0100
commitbb686c48354853aa725e493e85edce0602ed85e2 (patch)
tree6b0aeea58a7aebe0e3108da5302eaeae2c996ceb /src/include
parent2cbb614f694701c4afdab88f58ef7626629e1bc3 (diff)
downloadgnunet-bb686c48354853aa725e493e85edce0602ed85e2.tar.gz
gnunet-bb686c48354853aa725e493e85edce0602ed85e2.zip
revise DHT hashing functions, add test logic
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gnunet_crypto_lib.h68
1 files changed, 30 insertions, 38 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index bd318ab84..4e26429c9 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -1038,61 +1038,53 @@ GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode *a,
1038 1038
1039 1039
1040/** 1040/**
1041 * @ingroup hash 1041 * Count the number of leading 0 bits in @a h.
1042 * Convert a hashcode into a key.
1043 * 1042 *
1044 * @param hc hash code that serves to generate the key 1043 * @param h a hash
1045 * @param skey set to a valid session key 1044 * @return number of leading 0 bits in @a h
1046 * @param iv set to a valid initialization vector
1047 */ 1045 */
1048void 1046unsigned int
1049GNUNET_CRYPTO_hash_to_aes_key ( 1047GNUNET_CRYPTO_hash_count_leading_zeros (const struct GNUNET_HashCode *h);
1050 const struct GNUNET_HashCode *hc,
1051 struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
1052 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv);
1053 1048
1054 1049
1055/** 1050/**
1056 * @ingroup hash 1051 * Count the number of tailing 0 bits in @a h.
1057 * Obtain a bit from a hashcode.
1058 * 1052 *
1059 * @param code the `struct GNUNET_HashCode` to index bit-wise 1053 * @param h a hash
1060 * @param bit index into the hashcode, [0...159] where 0 is the leftmost bit 1054 * @return number of tailing 0 bits in @a h
1061 * (bytes in code interpreted big endian)
1062 * @return Bit \a bit from hashcode \a code, -1 for invalid index
1063 */ 1055 */
1064int 1056unsigned int
1065GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code, 1057GNUNET_CRYPTO_hash_count_tailing_zeros (const struct GNUNET_HashCode *h);
1066 unsigned int bit);
1067 1058
1068 1059
1069/** 1060/**
1070 * Obtain a bit from a hashcode. 1061 * Compute the distance between have and target as a 64-bit value.
1071 * @param code the GNUNET_CRYPTO_hash to index bit-wise 1062 * Differences in the lower bits must count stronger than differences
1072 * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit 1063 * in the higher bits.
1073 * (bytes in code interpreted little endian) 1064 *
1074 * @return Bit \a bit from hashcode \a code, -1 for invalid index 1065 * @param xor input hash
1066 * @param bucket up to which offset we are to ignore @a xor
1067 * @return the subsequent 64 bits after @a bucket from @a xor, in
1068 * host byte order.
1075 */ 1069 */
1076int 1070uint64_t
1077GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code, 1071GNUNET_CRYPTO_hash_bucket_distance (const struct GNUNET_HashCode *xor,
1078 unsigned int bit); 1072 unsigned int bucket);
1079 1073
1080 1074
1081/** 1075/**
1082 * @ingroup hash 1076 * @ingroup hash
1083 * Determine how many low order bits match in two 1077 * Convert a hashcode into a key.
1084 * `struct GNUNET_HashCodes`. e.g. - 010011 and 011111 share
1085 * the first two lowest order bits, and therefore the
1086 * return value is two (NOT XOR distance, nor how many
1087 * bits match absolutely!).
1088 * 1078 *
1089 * @param first the first hashcode 1079 * @param hc hash code that serves to generate the key
1090 * @param second the hashcode to compare first to 1080 * @param skey set to a valid session key
1091 * @return the number of bits that match 1081 * @param iv set to a valid initialization vector
1092 */ 1082 */
1093unsigned int 1083void
1094GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode *first, 1084GNUNET_CRYPTO_hash_to_aes_key (
1095 const struct GNUNET_HashCode *second); 1085 const struct GNUNET_HashCode *hc,
1086 struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
1087 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv);
1096 1088
1097 1089
1098/** 1090/**