aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/asymmetric_keys
diff options
context:
space:
mode:
authorGilad Ben-Yossef <gilad@benyossef.com>2017-10-18 03:00:40 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2017-11-03 10:11:18 -0400
commit0ca2a04ac398a71e49b0b093f365d1188cc13e01 (patch)
treece65b6de53f3b633544eb851768ae6f96ec2b384 /crypto/asymmetric_keys
parent2c3f8b162106a7d12097d02eb22459f57fab8247 (diff)
crypto: move pub key to generic async completion
public_key_verify_signature() is starting an async crypto op and waiting for it to complete. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/asymmetric_keys')
-rw-r--r--crypto/asymmetric_keys/public_key.c28
1 files changed, 4 insertions, 24 deletions
diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index 3cd6e12cfc46..d916235d6cf5 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -57,29 +57,13 @@ static void public_key_destroy(void *payload0, void *payload3)
57 public_key_signature_free(payload3); 57 public_key_signature_free(payload3);
58} 58}
59 59
60struct public_key_completion {
61 struct completion completion;
62 int err;
63};
64
65static void public_key_verify_done(struct crypto_async_request *req, int err)
66{
67 struct public_key_completion *compl = req->data;
68
69 if (err == -EINPROGRESS)
70 return;
71
72 compl->err = err;
73 complete(&compl->completion);
74}
75
76/* 60/*
77 * Verify a signature using a public key. 61 * Verify a signature using a public key.
78 */ 62 */
79int public_key_verify_signature(const struct public_key *pkey, 63int public_key_verify_signature(const struct public_key *pkey,
80 const struct public_key_signature *sig) 64 const struct public_key_signature *sig)
81{ 65{
82 struct public_key_completion compl; 66 struct crypto_wait cwait;
83 struct crypto_akcipher *tfm; 67 struct crypto_akcipher *tfm;
84 struct akcipher_request *req; 68 struct akcipher_request *req;
85 struct scatterlist sig_sg, digest_sg; 69 struct scatterlist sig_sg, digest_sg;
@@ -131,20 +115,16 @@ int public_key_verify_signature(const struct public_key *pkey,
131 sg_init_one(&digest_sg, output, outlen); 115 sg_init_one(&digest_sg, output, outlen);
132 akcipher_request_set_crypt(req, &sig_sg, &digest_sg, sig->s_size, 116 akcipher_request_set_crypt(req, &sig_sg, &digest_sg, sig->s_size,
133 outlen); 117 outlen);
134 init_completion(&compl.completion); 118 crypto_init_wait(&cwait);
135 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG | 119 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG |
136 CRYPTO_TFM_REQ_MAY_SLEEP, 120 CRYPTO_TFM_REQ_MAY_SLEEP,
137 public_key_verify_done, &compl); 121 crypto_req_done, &cwait);
138 122
139 /* Perform the verification calculation. This doesn't actually do the 123 /* Perform the verification calculation. This doesn't actually do the
140 * verification, but rather calculates the hash expected by the 124 * verification, but rather calculates the hash expected by the
141 * signature and returns that to us. 125 * signature and returns that to us.
142 */ 126 */
143 ret = crypto_akcipher_verify(req); 127 ret = crypto_wait_req(crypto_akcipher_verify(req), &cwait);
144 if ((ret == -EINPROGRESS) || (ret == -EBUSY)) {
145 wait_for_completion(&compl.completion);
146 ret = compl.err;
147 }
148 if (ret < 0) 128 if (ret < 0)
149 goto out_free_output; 129 goto out_free_output;
150 130