Skip to content

Commit

Permalink
crypto: sig - Fix verify call
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Herbert Xu committed Jun 27, 2023
1 parent 767cfee commit 891ebfd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 9 additions & 3 deletions crypto/akcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,17 @@ EXPORT_SYMBOL_GPL(akcipher_register_instance);
int crypto_akcipher_sync_prep(struct crypto_akcipher_sync_data *data)
{
unsigned int reqsize = crypto_akcipher_reqsize(data->tfm);
unsigned int mlen = max(data->slen, data->dlen);
struct akcipher_request *req;
struct scatterlist *sg;
unsigned int mlen;
unsigned int len;
u8 *buf;

if (data->dst)
mlen = max(data->slen, data->dlen);
else
mlen = data->slen + data->dlen;

len = sizeof(*req) + reqsize + mlen;
if (len < mlen)
return -EOVERFLOW;
Expand All @@ -213,9 +218,10 @@ int crypto_akcipher_sync_prep(struct crypto_akcipher_sync_data *data)
data->buf = buf;
memcpy(buf, data->src, data->slen);

sg = data->sg;
sg = &data->sg;
sg_init_one(sg, buf, mlen);
akcipher_request_set_crypt(req, sg, sg, data->slen, data->dlen);
akcipher_request_set_crypt(req, sg, data->dst ? sg : NULL,
data->slen, data->dlen);

crypto_init_wait(&data->cwait);
akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP,
Expand Down
2 changes: 1 addition & 1 deletion crypto/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct crypto_akcipher_sync_data {

struct akcipher_request *req;
struct crypto_wait cwait;
struct scatterlist sg[2];
struct scatterlist sg;
u8 *buf;
};

Expand Down
4 changes: 1 addition & 3 deletions crypto/sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ int crypto_sig_verify(struct crypto_sig *tfm,
if (err)
return err;

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

return crypto_akcipher_sync_post(&data,
crypto_akcipher_verify(data.req));
Expand Down

0 comments on commit 891ebfd

Please sign in to comment.