aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_crypto_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_crypto_lib.h')
-rw-r--r--src/include/gnunet_crypto_lib.h166
1 files changed, 77 insertions, 89 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 883664534..ec71a791b 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -231,8 +231,7 @@ 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 */
234int32_t GNUNET_CRYPTO_crc32_n (const void *buf, 234int32_t GNUNET_CRYPTO_crc32_n (const void *buf, size_t len);
235 size_t len);
236 235
237 236
238/** 237/**
@@ -242,8 +241,7 @@ int32_t GNUNET_CRYPTO_crc32_n (const void *buf,
242 * @param i the upper limit (exclusive) for the random number 241 * @param i the upper limit (exclusive) for the random number
243 * @return a random value in the interval [0,i) (exclusive). 242 * @return a random value in the interval [0,i) (exclusive).
244 */ 243 */
245uint32_t GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, 244uint32_t GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i);
246 uint32_t i);
247 245
248 246
249/** 247/**
@@ -254,7 +252,7 @@ uint32_t GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
254 * @return random 64-bit number 252 * @return random 64-bit number
255 */ 253 */
256uint64_t GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, 254uint64_t GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
257 uint64_t max); 255 uint64_t max);
258 256
259 257
260/** 258/**
@@ -298,12 +296,12 @@ int GNUNET_CRYPTO_aes_check_session_key (const struct
298 * @return the size of the encrypted block, -1 for errors 296 * @return the size of the encrypted block, -1 for errors
299 */ 297 */
300ssize_t GNUNET_CRYPTO_aes_encrypt (const void *block, 298ssize_t GNUNET_CRYPTO_aes_encrypt (const void *block,
301 size_t len, 299 size_t len,
302 const struct GNUNET_CRYPTO_AesSessionKey 300 const struct GNUNET_CRYPTO_AesSessionKey
303 *sessionkey, 301 *sessionkey,
304 const struct 302 const struct
305 GNUNET_CRYPTO_AesInitializationVector *iv, 303 GNUNET_CRYPTO_AesInitializationVector *iv,
306 void *result); 304 void *result);
307 305
308 306
309/** 307/**
@@ -316,11 +314,13 @@ ssize_t GNUNET_CRYPTO_aes_encrypt (const void *block,
316 * @param result address to store the result at 314 * @param result address to store the result at
317 * @return -1 on failure, size of decrypted block on success 315 * @return -1 on failure, size of decrypted block on success
318 */ 316 */
319ssize_t GNUNET_CRYPTO_aes_decrypt (const void *block, 317ssize_t GNUNET_CRYPTO_aes_decrypt (const void *block,
320 size_t size, 318 size_t size,
321 const struct GNUNET_CRYPTO_AesSessionKey *sessionkey, 319 const struct GNUNET_CRYPTO_AesSessionKey
322 const struct GNUNET_CRYPTO_AesInitializationVector *iv, 320 *sessionkey,
323 void *result); 321 const struct
322 GNUNET_CRYPTO_AesInitializationVector *iv,
323 void *result);
324 324
325 325
326/** 326/**
@@ -333,9 +333,8 @@ ssize_t GNUNET_CRYPTO_aes_decrypt (const void *block,
333 */ 333 */
334void 334void
335GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, 335GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
336 const struct GNUNET_CRYPTO_AesSessionKey *skey, 336 const struct GNUNET_CRYPTO_AesSessionKey *skey,
337 const void *salt, size_t salt_len, 337 const void *salt, size_t salt_len, ...);
338 ...);
339 338
340 339
341/** 340/**
@@ -348,9 +347,8 @@ GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
348 */ 347 */
349void 348void
350GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv, 349GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv,
351 const struct GNUNET_CRYPTO_AesSessionKey *skey, 350 const struct GNUNET_CRYPTO_AesSessionKey *skey,
352 const void *salt, size_t salt_len, 351 const void *salt, size_t salt_len, va_list argp);
353 va_list argp);
354 352
355 353
356/** 354/**
@@ -360,8 +358,7 @@ GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv,
360 * safely cast to char*, a '\\0' termination is set). 358 * safely cast to char*, a '\\0' termination is set).
361 */ 359 */
362void GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, 360void GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block,
363 struct GNUNET_CRYPTO_HashAsciiEncoded 361 struct GNUNET_CRYPTO_HashAsciiEncoded *result);
364 *result);
365 362
366 363
367/** 364/**
@@ -370,8 +367,7 @@ void GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block,
370 * @param result where to store the GNUNET_CRYPTO_hash code 367 * @param result where to store the GNUNET_CRYPTO_hash code
371 * @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
372 */ 369 */
373int GNUNET_CRYPTO_hash_from_string (const char *enc, 370int GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result);
374 GNUNET_HashCode * result);
375 371
376 372
377/** 373/**
@@ -386,7 +382,7 @@ int GNUNET_CRYPTO_hash_from_string (const char *enc,
386 * @return number between 0 and UINT32_MAX 382 * @return number between 0 and UINT32_MAX
387 */ 383 */
388uint32_t GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, 384uint32_t GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
389 const GNUNET_HashCode * b); 385 const GNUNET_HashCode * b);
390 386
391 387
392/** 388/**
@@ -396,9 +392,7 @@ uint32_t GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
396 * @param size size of the block 392 * @param size size of the block
397 * @param ret pointer to where to write the hashcode 393 * @param ret pointer to where to write the hashcode
398 */ 394 */
399void GNUNET_CRYPTO_hash (const void *block, 395void GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret);
400 size_t size,
401 GNUNET_HashCode * ret);
402 396
403 397
404/** 398/**
@@ -409,11 +403,10 @@ void GNUNET_CRYPTO_hash (const void *block,
409 * @param plaintext_len length of plaintext 403 * @param plaintext_len length of plaintext
410 * @param hmac where to store the hmac 404 * @param hmac where to store the hmac
411 */ 405 */
412void 406void
413GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, 407GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
414 const void *plaintext, 408 const void *plaintext,
415 size_t plaintext_len, 409 size_t plaintext_len, GNUNET_HashCode * hmac);
416 GNUNET_HashCode *hmac);
417 410
418 411
419/** 412/**
@@ -443,12 +436,16 @@ struct GNUNET_CRYPTO_FileHashContext;
443 * @param callback_cls closure for callback 436 * @param callback_cls closure for callback
444 * @return NULL on (immediate) errror 437 * @return NULL on (immediate) errror
445 */ 438 */
446struct GNUNET_CRYPTO_FileHashContext * 439struct GNUNET_CRYPTO_FileHashContext *GNUNET_CRYPTO_hash_file (enum
447GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, 440 GNUNET_SCHEDULER_Priority
448 const char *filename, 441 priority,
449 size_t blocksize, 442 const char
450 GNUNET_CRYPTO_HashCompletedCallback callback, 443 *filename,
451 void *callback_cls); 444 size_t blocksize,
445 GNUNET_CRYPTO_HashCompletedCallback
446 callback,
447 void
448 *callback_cls);
452 449
453 450
454/** 451/**
@@ -456,8 +453,7 @@ GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
456 * 453 *
457 * @param fhc operation to cancel (callback must not yet have been invoked) 454 * @param fhc operation to cancel (callback must not yet have been invoked)
458 */ 455 */
459void 456void GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc);
460GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc);
461 457
462 458
463/** 459/**
@@ -467,7 +463,7 @@ GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc);
467 * @param result hash code that is randomized 463 * @param result hash code that is randomized
468 */ 464 */
469void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, 465void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
470 GNUNET_HashCode * result); 466 GNUNET_HashCode * result);
471 467
472 468
473/** 469/**
@@ -516,8 +512,7 @@ void GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a,
516void GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, 512void GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
517 struct GNUNET_CRYPTO_AesSessionKey *skey, 513 struct GNUNET_CRYPTO_AesSessionKey *skey,
518 struct 514 struct
519 GNUNET_CRYPTO_AesInitializationVector 515 GNUNET_CRYPTO_AesInitializationVector *iv);
520 *iv);
521 516
522 517
523/** 518/**
@@ -527,8 +522,7 @@ void GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
527 * @param bit index into the hashcode, [0...159] 522 * @param bit index into the hashcode, [0...159]
528 * @return Bit \a bit from hashcode \a code, -1 for invalid index 523 * @return Bit \a bit from hashcode \a code, -1 for invalid index
529 */ 524 */
530int GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, 525int GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit);
531 unsigned int bit);
532 526
533/** 527/**
534 * Determine how many low order bits match in two 528 * Determine how many low order bits match in two
@@ -542,7 +536,8 @@ int GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code,
542 * 536 *
543 * @return the number of bits that match 537 * @return the number of bits that match
544 */ 538 */
545unsigned int GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first, const GNUNET_HashCode *second); 539unsigned int GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first,
540 const GNUNET_HashCode * second);
546 541
547 542
548/** 543/**
@@ -580,11 +575,10 @@ int GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
580 * @param argp pair of void * & size_t for context chunks, terminated by NULL 575 * @param argp pair of void * & size_t for context chunks, terminated by NULL
581 */ 576 */
582void 577void
583GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key, 578GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
584 const struct GNUNET_CRYPTO_AesSessionKey *rkey, 579 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
585 const void *salt, 580 const void *salt,
586 size_t salt_len, 581 size_t salt_len, va_list argp);
587 va_list argp);
588 582
589 583
590/** 584/**
@@ -596,11 +590,9 @@ GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key,
596 * @param ... pair of void * & size_t for context chunks, terminated by NULL 590 * @param ... pair of void * & size_t for context chunks, terminated by NULL
597 */ 591 */
598void 592void
599GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, 593GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
600 const struct GNUNET_CRYPTO_AesSessionKey *rkey, 594 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
601 const void *salt, 595 const void *salt, size_t salt_len, ...);
602 size_t salt_len,
603 ...);
604 596
605/** 597/**
606 * @brief Derive key 598 * @brief Derive key
@@ -615,12 +607,11 @@ GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key,
615 * @return GNUNET_YES on success 607 * @return GNUNET_YES on success
616 */ 608 */
617int 609int
618GNUNET_CRYPTO_hkdf (void *result, 610GNUNET_CRYPTO_hkdf (void *result,
619 size_t out_len, 611 size_t out_len,
620 int xtr_algo, int prf_algo, 612 int xtr_algo, int prf_algo,
621 const void *xts, size_t xts_len, 613 const void *xts, size_t xts_len,
622 const void *skm, size_t skm_len, 614 const void *skm, size_t skm_len, ...);
623 ...);
624 615
625 616
626/** 617/**
@@ -637,13 +628,12 @@ GNUNET_CRYPTO_hkdf (void *result,
637 * @return GNUNET_YES on success 628 * @return GNUNET_YES on success
638 */ 629 */
639int 630int
640GNUNET_CRYPTO_hkdf_v (void *result, 631GNUNET_CRYPTO_hkdf_v (void *result,
641 size_t out_len, 632 size_t out_len,
642 int xtr_algo, 633 int xtr_algo,
643 int prf_algo, 634 int prf_algo,
644 const void *xts, size_t xts_len, 635 const void *xts, size_t xts_len,
645 const void *skm, size_t skm_len, 636 const void *skm, size_t skm_len, va_list argp);
646 va_list argp);
647 637
648 638
649/** 639/**
@@ -658,11 +648,10 @@ GNUNET_CRYPTO_hkdf_v (void *result,
658 * @return GNUNET_YES on success 648 * @return GNUNET_YES on success
659 */ 649 */
660int 650int
661GNUNET_CRYPTO_kdf_v (void *result, 651GNUNET_CRYPTO_kdf_v (void *result,
662 size_t out_len, 652 size_t out_len,
663 const void *xts, size_t xts_len, 653 const void *xts, size_t xts_len,
664 const void *skm, size_t skm_len, 654 const void *skm, size_t skm_len, va_list argp);
665 va_list argp);
666 655
667 656
668/** 657/**
@@ -678,8 +667,8 @@ GNUNET_CRYPTO_kdf_v (void *result,
678 */ 667 */
679int 668int
680GNUNET_CRYPTO_kdf (void *result, size_t out_len, 669GNUNET_CRYPTO_kdf (void *result, size_t out_len,
681 const void *xts, size_t xts_len, const void *skm, 670 const void *xts, size_t xts_len, const void *skm,
682 size_t skm_len, ...); 671 size_t skm_len, ...);
683 672
684 673
685/** 674/**
@@ -696,8 +685,9 @@ struct GNUNET_CRYPTO_RsaPrivateKey *GNUNET_CRYPTO_rsa_key_create (void);
696 * @param buf the buffer where the private key data is stored 685 * @param buf the buffer where the private key data is stored
697 * @param len the length of the data in 'buffer' 686 * @param len the length of the data in 'buffer'
698 */ 687 */
699struct GNUNET_CRYPTO_RsaPrivateKey * 688struct GNUNET_CRYPTO_RsaPrivateKey *GNUNET_CRYPTO_rsa_decode_key (const char
700GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len); 689 *buf,
690 uint16_t len);
701 691
702/** 692/**
703 * Create a new private key by reading it from a file. If the 693 * Create a new private key by reading it from a file. If the
@@ -714,7 +704,7 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len);
714 * permission denied) 704 * permission denied)
715 */ 705 */
716struct GNUNET_CRYPTO_RsaPrivateKey 706struct GNUNET_CRYPTO_RsaPrivateKey
717 *GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename); 707 *GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename);
718 708
719 709
720/** 710/**
@@ -725,7 +715,7 @@ struct GNUNET_CRYPTO_RsaPrivateKey
725 * @return some private key purely dependent on input 715 * @return some private key purely dependent on input
726 */ 716 */
727struct GNUNET_CRYPTO_RsaPrivateKey 717struct GNUNET_CRYPTO_RsaPrivateKey
728 *GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc); 718 *GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc);
729 719
730 720
731/** 721/**
@@ -775,11 +765,10 @@ int GNUNET_CRYPTO_rsa_encrypt (const void *block,
775 * @param max how many bytes of a result are expected? Must be exact. 765 * @param max how many bytes of a result are expected? Must be exact.
776 * @return the size of the decrypted block (that is, size) or -1 on error 766 * @return the size of the decrypted block (that is, size) or -1 on error
777 */ 767 */
778ssize_t GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 768ssize_t GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey
779 const struct GNUNET_CRYPTO_RsaEncryptedData 769 *key,
780 *block, 770 const struct GNUNET_CRYPTO_RsaEncryptedData
781 void *result, 771 *block, void *result, size_t max);
782 size_t max);
783 772
784 773
785/** 774/**
@@ -792,8 +781,7 @@ ssize_t GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key
792 */ 781 */
793int GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 782int GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
794 const struct GNUNET_CRYPTO_RsaSignaturePurpose 783 const struct GNUNET_CRYPTO_RsaSignaturePurpose
795 *purpose, 784 *purpose, struct GNUNET_CRYPTO_RsaSignature *sig);
796 struct GNUNET_CRYPTO_RsaSignature *sig);
797 785
798 786
799/** 787/**