aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Douglass <dan.douglass@nxp.com>2018-10-02 15:01:48 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2018-10-08 01:45:41 -0400
commitea9e7568f7a7f0a6695e046316132afe382969a8 (patch)
tree29f9cc64d2d9ca7778ea7bf712b66f9b08bf48d2
parent4a34e3c2f2f48f47213702a84a123af0fe21ad60 (diff)
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 8996eafdcbad ("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 9190b6fd5db9 ("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>
-rw-r--r--drivers/crypto/mxs-dcp.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 430174be6f92..6bcd9157a02f 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -99,6 +99,11 @@ struct dcp_sha_req_ctx {
99 unsigned int fini:1; 99 unsigned int fini:1;
100}; 100};
101 101
102struct dcp_export_state {
103 struct dcp_sha_req_ctx req_ctx;
104 struct dcp_async_ctx async_ctx;
105};
106
102/* 107/*
103 * There can even be only one instance of the MXS DCP due to the 108 * There can even be only one instance of the MXS DCP due to the
104 * design of Linux Crypto API. 109 * design of Linux Crypto API.
@@ -758,14 +763,32 @@ static int dcp_sha_digest(struct ahash_request *req)
758 return dcp_sha_finup(req); 763 return dcp_sha_finup(req);
759} 764}
760 765
761static int dcp_sha_noimport(struct ahash_request *req, const void *in) 766static int dcp_sha_import(struct ahash_request *req, const void *in)
762{ 767{
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;
764} 779}
765 780
766static int dcp_sha_noexport(struct ahash_request *req, void *out) 781static int dcp_sha_export(struct ahash_request *req, void *out)
767{ 782{
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;
769} 792}
770 793
771static int dcp_sha_cra_init(struct crypto_tfm *tfm) 794static int dcp_sha_cra_init(struct crypto_tfm *tfm)
@@ -838,10 +861,11 @@ static struct ahash_alg dcp_sha1_alg = {
838 .final = dcp_sha_final, 861 .final = dcp_sha_final,
839 .finup = dcp_sha_finup, 862 .finup = dcp_sha_finup,
840 .digest = dcp_sha_digest, 863 .digest = dcp_sha_digest,
841 .import = dcp_sha_noimport, 864 .import = dcp_sha_import,
842 .export = dcp_sha_noexport, 865 .export = dcp_sha_export,
843 .halg = { 866 .halg = {
844 .digestsize = SHA1_DIGEST_SIZE, 867 .digestsize = SHA1_DIGEST_SIZE,
868 .statesize = sizeof(struct dcp_export_state),
845 .base = { 869 .base = {
846 .cra_name = "sha1", 870 .cra_name = "sha1",
847 .cra_driver_name = "sha1-dcp", 871 .cra_driver_name = "sha1-dcp",
@@ -864,10 +888,11 @@ static struct ahash_alg dcp_sha256_alg = {
864 .final = dcp_sha_final, 888 .final = dcp_sha_final,
865 .finup = dcp_sha_finup, 889 .finup = dcp_sha_finup,
866 .digest = dcp_sha_digest, 890 .digest = dcp_sha_digest,
867 .import = dcp_sha_noimport, 891 .import = dcp_sha_import,
868 .export = dcp_sha_noexport, 892 .export = dcp_sha_export,
869 .halg = { 893 .halg = {
870 .digestsize = SHA256_DIGEST_SIZE, 894 .digestsize = SHA256_DIGEST_SIZE,
895 .statesize = sizeof(struct dcp_export_state),
871 .base = { 896 .base = {
872 .cra_name = "sha256", 897 .cra_name = "sha256",
873 .cra_driver_name = "sha256-dcp", 898 .cra_driver_name = "sha256-dcp",