summaryrefslogtreecommitdiff
path: root/src/util/crypto_hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/crypto_hash.c')
-rw-r--r--src/util/crypto_hash.c305
1 files changed, 152 insertions, 153 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 925d6b94d..ebb1266b2 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -11,13 +11,13 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 19
20*/ 20 */
21/** 21/**
22 * @file util/crypto_hash.c 22 * @file util/crypto_hash.c
23 * @brief SHA-512 #GNUNET_CRYPTO_hash() related functions 23 * @brief SHA-512 #GNUNET_CRYPTO_hash() related functions
@@ -29,9 +29,9 @@
29#include "benchmark.h" 29#include "benchmark.h"
30#include <gcrypt.h> 30#include <gcrypt.h>
31 31
32#define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-hash", __VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from(kind, "util-crypto-hash", __VA_ARGS__)
33 33
34#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-crypto-hash", syscall, filename) 34#define LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file(kind, "util-crypto-hash", syscall, filename)
35 35
36/** 36/**
37 * Hash block of given size. 37 * Hash block of given size.
@@ -41,13 +41,13 @@
41 * @param ret pointer to where to write the hashcode 41 * @param ret pointer to where to write the hashcode
42 */ 42 */
43void 43void
44GNUNET_CRYPTO_hash (const void *block, 44GNUNET_CRYPTO_hash(const void *block,
45 size_t size, 45 size_t size,
46 struct GNUNET_HashCode *ret) 46 struct GNUNET_HashCode *ret)
47{ 47{
48 BENCHMARK_START (hash); 48 BENCHMARK_START(hash);
49 gcry_md_hash_buffer (GCRY_MD_SHA512, ret, block, size); 49 gcry_md_hash_buffer(GCRY_MD_SHA512, ret, block, size);
50 BENCHMARK_END (hash); 50 BENCHMARK_END(hash);
51} 51}
52 52
53 53
@@ -66,16 +66,16 @@ GNUNET_CRYPTO_hash (const void *block,
66 * safely cast to char*, a '\\0' termination is set). 66 * safely cast to char*, a '\\0' termination is set).
67 */ 67 */
68void 68void
69GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block, 69GNUNET_CRYPTO_hash_to_enc(const struct GNUNET_HashCode *block,
70 struct GNUNET_CRYPTO_HashAsciiEncoded *result) 70 struct GNUNET_CRYPTO_HashAsciiEncoded *result)
71{ 71{
72 char *np; 72 char *np;
73 73
74 np = GNUNET_STRINGS_data_to_string ((const unsigned char *) block, 74 np = GNUNET_STRINGS_data_to_string((const unsigned char *)block,
75 sizeof (struct GNUNET_HashCode), 75 sizeof(struct GNUNET_HashCode),
76 (char *) result, 76 (char *)result,
77 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); 77 sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
78 GNUNET_assert (NULL != np); 78 GNUNET_assert(NULL != np);
79 *np = '\0'; 79 *np = '\0';
80} 80}
81 81
@@ -89,18 +89,18 @@ GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block,
89 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 89 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
90 */ 90 */
91int 91int
92GNUNET_CRYPTO_hash_from_string2 (const char *enc, 92GNUNET_CRYPTO_hash_from_string2(const char *enc,
93 size_t enclen, 93 size_t enclen,
94 struct GNUNET_HashCode *result) 94 struct GNUNET_HashCode *result)
95{ 95{
96 char upper_enc[enclen]; 96 char upper_enc[enclen];
97 char *up_ptr = upper_enc; 97 char *up_ptr = upper_enc;
98 98
99 GNUNET_STRINGS_utf8_toupper (enc, up_ptr); 99 GNUNET_STRINGS_utf8_toupper(enc, up_ptr);
100 100
101 return GNUNET_STRINGS_string_to_data (upper_enc, enclen, 101 return GNUNET_STRINGS_string_to_data(upper_enc, enclen,
102 (unsigned char*) result, 102 (unsigned char*)result,
103 sizeof (struct GNUNET_HashCode)); 103 sizeof(struct GNUNET_HashCode));
104} 104}
105 105
106 106
@@ -118,13 +118,13 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc,
118 * hashcode proximity. 118 * hashcode proximity.
119 */ 119 */
120unsigned int 120unsigned int
121GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode *a, 121GNUNET_CRYPTO_hash_distance_u32(const struct GNUNET_HashCode *a,
122 const struct GNUNET_HashCode *b) 122 const struct GNUNET_HashCode *b)
123{ 123{
124 unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16; 124 unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16;
125 unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16; 125 unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16;
126 126
127 return (x1 * x2); 127 return(x1 * x2);
128} 128}
129 129
130 130
@@ -135,13 +135,13 @@ GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode *a,
135 * @param result hash code that is randomized 135 * @param result hash code that is randomized
136 */ 136 */
137void 137void
138GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, 138GNUNET_CRYPTO_hash_create_random(enum GNUNET_CRYPTO_Quality mode,
139 struct GNUNET_HashCode *result) 139 struct GNUNET_HashCode *result)
140{ 140{
141 int i; 141 int i;
142 142
143 for (i = (sizeof (struct GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; i--) 143 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(uint32_t)) - 1; i >= 0; i--)
144 result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, UINT32_MAX); 144 result->bits[i] = GNUNET_CRYPTO_random_u32(mode, UINT32_MAX);
145} 145}
146 146
147 147
@@ -153,13 +153,13 @@ GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
153 * @param result set to b - a 153 * @param result set to b - a
154 */ 154 */
155void 155void
156GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode *a, 156GNUNET_CRYPTO_hash_difference(const struct GNUNET_HashCode *a,
157 const struct GNUNET_HashCode *b, 157 const struct GNUNET_HashCode *b,
158 struct GNUNET_HashCode *result) 158 struct GNUNET_HashCode *result)
159{ 159{
160 int i; 160 int i;
161 161
162 for (i = (sizeof (struct GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) 162 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0; i--)
163 result->bits[i] = b->bits[i] - a->bits[i]; 163 result->bits[i] = b->bits[i] - a->bits[i];
164} 164}
165 165
@@ -172,12 +172,12 @@ GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode *a,
172 * @param result set to a + delta 172 * @param result set to a + delta
173 */ 173 */
174void 174void
175GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode * a, 175GNUNET_CRYPTO_hash_sum(const struct GNUNET_HashCode * a,
176 const struct GNUNET_HashCode * delta, struct GNUNET_HashCode * result) 176 const struct GNUNET_HashCode * delta, struct GNUNET_HashCode * result)
177{ 177{
178 int i; 178 int i;
179 179
180 for (i = (sizeof (struct GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) 180 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0; i--)
181 result->bits[i] = delta->bits[i] + a->bits[i]; 181 result->bits[i] = delta->bits[i] + a->bits[i];
182} 182}
183 183
@@ -190,13 +190,13 @@ GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode * a,
190 * @param result set to a ^ b 190 * @param result set to a ^ b
191 */ 191 */
192void 192void
193GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode *a, 193GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a,
194 const struct GNUNET_HashCode *b, 194 const struct GNUNET_HashCode *b,
195 struct GNUNET_HashCode *result) 195 struct GNUNET_HashCode *result)
196{ 196{
197 int i; 197 int i;
198 198
199 for (i = (sizeof (struct GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) 199 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0; i--)
200 result->bits[i] = a->bits[i] ^ b->bits[i]; 200 result->bits[i] = a->bits[i] ^ b->bits[i];
201} 201}
202 202
@@ -209,20 +209,20 @@ GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode *a,
209 * @param iv set to a valid initialization vector 209 * @param iv set to a valid initialization vector
210 */ 210 */
211void 211void
212GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode *hc, 212GNUNET_CRYPTO_hash_to_aes_key(const struct GNUNET_HashCode *hc,
213 struct GNUNET_CRYPTO_SymmetricSessionKey *skey, 213 struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
214 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv) 214 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
215{ 215{
216 GNUNET_assert (GNUNET_YES == 216 GNUNET_assert(GNUNET_YES ==
217 GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), 217 GNUNET_CRYPTO_kdf(skey, sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey),
218 "Hash key derivation", strlen ("Hash key derivation"), 218 "Hash key derivation", strlen("Hash key derivation"),
219 hc, sizeof (struct GNUNET_HashCode), 219 hc, sizeof(struct GNUNET_HashCode),
220 NULL, 0)); 220 NULL, 0));
221 GNUNET_assert (GNUNET_YES == 221 GNUNET_assert(GNUNET_YES ==
222 GNUNET_CRYPTO_kdf (iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector), 222 GNUNET_CRYPTO_kdf(iv, sizeof(struct GNUNET_CRYPTO_SymmetricInitializationVector),
223 "Initialization vector derivation", strlen ("Initialization vector derivation"), 223 "Initialization vector derivation", strlen("Initialization vector derivation"),
224 hc, sizeof (struct GNUNET_HashCode), 224 hc, sizeof(struct GNUNET_HashCode),
225 NULL, 0)); 225 NULL, 0));
226} 226}
227 227
228 228
@@ -233,10 +233,10 @@ GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode *hc,
233 * @return Bit \a bit from hashcode \a code, -1 for invalid index 233 * @return Bit \a bit from hashcode \a code, -1 for invalid index
234 */ 234 */
235int 235int
236GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode * code, unsigned int bit) 236GNUNET_CRYPTO_hash_get_bit(const struct GNUNET_HashCode * code, unsigned int bit)
237{ 237{
238 GNUNET_assert (bit < 8 * sizeof (struct GNUNET_HashCode)); 238 GNUNET_assert(bit < 8 * sizeof(struct GNUNET_HashCode));
239 return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0; 239 return (((unsigned char *)code)[bit >> 3] & (1 << (bit & 7))) > 0;
240} 240}
241 241
242 242
@@ -253,16 +253,16 @@ GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode * code, unsigned int bi
253 * @return the number of bits that match 253 * @return the number of bits that match
254 */ 254 */
255unsigned int 255unsigned int
256GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode * first, 256GNUNET_CRYPTO_hash_matching_bits(const struct GNUNET_HashCode * first,
257 const struct GNUNET_HashCode * second) 257 const struct GNUNET_HashCode * second)
258{ 258{
259 unsigned int i; 259 unsigned int i;
260 260
261 for (i = 0; i < sizeof (struct GNUNET_HashCode) * 8; i++) 261 for (i = 0; i < sizeof(struct GNUNET_HashCode) * 8; i++)
262 if (GNUNET_CRYPTO_hash_get_bit (first, i) != 262 if (GNUNET_CRYPTO_hash_get_bit(first, i) !=
263 GNUNET_CRYPTO_hash_get_bit (second, i)) 263 GNUNET_CRYPTO_hash_get_bit(second, i))
264 return i; 264 return i;
265 return sizeof (struct GNUNET_HashCode) * 8; 265 return sizeof(struct GNUNET_HashCode) * 8;
266} 266}
267 267
268 268
@@ -275,22 +275,22 @@ GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode * first,
275 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. 275 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
276 */ 276 */
277int 277int
278GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode *h1, 278GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1,
279 const struct GNUNET_HashCode *h2) 279 const struct GNUNET_HashCode *h2)
280{ 280{
281 unsigned int *i1; 281 unsigned int *i1;
282 unsigned int *i2; 282 unsigned int *i2;
283 int i; 283 int i;
284 284
285 i1 = (unsigned int *) h1; 285 i1 = (unsigned int *)h1;
286 i2 = (unsigned int *) h2; 286 i2 = (unsigned int *)h2;
287 for (i = (sizeof (struct GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) 287 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0; i--)
288 { 288 {
289 if (i1[i] > i2[i]) 289 if (i1[i] > i2[i])
290 return 1; 290 return 1;
291 if (i1[i] < i2[i]) 291 if (i1[i] < i2[i])
292 return -1; 292 return -1;
293 } 293 }
294 return 0; 294 return 0;
295} 295}
296 296
@@ -305,23 +305,23 @@ GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode *h1,
305 * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2. 305 * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2.
306 */ 306 */
307int 307int
308GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode *h1, 308GNUNET_CRYPTO_hash_xorcmp(const struct GNUNET_HashCode *h1,
309 const struct GNUNET_HashCode *h2, 309 const struct GNUNET_HashCode *h2,
310 const struct GNUNET_HashCode *target) 310 const struct GNUNET_HashCode *target)
311{ 311{
312 int i; 312 int i;
313 unsigned int d1; 313 unsigned int d1;
314 unsigned int d2; 314 unsigned int d2;
315 315
316 for (i = sizeof (struct GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) 316 for (i = sizeof(struct GNUNET_HashCode) / sizeof(unsigned int) - 1; i >= 0; i--)
317 { 317 {
318 d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; 318 d1 = ((unsigned int *)h1)[i] ^ ((unsigned int *)target)[i];
319 d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; 319 d2 = ((unsigned int *)h2)[i] ^ ((unsigned int *)target)[i];
320 if (d1 > d2) 320 if (d1 > d2)
321 return 1; 321 return 1;
322 else if (d1 < d2) 322 else if (d1 < d2)
323 return -1; 323 return -1;
324 } 324 }
325 return 0; 325 return 0;
326} 326}
327 327
@@ -335,15 +335,15 @@ GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode *h1,
335 * @param ... pair of void * & size_t for context chunks, terminated by NULL 335 * @param ... pair of void * & size_t for context chunks, terminated by NULL
336 */ 336 */
337void 337void
338GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, 338GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key,
339 const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, 339 const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey,
340 const void *salt, size_t salt_len, ...) 340 const void *salt, size_t salt_len, ...)
341{ 341{
342 va_list argp; 342 va_list argp;
343 343
344 va_start (argp, salt_len); 344 va_start(argp, salt_len);
345 GNUNET_CRYPTO_hmac_derive_key_v (key, rkey, salt, salt_len, argp); 345 GNUNET_CRYPTO_hmac_derive_key_v(key, rkey, salt, salt_len, argp);
346 va_end (argp); 346 va_end(argp);
347} 347}
348 348
349 349
@@ -356,15 +356,15 @@ GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
356 * @param argp pair of void * & size_t for context chunks, terminated by NULL 356 * @param argp pair of void * & size_t for context chunks, terminated by NULL
357 */ 357 */
358void 358void
359GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, 359GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key,
360 const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, 360 const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey,
361 const void *salt, size_t salt_len, 361 const void *salt, size_t salt_len,
362 va_list argp) 362 va_list argp)
363{ 363{
364 GNUNET_CRYPTO_kdf_v (key->key, sizeof (key->key), 364 GNUNET_CRYPTO_kdf_v(key->key, sizeof(key->key),
365 salt, salt_len, 365 salt, salt_len,
366 rkey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), 366 rkey, sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey),
367 argp); 367 argp);
368} 368}
369 369
370 370
@@ -380,29 +380,29 @@ GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
380 * @param hmac where to store the hmac 380 * @param hmac where to store the hmac
381 */ 381 */
382void 382void
383GNUNET_CRYPTO_hmac_raw (const void *key, size_t key_len, 383GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len,
384 const void *plaintext, size_t plaintext_len, 384 const void *plaintext, size_t plaintext_len,
385 struct GNUNET_HashCode *hmac) 385 struct GNUNET_HashCode *hmac)
386{ 386{
387 static int once; 387 static int once;
388 static gcry_md_hd_t md; 388 static gcry_md_hd_t md;
389 const unsigned char *mc; 389 const unsigned char *mc;
390 390
391 if (! once) 391 if (!once)
392 { 392 {
393 once = 1; 393 once = 1;
394 GNUNET_assert (GPG_ERR_NO_ERROR == 394 GNUNET_assert(GPG_ERR_NO_ERROR ==
395 gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC)); 395 gcry_md_open(&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
396 } 396 }
397 else 397 else
398 { 398 {
399 gcry_md_reset (md); 399 gcry_md_reset(md);
400 } 400 }
401 gcry_md_setkey (md, key, key_len); 401 gcry_md_setkey(md, key, key_len);
402 gcry_md_write (md, plaintext, plaintext_len); 402 gcry_md_write(md, plaintext, plaintext_len);
403 mc = gcry_md_read (md, GCRY_MD_SHA512); 403 mc = gcry_md_read(md, GCRY_MD_SHA512);
404 GNUNET_assert (NULL != mc); 404 GNUNET_assert(NULL != mc);
405 GNUNET_memcpy (hmac->bits, mc, sizeof (hmac->bits)); 405 GNUNET_memcpy(hmac->bits, mc, sizeof(hmac->bits));
406} 406}
407 407
408 408
@@ -415,21 +415,20 @@ GNUNET_CRYPTO_hmac_raw (const void *key, size_t key_len,
415 * @param hmac where to store the hmac 415 * @param hmac where to store the hmac
416 */ 416 */
417void 417void
418GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, 418GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key,
419 const void *plaintext, size_t plaintext_len, 419 const void *plaintext, size_t plaintext_len,
420 struct GNUNET_HashCode *hmac) 420 struct GNUNET_HashCode *hmac)
421{ 421{
422 GNUNET_CRYPTO_hmac_raw ((void*) key->key, sizeof (key->key), 422 GNUNET_CRYPTO_hmac_raw((void*)key->key, sizeof(key->key),
423 plaintext, plaintext_len, 423 plaintext, plaintext_len,
424 hmac); 424 hmac);
425} 425}
426 426
427 427
428/** 428/**
429 * Context for cummulative hashing. 429 * Context for cummulative hashing.
430 */ 430 */
431struct GNUNET_HashContext 431struct GNUNET_HashContext {
432{
433 /** 432 /**
434 * Internal state of the hash function. 433 * Internal state of the hash function.
435 */ 434 */
@@ -443,19 +442,19 @@ struct GNUNET_HashContext
443 * @return context for incremental hash computation 442 * @return context for incremental hash computation
444 */ 443 */
445struct GNUNET_HashContext * 444struct GNUNET_HashContext *
446GNUNET_CRYPTO_hash_context_start () 445GNUNET_CRYPTO_hash_context_start()
447{ 446{
448 struct GNUNET_HashContext *hc; 447 struct GNUNET_HashContext *hc;
449 448
450 BENCHMARK_START (hash_context_start); 449 BENCHMARK_START(hash_context_start);
451 450
452 hc = GNUNET_new (struct GNUNET_HashContext); 451 hc = GNUNET_new(struct GNUNET_HashContext);
453 GNUNET_assert (0 == 452 GNUNET_assert(0 ==
454 gcry_md_open (&hc->hd, 453 gcry_md_open(&hc->hd,
455 GCRY_MD_SHA512, 454 GCRY_MD_SHA512,
456 0)); 455 0));
457 456
458 BENCHMARK_END (hash_context_start); 457 BENCHMARK_END(hash_context_start);
459 458
460 return hc; 459 return hc;
461} 460}
@@ -469,13 +468,13 @@ GNUNET_CRYPTO_hash_context_start ()
469 * @param size number of bytes in @a buf 468 * @param size number of bytes in @a buf
470 */ 469 */
471void 470void
472GNUNET_CRYPTO_hash_context_read (struct GNUNET_HashContext *hc, 471GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc,
473 const void *buf, 472 const void *buf,
474 size_t size) 473 size_t size)
475{ 474{
476 BENCHMARK_START (hash_context_read); 475 BENCHMARK_START(hash_context_read);
477 gcry_md_write (hc->hd, buf, size); 476 gcry_md_write(hc->hd, buf, size);
478 BENCHMARK_END (hash_context_read); 477 BENCHMARK_END(hash_context_read);
479} 478}
480 479
481 480
@@ -486,20 +485,20 @@ GNUNET_CRYPTO_hash_context_read (struct GNUNET_HashContext *hc,
486 * @param r_hash where to write the latest / final hash code 485 * @param r_hash where to write the latest / final hash code
487 */ 486 */
488void 487void
489GNUNET_CRYPTO_hash_context_finish (struct GNUNET_HashContext *hc, 488GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc,
490 struct GNUNET_HashCode *r_hash) 489 struct GNUNET_HashCode *r_hash)
491{ 490{
492 const void *res = gcry_md_read (hc->hd, 0); 491 const void *res = gcry_md_read(hc->hd, 0);
493 492
494 BENCHMARK_START (hash_context_finish); 493 BENCHMARK_START(hash_context_finish);
495 494
496 GNUNET_assert (NULL != res); 495 GNUNET_assert(NULL != res);
497 if (NULL != r_hash) 496 if (NULL != r_hash)
498 GNUNET_memcpy (r_hash, 497 GNUNET_memcpy(r_hash,
499 res, 498 res,
500 sizeof (struct GNUNET_HashCode)); 499 sizeof(struct GNUNET_HashCode));
501 GNUNET_CRYPTO_hash_context_abort (hc); 500 GNUNET_CRYPTO_hash_context_abort(hc);
502 BENCHMARK_END (hash_context_finish); 501 BENCHMARK_END(hash_context_finish);
503} 502}
504 503
505 504
@@ -509,10 +508,10 @@ GNUNET_CRYPTO_hash_context_finish (struct GNUNET_HashContext *hc,
509 * @param hc hash context to destroy 508 * @param hc hash context to destroy
510 */ 509 */
511void 510void
512GNUNET_CRYPTO_hash_context_abort (struct GNUNET_HashContext *hc) 511GNUNET_CRYPTO_hash_context_abort(struct GNUNET_HashContext *hc)
513{ 512{
514 gcry_md_close (hc->hd); 513 gcry_md_close(hc->hd);
515 GNUNET_free (hc); 514 GNUNET_free(hc);
516} 515}
517 516
518 517