^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Hash: Hash algorithms under the crypto API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef _CRYPTO_HASH_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define _CRYPTO_HASH_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct crypto_ahash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * DOC: Message Digest Algorithm Definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * These data structures define modular message digest algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * implementations, managed via crypto_register_ahash(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * crypto_register_shash(), crypto_unregister_ahash() and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * crypto_unregister_shash().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * struct hash_alg_common - define properties of message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * @digestsize: Size of the result of the transformation. A buffer of this size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * must be available to the @final and @finup calls, so they can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * store the resulting hash into it. For various predefined sizes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * search include/crypto/ using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * git grep _DIGEST_SIZE include/crypto.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * @statesize: Size of the block for partial state of the transformation. A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * buffer of this size must be passed to the @export function as it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * will save the partial state of the transformation into it. On the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * other side, the @import function will load the state from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * buffer of this size as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * @base: Start of data structure of cipher algorithm. The common data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * structure of crypto_alg contains information common to all ciphers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * The hash_alg_common data structure now adds the hash-specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct hash_alg_common {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned int digestsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned int statesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct crypto_alg base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct ahash_request {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct crypto_async_request base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct scatterlist *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u8 *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* This field may only be used by the ahash API code. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) void *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) void *__ctx[] CRYPTO_MINALIGN_ATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * struct ahash_alg - asynchronous message digest definition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * @init: **[mandatory]** Initialize the transformation context. Intended only to initialize the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * state of the HASH transformation at the beginning. This shall fill in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * the internal structures used during the entire duration of the whole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * transformation. No data processing happens at this point. Driver code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * implementation must not use req->result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * @update: **[mandatory]** Push a chunk of data into the driver for transformation. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * function actually pushes blocks of data from upper layers into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * driver, which then passes those to the hardware as seen fit. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * function must not finalize the HASH transformation by calculating the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * final message digest as this only adds more data into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * transformation. This function shall not modify the transformation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * context, as this function may be called in parallel with the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * transformation object. Data processing can happen synchronously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * [SHASH] or asynchronously [AHASH] at this point. Driver must not use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * req->result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * @final: **[mandatory]** Retrieve result from the driver. This function finalizes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * transformation and retrieves the resulting hash from the driver and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * pushes it back to upper layers. No data processing happens at this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * point unless hardware requires it to finish the transformation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * (then the data buffered by the device driver is processed).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * @finup: **[optional]** Combination of @update and @final. This function is effectively a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * combination of @update and @final calls issued in sequence. As some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * hardware cannot do @update and @final separately, this callback was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * added to allow such hardware to be used at least by IPsec. Data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * processing can happen synchronously [SHASH] or asynchronously [AHASH]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * at this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * @digest: Combination of @init and @update and @final. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * effectively behaves as the entire chain of operations, @init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * @update and @final issued in sequence. Just like @finup, this was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * added for hardware which cannot do even the @finup, but can only do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * the whole transformation in one run. Data processing can happen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * synchronously [SHASH] or asynchronously [AHASH] at this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * @setkey: Set optional key used by the hashing algorithm. Intended to push
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * optional key used by the hashing algorithm from upper layers into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * the driver. This function can store the key in the transformation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * context or can outright program it into the hardware. In the former
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * case, one must be careful to program the key into the hardware at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * appropriate time and one must be careful that .setkey() can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * called multiple times during the existence of the transformation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * object. Not all hashing algorithms do implement this function as it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * is only needed for keyed message digests. SHAx/MDx/CRCx do NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * implement this function. HMAC(MDx)/HMAC(SHAx)/CMAC(AES) do implement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * this function. This function must be called before any other of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @init, @update, @final, @finup, @digest is called. No data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * processing happens at this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * @export: Export partial state of the transformation. This function dumps the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * entire state of the ongoing transformation into a provided block of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * data so it can be @import 'ed back later on. This is useful in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * you want to save partial result of the transformation after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * processing certain amount of data and reload this partial result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * multiple times later on for multiple re-use. No data processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * happens at this point. Driver must not use req->result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * @import: Import partial state of the transformation. This function loads the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * entire state of the ongoing transformation from a provided block of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * data so the transformation can continue from this point onward. No
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * data processing happens at this point. Driver must not use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * req->result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * @init_tfm: Initialize the cryptographic transformation object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * This function is called only once at the instantiation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * time, right after the transformation context was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * allocated. In case the cryptographic hardware has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * some special requirements which need to be handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * by software, this function shall check for the precise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * requirement of the transformation and put any software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * fallbacks in place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * @exit_tfm: Deinitialize the cryptographic transformation object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * This is a counterpart to @init_tfm, used to remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * various changes set in @init_tfm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * @halg: see struct hash_alg_common
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct ahash_alg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int (*init)(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int (*update)(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int (*final)(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int (*finup)(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int (*digest)(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int (*export)(struct ahash_request *req, void *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int (*import)(struct ahash_request *req, const void *in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) int (*setkey)(struct crypto_ahash *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int (*init_tfm)(struct crypto_ahash *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) void (*exit_tfm)(struct crypto_ahash *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct hash_alg_common halg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct shash_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct crypto_shash *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) void *__ctx[] __aligned(ARCH_SLAB_MINALIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define HASH_MAX_DIGESTSIZE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * Worst case is hmac(sha3-224-generic). Its context is a nested 'shash_desc'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * containing a 'struct sha3_state'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #define HASH_MAX_DESCSIZE (sizeof(struct shash_desc) + 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) #define HASH_MAX_STATESIZE 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #define SHASH_DESC_ON_STACK(shash, ctx) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) char __##shash##_desc[sizeof(struct shash_desc) + HASH_MAX_DESCSIZE] \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) __aligned(__alignof__(struct shash_desc)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct shash_desc *shash = (struct shash_desc *)__##shash##_desc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * struct shash_alg - synchronous message digest definition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * @init: see struct ahash_alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * @update: see struct ahash_alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * @final: see struct ahash_alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * @finup: see struct ahash_alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * @digest: see struct ahash_alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * @export: see struct ahash_alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * @import: see struct ahash_alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * @setkey: see struct ahash_alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * @init_tfm: Initialize the cryptographic transformation object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * This function is called only once at the instantiation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * time, right after the transformation context was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * allocated. In case the cryptographic hardware has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * some special requirements which need to be handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * by software, this function shall check for the precise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * requirement of the transformation and put any software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * fallbacks in place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * @exit_tfm: Deinitialize the cryptographic transformation object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * This is a counterpart to @init_tfm, used to remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * various changes set in @init_tfm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * @digestsize: see struct ahash_alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * @statesize: see struct ahash_alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * @descsize: Size of the operational state for the message digest. This state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * size is the memory size that needs to be allocated for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * shash_desc.__ctx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * @base: internally used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct shash_alg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int (*init)(struct shash_desc *desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int (*update)(struct shash_desc *desc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int (*final)(struct shash_desc *desc, u8 *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) int (*finup)(struct shash_desc *desc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned int len, u8 *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int (*digest)(struct shash_desc *desc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) unsigned int len, u8 *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int (*export)(struct shash_desc *desc, void *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int (*import)(struct shash_desc *desc, const void *in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int (*setkey)(struct crypto_shash *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int (*init_tfm)(struct crypto_shash *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) void (*exit_tfm)(struct crypto_shash *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) unsigned int descsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* These fields must match hash_alg_common. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) unsigned int digestsize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) __attribute__ ((aligned(__alignof__(struct hash_alg_common))));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) unsigned int statesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct crypto_alg base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct crypto_ahash {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int (*init)(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) int (*update)(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int (*final)(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int (*finup)(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int (*digest)(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int (*export)(struct ahash_request *req, void *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int (*import)(struct ahash_request *req, const void *in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) int (*setkey)(struct crypto_ahash *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) unsigned int reqsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct crypto_tfm base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct crypto_shash {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) unsigned int descsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct crypto_tfm base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * DOC: Asynchronous Message Digest API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * The asynchronous message digest API is used with the ciphers of type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * CRYPTO_ALG_TYPE_AHASH (listed as type "ahash" in /proc/crypto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * The asynchronous cipher operation discussion provided for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * CRYPTO_ALG_TYPE_SKCIPHER API applies here as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return container_of(tfm, struct crypto_ahash, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * crypto_alloc_ahash() - allocate ahash cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * ahash cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * @type: specifies the type of the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * @mask: specifies the mask for the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * Allocate a cipher handle for an ahash. The returned struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * crypto_ahash is the cipher handle that is required for any subsequent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * API invocation for that ahash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * Return: allocated cipher handle in case of success; IS_ERR() is true in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * of an error, PTR_ERR() returns the error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, u32 type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) u32 mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return &tfm->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * crypto_free_ahash() - zeroize and free the ahash handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * @tfm: cipher handle to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * If @tfm is a NULL or error pointer, this function does nothing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static inline void crypto_free_ahash(struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) crypto_destroy_tfm(tfm, crypto_ahash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * crypto_has_ahash() - Search for the availability of an ahash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * ahash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * @type: specifies the type of the ahash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * @mask: specifies the mask for the ahash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * Return: true when the ahash is known to the kernel crypto API; false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) int crypto_has_ahash(const char *alg_name, u32 type, u32 mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static inline const char *crypto_ahash_alg_name(struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return crypto_tfm_alg_name(crypto_ahash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static inline const char *crypto_ahash_driver_name(struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static inline unsigned int crypto_ahash_alignmask(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * crypto_ahash_blocksize() - obtain block size for cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * The block size for the message digest cipher referenced with the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * handle is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * Return: block size of cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static inline unsigned int crypto_ahash_blocksize(struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static inline struct hash_alg_common *__crypto_hash_alg_common(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return container_of(alg, struct hash_alg_common, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static inline struct hash_alg_common *crypto_hash_alg_common(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return __crypto_hash_alg_common(crypto_ahash_tfm(tfm)->__crt_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * crypto_ahash_digestsize() - obtain message digest size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * The size for the message digest created by the message digest cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * referenced with the cipher handle is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * Return: message digest size of cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return crypto_hash_alg_common(tfm)->digestsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * crypto_ahash_statesize() - obtain size of the ahash state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * Return the size of the ahash state. With the crypto_ahash_export()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * function, the caller can export the state into a buffer whose size is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * defined with this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * Return: size of the ahash state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static inline unsigned int crypto_ahash_statesize(struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return crypto_hash_alg_common(tfm)->statesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return crypto_tfm_get_flags(crypto_ahash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static inline void crypto_ahash_set_flags(struct crypto_ahash *tfm, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) crypto_tfm_set_flags(crypto_ahash_tfm(tfm), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static inline void crypto_ahash_clear_flags(struct crypto_ahash *tfm, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) crypto_tfm_clear_flags(crypto_ahash_tfm(tfm), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * crypto_ahash_reqtfm() - obtain cipher handle from request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * @req: asynchronous request handle that contains the reference to the ahash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * Return the ahash cipher handle that is registered with the asynchronous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * request handle ahash_request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * Return: ahash cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static inline struct crypto_ahash *crypto_ahash_reqtfm(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct ahash_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return __crypto_ahash_cast(req->base.tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) * crypto_ahash_reqsize() - obtain size of the request data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * Return: size of the request data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return tfm->reqsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static inline void *ahash_request_ctx(struct ahash_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return req->__ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * crypto_ahash_setkey - set key for cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * @key: buffer holding the key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * @keylen: length of the key in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * The caller provided key is set for the ahash cipher. The cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) * handle must point to a keyed hash in order for this function to succeed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) * Return: 0 if the setting of the key was successful; < 0 if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) int crypto_ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * crypto_ahash_finup() - update and finalize message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * @req: reference to the ahash_request handle that holds all information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * needed to perform the cipher operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * This function is a "short-hand" for the function calls of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * crypto_ahash_update and crypto_ahash_final. The parameters have the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * meaning as discussed for those separate functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * Return: see crypto_ahash_final()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) int crypto_ahash_finup(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * crypto_ahash_final() - calculate message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * @req: reference to the ahash_request handle that holds all information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) * needed to perform the cipher operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * Finalize the message digest operation and create the message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * based on all data added to the cipher handle. The message digest is placed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * into the output buffer registered with the ahash_request handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * 0 if the message digest was successfully calculated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * -EINPROGRESS if data is feeded into hardware (DMA) or queued for later;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * -EBUSY if queue is full and request should be resubmitted later;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * other < 0 if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) int crypto_ahash_final(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * crypto_ahash_digest() - calculate message digest for a buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * @req: reference to the ahash_request handle that holds all information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * needed to perform the cipher operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * This function is a "short-hand" for the function calls of crypto_ahash_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * crypto_ahash_update and crypto_ahash_final. The parameters have the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * meaning as discussed for those separate three functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * Return: see crypto_ahash_final()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int crypto_ahash_digest(struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * crypto_ahash_export() - extract current message digest state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * @req: reference to the ahash_request handle whose state is exported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * @out: output buffer of sufficient size that can hold the hash state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * This function exports the hash state of the ahash_request handle into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * caller-allocated output buffer out which must have sufficient size (e.g. by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) * calling crypto_ahash_statesize()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * Return: 0 if the export was successful; < 0 if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static inline int crypto_ahash_export(struct ahash_request *req, void *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return crypto_ahash_reqtfm(req)->export(req, out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * crypto_ahash_import() - import message digest state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * @req: reference to ahash_request handle the state is imported into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * @in: buffer holding the state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * This function imports the hash state into the ahash_request handle from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * input buffer. That buffer should have been generated with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * crypto_ahash_export function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * Return: 0 if the import was successful; < 0 if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static inline int crypto_ahash_import(struct ahash_request *req, const void *in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return tfm->import(req, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * crypto_ahash_init() - (re)initialize message digest handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * @req: ahash_request handle that already is initialized with all necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * data using the ahash_request_* API functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * The call (re-)initializes the message digest referenced by the ahash_request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * handle. Any potentially existing state created by previous operations is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * discarded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) * Return: see crypto_ahash_final()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static inline int crypto_ahash_init(struct ahash_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return tfm->init(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * crypto_ahash_update() - add data to message digest for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * @req: ahash_request handle that was previously initialized with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * crypto_ahash_init call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * Updates the message digest state of the &ahash_request handle. The input data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * is pointed to by the scatter/gather list registered in the &ahash_request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * Return: see crypto_ahash_final()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static inline int crypto_ahash_update(struct ahash_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct crypto_alg *alg = tfm->base.__crt_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) unsigned int nbytes = req->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) crypto_stats_get(alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) ret = crypto_ahash_reqtfm(req)->update(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) crypto_stats_ahash_update(nbytes, ret, alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) * DOC: Asynchronous Hash Request Handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * The &ahash_request data structure contains all pointers to data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * required for the asynchronous cipher operation. This includes the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * handle (which can be used by multiple &ahash_request instances), pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * to plaintext and the message digest output buffer, asynchronous callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * function, etc. It acts as a handle to the ahash_request_* API calls in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * similar way as ahash handle to the crypto_ahash_* API calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * ahash_request_set_tfm() - update cipher handle reference in request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * @req: request handle to be modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * @tfm: cipher handle that shall be added to the request handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * Allow the caller to replace the existing ahash handle in the request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * data structure with a different one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static inline void ahash_request_set_tfm(struct ahash_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) req->base.tfm = crypto_ahash_tfm(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * ahash_request_alloc() - allocate request data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * @tfm: cipher handle to be registered with the request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * @gfp: memory allocation flag that is handed to kmalloc by the API call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * Allocate the request data structure that must be used with the ahash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) * message digest API calls. During
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) * the allocation, the provided ahash handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * is registered in the request data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) * Return: allocated request handle in case of success, or NULL if out of memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static inline struct ahash_request *ahash_request_alloc(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct crypto_ahash *tfm, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) struct ahash_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) req = kmalloc(sizeof(struct ahash_request) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) crypto_ahash_reqsize(tfm), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (likely(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) ahash_request_set_tfm(req, tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) * ahash_request_free() - zeroize and free the request data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * @req: request data structure cipher handle to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) static inline void ahash_request_free(struct ahash_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) kfree_sensitive(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) static inline void ahash_request_zero(struct ahash_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) memzero_explicit(req, sizeof(*req) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) crypto_ahash_reqsize(crypto_ahash_reqtfm(req)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) static inline struct ahash_request *ahash_request_cast(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) struct crypto_async_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) return container_of(req, struct ahash_request, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * ahash_request_set_callback() - set asynchronous callback function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * @req: request handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * @flags: specify zero or an ORing of the flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * CRYPTO_TFM_REQ_MAY_BACKLOG the request queue may back log and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * increase the wait queue beyond the initial maximum size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) * CRYPTO_TFM_REQ_MAY_SLEEP the request processing may sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) * @compl: callback function pointer to be registered with the request handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) * @data: The data pointer refers to memory that is not used by the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) * crypto API, but provided to the callback function for it to use. Here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) * the caller can provide a reference to memory the callback function can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * operate on. As the callback function is invoked asynchronously to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * related functionality, it may need to access data structures of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * related functionality which can be referenced using this pointer. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) * callback function can access the memory via the "data" field in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) * &crypto_async_request data structure provided to the callback function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) * This function allows setting the callback function that is triggered once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * the cipher operation completes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) * The callback function is registered with the &ahash_request handle and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * must comply with the following template::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * void callback_function(struct crypto_async_request *req, int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) static inline void ahash_request_set_callback(struct ahash_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) u32 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) crypto_completion_t compl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) req->base.complete = compl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) req->base.data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) req->base.flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * ahash_request_set_crypt() - set data buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * @req: ahash_request handle to be updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * @src: source scatter/gather list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) * @result: buffer that is filled with the message digest -- the caller must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) * ensure that the buffer has sufficient space by, for example, calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * crypto_ahash_digestsize()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) * @nbytes: number of bytes to process from the source scatter/gather list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * By using this call, the caller references the source scatter/gather list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) * The source scatter/gather list points to the data the message digest is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) * be calculated for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) static inline void ahash_request_set_crypt(struct ahash_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) struct scatterlist *src, u8 *result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) unsigned int nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) req->src = src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) req->nbytes = nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) req->result = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * DOC: Synchronous Message Digest API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * The synchronous message digest API is used with the ciphers of type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) * CRYPTO_ALG_TYPE_SHASH (listed as type "shash" in /proc/crypto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) * The message digest API is able to maintain state information for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) * caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) * The synchronous message digest API can store user-related context in its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * shash_desc request data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * crypto_alloc_shash() - allocate message digest handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * message digest cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) * @type: specifies the type of the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) * @mask: specifies the mask for the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) * Allocate a cipher handle for a message digest. The returned &struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) * crypto_shash is the cipher handle that is required for any subsequent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) * API invocation for that message digest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) * Return: allocated cipher handle in case of success; IS_ERR() is true in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * of an error, PTR_ERR() returns the error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) u32 mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) static inline struct crypto_tfm *crypto_shash_tfm(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) return &tfm->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) * crypto_free_shash() - zeroize and free the message digest handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) * @tfm: cipher handle to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * If @tfm is a NULL or error pointer, this function does nothing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) static inline void crypto_free_shash(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) crypto_destroy_tfm(tfm, crypto_shash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) static inline const char *crypto_shash_alg_name(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) return crypto_tfm_alg_name(crypto_shash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) static inline const char *crypto_shash_driver_name(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) return crypto_tfm_alg_driver_name(crypto_shash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) static inline unsigned int crypto_shash_alignmask(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) return crypto_tfm_alg_alignmask(crypto_shash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) * crypto_shash_blocksize() - obtain block size for cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) * The block size for the message digest cipher referenced with the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) * handle is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * Return: block size of cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) static inline unsigned int crypto_shash_blocksize(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) return crypto_tfm_alg_blocksize(crypto_shash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) static inline struct shash_alg *__crypto_shash_alg(struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) return container_of(alg, struct shash_alg, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) static inline struct shash_alg *crypto_shash_alg(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return __crypto_shash_alg(crypto_shash_tfm(tfm)->__crt_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * crypto_shash_digestsize() - obtain message digest size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) * The size for the message digest created by the message digest cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) * referenced with the cipher handle is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) * Return: digest size of cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) static inline unsigned int crypto_shash_digestsize(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) return crypto_shash_alg(tfm)->digestsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) static inline unsigned int crypto_shash_statesize(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) return crypto_shash_alg(tfm)->statesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) static inline u32 crypto_shash_get_flags(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) return crypto_tfm_get_flags(crypto_shash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) static inline void crypto_shash_set_flags(struct crypto_shash *tfm, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) crypto_tfm_set_flags(crypto_shash_tfm(tfm), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) static inline void crypto_shash_clear_flags(struct crypto_shash *tfm, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) crypto_tfm_clear_flags(crypto_shash_tfm(tfm), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * crypto_shash_descsize() - obtain the operational state size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) * The size of the operational state the cipher needs during operation is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) * returned for the hash referenced with the cipher handle. This size is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) * required to calculate the memory requirements to allow the caller allocating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) * sufficient memory for operational state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) * The operational state is defined with struct shash_desc where the size of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) * that data structure is to be calculated as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) * sizeof(struct shash_desc) + crypto_shash_descsize(alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) * Return: size of the operational state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) static inline unsigned int crypto_shash_descsize(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) return tfm->descsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) static inline void *shash_desc_ctx(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) return desc->__ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) * crypto_shash_setkey() - set key for message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) * @key: buffer holding the key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) * @keylen: length of the key in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) * The caller provided key is set for the keyed message digest cipher. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) * cipher handle must point to a keyed message digest cipher in order for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) * function to succeed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) * Context: Any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) * Return: 0 if the setting of the key was successful; < 0 if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) * crypto_shash_digest() - calculate message digest for buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) * @desc: see crypto_shash_final()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) * @data: see crypto_shash_update()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * @len: see crypto_shash_update()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) * @out: see crypto_shash_final()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) * This function is a "short-hand" for the function calls of crypto_shash_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) * crypto_shash_update and crypto_shash_final. The parameters have the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) * meaning as discussed for those separate three functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) * Context: Any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) * Return: 0 if the message digest creation was successful; < 0 if an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) * occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) unsigned int len, u8 *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) * crypto_shash_tfm_digest() - calculate message digest for buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * @tfm: hash transformation object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * @data: see crypto_shash_update()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * @len: see crypto_shash_update()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) * @out: see crypto_shash_final()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) * This is a simplified version of crypto_shash_digest() for users who don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * want to allocate their own hash descriptor (shash_desc). Instead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) * crypto_shash_tfm_digest() takes a hash transformation object (crypto_shash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) * directly, and it allocates a hash descriptor on the stack internally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * Note that this stack allocation may be fairly large.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) * Context: Any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) * Return: 0 on success; < 0 if an error occurred.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) int crypto_shash_tfm_digest(struct crypto_shash *tfm, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) unsigned int len, u8 *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) * crypto_shash_export() - extract operational state for message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) * @desc: reference to the operational state handle whose state is exported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) * @out: output buffer of sufficient size that can hold the hash state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) * This function exports the hash state of the operational state handle into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) * caller-allocated output buffer out which must have sufficient size (e.g. by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) * calling crypto_shash_descsize).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) * Context: Any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) * Return: 0 if the export creation was successful; < 0 if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) static inline int crypto_shash_export(struct shash_desc *desc, void *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) return crypto_shash_alg(desc->tfm)->export(desc, out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) * crypto_shash_import() - import operational state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) * @desc: reference to the operational state handle the state imported into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) * @in: buffer holding the state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) * This function imports the hash state into the operational state handle from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) * the input buffer. That buffer should have been generated with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) * crypto_ahash_export function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) * Context: Any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) * Return: 0 if the import was successful; < 0 if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) static inline int crypto_shash_import(struct shash_desc *desc, const void *in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) struct crypto_shash *tfm = desc->tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) return crypto_shash_alg(tfm)->import(desc, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) * crypto_shash_init() - (re)initialize message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) * @desc: operational state handle that is already filled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) * The call (re-)initializes the message digest referenced by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) * operational state handle. Any potentially existing state created by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) * previous operations is discarded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) * Context: Any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) * Return: 0 if the message digest initialization was successful; < 0 if an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) * error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) static inline int crypto_shash_init(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) struct crypto_shash *tfm = desc->tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) return crypto_shash_alg(tfm)->init(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) * crypto_shash_update() - add data to message digest for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) * @desc: operational state handle that is already initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) * @data: input data to be added to the message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) * @len: length of the input data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) * Updates the message digest state of the operational state handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) * Context: Any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) * Return: 0 if the message digest update was successful; < 0 if an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) * occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) int crypto_shash_update(struct shash_desc *desc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) * crypto_shash_final() - calculate message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) * @desc: operational state handle that is already filled with data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) * @out: output buffer filled with the message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) * Finalize the message digest operation and create the message digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) * based on all data added to the cipher handle. The message digest is placed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) * into the output buffer. The caller must ensure that the output buffer is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) * large enough by using crypto_shash_digestsize.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) * Context: Any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) * Return: 0 if the message digest creation was successful; < 0 if an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) * occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) int crypto_shash_final(struct shash_desc *desc, u8 *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) * crypto_shash_finup() - calculate message digest of buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) * @desc: see crypto_shash_final()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) * @data: see crypto_shash_update()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) * @len: see crypto_shash_update()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) * @out: see crypto_shash_final()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) * This function is a "short-hand" for the function calls of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) * crypto_shash_update and crypto_shash_final. The parameters have the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) * meaning as discussed for those separate functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) * Context: Any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) * Return: 0 if the message digest creation was successful; < 0 if an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) * occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) int crypto_shash_finup(struct shash_desc *desc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) unsigned int len, u8 *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) static inline void shash_desc_zero(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) memzero_explicit(desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) sizeof(*desc) + crypto_shash_descsize(desc->tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) #endif /* _CRYPTO_HASH_H */