Commit 132e9068 authored by Tom Lendacky's avatar Tom Lendacky Committed by Ben Hutchings

crypto: ccp - Add hash state import and export support

commit 952bce97 upstream.

Commit 8996eafd ("crypto: ahash - ensure statesize is non-zero")
added a check to prevent ahash algorithms from successfully registering
if the import and export functions were not implemented. This prevents
an oops in the hash_accept function of algif_hash. This commit causes
the ccp-crypto module SHA support and AES CMAC support from successfully
registering and causing the ccp-crypto module load to fail because the
ahash import and export functions are not implemented.

Update the CCP Crypto API support to provide import and export support
for ahash algorithms.
Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 1dcba551
...@@ -201,6 +201,26 @@ static int ccp_aes_cmac_digest(struct ahash_request *req) ...@@ -201,6 +201,26 @@ static int ccp_aes_cmac_digest(struct ahash_request *req)
return ccp_aes_cmac_finup(req); return ccp_aes_cmac_finup(req);
} }
static int ccp_aes_cmac_export(struct ahash_request *req, void *out)
{
struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
struct ccp_aes_cmac_req_ctx *state = out;
*state = *rctx;
return 0;
}
static int ccp_aes_cmac_import(struct ahash_request *req, const void *in)
{
struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
const struct ccp_aes_cmac_req_ctx *state = in;
*rctx = *state;
return 0;
}
static int ccp_aes_cmac_setkey(struct crypto_ahash *tfm, const u8 *key, static int ccp_aes_cmac_setkey(struct crypto_ahash *tfm, const u8 *key,
unsigned int key_len) unsigned int key_len)
{ {
...@@ -332,10 +352,13 @@ int ccp_register_aes_cmac_algs(struct list_head *head) ...@@ -332,10 +352,13 @@ int ccp_register_aes_cmac_algs(struct list_head *head)
alg->final = ccp_aes_cmac_final; alg->final = ccp_aes_cmac_final;
alg->finup = ccp_aes_cmac_finup; alg->finup = ccp_aes_cmac_finup;
alg->digest = ccp_aes_cmac_digest; alg->digest = ccp_aes_cmac_digest;
alg->export = ccp_aes_cmac_export;
alg->import = ccp_aes_cmac_import;
alg->setkey = ccp_aes_cmac_setkey; alg->setkey = ccp_aes_cmac_setkey;
halg = &alg->halg; halg = &alg->halg;
halg->digestsize = AES_BLOCK_SIZE; halg->digestsize = AES_BLOCK_SIZE;
halg->statesize = sizeof(struct ccp_aes_cmac_req_ctx);
base = &halg->base; base = &halg->base;
snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "cmac(aes)"); snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "cmac(aes)");
......
...@@ -193,6 +193,26 @@ static int ccp_sha_digest(struct ahash_request *req) ...@@ -193,6 +193,26 @@ static int ccp_sha_digest(struct ahash_request *req)
return ccp_sha_finup(req); return ccp_sha_finup(req);
} }
static int ccp_sha_export(struct ahash_request *req, void *out)
{
struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
struct ccp_sha_req_ctx *state = out;
*state = *rctx;
return 0;
}
static int ccp_sha_import(struct ahash_request *req, const void *in)
{
struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
const struct ccp_sha_req_ctx *state = in;
*rctx = *state;
return 0;
}
static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key, static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
unsigned int key_len) unsigned int key_len)
{ {
...@@ -389,9 +409,12 @@ static int ccp_register_sha_alg(struct list_head *head, ...@@ -389,9 +409,12 @@ static int ccp_register_sha_alg(struct list_head *head,
alg->final = ccp_sha_final; alg->final = ccp_sha_final;
alg->finup = ccp_sha_finup; alg->finup = ccp_sha_finup;
alg->digest = ccp_sha_digest; alg->digest = ccp_sha_digest;
alg->export = ccp_sha_export;
alg->import = ccp_sha_import;
halg = &alg->halg; halg = &alg->halg;
halg->digestsize = def->digest_size; halg->digestsize = def->digest_size;
halg->statesize = sizeof(struct ccp_sha_req_ctx);
base = &halg->base; base = &halg->base;
snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name); snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment