aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_hash.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-11 09:43:04 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-11 09:43:04 +0000
commitd9d94d0e53d26af75ec8241383d166544ebd79f3 (patch)
tree9080b73624389403a198257fe0547bb4634e64d2 /src/util/crypto_hash.c
parent2d792ee2e9cc0c993b8907e2c8edb0c2b8465343 (diff)
downloadgnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.tar.gz
gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.zip
converting to GNUNET_LOG_from*
Diffstat (limited to 'src/util/crypto_hash.c')
-rw-r--r--src/util/crypto_hash.c217
1 files changed, 114 insertions, 103 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index c253bbf2f..b8c9a8082 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -36,6 +36,9 @@
36#include "gnunet_disk_lib.h" 36#include "gnunet_disk_lib.h"
37#include <gcrypt.h> 37#include <gcrypt.h>
38 38
39#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
40
41#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
39 42
40/** 43/**
41 * Hash block of given size. 44 * Hash block of given size.
@@ -116,14 +119,14 @@ struct GNUNET_CRYPTO_FileHashContext
116 */ 119 */
117static void 120static void
118file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc, 121file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc,
119 const GNUNET_HashCode * res) 122 const GNUNET_HashCode * res)
120{ 123{
121 fhc->callback (fhc->callback_cls, res); 124 fhc->callback (fhc->callback_cls, res);
122 GNUNET_free (fhc->filename); 125 GNUNET_free (fhc->filename);
123 if (!GNUNET_DISK_handle_invalid (fhc->fh)) 126 if (!GNUNET_DISK_handle_invalid (fhc->fh))
124 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh)); 127 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh));
125 gcry_md_close (fhc->md); 128 gcry_md_close (fhc->md);
126 GNUNET_free (fhc); /* also frees fhc->buffer */ 129 GNUNET_free (fhc); /* also frees fhc->buffer */
127} 130}
128 131
129 132
@@ -146,19 +149,19 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
146 if (fhc->fsize - fhc->offset < delta) 149 if (fhc->fsize - fhc->offset < delta)
147 delta = fhc->fsize - fhc->offset; 150 delta = fhc->fsize - fhc->offset;
148 if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta)) 151 if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta))
149 { 152 {
150 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename); 153 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename);
151 file_hash_finish (fhc, NULL); 154 file_hash_finish (fhc, NULL);
152 return; 155 return;
153 } 156 }
154 gcry_md_write (fhc->md, fhc->buffer, delta); 157 gcry_md_write (fhc->md, fhc->buffer, delta);
155 fhc->offset += delta; 158 fhc->offset += delta;
156 if (fhc->offset == fhc->fsize) 159 if (fhc->offset == fhc->fsize)
157 { 160 {
158 res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512); 161 res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512);
159 file_hash_finish (fhc, res); 162 file_hash_finish (fhc, res);
160 return; 163 return;
161 } 164 }
162 fhc->task = GNUNET_SCHEDULER_add_now (&file_hash_task, fhc); 165 fhc->task = GNUNET_SCHEDULER_add_now (&file_hash_task, fhc);
163} 166}
164 167
@@ -175,43 +178,43 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
175 */ 178 */
176struct GNUNET_CRYPTO_FileHashContext * 179struct GNUNET_CRYPTO_FileHashContext *
177GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, 180GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
178 const char *filename, size_t blocksize, 181 const char *filename, size_t blocksize,
179 GNUNET_CRYPTO_HashCompletedCallback callback, 182 GNUNET_CRYPTO_HashCompletedCallback callback,
180 void *callback_cls) 183 void *callback_cls)
181{ 184{
182 struct GNUNET_CRYPTO_FileHashContext *fhc; 185 struct GNUNET_CRYPTO_FileHashContext *fhc;
183 186
184 GNUNET_assert (blocksize > 0); 187 GNUNET_assert (blocksize > 0);
185 fhc = 188 fhc =
186 GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) + blocksize); 189 GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) + blocksize);
187 fhc->callback = callback; 190 fhc->callback = callback;
188 fhc->callback_cls = callback_cls; 191 fhc->callback_cls = callback_cls;
189 fhc->buffer = (unsigned char *) &fhc[1]; 192 fhc->buffer = (unsigned char *) &fhc[1];
190 fhc->filename = GNUNET_strdup (filename); 193 fhc->filename = GNUNET_strdup (filename);
191 if (GPG_ERR_NO_ERROR != gcry_md_open (&fhc->md, GCRY_MD_SHA512, 0)) 194 if (GPG_ERR_NO_ERROR != gcry_md_open (&fhc->md, GCRY_MD_SHA512, 0))
192 { 195 {
193 GNUNET_break (0); 196 GNUNET_break (0);
194 GNUNET_free (fhc); 197 GNUNET_free (fhc);
195 return NULL; 198 return NULL;
196 } 199 }
197 fhc->bsize = blocksize; 200 fhc->bsize = blocksize;
198 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO)) 201 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO))
199 { 202 {
200 GNUNET_free (fhc->filename); 203 GNUNET_free (fhc->filename);
201 GNUNET_free (fhc); 204 GNUNET_free (fhc);
202 return NULL; 205 return NULL;
203 } 206 }
204 fhc->fh = 207 fhc->fh =
205 GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 208 GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
206 GNUNET_DISK_PERM_NONE); 209 GNUNET_DISK_PERM_NONE);
207 if (!fhc->fh) 210 if (!fhc->fh)
208 { 211 {
209 GNUNET_free (fhc->filename); 212 GNUNET_free (fhc->filename);
210 GNUNET_free (fhc); 213 GNUNET_free (fhc);
211 return NULL; 214 return NULL;
212 } 215 }
213 fhc->task = 216 fhc->task =
214 GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc); 217 GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc);
215 return fhc; 218 return fhc;
216} 219}
217 220
@@ -257,7 +260,7 @@ getValue__ (unsigned char a)
257 */ 260 */
258void 261void
259GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, 262GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block,
260 struct GNUNET_CRYPTO_HashAsciiEncoded *result) 263 struct GNUNET_CRYPTO_HashAsciiEncoded *result)
261{ 264{
262 /** 265 /**
263 * 32 characters for encoding (GNUNET_CRYPTO_hash => 32 characters) 266 * 32 characters for encoding (GNUNET_CRYPTO_hash => 32 characters)
@@ -275,22 +278,23 @@ GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block,
275 rpos = 0; 278 rpos = 0;
276 bits = 0; 279 bits = 0;
277 while ((rpos < sizeof (GNUNET_HashCode)) || (vbit > 0)) 280 while ((rpos < sizeof (GNUNET_HashCode)) || (vbit > 0))
278 {
279 if ((rpos < sizeof (GNUNET_HashCode)) && (vbit < 5))
280 {
281 bits = (bits << 8) | ((unsigned char *) block)[rpos++]; /* eat 8 more bits */
282 vbit += 8;
283 }
284 if (vbit < 5)
285 { 281 {
286 bits <<= (5 - vbit); /* zero-padding */ 282 if ((rpos < sizeof (GNUNET_HashCode)) && (vbit < 5))
287 GNUNET_assert (vbit == 2); /* padding by 3: 512+3 mod 5 == 0 */ 283 {
288 vbit = 5; 284 bits = (bits << 8) | ((unsigned char *) block)[rpos++]; /* eat 8 more bits */
285 vbit += 8;
286 }
287 if (vbit < 5)
288 {
289 bits <<= (5 - vbit); /* zero-padding */
290 GNUNET_assert (vbit == 2); /* padding by 3: 512+3 mod 5 == 0 */
291 vbit = 5;
292 }
293 GNUNET_assert (wpos <
294 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
295 result->encoding[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
296 vbit -= 5;
289 } 297 }
290 GNUNET_assert (wpos < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
291 result->encoding[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
292 vbit -= 5;
293 }
294 GNUNET_assert (wpos == sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); 298 GNUNET_assert (wpos == sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
295 GNUNET_assert (vbit == 0); 299 GNUNET_assert (vbit == 0);
296 result->encoding[wpos] = '\0'; 300 result->encoding[wpos] = '\0';
@@ -314,22 +318,22 @@ GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result)
314 if (strlen (enc) != sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1) 318 if (strlen (enc) != sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1)
315 return GNUNET_SYSERR; 319 return GNUNET_SYSERR;
316 320
317 vbit = 2; /* padding! */ 321 vbit = 2; /* padding! */
318 wpos = sizeof (GNUNET_HashCode); 322 wpos = sizeof (GNUNET_HashCode);
319 rpos = sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1; 323 rpos = sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1;
320 bits = getValue__ (enc[--rpos]) >> 3; 324 bits = getValue__ (enc[--rpos]) >> 3;
321 while (wpos > 0) 325 while (wpos > 0)
322 {
323 GNUNET_assert (rpos > 0);
324 bits = (getValue__ (enc[--rpos]) << vbit) | bits;
325 vbit += 5;
326 if (vbit >= 8)
327 { 326 {
328 ((unsigned char *) result)[--wpos] = (unsigned char) bits; 327 GNUNET_assert (rpos > 0);
329 bits >>= 8; 328 bits = (getValue__ (enc[--rpos]) << vbit) | bits;
330 vbit -= 8; 329 vbit += 5;
330 if (vbit >= 8)
331 {
332 ((unsigned char *) result)[--wpos] = (unsigned char) bits;
333 bits >>= 8;
334 vbit -= 8;
335 }
331 } 336 }
332 }
333 GNUNET_assert (rpos == 0); 337 GNUNET_assert (rpos == 0);
334 GNUNET_assert (vbit == 0); 338 GNUNET_assert (vbit == 0);
335 return GNUNET_OK; 339 return GNUNET_OK;
@@ -348,7 +352,7 @@ GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result)
348 */ 352 */
349unsigned int 353unsigned int
350GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, 354GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
351 const GNUNET_HashCode * b) 355 const GNUNET_HashCode * b)
352{ 356{
353 unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16; 357 unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16;
354 unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16; 358 unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16;
@@ -358,7 +362,7 @@ GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
358 362
359void 363void
360GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, 364GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
361 GNUNET_HashCode * result) 365 GNUNET_HashCode * result)
362{ 366{
363 int i; 367 int i;
364 368
@@ -368,33 +372,37 @@ GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
368 372
369void 373void
370GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, 374GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a,
371 const GNUNET_HashCode * b, 375 const GNUNET_HashCode * b,
372 GNUNET_HashCode * result) 376 GNUNET_HashCode * result)
373{ 377{
374 int i; 378 int i;
375 379
376 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) 380 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
381 i--)
377 result->bits[i] = b->bits[i] - a->bits[i]; 382 result->bits[i] = b->bits[i] - a->bits[i];
378} 383}
379 384
380void 385void
381GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, 386GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a,
382 const GNUNET_HashCode * delta, GNUNET_HashCode * result) 387 const GNUNET_HashCode * delta,
388 GNUNET_HashCode * result)
383{ 389{
384 int i; 390 int i;
385 391
386 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) 392 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
393 i--)
387 result->bits[i] = delta->bits[i] + a->bits[i]; 394 result->bits[i] = delta->bits[i] + a->bits[i];
388} 395}
389 396
390 397
391void 398void
392GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b, 399GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b,
393 GNUNET_HashCode * result) 400 GNUNET_HashCode * result)
394{ 401{
395 int i; 402 int i;
396 403
397 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) 404 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
405 i--)
398 result->bits[i] = a->bits[i] ^ b->bits[i]; 406 result->bits[i] = a->bits[i] ^ b->bits[i];
399} 407}
400 408
@@ -404,17 +412,18 @@ GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b,
404 */ 412 */
405void 413void
406GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, 414GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
407 struct GNUNET_CRYPTO_AesSessionKey *skey, 415 struct GNUNET_CRYPTO_AesSessionKey *skey,
408 struct GNUNET_CRYPTO_AesInitializationVector *iv) 416 struct GNUNET_CRYPTO_AesInitializationVector
417 *iv)
409{ 418{
410 GNUNET_assert (sizeof (GNUNET_HashCode) >= 419 GNUNET_assert (sizeof (GNUNET_HashCode) >=
411 GNUNET_CRYPTO_AES_KEY_LENGTH + 420 GNUNET_CRYPTO_AES_KEY_LENGTH +
412 sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); 421 sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
413 memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); 422 memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH);
414 skey->crc32 = 423 skey->crc32 =
415 htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); 424 htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH));
416 memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH], 425 memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH],
417 sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); 426 sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
418} 427}
419 428
420 429
@@ -445,13 +454,13 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit)
445 */ 454 */
446unsigned int 455unsigned int
447GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, 456GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first,
448 const GNUNET_HashCode * second) 457 const GNUNET_HashCode * second)
449{ 458{
450 unsigned int i; 459 unsigned int i;
451 460
452 for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++) 461 for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++)
453 if (GNUNET_CRYPTO_hash_get_bit (first, i) != 462 if (GNUNET_CRYPTO_hash_get_bit (first, i) !=
454 GNUNET_CRYPTO_hash_get_bit (second, i)) 463 GNUNET_CRYPTO_hash_get_bit (second, i))
455 return i; 464 return i;
456 return sizeof (GNUNET_HashCode) * 8; 465 return sizeof (GNUNET_HashCode) * 8;
457} 466}
@@ -463,7 +472,8 @@ GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first,
463 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. 472 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
464 */ 473 */
465int 474int
466GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2) 475GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1,
476 const GNUNET_HashCode * h2)
467{ 477{
468 unsigned int *i1; 478 unsigned int *i1;
469 unsigned int *i2; 479 unsigned int *i2;
@@ -471,13 +481,14 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2)
471 481
472 i1 = (unsigned int *) h1; 482 i1 = (unsigned int *) h1;
473 i2 = (unsigned int *) h2; 483 i2 = (unsigned int *) h2;
474 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) 484 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
475 { 485 i--)
476 if (i1[i] > i2[i]) 486 {
477 return 1; 487 if (i1[i] > i2[i])
478 if (i1[i] < i2[i]) 488 return 1;
479 return -1; 489 if (i1[i] < i2[i])
480 } 490 return -1;
491 }
481 return 0; 492 return 0;
482} 493}
483 494
@@ -489,22 +500,22 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2)
489 */ 500 */
490int 501int
491GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, 502GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
492 const GNUNET_HashCode * h2, 503 const GNUNET_HashCode * h2,
493 const GNUNET_HashCode * target) 504 const GNUNET_HashCode * target)
494{ 505{
495 int i; 506 int i;
496 unsigned int d1; 507 unsigned int d1;
497 unsigned int d2; 508 unsigned int d2;
498 509
499 for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) 510 for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--)
500 { 511 {
501 d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; 512 d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i];
502 d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; 513 d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i];
503 if (d1 > d2) 514 if (d1 > d2)
504 return 1; 515 return 1;
505 else if (d1 < d2) 516 else if (d1 < d2)
506 return -1; 517 return -1;
507 } 518 }
508 return 0; 519 return 0;
509} 520}
510 521
@@ -519,8 +530,8 @@ GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
519 */ 530 */
520void 531void
521GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, 532GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
522 const struct GNUNET_CRYPTO_AesSessionKey *rkey, 533 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
523 const void *salt, size_t salt_len, ...) 534 const void *salt, size_t salt_len, ...)
524{ 535{
525 va_list argp; 536 va_list argp;
526 537
@@ -540,12 +551,12 @@ GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
540 */ 551 */
541void 552void
542GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, 553GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
543 const struct GNUNET_CRYPTO_AesSessionKey *rkey, 554 const struct GNUNET_CRYPTO_AesSessionKey
544 const void *salt, size_t salt_len, 555 *rkey, const void *salt, size_t salt_len,
545 va_list argp) 556 va_list argp)
546{ 557{
547 GNUNET_CRYPTO_kdf_v (key->key, sizeof (key->key), salt, salt_len, rkey->key, 558 GNUNET_CRYPTO_kdf_v (key->key, sizeof (key->key), salt, salt_len, rkey->key,
548 sizeof (rkey->key), argp); 559 sizeof (rkey->key), argp);
549} 560}
550 561
551 562
@@ -559,14 +570,14 @@ GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
559 */ 570 */
560void 571void
561GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, 572GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
562 const void *plaintext, size_t plaintext_len, 573 const void *plaintext, size_t plaintext_len,
563 GNUNET_HashCode * hmac) 574 GNUNET_HashCode * hmac)
564{ 575{
565 gcry_md_hd_t md; 576 gcry_md_hd_t md;
566 const unsigned char *mc; 577 const unsigned char *mc;
567 578
568 GNUNET_assert (GPG_ERR_NO_ERROR == 579 GNUNET_assert (GPG_ERR_NO_ERROR ==
569 gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC)); 580 gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
570 gcry_md_setkey (md, key->key, sizeof (key->key)); 581 gcry_md_setkey (md, key->key, sizeof (key->key));
571 gcry_md_write (md, plaintext, plaintext_len); 582 gcry_md_write (md, plaintext, plaintext_len);
572 mc = gcry_md_read (md, GCRY_MD_SHA512); 583 mc = gcry_md_read (md, GCRY_MD_SHA512);