diff options
author | Vitaly Chikunov <vt@altlinux.org> | 2019-04-11 11:51:15 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2019-04-18 10:15:02 -0400 |
commit | c7381b01287240abe942a081729203e26782d981 (patch) | |
tree | f70bd59c5b8b110b9116d1660d5fe03033ed3596 /crypto/rsa-pkcs1pad.c | |
parent | 3ecc97259934489e7e03cbeb1d70f6a23cccb3ae (diff) |
crypto: akcipher - new verify API for public key algorithms
Previous akcipher .verify() just `decrypts' (using RSA encrypt which is
using public key) signature to uncover message hash, which was then
compared in upper level public_key_verify_signature() with the expected
hash value, which itself was never passed into verify().
This approach was incompatible with EC-DSA family of algorithms,
because, to verify a signature EC-DSA algorithm also needs a hash value
as input; then it's used (together with a signature divided into halves
`r||s') to produce a witness value, which is then compared with `r' to
determine if the signature is correct. Thus, for EC-DSA, nor
requirements of .verify() itself, nor its output expectations in
public_key_verify_signature() wasn't sufficient.
Make improved .verify() call which gets hash value as input and produce
complete signature check without any output besides status.
Now for the top level verification only crypto_akcipher_verify() needs
to be called and its return value inspected.
Make sure that `digest' is in kmalloc'd memory (in place of `output`) in
{public,tpm}_key_verify_signature() as insisted by Herbert Xu, and will
be changed in the following commit.
Cc: David Howells <dhowells@redhat.com>
Cc: keyrings@vger.kernel.org
Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
Reviewed-by: Denis Kenzior <denkenz@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/rsa-pkcs1pad.c')
-rw-r--r-- | crypto/rsa-pkcs1pad.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index 94382fa2c6ac..29c336068dc0 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c | |||
@@ -488,14 +488,21 @@ static int pkcs1pad_verify_complete(struct akcipher_request *req, int err) | |||
488 | 488 | ||
489 | err = 0; | 489 | err = 0; |
490 | 490 | ||
491 | if (req->dst_len < dst_len - pos) | 491 | if (req->dst_len != dst_len - pos) { |
492 | err = -EOVERFLOW; | 492 | err = -EKEYREJECTED; |
493 | req->dst_len = dst_len - pos; | 493 | req->dst_len = dst_len - pos; |
494 | 494 | goto done; | |
495 | if (!err) | 495 | } |
496 | sg_copy_from_buffer(req->dst, | 496 | /* Extract appended digest. */ |
497 | sg_nents_for_len(req->dst, req->dst_len), | 497 | sg_pcopy_to_buffer(req->src, |
498 | out_buf + pos, req->dst_len); | 498 | sg_nents_for_len(req->src, |
499 | req->src_len + req->dst_len), | ||
500 | req_ctx->out_buf + ctx->key_size, | ||
501 | req->dst_len, ctx->key_size); | ||
502 | /* Do the actual verification step. */ | ||
503 | if (memcmp(req_ctx->out_buf + ctx->key_size, out_buf + pos, | ||
504 | req->dst_len) != 0) | ||
505 | err = -EKEYREJECTED; | ||
499 | done: | 506 | done: |
500 | kzfree(req_ctx->out_buf); | 507 | kzfree(req_ctx->out_buf); |
501 | 508 | ||
@@ -532,10 +539,12 @@ static int pkcs1pad_verify(struct akcipher_request *req) | |||
532 | struct pkcs1pad_request *req_ctx = akcipher_request_ctx(req); | 539 | struct pkcs1pad_request *req_ctx = akcipher_request_ctx(req); |
533 | int err; | 540 | int err; |
534 | 541 | ||
535 | if (!ctx->key_size || req->src_len < ctx->key_size) | 542 | if (WARN_ON(req->dst) || |
543 | WARN_ON(!req->dst_len) || | ||
544 | !ctx->key_size || req->src_len < ctx->key_size) | ||
536 | return -EINVAL; | 545 | return -EINVAL; |
537 | 546 | ||
538 | req_ctx->out_buf = kmalloc(ctx->key_size, GFP_KERNEL); | 547 | req_ctx->out_buf = kmalloc(ctx->key_size + req->dst_len, GFP_KERNEL); |
539 | if (!req_ctx->out_buf) | 548 | if (!req_ctx->out_buf) |
540 | return -ENOMEM; | 549 | return -ENOMEM; |
541 | 550 | ||