18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Hash: Hash algorithms under the crypto API 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _CRYPTO_HASH_H 98c2ecf20Sopenharmony_ci#define _CRYPTO_HASH_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/crypto.h> 128c2ecf20Sopenharmony_ci#include <linux/string.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistruct crypto_ahash; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/** 178c2ecf20Sopenharmony_ci * DOC: Message Digest Algorithm Definitions 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * These data structures define modular message digest algorithm 208c2ecf20Sopenharmony_ci * implementations, managed via crypto_register_ahash(), 218c2ecf20Sopenharmony_ci * crypto_register_shash(), crypto_unregister_ahash() and 228c2ecf20Sopenharmony_ci * crypto_unregister_shash(). 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/** 268c2ecf20Sopenharmony_ci * struct hash_alg_common - define properties of message digest 278c2ecf20Sopenharmony_ci * @digestsize: Size of the result of the transformation. A buffer of this size 288c2ecf20Sopenharmony_ci * must be available to the @final and @finup calls, so they can 298c2ecf20Sopenharmony_ci * store the resulting hash into it. For various predefined sizes, 308c2ecf20Sopenharmony_ci * search include/crypto/ using 318c2ecf20Sopenharmony_ci * git grep _DIGEST_SIZE include/crypto. 328c2ecf20Sopenharmony_ci * @statesize: Size of the block for partial state of the transformation. A 338c2ecf20Sopenharmony_ci * buffer of this size must be passed to the @export function as it 348c2ecf20Sopenharmony_ci * will save the partial state of the transformation into it. On the 358c2ecf20Sopenharmony_ci * other side, the @import function will load the state from a 368c2ecf20Sopenharmony_ci * buffer of this size as well. 378c2ecf20Sopenharmony_ci * @base: Start of data structure of cipher algorithm. The common data 388c2ecf20Sopenharmony_ci * structure of crypto_alg contains information common to all ciphers. 398c2ecf20Sopenharmony_ci * The hash_alg_common data structure now adds the hash-specific 408c2ecf20Sopenharmony_ci * information. 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_cistruct hash_alg_common { 438c2ecf20Sopenharmony_ci unsigned int digestsize; 448c2ecf20Sopenharmony_ci unsigned int statesize; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci struct crypto_alg base; 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistruct ahash_request { 508c2ecf20Sopenharmony_ci struct crypto_async_request base; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci unsigned int nbytes; 538c2ecf20Sopenharmony_ci struct scatterlist *src; 548c2ecf20Sopenharmony_ci u8 *result; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci /* This field may only be used by the ahash API code. */ 578c2ecf20Sopenharmony_ci void *priv; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci void *__ctx[] CRYPTO_MINALIGN_ATTR; 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/** 638c2ecf20Sopenharmony_ci * struct ahash_alg - asynchronous message digest definition 648c2ecf20Sopenharmony_ci * @init: **[mandatory]** Initialize the transformation context. Intended only to initialize the 658c2ecf20Sopenharmony_ci * state of the HASH transformation at the beginning. This shall fill in 668c2ecf20Sopenharmony_ci * the internal structures used during the entire duration of the whole 678c2ecf20Sopenharmony_ci * transformation. No data processing happens at this point. Driver code 688c2ecf20Sopenharmony_ci * implementation must not use req->result. 698c2ecf20Sopenharmony_ci * @update: **[mandatory]** Push a chunk of data into the driver for transformation. This 708c2ecf20Sopenharmony_ci * function actually pushes blocks of data from upper layers into the 718c2ecf20Sopenharmony_ci * driver, which then passes those to the hardware as seen fit. This 728c2ecf20Sopenharmony_ci * function must not finalize the HASH transformation by calculating the 738c2ecf20Sopenharmony_ci * final message digest as this only adds more data into the 748c2ecf20Sopenharmony_ci * transformation. This function shall not modify the transformation 758c2ecf20Sopenharmony_ci * context, as this function may be called in parallel with the same 768c2ecf20Sopenharmony_ci * transformation object. Data processing can happen synchronously 778c2ecf20Sopenharmony_ci * [SHASH] or asynchronously [AHASH] at this point. Driver must not use 788c2ecf20Sopenharmony_ci * req->result. 798c2ecf20Sopenharmony_ci * @final: **[mandatory]** Retrieve result from the driver. This function finalizes the 808c2ecf20Sopenharmony_ci * transformation and retrieves the resulting hash from the driver and 818c2ecf20Sopenharmony_ci * pushes it back to upper layers. No data processing happens at this 828c2ecf20Sopenharmony_ci * point unless hardware requires it to finish the transformation 838c2ecf20Sopenharmony_ci * (then the data buffered by the device driver is processed). 848c2ecf20Sopenharmony_ci * @finup: **[optional]** Combination of @update and @final. This function is effectively a 858c2ecf20Sopenharmony_ci * combination of @update and @final calls issued in sequence. As some 868c2ecf20Sopenharmony_ci * hardware cannot do @update and @final separately, this callback was 878c2ecf20Sopenharmony_ci * added to allow such hardware to be used at least by IPsec. Data 888c2ecf20Sopenharmony_ci * processing can happen synchronously [SHASH] or asynchronously [AHASH] 898c2ecf20Sopenharmony_ci * at this point. 908c2ecf20Sopenharmony_ci * @digest: Combination of @init and @update and @final. This function 918c2ecf20Sopenharmony_ci * effectively behaves as the entire chain of operations, @init, 928c2ecf20Sopenharmony_ci * @update and @final issued in sequence. Just like @finup, this was 938c2ecf20Sopenharmony_ci * added for hardware which cannot do even the @finup, but can only do 948c2ecf20Sopenharmony_ci * the whole transformation in one run. Data processing can happen 958c2ecf20Sopenharmony_ci * synchronously [SHASH] or asynchronously [AHASH] at this point. 968c2ecf20Sopenharmony_ci * @setkey: Set optional key used by the hashing algorithm. Intended to push 978c2ecf20Sopenharmony_ci * optional key used by the hashing algorithm from upper layers into 988c2ecf20Sopenharmony_ci * the driver. This function can store the key in the transformation 998c2ecf20Sopenharmony_ci * context or can outright program it into the hardware. In the former 1008c2ecf20Sopenharmony_ci * case, one must be careful to program the key into the hardware at 1018c2ecf20Sopenharmony_ci * appropriate time and one must be careful that .setkey() can be 1028c2ecf20Sopenharmony_ci * called multiple times during the existence of the transformation 1038c2ecf20Sopenharmony_ci * object. Not all hashing algorithms do implement this function as it 1048c2ecf20Sopenharmony_ci * is only needed for keyed message digests. SHAx/MDx/CRCx do NOT 1058c2ecf20Sopenharmony_ci * implement this function. HMAC(MDx)/HMAC(SHAx)/CMAC(AES) do implement 1068c2ecf20Sopenharmony_ci * this function. This function must be called before any other of the 1078c2ecf20Sopenharmony_ci * @init, @update, @final, @finup, @digest is called. No data 1088c2ecf20Sopenharmony_ci * processing happens at this point. 1098c2ecf20Sopenharmony_ci * @export: Export partial state of the transformation. This function dumps the 1108c2ecf20Sopenharmony_ci * entire state of the ongoing transformation into a provided block of 1118c2ecf20Sopenharmony_ci * data so it can be @import 'ed back later on. This is useful in case 1128c2ecf20Sopenharmony_ci * you want to save partial result of the transformation after 1138c2ecf20Sopenharmony_ci * processing certain amount of data and reload this partial result 1148c2ecf20Sopenharmony_ci * multiple times later on for multiple re-use. No data processing 1158c2ecf20Sopenharmony_ci * happens at this point. Driver must not use req->result. 1168c2ecf20Sopenharmony_ci * @import: Import partial state of the transformation. This function loads the 1178c2ecf20Sopenharmony_ci * entire state of the ongoing transformation from a provided block of 1188c2ecf20Sopenharmony_ci * data so the transformation can continue from this point onward. No 1198c2ecf20Sopenharmony_ci * data processing happens at this point. Driver must not use 1208c2ecf20Sopenharmony_ci * req->result. 1218c2ecf20Sopenharmony_ci * @init_tfm: Initialize the cryptographic transformation object. 1228c2ecf20Sopenharmony_ci * This function is called only once at the instantiation 1238c2ecf20Sopenharmony_ci * time, right after the transformation context was 1248c2ecf20Sopenharmony_ci * allocated. In case the cryptographic hardware has 1258c2ecf20Sopenharmony_ci * some special requirements which need to be handled 1268c2ecf20Sopenharmony_ci * by software, this function shall check for the precise 1278c2ecf20Sopenharmony_ci * requirement of the transformation and put any software 1288c2ecf20Sopenharmony_ci * fallbacks in place. 1298c2ecf20Sopenharmony_ci * @exit_tfm: Deinitialize the cryptographic transformation object. 1308c2ecf20Sopenharmony_ci * This is a counterpart to @init_tfm, used to remove 1318c2ecf20Sopenharmony_ci * various changes set in @init_tfm. 1328c2ecf20Sopenharmony_ci * @halg: see struct hash_alg_common 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_cistruct ahash_alg { 1358c2ecf20Sopenharmony_ci int (*init)(struct ahash_request *req); 1368c2ecf20Sopenharmony_ci int (*update)(struct ahash_request *req); 1378c2ecf20Sopenharmony_ci int (*final)(struct ahash_request *req); 1388c2ecf20Sopenharmony_ci int (*finup)(struct ahash_request *req); 1398c2ecf20Sopenharmony_ci int (*digest)(struct ahash_request *req); 1408c2ecf20Sopenharmony_ci int (*export)(struct ahash_request *req, void *out); 1418c2ecf20Sopenharmony_ci int (*import)(struct ahash_request *req, const void *in); 1428c2ecf20Sopenharmony_ci int (*setkey)(struct crypto_ahash *tfm, const u8 *key, 1438c2ecf20Sopenharmony_ci unsigned int keylen); 1448c2ecf20Sopenharmony_ci int (*init_tfm)(struct crypto_ahash *tfm); 1458c2ecf20Sopenharmony_ci void (*exit_tfm)(struct crypto_ahash *tfm); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci struct hash_alg_common halg; 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistruct shash_desc { 1518c2ecf20Sopenharmony_ci struct crypto_shash *tfm; 1528c2ecf20Sopenharmony_ci void *__ctx[] __aligned(ARCH_SLAB_MINALIGN); 1538c2ecf20Sopenharmony_ci}; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#define HASH_MAX_DIGESTSIZE 64 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci/* 1588c2ecf20Sopenharmony_ci * Worst case is hmac(sha3-224-generic). Its context is a nested 'shash_desc' 1598c2ecf20Sopenharmony_ci * containing a 'struct sha3_state'. 1608c2ecf20Sopenharmony_ci */ 1618c2ecf20Sopenharmony_ci#define HASH_MAX_DESCSIZE (sizeof(struct shash_desc) + 360) 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci#define HASH_MAX_STATESIZE 512 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci#define SHASH_DESC_ON_STACK(shash, ctx) \ 1668c2ecf20Sopenharmony_ci char __##shash##_desc[sizeof(struct shash_desc) + HASH_MAX_DESCSIZE] \ 1678c2ecf20Sopenharmony_ci __aligned(__alignof__(struct shash_desc)); \ 1688c2ecf20Sopenharmony_ci struct shash_desc *shash = (struct shash_desc *)__##shash##_desc 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci/** 1718c2ecf20Sopenharmony_ci * struct shash_alg - synchronous message digest definition 1728c2ecf20Sopenharmony_ci * @init: see struct ahash_alg 1738c2ecf20Sopenharmony_ci * @update: see struct ahash_alg 1748c2ecf20Sopenharmony_ci * @final: see struct ahash_alg 1758c2ecf20Sopenharmony_ci * @finup: see struct ahash_alg 1768c2ecf20Sopenharmony_ci * @digest: see struct ahash_alg 1778c2ecf20Sopenharmony_ci * @export: see struct ahash_alg 1788c2ecf20Sopenharmony_ci * @import: see struct ahash_alg 1798c2ecf20Sopenharmony_ci * @setkey: see struct ahash_alg 1808c2ecf20Sopenharmony_ci * @init_tfm: Initialize the cryptographic transformation object. 1818c2ecf20Sopenharmony_ci * This function is called only once at the instantiation 1828c2ecf20Sopenharmony_ci * time, right after the transformation context was 1838c2ecf20Sopenharmony_ci * allocated. In case the cryptographic hardware has 1848c2ecf20Sopenharmony_ci * some special requirements which need to be handled 1858c2ecf20Sopenharmony_ci * by software, this function shall check for the precise 1868c2ecf20Sopenharmony_ci * requirement of the transformation and put any software 1878c2ecf20Sopenharmony_ci * fallbacks in place. 1888c2ecf20Sopenharmony_ci * @exit_tfm: Deinitialize the cryptographic transformation object. 1898c2ecf20Sopenharmony_ci * This is a counterpart to @init_tfm, used to remove 1908c2ecf20Sopenharmony_ci * various changes set in @init_tfm. 1918c2ecf20Sopenharmony_ci * @digestsize: see struct ahash_alg 1928c2ecf20Sopenharmony_ci * @statesize: see struct ahash_alg 1938c2ecf20Sopenharmony_ci * @descsize: Size of the operational state for the message digest. This state 1948c2ecf20Sopenharmony_ci * size is the memory size that needs to be allocated for 1958c2ecf20Sopenharmony_ci * shash_desc.__ctx 1968c2ecf20Sopenharmony_ci * @base: internally used 1978c2ecf20Sopenharmony_ci */ 1988c2ecf20Sopenharmony_cistruct shash_alg { 1998c2ecf20Sopenharmony_ci int (*init)(struct shash_desc *desc); 2008c2ecf20Sopenharmony_ci int (*update)(struct shash_desc *desc, const u8 *data, 2018c2ecf20Sopenharmony_ci unsigned int len); 2028c2ecf20Sopenharmony_ci int (*final)(struct shash_desc *desc, u8 *out); 2038c2ecf20Sopenharmony_ci int (*finup)(struct shash_desc *desc, const u8 *data, 2048c2ecf20Sopenharmony_ci unsigned int len, u8 *out); 2058c2ecf20Sopenharmony_ci int (*digest)(struct shash_desc *desc, const u8 *data, 2068c2ecf20Sopenharmony_ci unsigned int len, u8 *out); 2078c2ecf20Sopenharmony_ci int (*export)(struct shash_desc *desc, void *out); 2088c2ecf20Sopenharmony_ci int (*import)(struct shash_desc *desc, const void *in); 2098c2ecf20Sopenharmony_ci int (*setkey)(struct crypto_shash *tfm, const u8 *key, 2108c2ecf20Sopenharmony_ci unsigned int keylen); 2118c2ecf20Sopenharmony_ci int (*init_tfm)(struct crypto_shash *tfm); 2128c2ecf20Sopenharmony_ci void (*exit_tfm)(struct crypto_shash *tfm); 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci unsigned int descsize; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci /* These fields must match hash_alg_common. */ 2178c2ecf20Sopenharmony_ci unsigned int digestsize 2188c2ecf20Sopenharmony_ci __attribute__ ((aligned(__alignof__(struct hash_alg_common)))); 2198c2ecf20Sopenharmony_ci unsigned int statesize; 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci struct crypto_alg base; 2228c2ecf20Sopenharmony_ci}; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_cistruct crypto_ahash { 2258c2ecf20Sopenharmony_ci int (*init)(struct ahash_request *req); 2268c2ecf20Sopenharmony_ci int (*update)(struct ahash_request *req); 2278c2ecf20Sopenharmony_ci int (*final)(struct ahash_request *req); 2288c2ecf20Sopenharmony_ci int (*finup)(struct ahash_request *req); 2298c2ecf20Sopenharmony_ci int (*digest)(struct ahash_request *req); 2308c2ecf20Sopenharmony_ci int (*export)(struct ahash_request *req, void *out); 2318c2ecf20Sopenharmony_ci int (*import)(struct ahash_request *req, const void *in); 2328c2ecf20Sopenharmony_ci int (*setkey)(struct crypto_ahash *tfm, const u8 *key, 2338c2ecf20Sopenharmony_ci unsigned int keylen); 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci unsigned int reqsize; 2368c2ecf20Sopenharmony_ci struct crypto_tfm base; 2378c2ecf20Sopenharmony_ci}; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cistruct crypto_shash { 2408c2ecf20Sopenharmony_ci unsigned int descsize; 2418c2ecf20Sopenharmony_ci struct crypto_tfm base; 2428c2ecf20Sopenharmony_ci}; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci/** 2458c2ecf20Sopenharmony_ci * DOC: Asynchronous Message Digest API 2468c2ecf20Sopenharmony_ci * 2478c2ecf20Sopenharmony_ci * The asynchronous message digest API is used with the ciphers of type 2488c2ecf20Sopenharmony_ci * CRYPTO_ALG_TYPE_AHASH (listed as type "ahash" in /proc/crypto) 2498c2ecf20Sopenharmony_ci * 2508c2ecf20Sopenharmony_ci * The asynchronous cipher operation discussion provided for the 2518c2ecf20Sopenharmony_ci * CRYPTO_ALG_TYPE_SKCIPHER API applies here as well. 2528c2ecf20Sopenharmony_ci */ 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_cistatic inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) 2558c2ecf20Sopenharmony_ci{ 2568c2ecf20Sopenharmony_ci return container_of(tfm, struct crypto_ahash, base); 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci/** 2608c2ecf20Sopenharmony_ci * crypto_alloc_ahash() - allocate ahash cipher handle 2618c2ecf20Sopenharmony_ci * @alg_name: is the cra_name / name or cra_driver_name / driver name of the 2628c2ecf20Sopenharmony_ci * ahash cipher 2638c2ecf20Sopenharmony_ci * @type: specifies the type of the cipher 2648c2ecf20Sopenharmony_ci * @mask: specifies the mask for the cipher 2658c2ecf20Sopenharmony_ci * 2668c2ecf20Sopenharmony_ci * Allocate a cipher handle for an ahash. The returned struct 2678c2ecf20Sopenharmony_ci * crypto_ahash is the cipher handle that is required for any subsequent 2688c2ecf20Sopenharmony_ci * API invocation for that ahash. 2698c2ecf20Sopenharmony_ci * 2708c2ecf20Sopenharmony_ci * Return: allocated cipher handle in case of success; IS_ERR() is true in case 2718c2ecf20Sopenharmony_ci * of an error, PTR_ERR() returns the error code. 2728c2ecf20Sopenharmony_ci */ 2738c2ecf20Sopenharmony_cistruct crypto_ahash *crypto_alloc_ahash(const char *alg_name, u32 type, 2748c2ecf20Sopenharmony_ci u32 mask); 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_cistatic inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) 2778c2ecf20Sopenharmony_ci{ 2788c2ecf20Sopenharmony_ci return &tfm->base; 2798c2ecf20Sopenharmony_ci} 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci/** 2828c2ecf20Sopenharmony_ci * crypto_free_ahash() - zeroize and free the ahash handle 2838c2ecf20Sopenharmony_ci * @tfm: cipher handle to be freed 2848c2ecf20Sopenharmony_ci * 2858c2ecf20Sopenharmony_ci * If @tfm is a NULL or error pointer, this function does nothing. 2868c2ecf20Sopenharmony_ci */ 2878c2ecf20Sopenharmony_cistatic inline void crypto_free_ahash(struct crypto_ahash *tfm) 2888c2ecf20Sopenharmony_ci{ 2898c2ecf20Sopenharmony_ci crypto_destroy_tfm(tfm, crypto_ahash_tfm(tfm)); 2908c2ecf20Sopenharmony_ci} 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci/** 2938c2ecf20Sopenharmony_ci * crypto_has_ahash() - Search for the availability of an ahash. 2948c2ecf20Sopenharmony_ci * @alg_name: is the cra_name / name or cra_driver_name / driver name of the 2958c2ecf20Sopenharmony_ci * ahash 2968c2ecf20Sopenharmony_ci * @type: specifies the type of the ahash 2978c2ecf20Sopenharmony_ci * @mask: specifies the mask for the ahash 2988c2ecf20Sopenharmony_ci * 2998c2ecf20Sopenharmony_ci * Return: true when the ahash is known to the kernel crypto API; false 3008c2ecf20Sopenharmony_ci * otherwise 3018c2ecf20Sopenharmony_ci */ 3028c2ecf20Sopenharmony_ciint crypto_has_ahash(const char *alg_name, u32 type, u32 mask); 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_cistatic inline const char *crypto_ahash_alg_name(struct crypto_ahash *tfm) 3058c2ecf20Sopenharmony_ci{ 3068c2ecf20Sopenharmony_ci return crypto_tfm_alg_name(crypto_ahash_tfm(tfm)); 3078c2ecf20Sopenharmony_ci} 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cistatic inline const char *crypto_ahash_driver_name(struct crypto_ahash *tfm) 3108c2ecf20Sopenharmony_ci{ 3118c2ecf20Sopenharmony_ci return crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); 3128c2ecf20Sopenharmony_ci} 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_cistatic inline unsigned int crypto_ahash_alignmask( 3158c2ecf20Sopenharmony_ci struct crypto_ahash *tfm) 3168c2ecf20Sopenharmony_ci{ 3178c2ecf20Sopenharmony_ci return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm)); 3188c2ecf20Sopenharmony_ci} 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci/** 3218c2ecf20Sopenharmony_ci * crypto_ahash_blocksize() - obtain block size for cipher 3228c2ecf20Sopenharmony_ci * @tfm: cipher handle 3238c2ecf20Sopenharmony_ci * 3248c2ecf20Sopenharmony_ci * The block size for the message digest cipher referenced with the cipher 3258c2ecf20Sopenharmony_ci * handle is returned. 3268c2ecf20Sopenharmony_ci * 3278c2ecf20Sopenharmony_ci * Return: block size of cipher 3288c2ecf20Sopenharmony_ci */ 3298c2ecf20Sopenharmony_cistatic inline unsigned int crypto_ahash_blocksize(struct crypto_ahash *tfm) 3308c2ecf20Sopenharmony_ci{ 3318c2ecf20Sopenharmony_ci return crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm)); 3328c2ecf20Sopenharmony_ci} 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_cistatic inline struct hash_alg_common *__crypto_hash_alg_common( 3358c2ecf20Sopenharmony_ci struct crypto_alg *alg) 3368c2ecf20Sopenharmony_ci{ 3378c2ecf20Sopenharmony_ci return container_of(alg, struct hash_alg_common, base); 3388c2ecf20Sopenharmony_ci} 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_cistatic inline struct hash_alg_common *crypto_hash_alg_common( 3418c2ecf20Sopenharmony_ci struct crypto_ahash *tfm) 3428c2ecf20Sopenharmony_ci{ 3438c2ecf20Sopenharmony_ci return __crypto_hash_alg_common(crypto_ahash_tfm(tfm)->__crt_alg); 3448c2ecf20Sopenharmony_ci} 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci/** 3478c2ecf20Sopenharmony_ci * crypto_ahash_digestsize() - obtain message digest size 3488c2ecf20Sopenharmony_ci * @tfm: cipher handle 3498c2ecf20Sopenharmony_ci * 3508c2ecf20Sopenharmony_ci * The size for the message digest created by the message digest cipher 3518c2ecf20Sopenharmony_ci * referenced with the cipher handle is returned. 3528c2ecf20Sopenharmony_ci * 3538c2ecf20Sopenharmony_ci * 3548c2ecf20Sopenharmony_ci * Return: message digest size of cipher 3558c2ecf20Sopenharmony_ci */ 3568c2ecf20Sopenharmony_cistatic inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm) 3578c2ecf20Sopenharmony_ci{ 3588c2ecf20Sopenharmony_ci return crypto_hash_alg_common(tfm)->digestsize; 3598c2ecf20Sopenharmony_ci} 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci/** 3628c2ecf20Sopenharmony_ci * crypto_ahash_statesize() - obtain size of the ahash state 3638c2ecf20Sopenharmony_ci * @tfm: cipher handle 3648c2ecf20Sopenharmony_ci * 3658c2ecf20Sopenharmony_ci * Return the size of the ahash state. With the crypto_ahash_export() 3668c2ecf20Sopenharmony_ci * function, the caller can export the state into a buffer whose size is 3678c2ecf20Sopenharmony_ci * defined with this function. 3688c2ecf20Sopenharmony_ci * 3698c2ecf20Sopenharmony_ci * Return: size of the ahash state 3708c2ecf20Sopenharmony_ci */ 3718c2ecf20Sopenharmony_cistatic inline unsigned int crypto_ahash_statesize(struct crypto_ahash *tfm) 3728c2ecf20Sopenharmony_ci{ 3738c2ecf20Sopenharmony_ci return crypto_hash_alg_common(tfm)->statesize; 3748c2ecf20Sopenharmony_ci} 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_cistatic inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm) 3778c2ecf20Sopenharmony_ci{ 3788c2ecf20Sopenharmony_ci return crypto_tfm_get_flags(crypto_ahash_tfm(tfm)); 3798c2ecf20Sopenharmony_ci} 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistatic inline void crypto_ahash_set_flags(struct crypto_ahash *tfm, u32 flags) 3828c2ecf20Sopenharmony_ci{ 3838c2ecf20Sopenharmony_ci crypto_tfm_set_flags(crypto_ahash_tfm(tfm), flags); 3848c2ecf20Sopenharmony_ci} 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_cistatic inline void crypto_ahash_clear_flags(struct crypto_ahash *tfm, u32 flags) 3878c2ecf20Sopenharmony_ci{ 3888c2ecf20Sopenharmony_ci crypto_tfm_clear_flags(crypto_ahash_tfm(tfm), flags); 3898c2ecf20Sopenharmony_ci} 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci/** 3928c2ecf20Sopenharmony_ci * crypto_ahash_reqtfm() - obtain cipher handle from request 3938c2ecf20Sopenharmony_ci * @req: asynchronous request handle that contains the reference to the ahash 3948c2ecf20Sopenharmony_ci * cipher handle 3958c2ecf20Sopenharmony_ci * 3968c2ecf20Sopenharmony_ci * Return the ahash cipher handle that is registered with the asynchronous 3978c2ecf20Sopenharmony_ci * request handle ahash_request. 3988c2ecf20Sopenharmony_ci * 3998c2ecf20Sopenharmony_ci * Return: ahash cipher handle 4008c2ecf20Sopenharmony_ci */ 4018c2ecf20Sopenharmony_cistatic inline struct crypto_ahash *crypto_ahash_reqtfm( 4028c2ecf20Sopenharmony_ci struct ahash_request *req) 4038c2ecf20Sopenharmony_ci{ 4048c2ecf20Sopenharmony_ci return __crypto_ahash_cast(req->base.tfm); 4058c2ecf20Sopenharmony_ci} 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci/** 4088c2ecf20Sopenharmony_ci * crypto_ahash_reqsize() - obtain size of the request data structure 4098c2ecf20Sopenharmony_ci * @tfm: cipher handle 4108c2ecf20Sopenharmony_ci * 4118c2ecf20Sopenharmony_ci * Return: size of the request data 4128c2ecf20Sopenharmony_ci */ 4138c2ecf20Sopenharmony_cistatic inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) 4148c2ecf20Sopenharmony_ci{ 4158c2ecf20Sopenharmony_ci return tfm->reqsize; 4168c2ecf20Sopenharmony_ci} 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_cistatic inline void *ahash_request_ctx(struct ahash_request *req) 4198c2ecf20Sopenharmony_ci{ 4208c2ecf20Sopenharmony_ci return req->__ctx; 4218c2ecf20Sopenharmony_ci} 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci/** 4248c2ecf20Sopenharmony_ci * crypto_ahash_setkey - set key for cipher handle 4258c2ecf20Sopenharmony_ci * @tfm: cipher handle 4268c2ecf20Sopenharmony_ci * @key: buffer holding the key 4278c2ecf20Sopenharmony_ci * @keylen: length of the key in bytes 4288c2ecf20Sopenharmony_ci * 4298c2ecf20Sopenharmony_ci * The caller provided key is set for the ahash cipher. The cipher 4308c2ecf20Sopenharmony_ci * handle must point to a keyed hash in order for this function to succeed. 4318c2ecf20Sopenharmony_ci * 4328c2ecf20Sopenharmony_ci * Return: 0 if the setting of the key was successful; < 0 if an error occurred 4338c2ecf20Sopenharmony_ci */ 4348c2ecf20Sopenharmony_ciint crypto_ahash_setkey(struct crypto_ahash *tfm, const u8 *key, 4358c2ecf20Sopenharmony_ci unsigned int keylen); 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci/** 4388c2ecf20Sopenharmony_ci * crypto_ahash_finup() - update and finalize message digest 4398c2ecf20Sopenharmony_ci * @req: reference to the ahash_request handle that holds all information 4408c2ecf20Sopenharmony_ci * needed to perform the cipher operation 4418c2ecf20Sopenharmony_ci * 4428c2ecf20Sopenharmony_ci * This function is a "short-hand" for the function calls of 4438c2ecf20Sopenharmony_ci * crypto_ahash_update and crypto_ahash_final. The parameters have the same 4448c2ecf20Sopenharmony_ci * meaning as discussed for those separate functions. 4458c2ecf20Sopenharmony_ci * 4468c2ecf20Sopenharmony_ci * Return: see crypto_ahash_final() 4478c2ecf20Sopenharmony_ci */ 4488c2ecf20Sopenharmony_ciint crypto_ahash_finup(struct ahash_request *req); 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci/** 4518c2ecf20Sopenharmony_ci * crypto_ahash_final() - calculate message digest 4528c2ecf20Sopenharmony_ci * @req: reference to the ahash_request handle that holds all information 4538c2ecf20Sopenharmony_ci * needed to perform the cipher operation 4548c2ecf20Sopenharmony_ci * 4558c2ecf20Sopenharmony_ci * Finalize the message digest operation and create the message digest 4568c2ecf20Sopenharmony_ci * based on all data added to the cipher handle. The message digest is placed 4578c2ecf20Sopenharmony_ci * into the output buffer registered with the ahash_request handle. 4588c2ecf20Sopenharmony_ci * 4598c2ecf20Sopenharmony_ci * Return: 4608c2ecf20Sopenharmony_ci * 0 if the message digest was successfully calculated; 4618c2ecf20Sopenharmony_ci * -EINPROGRESS if data is feeded into hardware (DMA) or queued for later; 4628c2ecf20Sopenharmony_ci * -EBUSY if queue is full and request should be resubmitted later; 4638c2ecf20Sopenharmony_ci * other < 0 if an error occurred 4648c2ecf20Sopenharmony_ci */ 4658c2ecf20Sopenharmony_ciint crypto_ahash_final(struct ahash_request *req); 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci/** 4688c2ecf20Sopenharmony_ci * crypto_ahash_digest() - calculate message digest for a buffer 4698c2ecf20Sopenharmony_ci * @req: reference to the ahash_request handle that holds all information 4708c2ecf20Sopenharmony_ci * needed to perform the cipher operation 4718c2ecf20Sopenharmony_ci * 4728c2ecf20Sopenharmony_ci * This function is a "short-hand" for the function calls of crypto_ahash_init, 4738c2ecf20Sopenharmony_ci * crypto_ahash_update and crypto_ahash_final. The parameters have the same 4748c2ecf20Sopenharmony_ci * meaning as discussed for those separate three functions. 4758c2ecf20Sopenharmony_ci * 4768c2ecf20Sopenharmony_ci * Return: see crypto_ahash_final() 4778c2ecf20Sopenharmony_ci */ 4788c2ecf20Sopenharmony_ciint crypto_ahash_digest(struct ahash_request *req); 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci/** 4818c2ecf20Sopenharmony_ci * crypto_ahash_export() - extract current message digest state 4828c2ecf20Sopenharmony_ci * @req: reference to the ahash_request handle whose state is exported 4838c2ecf20Sopenharmony_ci * @out: output buffer of sufficient size that can hold the hash state 4848c2ecf20Sopenharmony_ci * 4858c2ecf20Sopenharmony_ci * This function exports the hash state of the ahash_request handle into the 4868c2ecf20Sopenharmony_ci * caller-allocated output buffer out which must have sufficient size (e.g. by 4878c2ecf20Sopenharmony_ci * calling crypto_ahash_statesize()). 4888c2ecf20Sopenharmony_ci * 4898c2ecf20Sopenharmony_ci * Return: 0 if the export was successful; < 0 if an error occurred 4908c2ecf20Sopenharmony_ci */ 4918c2ecf20Sopenharmony_cistatic inline int crypto_ahash_export(struct ahash_request *req, void *out) 4928c2ecf20Sopenharmony_ci{ 4938c2ecf20Sopenharmony_ci return crypto_ahash_reqtfm(req)->export(req, out); 4948c2ecf20Sopenharmony_ci} 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci/** 4978c2ecf20Sopenharmony_ci * crypto_ahash_import() - import message digest state 4988c2ecf20Sopenharmony_ci * @req: reference to ahash_request handle the state is imported into 4998c2ecf20Sopenharmony_ci * @in: buffer holding the state 5008c2ecf20Sopenharmony_ci * 5018c2ecf20Sopenharmony_ci * This function imports the hash state into the ahash_request handle from the 5028c2ecf20Sopenharmony_ci * input buffer. That buffer should have been generated with the 5038c2ecf20Sopenharmony_ci * crypto_ahash_export function. 5048c2ecf20Sopenharmony_ci * 5058c2ecf20Sopenharmony_ci * Return: 0 if the import was successful; < 0 if an error occurred 5068c2ecf20Sopenharmony_ci */ 5078c2ecf20Sopenharmony_cistatic inline int crypto_ahash_import(struct ahash_request *req, const void *in) 5088c2ecf20Sopenharmony_ci{ 5098c2ecf20Sopenharmony_ci struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) 5128c2ecf20Sopenharmony_ci return -ENOKEY; 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci return tfm->import(req, in); 5158c2ecf20Sopenharmony_ci} 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci/** 5188c2ecf20Sopenharmony_ci * crypto_ahash_init() - (re)initialize message digest handle 5198c2ecf20Sopenharmony_ci * @req: ahash_request handle that already is initialized with all necessary 5208c2ecf20Sopenharmony_ci * data using the ahash_request_* API functions 5218c2ecf20Sopenharmony_ci * 5228c2ecf20Sopenharmony_ci * The call (re-)initializes the message digest referenced by the ahash_request 5238c2ecf20Sopenharmony_ci * handle. Any potentially existing state created by previous operations is 5248c2ecf20Sopenharmony_ci * discarded. 5258c2ecf20Sopenharmony_ci * 5268c2ecf20Sopenharmony_ci * Return: see crypto_ahash_final() 5278c2ecf20Sopenharmony_ci */ 5288c2ecf20Sopenharmony_cistatic inline int crypto_ahash_init(struct ahash_request *req) 5298c2ecf20Sopenharmony_ci{ 5308c2ecf20Sopenharmony_ci struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) 5338c2ecf20Sopenharmony_ci return -ENOKEY; 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci return tfm->init(req); 5368c2ecf20Sopenharmony_ci} 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci/** 5398c2ecf20Sopenharmony_ci * crypto_ahash_update() - add data to message digest for processing 5408c2ecf20Sopenharmony_ci * @req: ahash_request handle that was previously initialized with the 5418c2ecf20Sopenharmony_ci * crypto_ahash_init call. 5428c2ecf20Sopenharmony_ci * 5438c2ecf20Sopenharmony_ci * Updates the message digest state of the &ahash_request handle. The input data 5448c2ecf20Sopenharmony_ci * is pointed to by the scatter/gather list registered in the &ahash_request 5458c2ecf20Sopenharmony_ci * handle 5468c2ecf20Sopenharmony_ci * 5478c2ecf20Sopenharmony_ci * Return: see crypto_ahash_final() 5488c2ecf20Sopenharmony_ci */ 5498c2ecf20Sopenharmony_cistatic inline int crypto_ahash_update(struct ahash_request *req) 5508c2ecf20Sopenharmony_ci{ 5518c2ecf20Sopenharmony_ci struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 5528c2ecf20Sopenharmony_ci struct crypto_alg *alg = tfm->base.__crt_alg; 5538c2ecf20Sopenharmony_ci unsigned int nbytes = req->nbytes; 5548c2ecf20Sopenharmony_ci int ret; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci crypto_stats_get(alg); 5578c2ecf20Sopenharmony_ci ret = crypto_ahash_reqtfm(req)->update(req); 5588c2ecf20Sopenharmony_ci crypto_stats_ahash_update(nbytes, ret, alg); 5598c2ecf20Sopenharmony_ci return ret; 5608c2ecf20Sopenharmony_ci} 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci/** 5638c2ecf20Sopenharmony_ci * DOC: Asynchronous Hash Request Handle 5648c2ecf20Sopenharmony_ci * 5658c2ecf20Sopenharmony_ci * The &ahash_request data structure contains all pointers to data 5668c2ecf20Sopenharmony_ci * required for the asynchronous cipher operation. This includes the cipher 5678c2ecf20Sopenharmony_ci * handle (which can be used by multiple &ahash_request instances), pointer 5688c2ecf20Sopenharmony_ci * to plaintext and the message digest output buffer, asynchronous callback 5698c2ecf20Sopenharmony_ci * function, etc. It acts as a handle to the ahash_request_* API calls in a 5708c2ecf20Sopenharmony_ci * similar way as ahash handle to the crypto_ahash_* API calls. 5718c2ecf20Sopenharmony_ci */ 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci/** 5748c2ecf20Sopenharmony_ci * ahash_request_set_tfm() - update cipher handle reference in request 5758c2ecf20Sopenharmony_ci * @req: request handle to be modified 5768c2ecf20Sopenharmony_ci * @tfm: cipher handle that shall be added to the request handle 5778c2ecf20Sopenharmony_ci * 5788c2ecf20Sopenharmony_ci * Allow the caller to replace the existing ahash handle in the request 5798c2ecf20Sopenharmony_ci * data structure with a different one. 5808c2ecf20Sopenharmony_ci */ 5818c2ecf20Sopenharmony_cistatic inline void ahash_request_set_tfm(struct ahash_request *req, 5828c2ecf20Sopenharmony_ci struct crypto_ahash *tfm) 5838c2ecf20Sopenharmony_ci{ 5848c2ecf20Sopenharmony_ci req->base.tfm = crypto_ahash_tfm(tfm); 5858c2ecf20Sopenharmony_ci} 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci/** 5888c2ecf20Sopenharmony_ci * ahash_request_alloc() - allocate request data structure 5898c2ecf20Sopenharmony_ci * @tfm: cipher handle to be registered with the request 5908c2ecf20Sopenharmony_ci * @gfp: memory allocation flag that is handed to kmalloc by the API call. 5918c2ecf20Sopenharmony_ci * 5928c2ecf20Sopenharmony_ci * Allocate the request data structure that must be used with the ahash 5938c2ecf20Sopenharmony_ci * message digest API calls. During 5948c2ecf20Sopenharmony_ci * the allocation, the provided ahash handle 5958c2ecf20Sopenharmony_ci * is registered in the request data structure. 5968c2ecf20Sopenharmony_ci * 5978c2ecf20Sopenharmony_ci * Return: allocated request handle in case of success, or NULL if out of memory 5988c2ecf20Sopenharmony_ci */ 5998c2ecf20Sopenharmony_cistatic inline struct ahash_request *ahash_request_alloc( 6008c2ecf20Sopenharmony_ci struct crypto_ahash *tfm, gfp_t gfp) 6018c2ecf20Sopenharmony_ci{ 6028c2ecf20Sopenharmony_ci struct ahash_request *req; 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci req = kmalloc(sizeof(struct ahash_request) + 6058c2ecf20Sopenharmony_ci crypto_ahash_reqsize(tfm), gfp); 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci if (likely(req)) 6088c2ecf20Sopenharmony_ci ahash_request_set_tfm(req, tfm); 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci return req; 6118c2ecf20Sopenharmony_ci} 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci/** 6148c2ecf20Sopenharmony_ci * ahash_request_free() - zeroize and free the request data structure 6158c2ecf20Sopenharmony_ci * @req: request data structure cipher handle to be freed 6168c2ecf20Sopenharmony_ci */ 6178c2ecf20Sopenharmony_cistatic inline void ahash_request_free(struct ahash_request *req) 6188c2ecf20Sopenharmony_ci{ 6198c2ecf20Sopenharmony_ci kfree_sensitive(req); 6208c2ecf20Sopenharmony_ci} 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_cistatic inline void ahash_request_zero(struct ahash_request *req) 6238c2ecf20Sopenharmony_ci{ 6248c2ecf20Sopenharmony_ci memzero_explicit(req, sizeof(*req) + 6258c2ecf20Sopenharmony_ci crypto_ahash_reqsize(crypto_ahash_reqtfm(req))); 6268c2ecf20Sopenharmony_ci} 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_cistatic inline struct ahash_request *ahash_request_cast( 6298c2ecf20Sopenharmony_ci struct crypto_async_request *req) 6308c2ecf20Sopenharmony_ci{ 6318c2ecf20Sopenharmony_ci return container_of(req, struct ahash_request, base); 6328c2ecf20Sopenharmony_ci} 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_ci/** 6358c2ecf20Sopenharmony_ci * ahash_request_set_callback() - set asynchronous callback function 6368c2ecf20Sopenharmony_ci * @req: request handle 6378c2ecf20Sopenharmony_ci * @flags: specify zero or an ORing of the flags 6388c2ecf20Sopenharmony_ci * CRYPTO_TFM_REQ_MAY_BACKLOG the request queue may back log and 6398c2ecf20Sopenharmony_ci * increase the wait queue beyond the initial maximum size; 6408c2ecf20Sopenharmony_ci * CRYPTO_TFM_REQ_MAY_SLEEP the request processing may sleep 6418c2ecf20Sopenharmony_ci * @compl: callback function pointer to be registered with the request handle 6428c2ecf20Sopenharmony_ci * @data: The data pointer refers to memory that is not used by the kernel 6438c2ecf20Sopenharmony_ci * crypto API, but provided to the callback function for it to use. Here, 6448c2ecf20Sopenharmony_ci * the caller can provide a reference to memory the callback function can 6458c2ecf20Sopenharmony_ci * operate on. As the callback function is invoked asynchronously to the 6468c2ecf20Sopenharmony_ci * related functionality, it may need to access data structures of the 6478c2ecf20Sopenharmony_ci * related functionality which can be referenced using this pointer. The 6488c2ecf20Sopenharmony_ci * callback function can access the memory via the "data" field in the 6498c2ecf20Sopenharmony_ci * &crypto_async_request data structure provided to the callback function. 6508c2ecf20Sopenharmony_ci * 6518c2ecf20Sopenharmony_ci * This function allows setting the callback function that is triggered once 6528c2ecf20Sopenharmony_ci * the cipher operation completes. 6538c2ecf20Sopenharmony_ci * 6548c2ecf20Sopenharmony_ci * The callback function is registered with the &ahash_request handle and 6558c2ecf20Sopenharmony_ci * must comply with the following template:: 6568c2ecf20Sopenharmony_ci * 6578c2ecf20Sopenharmony_ci * void callback_function(struct crypto_async_request *req, int error) 6588c2ecf20Sopenharmony_ci */ 6598c2ecf20Sopenharmony_cistatic inline void ahash_request_set_callback(struct ahash_request *req, 6608c2ecf20Sopenharmony_ci u32 flags, 6618c2ecf20Sopenharmony_ci crypto_completion_t compl, 6628c2ecf20Sopenharmony_ci void *data) 6638c2ecf20Sopenharmony_ci{ 6648c2ecf20Sopenharmony_ci req->base.complete = compl; 6658c2ecf20Sopenharmony_ci req->base.data = data; 6668c2ecf20Sopenharmony_ci req->base.flags = flags; 6678c2ecf20Sopenharmony_ci} 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci/** 6708c2ecf20Sopenharmony_ci * ahash_request_set_crypt() - set data buffers 6718c2ecf20Sopenharmony_ci * @req: ahash_request handle to be updated 6728c2ecf20Sopenharmony_ci * @src: source scatter/gather list 6738c2ecf20Sopenharmony_ci * @result: buffer that is filled with the message digest -- the caller must 6748c2ecf20Sopenharmony_ci * ensure that the buffer has sufficient space by, for example, calling 6758c2ecf20Sopenharmony_ci * crypto_ahash_digestsize() 6768c2ecf20Sopenharmony_ci * @nbytes: number of bytes to process from the source scatter/gather list 6778c2ecf20Sopenharmony_ci * 6788c2ecf20Sopenharmony_ci * By using this call, the caller references the source scatter/gather list. 6798c2ecf20Sopenharmony_ci * The source scatter/gather list points to the data the message digest is to 6808c2ecf20Sopenharmony_ci * be calculated for. 6818c2ecf20Sopenharmony_ci */ 6828c2ecf20Sopenharmony_cistatic inline void ahash_request_set_crypt(struct ahash_request *req, 6838c2ecf20Sopenharmony_ci struct scatterlist *src, u8 *result, 6848c2ecf20Sopenharmony_ci unsigned int nbytes) 6858c2ecf20Sopenharmony_ci{ 6868c2ecf20Sopenharmony_ci req->src = src; 6878c2ecf20Sopenharmony_ci req->nbytes = nbytes; 6888c2ecf20Sopenharmony_ci req->result = result; 6898c2ecf20Sopenharmony_ci} 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci/** 6928c2ecf20Sopenharmony_ci * DOC: Synchronous Message Digest API 6938c2ecf20Sopenharmony_ci * 6948c2ecf20Sopenharmony_ci * The synchronous message digest API is used with the ciphers of type 6958c2ecf20Sopenharmony_ci * CRYPTO_ALG_TYPE_SHASH (listed as type "shash" in /proc/crypto) 6968c2ecf20Sopenharmony_ci * 6978c2ecf20Sopenharmony_ci * The message digest API is able to maintain state information for the 6988c2ecf20Sopenharmony_ci * caller. 6998c2ecf20Sopenharmony_ci * 7008c2ecf20Sopenharmony_ci * The synchronous message digest API can store user-related context in its 7018c2ecf20Sopenharmony_ci * shash_desc request data structure. 7028c2ecf20Sopenharmony_ci */ 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci/** 7058c2ecf20Sopenharmony_ci * crypto_alloc_shash() - allocate message digest handle 7068c2ecf20Sopenharmony_ci * @alg_name: is the cra_name / name or cra_driver_name / driver name of the 7078c2ecf20Sopenharmony_ci * message digest cipher 7088c2ecf20Sopenharmony_ci * @type: specifies the type of the cipher 7098c2ecf20Sopenharmony_ci * @mask: specifies the mask for the cipher 7108c2ecf20Sopenharmony_ci * 7118c2ecf20Sopenharmony_ci * Allocate a cipher handle for a message digest. The returned &struct 7128c2ecf20Sopenharmony_ci * crypto_shash is the cipher handle that is required for any subsequent 7138c2ecf20Sopenharmony_ci * API invocation for that message digest. 7148c2ecf20Sopenharmony_ci * 7158c2ecf20Sopenharmony_ci * Return: allocated cipher handle in case of success; IS_ERR() is true in case 7168c2ecf20Sopenharmony_ci * of an error, PTR_ERR() returns the error code. 7178c2ecf20Sopenharmony_ci */ 7188c2ecf20Sopenharmony_cistruct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type, 7198c2ecf20Sopenharmony_ci u32 mask); 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_cistatic inline struct crypto_tfm *crypto_shash_tfm(struct crypto_shash *tfm) 7228c2ecf20Sopenharmony_ci{ 7238c2ecf20Sopenharmony_ci return &tfm->base; 7248c2ecf20Sopenharmony_ci} 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci/** 7278c2ecf20Sopenharmony_ci * crypto_free_shash() - zeroize and free the message digest handle 7288c2ecf20Sopenharmony_ci * @tfm: cipher handle to be freed 7298c2ecf20Sopenharmony_ci * 7308c2ecf20Sopenharmony_ci * If @tfm is a NULL or error pointer, this function does nothing. 7318c2ecf20Sopenharmony_ci */ 7328c2ecf20Sopenharmony_cistatic inline void crypto_free_shash(struct crypto_shash *tfm) 7338c2ecf20Sopenharmony_ci{ 7348c2ecf20Sopenharmony_ci crypto_destroy_tfm(tfm, crypto_shash_tfm(tfm)); 7358c2ecf20Sopenharmony_ci} 7368c2ecf20Sopenharmony_ci 7378c2ecf20Sopenharmony_cistatic inline const char *crypto_shash_alg_name(struct crypto_shash *tfm) 7388c2ecf20Sopenharmony_ci{ 7398c2ecf20Sopenharmony_ci return crypto_tfm_alg_name(crypto_shash_tfm(tfm)); 7408c2ecf20Sopenharmony_ci} 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_cistatic inline const char *crypto_shash_driver_name(struct crypto_shash *tfm) 7438c2ecf20Sopenharmony_ci{ 7448c2ecf20Sopenharmony_ci return crypto_tfm_alg_driver_name(crypto_shash_tfm(tfm)); 7458c2ecf20Sopenharmony_ci} 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_cistatic inline unsigned int crypto_shash_alignmask( 7488c2ecf20Sopenharmony_ci struct crypto_shash *tfm) 7498c2ecf20Sopenharmony_ci{ 7508c2ecf20Sopenharmony_ci return crypto_tfm_alg_alignmask(crypto_shash_tfm(tfm)); 7518c2ecf20Sopenharmony_ci} 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci/** 7548c2ecf20Sopenharmony_ci * crypto_shash_blocksize() - obtain block size for cipher 7558c2ecf20Sopenharmony_ci * @tfm: cipher handle 7568c2ecf20Sopenharmony_ci * 7578c2ecf20Sopenharmony_ci * The block size for the message digest cipher referenced with the cipher 7588c2ecf20Sopenharmony_ci * handle is returned. 7598c2ecf20Sopenharmony_ci * 7608c2ecf20Sopenharmony_ci * Return: block size of cipher 7618c2ecf20Sopenharmony_ci */ 7628c2ecf20Sopenharmony_cistatic inline unsigned int crypto_shash_blocksize(struct crypto_shash *tfm) 7638c2ecf20Sopenharmony_ci{ 7648c2ecf20Sopenharmony_ci return crypto_tfm_alg_blocksize(crypto_shash_tfm(tfm)); 7658c2ecf20Sopenharmony_ci} 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_cistatic inline struct shash_alg *__crypto_shash_alg(struct crypto_alg *alg) 7688c2ecf20Sopenharmony_ci{ 7698c2ecf20Sopenharmony_ci return container_of(alg, struct shash_alg, base); 7708c2ecf20Sopenharmony_ci} 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_cistatic inline struct shash_alg *crypto_shash_alg(struct crypto_shash *tfm) 7738c2ecf20Sopenharmony_ci{ 7748c2ecf20Sopenharmony_ci return __crypto_shash_alg(crypto_shash_tfm(tfm)->__crt_alg); 7758c2ecf20Sopenharmony_ci} 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci/** 7788c2ecf20Sopenharmony_ci * crypto_shash_digestsize() - obtain message digest size 7798c2ecf20Sopenharmony_ci * @tfm: cipher handle 7808c2ecf20Sopenharmony_ci * 7818c2ecf20Sopenharmony_ci * The size for the message digest created by the message digest cipher 7828c2ecf20Sopenharmony_ci * referenced with the cipher handle is returned. 7838c2ecf20Sopenharmony_ci * 7848c2ecf20Sopenharmony_ci * Return: digest size of cipher 7858c2ecf20Sopenharmony_ci */ 7868c2ecf20Sopenharmony_cistatic inline unsigned int crypto_shash_digestsize(struct crypto_shash *tfm) 7878c2ecf20Sopenharmony_ci{ 7888c2ecf20Sopenharmony_ci return crypto_shash_alg(tfm)->digestsize; 7898c2ecf20Sopenharmony_ci} 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_cistatic inline unsigned int crypto_shash_statesize(struct crypto_shash *tfm) 7928c2ecf20Sopenharmony_ci{ 7938c2ecf20Sopenharmony_ci return crypto_shash_alg(tfm)->statesize; 7948c2ecf20Sopenharmony_ci} 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_cistatic inline u32 crypto_shash_get_flags(struct crypto_shash *tfm) 7978c2ecf20Sopenharmony_ci{ 7988c2ecf20Sopenharmony_ci return crypto_tfm_get_flags(crypto_shash_tfm(tfm)); 7998c2ecf20Sopenharmony_ci} 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_cistatic inline void crypto_shash_set_flags(struct crypto_shash *tfm, u32 flags) 8028c2ecf20Sopenharmony_ci{ 8038c2ecf20Sopenharmony_ci crypto_tfm_set_flags(crypto_shash_tfm(tfm), flags); 8048c2ecf20Sopenharmony_ci} 8058c2ecf20Sopenharmony_ci 8068c2ecf20Sopenharmony_cistatic inline void crypto_shash_clear_flags(struct crypto_shash *tfm, u32 flags) 8078c2ecf20Sopenharmony_ci{ 8088c2ecf20Sopenharmony_ci crypto_tfm_clear_flags(crypto_shash_tfm(tfm), flags); 8098c2ecf20Sopenharmony_ci} 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci/** 8128c2ecf20Sopenharmony_ci * crypto_shash_descsize() - obtain the operational state size 8138c2ecf20Sopenharmony_ci * @tfm: cipher handle 8148c2ecf20Sopenharmony_ci * 8158c2ecf20Sopenharmony_ci * The size of the operational state the cipher needs during operation is 8168c2ecf20Sopenharmony_ci * returned for the hash referenced with the cipher handle. This size is 8178c2ecf20Sopenharmony_ci * required to calculate the memory requirements to allow the caller allocating 8188c2ecf20Sopenharmony_ci * sufficient memory for operational state. 8198c2ecf20Sopenharmony_ci * 8208c2ecf20Sopenharmony_ci * The operational state is defined with struct shash_desc where the size of 8218c2ecf20Sopenharmony_ci * that data structure is to be calculated as 8228c2ecf20Sopenharmony_ci * sizeof(struct shash_desc) + crypto_shash_descsize(alg) 8238c2ecf20Sopenharmony_ci * 8248c2ecf20Sopenharmony_ci * Return: size of the operational state 8258c2ecf20Sopenharmony_ci */ 8268c2ecf20Sopenharmony_cistatic inline unsigned int crypto_shash_descsize(struct crypto_shash *tfm) 8278c2ecf20Sopenharmony_ci{ 8288c2ecf20Sopenharmony_ci return tfm->descsize; 8298c2ecf20Sopenharmony_ci} 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_cistatic inline void *shash_desc_ctx(struct shash_desc *desc) 8328c2ecf20Sopenharmony_ci{ 8338c2ecf20Sopenharmony_ci return desc->__ctx; 8348c2ecf20Sopenharmony_ci} 8358c2ecf20Sopenharmony_ci 8368c2ecf20Sopenharmony_ci/** 8378c2ecf20Sopenharmony_ci * crypto_shash_setkey() - set key for message digest 8388c2ecf20Sopenharmony_ci * @tfm: cipher handle 8398c2ecf20Sopenharmony_ci * @key: buffer holding the key 8408c2ecf20Sopenharmony_ci * @keylen: length of the key in bytes 8418c2ecf20Sopenharmony_ci * 8428c2ecf20Sopenharmony_ci * The caller provided key is set for the keyed message digest cipher. The 8438c2ecf20Sopenharmony_ci * cipher handle must point to a keyed message digest cipher in order for this 8448c2ecf20Sopenharmony_ci * function to succeed. 8458c2ecf20Sopenharmony_ci * 8468c2ecf20Sopenharmony_ci * Context: Any context. 8478c2ecf20Sopenharmony_ci * Return: 0 if the setting of the key was successful; < 0 if an error occurred 8488c2ecf20Sopenharmony_ci */ 8498c2ecf20Sopenharmony_ciint crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key, 8508c2ecf20Sopenharmony_ci unsigned int keylen); 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci/** 8538c2ecf20Sopenharmony_ci * crypto_shash_digest() - calculate message digest for buffer 8548c2ecf20Sopenharmony_ci * @desc: see crypto_shash_final() 8558c2ecf20Sopenharmony_ci * @data: see crypto_shash_update() 8568c2ecf20Sopenharmony_ci * @len: see crypto_shash_update() 8578c2ecf20Sopenharmony_ci * @out: see crypto_shash_final() 8588c2ecf20Sopenharmony_ci * 8598c2ecf20Sopenharmony_ci * This function is a "short-hand" for the function calls of crypto_shash_init, 8608c2ecf20Sopenharmony_ci * crypto_shash_update and crypto_shash_final. The parameters have the same 8618c2ecf20Sopenharmony_ci * meaning as discussed for those separate three functions. 8628c2ecf20Sopenharmony_ci * 8638c2ecf20Sopenharmony_ci * Context: Any context. 8648c2ecf20Sopenharmony_ci * Return: 0 if the message digest creation was successful; < 0 if an error 8658c2ecf20Sopenharmony_ci * occurred 8668c2ecf20Sopenharmony_ci */ 8678c2ecf20Sopenharmony_ciint crypto_shash_digest(struct shash_desc *desc, const u8 *data, 8688c2ecf20Sopenharmony_ci unsigned int len, u8 *out); 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci/** 8718c2ecf20Sopenharmony_ci * crypto_shash_tfm_digest() - calculate message digest for buffer 8728c2ecf20Sopenharmony_ci * @tfm: hash transformation object 8738c2ecf20Sopenharmony_ci * @data: see crypto_shash_update() 8748c2ecf20Sopenharmony_ci * @len: see crypto_shash_update() 8758c2ecf20Sopenharmony_ci * @out: see crypto_shash_final() 8768c2ecf20Sopenharmony_ci * 8778c2ecf20Sopenharmony_ci * This is a simplified version of crypto_shash_digest() for users who don't 8788c2ecf20Sopenharmony_ci * want to allocate their own hash descriptor (shash_desc). Instead, 8798c2ecf20Sopenharmony_ci * crypto_shash_tfm_digest() takes a hash transformation object (crypto_shash) 8808c2ecf20Sopenharmony_ci * directly, and it allocates a hash descriptor on the stack internally. 8818c2ecf20Sopenharmony_ci * Note that this stack allocation may be fairly large. 8828c2ecf20Sopenharmony_ci * 8838c2ecf20Sopenharmony_ci * Context: Any context. 8848c2ecf20Sopenharmony_ci * Return: 0 on success; < 0 if an error occurred. 8858c2ecf20Sopenharmony_ci */ 8868c2ecf20Sopenharmony_ciint crypto_shash_tfm_digest(struct crypto_shash *tfm, const u8 *data, 8878c2ecf20Sopenharmony_ci unsigned int len, u8 *out); 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_ci/** 8908c2ecf20Sopenharmony_ci * crypto_shash_export() - extract operational state for message digest 8918c2ecf20Sopenharmony_ci * @desc: reference to the operational state handle whose state is exported 8928c2ecf20Sopenharmony_ci * @out: output buffer of sufficient size that can hold the hash state 8938c2ecf20Sopenharmony_ci * 8948c2ecf20Sopenharmony_ci * This function exports the hash state of the operational state handle into the 8958c2ecf20Sopenharmony_ci * caller-allocated output buffer out which must have sufficient size (e.g. by 8968c2ecf20Sopenharmony_ci * calling crypto_shash_descsize). 8978c2ecf20Sopenharmony_ci * 8988c2ecf20Sopenharmony_ci * Context: Any context. 8998c2ecf20Sopenharmony_ci * Return: 0 if the export creation was successful; < 0 if an error occurred 9008c2ecf20Sopenharmony_ci */ 9018c2ecf20Sopenharmony_cistatic inline int crypto_shash_export(struct shash_desc *desc, void *out) 9028c2ecf20Sopenharmony_ci{ 9038c2ecf20Sopenharmony_ci return crypto_shash_alg(desc->tfm)->export(desc, out); 9048c2ecf20Sopenharmony_ci} 9058c2ecf20Sopenharmony_ci 9068c2ecf20Sopenharmony_ci/** 9078c2ecf20Sopenharmony_ci * crypto_shash_import() - import operational state 9088c2ecf20Sopenharmony_ci * @desc: reference to the operational state handle the state imported into 9098c2ecf20Sopenharmony_ci * @in: buffer holding the state 9108c2ecf20Sopenharmony_ci * 9118c2ecf20Sopenharmony_ci * This function imports the hash state into the operational state handle from 9128c2ecf20Sopenharmony_ci * the input buffer. That buffer should have been generated with the 9138c2ecf20Sopenharmony_ci * crypto_ahash_export function. 9148c2ecf20Sopenharmony_ci * 9158c2ecf20Sopenharmony_ci * Context: Any context. 9168c2ecf20Sopenharmony_ci * Return: 0 if the import was successful; < 0 if an error occurred 9178c2ecf20Sopenharmony_ci */ 9188c2ecf20Sopenharmony_cistatic inline int crypto_shash_import(struct shash_desc *desc, const void *in) 9198c2ecf20Sopenharmony_ci{ 9208c2ecf20Sopenharmony_ci struct crypto_shash *tfm = desc->tfm; 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_ci if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) 9238c2ecf20Sopenharmony_ci return -ENOKEY; 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ci return crypto_shash_alg(tfm)->import(desc, in); 9268c2ecf20Sopenharmony_ci} 9278c2ecf20Sopenharmony_ci 9288c2ecf20Sopenharmony_ci/** 9298c2ecf20Sopenharmony_ci * crypto_shash_init() - (re)initialize message digest 9308c2ecf20Sopenharmony_ci * @desc: operational state handle that is already filled 9318c2ecf20Sopenharmony_ci * 9328c2ecf20Sopenharmony_ci * The call (re-)initializes the message digest referenced by the 9338c2ecf20Sopenharmony_ci * operational state handle. Any potentially existing state created by 9348c2ecf20Sopenharmony_ci * previous operations is discarded. 9358c2ecf20Sopenharmony_ci * 9368c2ecf20Sopenharmony_ci * Context: Any context. 9378c2ecf20Sopenharmony_ci * Return: 0 if the message digest initialization was successful; < 0 if an 9388c2ecf20Sopenharmony_ci * error occurred 9398c2ecf20Sopenharmony_ci */ 9408c2ecf20Sopenharmony_cistatic inline int crypto_shash_init(struct shash_desc *desc) 9418c2ecf20Sopenharmony_ci{ 9428c2ecf20Sopenharmony_ci struct crypto_shash *tfm = desc->tfm; 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) 9458c2ecf20Sopenharmony_ci return -ENOKEY; 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci return crypto_shash_alg(tfm)->init(desc); 9488c2ecf20Sopenharmony_ci} 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_ci/** 9518c2ecf20Sopenharmony_ci * crypto_shash_update() - add data to message digest for processing 9528c2ecf20Sopenharmony_ci * @desc: operational state handle that is already initialized 9538c2ecf20Sopenharmony_ci * @data: input data to be added to the message digest 9548c2ecf20Sopenharmony_ci * @len: length of the input data 9558c2ecf20Sopenharmony_ci * 9568c2ecf20Sopenharmony_ci * Updates the message digest state of the operational state handle. 9578c2ecf20Sopenharmony_ci * 9588c2ecf20Sopenharmony_ci * Context: Any context. 9598c2ecf20Sopenharmony_ci * Return: 0 if the message digest update was successful; < 0 if an error 9608c2ecf20Sopenharmony_ci * occurred 9618c2ecf20Sopenharmony_ci */ 9628c2ecf20Sopenharmony_ciint crypto_shash_update(struct shash_desc *desc, const u8 *data, 9638c2ecf20Sopenharmony_ci unsigned int len); 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ci/** 9668c2ecf20Sopenharmony_ci * crypto_shash_final() - calculate message digest 9678c2ecf20Sopenharmony_ci * @desc: operational state handle that is already filled with data 9688c2ecf20Sopenharmony_ci * @out: output buffer filled with the message digest 9698c2ecf20Sopenharmony_ci * 9708c2ecf20Sopenharmony_ci * Finalize the message digest operation and create the message digest 9718c2ecf20Sopenharmony_ci * based on all data added to the cipher handle. The message digest is placed 9728c2ecf20Sopenharmony_ci * into the output buffer. The caller must ensure that the output buffer is 9738c2ecf20Sopenharmony_ci * large enough by using crypto_shash_digestsize. 9748c2ecf20Sopenharmony_ci * 9758c2ecf20Sopenharmony_ci * Context: Any context. 9768c2ecf20Sopenharmony_ci * Return: 0 if the message digest creation was successful; < 0 if an error 9778c2ecf20Sopenharmony_ci * occurred 9788c2ecf20Sopenharmony_ci */ 9798c2ecf20Sopenharmony_ciint crypto_shash_final(struct shash_desc *desc, u8 *out); 9808c2ecf20Sopenharmony_ci 9818c2ecf20Sopenharmony_ci/** 9828c2ecf20Sopenharmony_ci * crypto_shash_finup() - calculate message digest of buffer 9838c2ecf20Sopenharmony_ci * @desc: see crypto_shash_final() 9848c2ecf20Sopenharmony_ci * @data: see crypto_shash_update() 9858c2ecf20Sopenharmony_ci * @len: see crypto_shash_update() 9868c2ecf20Sopenharmony_ci * @out: see crypto_shash_final() 9878c2ecf20Sopenharmony_ci * 9888c2ecf20Sopenharmony_ci * This function is a "short-hand" for the function calls of 9898c2ecf20Sopenharmony_ci * crypto_shash_update and crypto_shash_final. The parameters have the same 9908c2ecf20Sopenharmony_ci * meaning as discussed for those separate functions. 9918c2ecf20Sopenharmony_ci * 9928c2ecf20Sopenharmony_ci * Context: Any context. 9938c2ecf20Sopenharmony_ci * Return: 0 if the message digest creation was successful; < 0 if an error 9948c2ecf20Sopenharmony_ci * occurred 9958c2ecf20Sopenharmony_ci */ 9968c2ecf20Sopenharmony_ciint crypto_shash_finup(struct shash_desc *desc, const u8 *data, 9978c2ecf20Sopenharmony_ci unsigned int len, u8 *out); 9988c2ecf20Sopenharmony_ci 9998c2ecf20Sopenharmony_cistatic inline void shash_desc_zero(struct shash_desc *desc) 10008c2ecf20Sopenharmony_ci{ 10018c2ecf20Sopenharmony_ci memzero_explicit(desc, 10028c2ecf20Sopenharmony_ci sizeof(*desc) + crypto_shash_descsize(desc->tfm)); 10038c2ecf20Sopenharmony_ci} 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ci#endif /* _CRYPTO_HASH_H */ 1006