diff options
Diffstat (limited to 'src/include/gnunet_crypto_lib.h')
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 271 |
1 files changed, 143 insertions, 128 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 30a7d9ee0..d5a1685d1 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -231,7 +231,8 @@ struct GNUNET_CRYPTO_AuthKey | |||
231 | * @param len the length of the buffer in bytes | 231 | * @param len the length of the buffer in bytes |
232 | * @return the resulting CRC32 checksum | 232 | * @return the resulting CRC32 checksum |
233 | */ | 233 | */ |
234 | int32_t GNUNET_CRYPTO_crc32_n (const void *buf, size_t len); | 234 | int32_t |
235 | GNUNET_CRYPTO_crc32_n (const void *buf, size_t len); | ||
235 | 236 | ||
236 | 237 | ||
237 | /** | 238 | /** |
@@ -241,7 +242,8 @@ int32_t GNUNET_CRYPTO_crc32_n (const void *buf, size_t len); | |||
241 | * @param i the upper limit (exclusive) for the random number | 242 | * @param i the upper limit (exclusive) for the random number |
242 | * @return a random value in the interval [0,i) (exclusive). | 243 | * @return a random value in the interval [0,i) (exclusive). |
243 | */ | 244 | */ |
244 | uint32_t GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i); | 245 | uint32_t |
246 | GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i); | ||
245 | 247 | ||
246 | 248 | ||
247 | /** | 249 | /** |
@@ -251,8 +253,8 @@ uint32_t GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i); | |||
251 | * @param max value returned will be in range [0,max) (exclusive) | 253 | * @param max value returned will be in range [0,max) (exclusive) |
252 | * @return random 64-bit number | 254 | * @return random 64-bit number |
253 | */ | 255 | */ |
254 | uint64_t GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, | 256 | uint64_t |
255 | uint64_t max); | 257 | GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max); |
256 | 258 | ||
257 | 259 | ||
258 | /** | 260 | /** |
@@ -262,8 +264,8 @@ uint64_t GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, | |||
262 | * @param n the size of the array | 264 | * @param n the size of the array |
263 | * @return the permutation array (allocated from heap) | 265 | * @return the permutation array (allocated from heap) |
264 | */ | 266 | */ |
265 | unsigned int *GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, | 267 | unsigned int * |
266 | unsigned int n); | 268 | GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n); |
267 | 269 | ||
268 | 270 | ||
269 | /** | 271 | /** |
@@ -271,8 +273,8 @@ unsigned int *GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, | |||
271 | * | 273 | * |
272 | * @param key key to initialize | 274 | * @param key key to initialize |
273 | */ | 275 | */ |
274 | void GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey | 276 | void |
275 | *key); | 277 | GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key); |
276 | 278 | ||
277 | /** | 279 | /** |
278 | * Check that a new session key is well-formed. | 280 | * Check that a new session key is well-formed. |
@@ -280,8 +282,9 @@ void GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey | |||
280 | * @param key key to check | 282 | * @param key key to check |
281 | * @return GNUNET_OK if the key is valid | 283 | * @return GNUNET_OK if the key is valid |
282 | */ | 284 | */ |
283 | int GNUNET_CRYPTO_aes_check_session_key (const struct | 285 | int |
284 | GNUNET_CRYPTO_AesSessionKey *key); | 286 | GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey |
287 | *key); | ||
285 | 288 | ||
286 | 289 | ||
287 | /** | 290 | /** |
@@ -295,12 +298,11 @@ int GNUNET_CRYPTO_aes_check_session_key (const struct | |||
295 | * for streams. | 298 | * for streams. |
296 | * @return the size of the encrypted block, -1 for errors | 299 | * @return the size of the encrypted block, -1 for errors |
297 | */ | 300 | */ |
298 | ssize_t GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len, | 301 | ssize_t |
299 | const struct GNUNET_CRYPTO_AesSessionKey | 302 | GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len, |
300 | *sessionkey, | 303 | const struct GNUNET_CRYPTO_AesSessionKey *sessionkey, |
301 | const struct | 304 | const struct GNUNET_CRYPTO_AesInitializationVector |
302 | GNUNET_CRYPTO_AesInitializationVector *iv, | 305 | *iv, void *result); |
303 | void *result); | ||
304 | 306 | ||
305 | 307 | ||
306 | /** | 308 | /** |
@@ -313,12 +315,11 @@ ssize_t GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len, | |||
313 | * @param result address to store the result at | 315 | * @param result address to store the result at |
314 | * @return -1 on failure, size of decrypted block on success | 316 | * @return -1 on failure, size of decrypted block on success |
315 | */ | 317 | */ |
316 | ssize_t GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size, | 318 | ssize_t |
317 | const struct GNUNET_CRYPTO_AesSessionKey | 319 | GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size, |
318 | *sessionkey, | 320 | const struct GNUNET_CRYPTO_AesSessionKey *sessionkey, |
319 | const struct | 321 | const struct GNUNET_CRYPTO_AesInitializationVector |
320 | GNUNET_CRYPTO_AesInitializationVector *iv, | 322 | *iv, void *result); |
321 | void *result); | ||
322 | 323 | ||
323 | 324 | ||
324 | /** | 325 | /** |
@@ -329,11 +330,10 @@ ssize_t GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size, | |||
329 | * @param salt_len size of the salt | 330 | * @param salt_len size of the salt |
330 | * @param ... pairs of void * & size_t for context chunks, terminated by NULL | 331 | * @param ... pairs of void * & size_t for context chunks, terminated by NULL |
331 | */ | 332 | */ |
332 | void GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector | 333 | void |
333 | *iv, | 334 | GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, |
334 | const struct GNUNET_CRYPTO_AesSessionKey | 335 | const struct GNUNET_CRYPTO_AesSessionKey *skey, |
335 | *skey, const void *salt, size_t salt_len, | 336 | const void *salt, size_t salt_len, ...); |
336 | ...); | ||
337 | 337 | ||
338 | 338 | ||
339 | /** | 339 | /** |
@@ -344,11 +344,10 @@ void GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector | |||
344 | * @param salt_len size of the salt | 344 | * @param salt_len size of the salt |
345 | * @param argp pairs of void * & size_t for context chunks, terminated by NULL | 345 | * @param argp pairs of void * & size_t for context chunks, terminated by NULL |
346 | */ | 346 | */ |
347 | void GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector | 347 | void |
348 | *iv, | 348 | GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv, |
349 | const struct GNUNET_CRYPTO_AesSessionKey | 349 | const struct GNUNET_CRYPTO_AesSessionKey *skey, |
350 | *skey, const void *salt, size_t salt_len, | 350 | const void *salt, size_t salt_len, va_list argp); |
351 | va_list argp); | ||
352 | 351 | ||
353 | 352 | ||
354 | /** | 353 | /** |
@@ -357,8 +356,9 @@ void GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector | |||
357 | * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be | 356 | * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be |
358 | * safely cast to char*, a '\\0' termination is set). | 357 | * safely cast to char*, a '\\0' termination is set). |
359 | */ | 358 | */ |
360 | void GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, | 359 | void |
361 | struct GNUNET_CRYPTO_HashAsciiEncoded *result); | 360 | GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, |
361 | struct GNUNET_CRYPTO_HashAsciiEncoded *result); | ||
362 | 362 | ||
363 | 363 | ||
364 | /** | 364 | /** |
@@ -367,7 +367,8 @@ void GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, | |||
367 | * @param result where to store the GNUNET_CRYPTO_hash code | 367 | * @param result where to store the GNUNET_CRYPTO_hash code |
368 | * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding | 368 | * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding |
369 | */ | 369 | */ |
370 | int GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result); | 370 | int |
371 | GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result); | ||
371 | 372 | ||
372 | 373 | ||
373 | /** | 374 | /** |
@@ -381,8 +382,9 @@ int GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result); | |||
381 | * @param b some hash code | 382 | * @param b some hash code |
382 | * @return number between 0 and UINT32_MAX | 383 | * @return number between 0 and UINT32_MAX |
383 | */ | 384 | */ |
384 | uint32_t GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, | 385 | uint32_t |
385 | const GNUNET_HashCode * b); | 386 | GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, |
387 | const GNUNET_HashCode * b); | ||
386 | 388 | ||
387 | 389 | ||
388 | /** | 390 | /** |
@@ -392,7 +394,8 @@ uint32_t GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, | |||
392 | * @param size size of the block | 394 | * @param size size of the block |
393 | * @param ret pointer to where to write the hashcode | 395 | * @param ret pointer to where to write the hashcode |
394 | */ | 396 | */ |
395 | void GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret); | 397 | void |
398 | GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret); | ||
396 | 399 | ||
397 | 400 | ||
398 | /** | 401 | /** |
@@ -403,9 +406,10 @@ void GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret); | |||
403 | * @param plaintext_len length of plaintext | 406 | * @param plaintext_len length of plaintext |
404 | * @param hmac where to store the hmac | 407 | * @param hmac where to store the hmac |
405 | */ | 408 | */ |
406 | void GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, | 409 | void |
407 | const void *plaintext, size_t plaintext_len, | 410 | GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, |
408 | GNUNET_HashCode * hmac); | 411 | const void *plaintext, size_t plaintext_len, |
412 | GNUNET_HashCode * hmac); | ||
409 | 413 | ||
410 | 414 | ||
411 | /** | 415 | /** |
@@ -435,16 +439,11 @@ struct GNUNET_CRYPTO_FileHashContext; | |||
435 | * @param callback_cls closure for callback | 439 | * @param callback_cls closure for callback |
436 | * @return NULL on (immediate) errror | 440 | * @return NULL on (immediate) errror |
437 | */ | 441 | */ |
438 | struct GNUNET_CRYPTO_FileHashContext *GNUNET_CRYPTO_hash_file (enum | 442 | struct GNUNET_CRYPTO_FileHashContext * |
439 | GNUNET_SCHEDULER_Priority | 443 | GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, |
440 | priority, | 444 | const char *filename, size_t blocksize, |
441 | const char | 445 | GNUNET_CRYPTO_HashCompletedCallback callback, |
442 | *filename, | 446 | void *callback_cls); |
443 | size_t blocksize, | ||
444 | GNUNET_CRYPTO_HashCompletedCallback | ||
445 | callback, | ||
446 | void | ||
447 | *callback_cls); | ||
448 | 447 | ||
449 | 448 | ||
450 | /** | 449 | /** |
@@ -452,7 +451,8 @@ struct GNUNET_CRYPTO_FileHashContext *GNUNET_CRYPTO_hash_file (enum | |||
452 | * | 451 | * |
453 | * @param fhc operation to cancel (callback must not yet have been invoked) | 452 | * @param fhc operation to cancel (callback must not yet have been invoked) |
454 | */ | 453 | */ |
455 | void GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc); | 454 | void |
455 | GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc); | ||
456 | 456 | ||
457 | 457 | ||
458 | /** | 458 | /** |
@@ -461,8 +461,9 @@ void GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc); | |||
461 | * @param mode desired quality level | 461 | * @param mode desired quality level |
462 | * @param result hash code that is randomized | 462 | * @param result hash code that is randomized |
463 | */ | 463 | */ |
464 | void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, | 464 | void |
465 | GNUNET_HashCode * result); | 465 | GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, |
466 | GNUNET_HashCode * result); | ||
466 | 467 | ||
467 | 468 | ||
468 | /** | 469 | /** |
@@ -472,9 +473,10 @@ void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, | |||
472 | * @param b some hash code | 473 | * @param b some hash code |
473 | * @param result set to b - a | 474 | * @param result set to b - a |
474 | */ | 475 | */ |
475 | void GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, | 476 | void |
476 | const GNUNET_HashCode * b, | 477 | GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, |
477 | GNUNET_HashCode * result); | 478 | const GNUNET_HashCode * b, |
479 | GNUNET_HashCode * result); | ||
478 | 480 | ||
479 | 481 | ||
480 | /** | 482 | /** |
@@ -484,9 +486,10 @@ void GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, | |||
484 | * @param delta some hash code | 486 | * @param delta some hash code |
485 | * @param result set to a + delta | 487 | * @param result set to a + delta |
486 | */ | 488 | */ |
487 | void GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, | 489 | void |
488 | const GNUNET_HashCode * delta, | 490 | GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, |
489 | GNUNET_HashCode * result); | 491 | const GNUNET_HashCode * delta, |
492 | GNUNET_HashCode * result); | ||
490 | 493 | ||
491 | 494 | ||
492 | /** | 495 | /** |
@@ -496,9 +499,9 @@ void GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, | |||
496 | * @param b some hash code | 499 | * @param b some hash code |
497 | * @param result set to a ^ b | 500 | * @param result set to a ^ b |
498 | */ | 501 | */ |
499 | void GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, | 502 | void |
500 | const GNUNET_HashCode * b, | 503 | GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b, |
501 | GNUNET_HashCode * result); | 504 | GNUNET_HashCode * result); |
502 | 505 | ||
503 | 506 | ||
504 | /** | 507 | /** |
@@ -508,10 +511,11 @@ void GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, | |||
508 | * @param skey set to a valid session key | 511 | * @param skey set to a valid session key |
509 | * @param iv set to a valid initialization vector | 512 | * @param iv set to a valid initialization vector |
510 | */ | 513 | */ |
511 | void GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, | 514 | void |
512 | struct GNUNET_CRYPTO_AesSessionKey *skey, | 515 | GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, |
513 | struct GNUNET_CRYPTO_AesInitializationVector | 516 | struct GNUNET_CRYPTO_AesSessionKey *skey, |
514 | *iv); | 517 | struct GNUNET_CRYPTO_AesInitializationVector |
518 | *iv); | ||
515 | 519 | ||
516 | 520 | ||
517 | /** | 521 | /** |
@@ -521,7 +525,8 @@ void GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, | |||
521 | * @param bit index into the hashcode, [0...159] | 525 | * @param bit index into the hashcode, [0...159] |
522 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | 526 | * @return Bit \a bit from hashcode \a code, -1 for invalid index |
523 | */ | 527 | */ |
524 | int GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit); | 528 | int |
529 | GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit); | ||
525 | 530 | ||
526 | /** | 531 | /** |
527 | * Determine how many low order bits match in two | 532 | * Determine how many low order bits match in two |
@@ -535,8 +540,9 @@ int GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit); | |||
535 | * | 540 | * |
536 | * @return the number of bits that match | 541 | * @return the number of bits that match |
537 | */ | 542 | */ |
538 | unsigned int GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, | 543 | unsigned int |
539 | const GNUNET_HashCode * second); | 544 | GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, |
545 | const GNUNET_HashCode * second); | ||
540 | 546 | ||
541 | 547 | ||
542 | /** | 548 | /** |
@@ -547,8 +553,8 @@ unsigned int GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, | |||
547 | * @param h2 some hash code | 553 | * @param h2 some hash code |
548 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. | 554 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. |
549 | */ | 555 | */ |
550 | int GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, | 556 | int |
551 | const GNUNET_HashCode * h2); | 557 | GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2); |
552 | 558 | ||
553 | 559 | ||
554 | /** | 560 | /** |
@@ -560,9 +566,10 @@ int GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, | |||
560 | * @param target some hash code | 566 | * @param target some hash code |
561 | * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2. | 567 | * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2. |
562 | */ | 568 | */ |
563 | int GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, | 569 | int |
564 | const GNUNET_HashCode * h2, | 570 | GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, |
565 | const GNUNET_HashCode * target); | 571 | const GNUNET_HashCode * h2, |
572 | const GNUNET_HashCode * target); | ||
566 | 573 | ||
567 | 574 | ||
568 | /** | 575 | /** |
@@ -573,10 +580,11 @@ int GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, | |||
573 | * @param salt_len size of the salt | 580 | * @param salt_len size of the salt |
574 | * @param argp pair of void * & size_t for context chunks, terminated by NULL | 581 | * @param argp pair of void * & size_t for context chunks, terminated by NULL |
575 | */ | 582 | */ |
576 | void GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, | 583 | void |
577 | const struct GNUNET_CRYPTO_AesSessionKey | 584 | GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, |
578 | *rkey, const void *salt, size_t salt_len, | 585 | const struct GNUNET_CRYPTO_AesSessionKey *rkey, |
579 | va_list argp); | 586 | const void *salt, size_t salt_len, |
587 | va_list argp); | ||
580 | 588 | ||
581 | 589 | ||
582 | /** | 590 | /** |
@@ -587,10 +595,10 @@ void GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, | |||
587 | * @param salt_len size of the salt | 595 | * @param salt_len size of the salt |
588 | * @param ... pair of void * & size_t for context chunks, terminated by NULL | 596 | * @param ... pair of void * & size_t for context chunks, terminated by NULL |
589 | */ | 597 | */ |
590 | void GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, | 598 | void |
591 | const struct GNUNET_CRYPTO_AesSessionKey | 599 | GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, |
592 | *rkey, const void *salt, size_t salt_len, | 600 | const struct GNUNET_CRYPTO_AesSessionKey *rkey, |
593 | ...); | 601 | const void *salt, size_t salt_len, ...); |
594 | 602 | ||
595 | /** | 603 | /** |
596 | * @brief Derive key | 604 | * @brief Derive key |
@@ -604,9 +612,10 @@ void GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, | |||
604 | * @param skm_len length of skm | 612 | * @param skm_len length of skm |
605 | * @return GNUNET_YES on success | 613 | * @return GNUNET_YES on success |
606 | */ | 614 | */ |
607 | int GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, | 615 | int |
608 | int prf_algo, const void *xts, size_t xts_len, | 616 | GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo, |
609 | const void *skm, size_t skm_len, ...); | 617 | const void *xts, size_t xts_len, const void *skm, |
618 | size_t skm_len, ...); | ||
610 | 619 | ||
611 | 620 | ||
612 | /** | 621 | /** |
@@ -622,9 +631,10 @@ int GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, | |||
622 | * @param argp va_list of void * & size_t pairs for context chunks | 631 | * @param argp va_list of void * & size_t pairs for context chunks |
623 | * @return GNUNET_YES on success | 632 | * @return GNUNET_YES on success |
624 | */ | 633 | */ |
625 | int GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, | 634 | int |
626 | int prf_algo, const void *xts, size_t xts_len, | 635 | GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo, |
627 | const void *skm, size_t skm_len, va_list argp); | 636 | const void *xts, size_t xts_len, const void *skm, |
637 | size_t skm_len, va_list argp); | ||
628 | 638 | ||
629 | 639 | ||
630 | /** | 640 | /** |
@@ -638,9 +648,10 @@ int GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, | |||
638 | * @param argp va_list of void * & size_t pairs for context chunks | 648 | * @param argp va_list of void * & size_t pairs for context chunks |
639 | * @return GNUNET_YES on success | 649 | * @return GNUNET_YES on success |
640 | */ | 650 | */ |
641 | int GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, | 651 | int |
642 | size_t xts_len, const void *skm, size_t skm_len, | 652 | GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, |
643 | va_list argp); | 653 | size_t xts_len, const void *skm, size_t skm_len, |
654 | va_list argp); | ||
644 | 655 | ||
645 | 656 | ||
646 | /** | 657 | /** |
@@ -654,8 +665,9 @@ int GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, | |||
654 | * @param ... void * & size_t pairs for context chunks | 665 | * @param ... void * & size_t pairs for context chunks |
655 | * @return GNUNET_YES on success | 666 | * @return GNUNET_YES on success |
656 | */ | 667 | */ |
657 | int GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, | 668 | int |
658 | size_t xts_len, const void *skm, size_t skm_len, ...); | 669 | GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, |
670 | size_t xts_len, const void *skm, size_t skm_len, ...); | ||
659 | 671 | ||
660 | 672 | ||
661 | /** | 673 | /** |
@@ -663,7 +675,8 @@ int GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, | |||
663 | * | 675 | * |
664 | * @return fresh private key | 676 | * @return fresh private key |
665 | */ | 677 | */ |
666 | struct GNUNET_CRYPTO_RsaPrivateKey *GNUNET_CRYPTO_rsa_key_create (void); | 678 | struct GNUNET_CRYPTO_RsaPrivateKey * |
679 | GNUNET_CRYPTO_rsa_key_create (void); | ||
667 | 680 | ||
668 | /** | 681 | /** |
669 | * Decode the private key from the data-format back | 682 | * Decode the private key from the data-format back |
@@ -672,9 +685,8 @@ struct GNUNET_CRYPTO_RsaPrivateKey *GNUNET_CRYPTO_rsa_key_create (void); | |||
672 | * @param buf the buffer where the private key data is stored | 685 | * @param buf the buffer where the private key data is stored |
673 | * @param len the length of the data in 'buffer' | 686 | * @param len the length of the data in 'buffer' |
674 | */ | 687 | */ |
675 | struct GNUNET_CRYPTO_RsaPrivateKey *GNUNET_CRYPTO_rsa_decode_key (const char | 688 | struct GNUNET_CRYPTO_RsaPrivateKey * |
676 | *buf, | 689 | GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len); |
677 | uint16_t len); | ||
678 | 690 | ||
679 | /** | 691 | /** |
680 | * Create a new private key by reading it from a file. If the | 692 | * Create a new private key by reading it from a file. If the |
@@ -690,8 +702,8 @@ struct GNUNET_CRYPTO_RsaPrivateKey *GNUNET_CRYPTO_rsa_decode_key (const char | |||
690 | * @return new private key, NULL on error (for example, | 702 | * @return new private key, NULL on error (for example, |
691 | * permission denied) | 703 | * permission denied) |
692 | */ | 704 | */ |
693 | struct GNUNET_CRYPTO_RsaPrivateKey | 705 | struct GNUNET_CRYPTO_RsaPrivateKey * |
694 | *GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename); | 706 | GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename); |
695 | 707 | ||
696 | 708 | ||
697 | /** | 709 | /** |
@@ -701,15 +713,16 @@ struct GNUNET_CRYPTO_RsaPrivateKey | |||
701 | * @param hc "random" input to PRNG | 713 | * @param hc "random" input to PRNG |
702 | * @return some private key purely dependent on input | 714 | * @return some private key purely dependent on input |
703 | */ | 715 | */ |
704 | struct GNUNET_CRYPTO_RsaPrivateKey | 716 | struct GNUNET_CRYPTO_RsaPrivateKey * |
705 | *GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc); | 717 | GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc); |
706 | 718 | ||
707 | 719 | ||
708 | /** | 720 | /** |
709 | * Free memory occupied by the private key. | 721 | * Free memory occupied by the private key. |
710 | * @param hostkey pointer to the memory to free | 722 | * @param hostkey pointer to the memory to free |
711 | */ | 723 | */ |
712 | void GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey); | 724 | void |
725 | GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey); | ||
713 | 726 | ||
714 | 727 | ||
715 | /** | 728 | /** |
@@ -718,11 +731,11 @@ void GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey); | |||
718 | * @param priv the private key | 731 | * @param priv the private key |
719 | * @param pub where to write the public key | 732 | * @param pub where to write the public key |
720 | */ | 733 | */ |
721 | void GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey | 734 | void |
722 | *priv, | 735 | GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey |
723 | struct | 736 | *priv, |
724 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | 737 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
725 | *pub); | 738 | *pub); |
726 | 739 | ||
727 | 740 | ||
728 | /** | 741 | /** |
@@ -735,11 +748,11 @@ void GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey | |||
735 | * @param target where to store the encrypted block | 748 | * @param target where to store the encrypted block |
736 | * @return GNUNET_SYSERR on error, GNUNET_OK if ok | 749 | * @return GNUNET_SYSERR on error, GNUNET_OK if ok |
737 | */ | 750 | */ |
738 | int GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size, | 751 | int |
739 | const struct | 752 | GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size, |
740 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | 753 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
741 | *publicKey, | 754 | *publicKey, |
742 | struct GNUNET_CRYPTO_RsaEncryptedData *target); | 755 | struct GNUNET_CRYPTO_RsaEncryptedData *target); |
743 | 756 | ||
744 | 757 | ||
745 | /** | 758 | /** |
@@ -751,10 +764,10 @@ int GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size, | |||
751 | * @param max how many bytes of a result are expected? Must be exact. | 764 | * @param max how many bytes of a result are expected? Must be exact. |
752 | * @return the size of the decrypted block (that is, size) or -1 on error | 765 | * @return the size of the decrypted block (that is, size) or -1 on error |
753 | */ | 766 | */ |
754 | ssize_t GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey | 767 | ssize_t |
755 | *key, | 768 | GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
756 | const struct GNUNET_CRYPTO_RsaEncryptedData | 769 | const struct GNUNET_CRYPTO_RsaEncryptedData *block, |
757 | *block, void *result, size_t max); | 770 | void *result, size_t max); |
758 | 771 | ||
759 | 772 | ||
760 | /** | 773 | /** |
@@ -765,9 +778,10 @@ ssize_t GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey | |||
765 | * @param sig where to write the signature | 778 | * @param sig where to write the signature |
766 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | 779 | * @return GNUNET_SYSERR on error, GNUNET_OK on success |
767 | */ | 780 | */ |
768 | int GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | 781 | int |
769 | const struct GNUNET_CRYPTO_RsaSignaturePurpose | 782 | GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
770 | *purpose, struct GNUNET_CRYPTO_RsaSignature *sig); | 783 | const struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose, |
784 | struct GNUNET_CRYPTO_RsaSignature *sig); | ||
771 | 785 | ||
772 | 786 | ||
773 | /** | 787 | /** |
@@ -780,13 +794,13 @@ int GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | |||
780 | * @param publicKey public key of the signer | 794 | * @param publicKey public key of the signer |
781 | * @return GNUNET_OK if ok, GNUNET_SYSERR if invalid | 795 | * @return GNUNET_OK if ok, GNUNET_SYSERR if invalid |
782 | */ | 796 | */ |
783 | int GNUNET_CRYPTO_rsa_verify (uint32_t purpose, | 797 | int |
784 | const struct GNUNET_CRYPTO_RsaSignaturePurpose | 798 | GNUNET_CRYPTO_rsa_verify (uint32_t purpose, |
785 | *validate, | 799 | const struct GNUNET_CRYPTO_RsaSignaturePurpose |
786 | const struct GNUNET_CRYPTO_RsaSignature *sig, | 800 | *validate, |
787 | const struct | 801 | const struct GNUNET_CRYPTO_RsaSignature *sig, |
788 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | 802 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
789 | *publicKey); | 803 | *publicKey); |
790 | 804 | ||
791 | 805 | ||
792 | 806 | ||
@@ -795,7 +809,8 @@ int GNUNET_CRYPTO_rsa_verify (uint32_t purpose, | |||
795 | * where strong entropy gathering is not desired | 809 | * where strong entropy gathering is not desired |
796 | * (for example, for hostkey generation). | 810 | * (for example, for hostkey generation). |
797 | */ | 811 | */ |
798 | void GNUNET_CRYPTO_random_disable_entropy_gathering (void); | 812 | void |
813 | GNUNET_CRYPTO_random_disable_entropy_gathering (void); | ||
799 | 814 | ||
800 | #if 0 /* keep Emacsens' auto-indent happy */ | 815 | #if 0 /* keep Emacsens' auto-indent happy */ |
801 | { | 816 | { |