Skip to content

Commit ea9e756

Browse files
Dan Douglassherbertx
authored andcommitted
crypto: mxs-dcp - Implement sha import/export
The mxs-dcp driver fails to probe if sha1/sha256 are supported: [ 2.455404] mxs-dcp 80028000.dcp: Failed to register sha1 hash! [ 2.464042] mxs-dcp: probe of 80028000.dcp failed with error -22 This happens because since commit 8996eaf ("crypto: ahash - ensure statesize is non-zero") import/export is mandatory and ahash_prepare_alg fails on statesize == 0. A set of dummy import/export functions were implemented in commit 9190b6f ("crypto: mxs-dcp - Add empty hash export and import") but statesize is still zero and the driver fails to probe. That change was apparently part of some unrelated refactoring. Fix by actually implementing import/export. Signed-off-by: Dan Douglass <dan.douglass@nxp.com> Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 4a34e3c commit ea9e756

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

drivers/crypto/mxs-dcp.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ struct dcp_sha_req_ctx {
9999
unsigned int fini:1;
100100
};
101101

102+
struct dcp_export_state {
103+
struct dcp_sha_req_ctx req_ctx;
104+
struct dcp_async_ctx async_ctx;
105+
};
106+
102107
/*
103108
* There can even be only one instance of the MXS DCP due to the
104109
* design of Linux Crypto API.
@@ -758,14 +763,32 @@ static int dcp_sha_digest(struct ahash_request *req)
758763
return dcp_sha_finup(req);
759764
}
760765

761-
static int dcp_sha_noimport(struct ahash_request *req, const void *in)
766+
static int dcp_sha_import(struct ahash_request *req, const void *in)
762767
{
763-
return -ENOSYS;
768+
struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req);
769+
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
770+
struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm);
771+
const struct dcp_export_state *export = in;
772+
773+
memset(rctx, 0, sizeof(struct dcp_sha_req_ctx));
774+
memset(actx, 0, sizeof(struct dcp_async_ctx));
775+
memcpy(rctx, &export->req_ctx, sizeof(struct dcp_sha_req_ctx));
776+
memcpy(actx, &export->async_ctx, sizeof(struct dcp_async_ctx));
777+
778+
return 0;
764779
}
765780

766-
static int dcp_sha_noexport(struct ahash_request *req, void *out)
781+
static int dcp_sha_export(struct ahash_request *req, void *out)
767782
{
768-
return -ENOSYS;
783+
struct dcp_sha_req_ctx *rctx_state = ahash_request_ctx(req);
784+
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
785+
struct dcp_async_ctx *actx_state = crypto_ahash_ctx(tfm);
786+
struct dcp_export_state *export = out;
787+
788+
memcpy(&export->req_ctx, rctx_state, sizeof(struct dcp_sha_req_ctx));
789+
memcpy(&export->async_ctx, actx_state, sizeof(struct dcp_async_ctx));
790+
791+
return 0;
769792
}
770793

771794
static int dcp_sha_cra_init(struct crypto_tfm *tfm)
@@ -838,10 +861,11 @@ static struct ahash_alg dcp_sha1_alg = {
838861
.final = dcp_sha_final,
839862
.finup = dcp_sha_finup,
840863
.digest = dcp_sha_digest,
841-
.import = dcp_sha_noimport,
842-
.export = dcp_sha_noexport,
864+
.import = dcp_sha_import,
865+
.export = dcp_sha_export,
843866
.halg = {
844867
.digestsize = SHA1_DIGEST_SIZE,
868+
.statesize = sizeof(struct dcp_export_state),
845869
.base = {
846870
.cra_name = "sha1",
847871
.cra_driver_name = "sha1-dcp",
@@ -864,10 +888,11 @@ static struct ahash_alg dcp_sha256_alg = {
864888
.final = dcp_sha_final,
865889
.finup = dcp_sha_finup,
866890
.digest = dcp_sha_digest,
867-
.import = dcp_sha_noimport,
868-
.export = dcp_sha_noexport,
891+
.import = dcp_sha_import,
892+
.export = dcp_sha_export,
869893
.halg = {
870894
.digestsize = SHA256_DIGEST_SIZE,
895+
.statesize = sizeof(struct dcp_export_state),
871896
.base = {
872897
.cra_name = "sha256",
873898
.cra_driver_name = "sha256-dcp",

0 commit comments

Comments
 (0)