Skip to content

Commit 952bce9

Browse files
tlendackyherbertx
authored andcommitted
crypto: ccp - Add hash state import and export support
Commit 8996eaf ("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. Cc: <stable@vger.kernel.org> # 3.14.x- Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 624144a commit 952bce9

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

drivers/crypto/ccp/ccp-crypto-aes-cmac.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,26 @@ static int ccp_aes_cmac_digest(struct ahash_request *req)
220220
return ccp_aes_cmac_finup(req);
221221
}
222222

223+
static int ccp_aes_cmac_export(struct ahash_request *req, void *out)
224+
{
225+
struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
226+
struct ccp_aes_cmac_req_ctx *state = out;
227+
228+
*state = *rctx;
229+
230+
return 0;
231+
}
232+
233+
static int ccp_aes_cmac_import(struct ahash_request *req, const void *in)
234+
{
235+
struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
236+
const struct ccp_aes_cmac_req_ctx *state = in;
237+
238+
*rctx = *state;
239+
240+
return 0;
241+
}
242+
223243
static int ccp_aes_cmac_setkey(struct crypto_ahash *tfm, const u8 *key,
224244
unsigned int key_len)
225245
{
@@ -352,10 +372,13 @@ int ccp_register_aes_cmac_algs(struct list_head *head)
352372
alg->final = ccp_aes_cmac_final;
353373
alg->finup = ccp_aes_cmac_finup;
354374
alg->digest = ccp_aes_cmac_digest;
375+
alg->export = ccp_aes_cmac_export;
376+
alg->import = ccp_aes_cmac_import;
355377
alg->setkey = ccp_aes_cmac_setkey;
356378

357379
halg = &alg->halg;
358380
halg->digestsize = AES_BLOCK_SIZE;
381+
halg->statesize = sizeof(struct ccp_aes_cmac_req_ctx);
359382

360383
base = &halg->base;
361384
snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "cmac(aes)");

drivers/crypto/ccp/ccp-crypto-sha.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,26 @@ static int ccp_sha_digest(struct ahash_request *req)
207207
return ccp_sha_finup(req);
208208
}
209209

210+
static int ccp_sha_export(struct ahash_request *req, void *out)
211+
{
212+
struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
213+
struct ccp_sha_req_ctx *state = out;
214+
215+
*state = *rctx;
216+
217+
return 0;
218+
}
219+
220+
static int ccp_sha_import(struct ahash_request *req, const void *in)
221+
{
222+
struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
223+
const struct ccp_sha_req_ctx *state = in;
224+
225+
*rctx = *state;
226+
227+
return 0;
228+
}
229+
210230
static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
211231
unsigned int key_len)
212232
{
@@ -403,9 +423,12 @@ static int ccp_register_sha_alg(struct list_head *head,
403423
alg->final = ccp_sha_final;
404424
alg->finup = ccp_sha_finup;
405425
alg->digest = ccp_sha_digest;
426+
alg->export = ccp_sha_export;
427+
alg->import = ccp_sha_import;
406428

407429
halg = &alg->halg;
408430
halg->digestsize = def->digest_size;
431+
halg->statesize = sizeof(struct ccp_sha_req_ctx);
409432

410433
base = &halg->base;
411434
snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name);

0 commit comments

Comments
 (0)