Skip to content

Commit 891ebfd

Browse files
committed
crypto: sig - Fix verify call
The dst SG list needs to be set to NULL for verify calls. Do this as otherwise the underlying algorithm may fail. Furthermore the digest needs to be copied just like the source. Fixes: 6cb8815 ("crypto: sig - Add interface for sign/verify") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 767cfee commit 891ebfd

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

crypto/akcipher.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,17 @@ EXPORT_SYMBOL_GPL(akcipher_register_instance);
192192
int crypto_akcipher_sync_prep(struct crypto_akcipher_sync_data *data)
193193
{
194194
unsigned int reqsize = crypto_akcipher_reqsize(data->tfm);
195-
unsigned int mlen = max(data->slen, data->dlen);
196195
struct akcipher_request *req;
197196
struct scatterlist *sg;
197+
unsigned int mlen;
198198
unsigned int len;
199199
u8 *buf;
200200

201+
if (data->dst)
202+
mlen = max(data->slen, data->dlen);
203+
else
204+
mlen = data->slen + data->dlen;
205+
201206
len = sizeof(*req) + reqsize + mlen;
202207
if (len < mlen)
203208
return -EOVERFLOW;
@@ -213,9 +218,10 @@ int crypto_akcipher_sync_prep(struct crypto_akcipher_sync_data *data)
213218
data->buf = buf;
214219
memcpy(buf, data->src, data->slen);
215220

216-
sg = data->sg;
221+
sg = &data->sg;
217222
sg_init_one(sg, buf, mlen);
218-
akcipher_request_set_crypt(req, sg, sg, data->slen, data->dlen);
223+
akcipher_request_set_crypt(req, sg, data->dst ? sg : NULL,
224+
data->slen, data->dlen);
219225

220226
crypto_init_wait(&data->cwait);
221227
akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP,

crypto/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct crypto_akcipher_sync_data {
4444

4545
struct akcipher_request *req;
4646
struct crypto_wait cwait;
47-
struct scatterlist sg[2];
47+
struct scatterlist sg;
4848
u8 *buf;
4949
};
5050

crypto/sig.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ int crypto_sig_verify(struct crypto_sig *tfm,
128128
if (err)
129129
return err;
130130

131-
sg_init_table(data.sg, 2);
132-
sg_set_buf(&data.sg[0], src, slen);
133-
sg_set_buf(&data.sg[1], digest, dlen);
131+
memcpy(data.buf + slen, digest, dlen);
134132

135133
return crypto_akcipher_sync_post(&data,
136134
crypto_akcipher_verify(data.req));

0 commit comments

Comments
 (0)