diff options
| author | Stephan Mueller <smueller@chronox.de> | 2014-11-11 23:27:16 -0500 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2014-11-13 09:31:40 -0500 |
| commit | 968ab291078006de022b2245702a050ccdc32cd3 (patch) | |
| tree | af2d92bfdafae5f721ee747229288427b018e281 /include/crypto | |
| parent | 90240ffb127729713cd7d9c1b5c1c0c9451681cd (diff) | |
crypto: doc - SHASH API documentation
The API function calls exported by the kernel crypto API for SHASHes
to be used by consumers are documented.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/crypto')
| -rw-r--r-- | include/crypto/hash.h | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/include/crypto/hash.h b/include/crypto/hash.h index b2c193acc1ab..3d66e8bd0932 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h | |||
| @@ -583,6 +583,33 @@ static inline void ahash_request_set_crypt(struct ahash_request *req, | |||
| 583 | req->result = result; | 583 | req->result = result; |
| 584 | } | 584 | } |
| 585 | 585 | ||
| 586 | /** | ||
| 587 | * DOC: Synchronous Message Digest API | ||
| 588 | * | ||
| 589 | * The synchronous message digest API is used with the ciphers of type | ||
| 590 | * CRYPTO_ALG_TYPE_SHASH (listed as type "shash" in /proc/crypto) | ||
| 591 | * | ||
| 592 | * The message digest API is able to maintain state information for the | ||
| 593 | * caller. | ||
| 594 | * | ||
| 595 | * The synchronous message digest API can store user-related context in in its | ||
| 596 | * shash_desc request data structure. | ||
| 597 | */ | ||
| 598 | |||
| 599 | /** | ||
| 600 | * crypto_alloc_shash() - allocate message digest handle | ||
| 601 | * @alg_name: is the cra_name / name or cra_driver_name / driver name of the | ||
| 602 | * message digest cipher | ||
| 603 | * @type: specifies the type of the cipher | ||
| 604 | * @mask: specifies the mask for the cipher | ||
| 605 | * | ||
| 606 | * Allocate a cipher handle for a message digest. The returned &struct | ||
| 607 | * crypto_shash is the cipher handle that is required for any subsequent | ||
| 608 | * API invocation for that message digest. | ||
| 609 | * | ||
| 610 | * Return: allocated cipher handle in case of success; IS_ERR() is true in case | ||
| 611 | * of an error, PTR_ERR() returns the error code. | ||
| 612 | */ | ||
| 586 | struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type, | 613 | struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type, |
| 587 | u32 mask); | 614 | u32 mask); |
| 588 | 615 | ||
| @@ -591,6 +618,10 @@ static inline struct crypto_tfm *crypto_shash_tfm(struct crypto_shash *tfm) | |||
| 591 | return &tfm->base; | 618 | return &tfm->base; |
| 592 | } | 619 | } |
| 593 | 620 | ||
| 621 | /** | ||
| 622 | * crypto_free_shash() - zeroize and free the message digest handle | ||
| 623 | * @tfm: cipher handle to be freed | ||
| 624 | */ | ||
| 594 | static inline void crypto_free_shash(struct crypto_shash *tfm) | 625 | static inline void crypto_free_shash(struct crypto_shash *tfm) |
| 595 | { | 626 | { |
| 596 | crypto_destroy_tfm(tfm, crypto_shash_tfm(tfm)); | 627 | crypto_destroy_tfm(tfm, crypto_shash_tfm(tfm)); |
| @@ -602,6 +633,15 @@ static inline unsigned int crypto_shash_alignmask( | |||
| 602 | return crypto_tfm_alg_alignmask(crypto_shash_tfm(tfm)); | 633 | return crypto_tfm_alg_alignmask(crypto_shash_tfm(tfm)); |
| 603 | } | 634 | } |
| 604 | 635 | ||
| 636 | /** | ||
| 637 | * crypto_shash_blocksize() - obtain block size for cipher | ||
| 638 | * @tfm: cipher handle | ||
| 639 | * | ||
| 640 | * The block size for the message digest cipher referenced with the cipher | ||
| 641 | * handle is returned. | ||
| 642 | * | ||
| 643 | * Return: block size of cipher | ||
| 644 | */ | ||
| 605 | static inline unsigned int crypto_shash_blocksize(struct crypto_shash *tfm) | 645 | static inline unsigned int crypto_shash_blocksize(struct crypto_shash *tfm) |
| 606 | { | 646 | { |
| 607 | return crypto_tfm_alg_blocksize(crypto_shash_tfm(tfm)); | 647 | return crypto_tfm_alg_blocksize(crypto_shash_tfm(tfm)); |
| @@ -617,6 +657,15 @@ static inline struct shash_alg *crypto_shash_alg(struct crypto_shash *tfm) | |||
| 617 | return __crypto_shash_alg(crypto_shash_tfm(tfm)->__crt_alg); | 657 | return __crypto_shash_alg(crypto_shash_tfm(tfm)->__crt_alg); |
| 618 | } | 658 | } |
| 619 | 659 | ||
| 660 | /** | ||
| 661 | * crypto_shash_digestsize() - obtain message digest size | ||
| 662 | * @tfm: cipher handle | ||
| 663 | * | ||
| 664 | * The size for the message digest created by the message digest cipher | ||
| 665 | * referenced with the cipher handle is returned. | ||
| 666 | * | ||
| 667 | * Return: digest size of cipher | ||
| 668 | */ | ||
| 620 | static inline unsigned int crypto_shash_digestsize(struct crypto_shash *tfm) | 669 | static inline unsigned int crypto_shash_digestsize(struct crypto_shash *tfm) |
| 621 | { | 670 | { |
| 622 | return crypto_shash_alg(tfm)->digestsize; | 671 | return crypto_shash_alg(tfm)->digestsize; |
| @@ -642,6 +691,21 @@ static inline void crypto_shash_clear_flags(struct crypto_shash *tfm, u32 flags) | |||
| 642 | crypto_tfm_clear_flags(crypto_shash_tfm(tfm), flags); | 691 | crypto_tfm_clear_flags(crypto_shash_tfm(tfm), flags); |
| 643 | } | 692 | } |
| 644 | 693 | ||
| 694 | /** | ||
| 695 | * crypto_shash_descsize() - obtain the operational state size | ||
| 696 | * @tfm: cipher handle | ||
| 697 | * | ||
| 698 | * The size of the operational state the cipher needs during operation is | ||
| 699 | * returned for the hash referenced with the cipher handle. This size is | ||
| 700 | * required to calculate the memory requirements to allow the caller allocating | ||
| 701 | * sufficient memory for operational state. | ||
| 702 | * | ||
| 703 | * The operational state is defined with struct shash_desc where the size of | ||
| 704 | * that data structure is to be calculated as | ||
| 705 | * sizeof(struct shash_desc) + crypto_shash_descsize(alg) | ||
| 706 | * | ||
| 707 | * Return: size of the operational state | ||
| 708 | */ | ||
| 645 | static inline unsigned int crypto_shash_descsize(struct crypto_shash *tfm) | 709 | static inline unsigned int crypto_shash_descsize(struct crypto_shash *tfm) |
| 646 | { | 710 | { |
| 647 | return tfm->descsize; | 711 | return tfm->descsize; |
| @@ -652,29 +716,129 @@ static inline void *shash_desc_ctx(struct shash_desc *desc) | |||
| 652 | return desc->__ctx; | 716 | return desc->__ctx; |
| 653 | } | 717 | } |
| 654 | 718 | ||
| 719 | /** | ||
| 720 | * crypto_shash_setkey() - set key for message digest | ||
| 721 | * @tfm: cipher handle | ||
| 722 | * @key: buffer holding the key | ||
| 723 | * @keylen: length of the key in bytes | ||
| 724 | * | ||
| 725 | * The caller provided key is set for the keyed message digest cipher. The | ||
| 726 | * cipher handle must point to a keyed message digest cipher in order for this | ||
| 727 | * function to succeed. | ||
| 728 | * | ||
| 729 | * Return: 0 if the setting of the key was successful; < 0 if an error occurred | ||
| 730 | */ | ||
| 655 | int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key, | 731 | int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key, |
| 656 | unsigned int keylen); | 732 | unsigned int keylen); |
| 733 | |||
| 734 | /** | ||
| 735 | * crypto_shash_digest() - calculate message digest for buffer | ||
| 736 | * @desc: see crypto_shash_final() | ||
| 737 | * @data: see crypto_shash_update() | ||
| 738 | * @len: see crypto_shash_update() | ||
| 739 | * @out: see crypto_shash_final() | ||
| 740 | * | ||
| 741 | * This function is a "short-hand" for the function calls of crypto_shash_init, | ||
| 742 | * crypto_shash_update and crypto_shash_final. The parameters have the same | ||
| 743 | * meaning as discussed for those separate three functions. | ||
| 744 | * | ||
| 745 | * Return: 0 if the message digest creation was successful; < 0 if an error | ||
| 746 | * occurred | ||
| 747 | */ | ||
| 657 | int crypto_shash_digest(struct shash_desc *desc, const u8 *data, | 748 | int crypto_shash_digest(struct shash_desc *desc, const u8 *data, |
| 658 | unsigned int len, u8 *out); | 749 | unsigned int len, u8 *out); |
| 659 | 750 | ||
| 751 | /** | ||
| 752 | * crypto_shash_export() - extract operational state for message digest | ||
| 753 | * @desc: reference to the operational state handle whose state is exported | ||
| 754 | * @out: output buffer of sufficient size that can hold the hash state | ||
| 755 | * | ||
| 756 | * This function exports the hash state of the operational state handle into the | ||
| 757 | * caller-allocated output buffer out which must have sufficient size (e.g. by | ||
| 758 | * calling crypto_shash_descsize). | ||
| 759 | * | ||
| 760 | * Return: 0 if the export creation was successful; < 0 if an error occurred | ||
| 761 | */ | ||
| 660 | static inline int crypto_shash_export(struct shash_desc *desc, void *out) | 762 | static inline int crypto_shash_export(struct shash_desc *desc, void *out) |
| 661 | { | 763 | { |
| 662 | return crypto_shash_alg(desc->tfm)->export(desc, out); | 764 | return crypto_shash_alg(desc->tfm)->export(desc, out); |
| 663 | } | 765 | } |
| 664 | 766 | ||
| 767 | /** | ||
| 768 | * crypto_shash_import() - import operational state | ||
| 769 | * @desc: reference to the operational state handle the state imported into | ||
| 770 | * @in: buffer holding the state | ||
| 771 | * | ||
| 772 | * This function imports the hash state into the operational state handle from | ||
| 773 | * the input buffer. That buffer should have been generated with the | ||
| 774 | * crypto_ahash_export function. | ||
| 775 | * | ||
| 776 | * Return: 0 if the import was successful; < 0 if an error occurred | ||
| 777 | */ | ||
| 665 | static inline int crypto_shash_import(struct shash_desc *desc, const void *in) | 778 | static inline int crypto_shash_import(struct shash_desc *desc, const void *in) |
| 666 | { | 779 | { |
| 667 | return crypto_shash_alg(desc->tfm)->import(desc, in); | 780 | return crypto_shash_alg(desc->tfm)->import(desc, in); |
| 668 | } | 781 | } |
| 669 | 782 | ||
| 783 | /** | ||
| 784 | * crypto_shash_init() - (re)initialize message digest | ||
| 785 | * @desc: operational state handle that is already filled | ||
| 786 | * | ||
| 787 | * The call (re-)initializes the message digest referenced by the | ||
| 788 | * operational state handle. Any potentially existing state created by | ||
| 789 | * previous operations is discarded. | ||
| 790 | * | ||
| 791 | * Return: 0 if the message digest initialization was successful; < 0 if an | ||
| 792 | * error occurred | ||
| 793 | */ | ||
| 670 | static inline int crypto_shash_init(struct shash_desc *desc) | 794 | static inline int crypto_shash_init(struct shash_desc *desc) |
| 671 | { | 795 | { |
| 672 | return crypto_shash_alg(desc->tfm)->init(desc); | 796 | return crypto_shash_alg(desc->tfm)->init(desc); |
| 673 | } | 797 | } |
| 674 | 798 | ||
| 799 | /** | ||
| 800 | * crypto_shash_update() - add data to message digest for processing | ||
| 801 | * @desc: operational state handle that is already initialized | ||
| 802 | * @data: input data to be added to the message digest | ||
| 803 | * @len: length of the input data | ||
| 804 | * | ||
| 805 | * Updates the message digest state of the operational state handle. | ||
| 806 | * | ||
| 807 | * Return: 0 if the message digest update was successful; < 0 if an error | ||
| 808 | * occurred | ||
| 809 | */ | ||
| 675 | int crypto_shash_update(struct shash_desc *desc, const u8 *data, | 810 | int crypto_shash_update(struct shash_desc *desc, const u8 *data, |
| 676 | unsigned int len); | 811 | unsigned int len); |
| 812 | |||
| 813 | /** | ||
| 814 | * crypto_shash_final() - calculate message digest | ||
| 815 | * @desc: operational state handle that is already filled with data | ||
| 816 | * @out: output buffer filled with the message digest | ||
| 817 | * | ||
| 818 | * Finalize the message digest operation and create the message digest | ||
| 819 | * based on all data added to the cipher handle. The message digest is placed | ||
| 820 | * into the output buffer. The caller must ensure that the output buffer is | ||
| 821 | * large enough by using crypto_shash_digestsize. | ||
| 822 | * | ||
| 823 | * Return: 0 if the message digest creation was successful; < 0 if an error | ||
| 824 | * occurred | ||
| 825 | */ | ||
| 677 | int crypto_shash_final(struct shash_desc *desc, u8 *out); | 826 | int crypto_shash_final(struct shash_desc *desc, u8 *out); |
| 827 | |||
| 828 | /** | ||
| 829 | * crypto_shash_finup() - calculate message digest of buffer | ||
| 830 | * @desc: see crypto_shash_final() | ||
| 831 | * @data: see crypto_shash_update() | ||
| 832 | * @len: see crypto_shash_update() | ||
| 833 | * @out: see crypto_shash_final() | ||
| 834 | * | ||
| 835 | * This function is a "short-hand" for the function calls of | ||
| 836 | * crypto_shash_update and crypto_shash_final. The parameters have the same | ||
| 837 | * meaning as discussed for those separate functions. | ||
| 838 | * | ||
| 839 | * Return: 0 if the message digest creation was successful; < 0 if an error | ||
| 840 | * occurred | ||
| 841 | */ | ||
| 678 | int crypto_shash_finup(struct shash_desc *desc, const u8 *data, | 842 | int crypto_shash_finup(struct shash_desc *desc, const u8 *data, |
| 679 | unsigned int len, u8 *out); | 843 | unsigned int len, u8 *out); |
| 680 | 844 | ||
