crypto: ahash - Add virtual address support

This patch adds virtual address support to ahash.  Virtual addresses
were previously only supported through shash.  The user may choose
to use virtual addresses with ahash by calling ahash_request_set_virt
instead of ahash_request_set_crypt.

The API will take care of translating this to an SG list if necessary,
unless the algorithm declares that it supports chaining.  Therefore
in order for an ahash algorithm to support chaining, it must also
support virtual addresses directly.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Herbert Xu
2025-02-16 11:07:22 +08:00
parent c664f03417
commit 439963cdc3
4 changed files with 293 additions and 34 deletions
+36 -2
View File
@@ -12,6 +12,9 @@
#include <linux/crypto.h>
#include <linux/string.h>
/* Set this bit for virtual address instead of SG list. */
#define CRYPTO_AHASH_REQ_VIRT 0x00000001
struct crypto_ahash;
/**
@@ -52,7 +55,10 @@ struct ahash_request {
struct crypto_async_request base;
unsigned int nbytes;
struct scatterlist *src;
union {
struct scatterlist *src;
const u8 *svirt;
};
u8 *result;
void *__ctx[] CRYPTO_MINALIGN_ATTR;
@@ -610,9 +616,13 @@ static inline void ahash_request_set_callback(struct ahash_request *req,
crypto_completion_t compl,
void *data)
{
u32 keep = CRYPTO_AHASH_REQ_VIRT;
req->base.complete = compl;
req->base.data = data;
req->base.flags = flags;
flags &= ~keep;
req->base.flags &= keep;
req->base.flags |= flags;
crypto_reqchain_init(&req->base);
}
@@ -636,6 +646,30 @@ static inline void ahash_request_set_crypt(struct ahash_request *req,
req->src = src;
req->nbytes = nbytes;
req->result = result;
req->base.flags &= ~CRYPTO_AHASH_REQ_VIRT;
}
/**
* ahash_request_set_virt() - set virtual address data buffers
* @req: ahash_request handle to be updated
* @src: source virtual address
* @result: buffer that is filled with the message digest -- the caller must
* ensure that the buffer has sufficient space by, for example, calling
* crypto_ahash_digestsize()
* @nbytes: number of bytes to process from the source virtual address
*
* By using this call, the caller references the source virtual address.
* The source virtual address points to the data the message digest is to
* be calculated for.
*/
static inline void ahash_request_set_virt(struct ahash_request *req,
const u8 *src, u8 *result,
unsigned int nbytes)
{
req->svirt = src;
req->nbytes = nbytes;
req->result = result;
req->base.flags |= CRYPTO_AHASH_REQ_VIRT;
}
static inline void ahash_request_chain(struct ahash_request *req,
+5
View File
@@ -252,6 +252,11 @@ static inline bool ahash_request_chained(struct ahash_request *req)
return crypto_request_chained(&req->base);
}
static inline bool ahash_request_isvirt(struct ahash_request *req)
{
return req->base.flags & CRYPTO_AHASH_REQ_VIRT;
}
static inline bool crypto_ahash_req_chain(struct crypto_ahash *tfm)
{
return crypto_tfm_req_chain(&tfm->base);