2016-05-17 18:24:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 10:52:47 +00:00
|
|
|
*
|
2018-12-06 12:40:06 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 18:24:46 +00:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include <openssl/x509.h>
|
2015-11-30 09:25:36 +00:00
|
|
|
#include "internal/evp_int.h"
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2008-11-12 03:58:08 +00:00
|
|
|
int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
|
2015-01-22 03:40:55 +00:00
|
|
|
unsigned int siglen, EVP_PKEY *pkey)
|
|
|
|
{
|
|
|
|
unsigned char m[EVP_MAX_MD_SIZE];
|
2015-05-06 09:16:55 +00:00
|
|
|
unsigned int m_len = 0;
|
2015-12-02 13:57:04 +00:00
|
|
|
int i = 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
EVP_PKEY_CTX *pkctx = NULL;
|
2006-04-19 17:05:59 +00:00
|
|
|
|
2015-11-27 13:17:50 +00:00
|
|
|
if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_FINALISE)) {
|
2015-01-22 03:40:55 +00:00
|
|
|
if (!EVP_DigestFinal_ex(ctx, m, &m_len))
|
|
|
|
goto err;
|
|
|
|
} else {
|
2015-05-06 09:16:55 +00:00
|
|
|
int rv = 0;
|
2015-12-01 23:49:35 +00:00
|
|
|
EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();
|
2015-11-27 13:17:50 +00:00
|
|
|
if (tmp_ctx == NULL) {
|
|
|
|
EVPerr(EVP_F_EVP_VERIFYFINAL, ERR_R_MALLOC_FAILURE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rv = EVP_MD_CTX_copy_ex(tmp_ctx, ctx);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (rv)
|
2015-11-27 13:17:50 +00:00
|
|
|
rv = EVP_DigestFinal_ex(tmp_ctx, m, &m_len);
|
2015-12-01 23:49:35 +00:00
|
|
|
EVP_MD_CTX_free(tmp_ctx);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (!rv)
|
|
|
|
return 0;
|
|
|
|
}
|
2006-04-19 17:05:59 +00:00
|
|
|
|
2015-12-02 13:57:04 +00:00
|
|
|
i = -1;
|
|
|
|
pkctx = EVP_PKEY_CTX_new(pkey, NULL);
|
|
|
|
if (pkctx == NULL)
|
|
|
|
goto err;
|
|
|
|
if (EVP_PKEY_verify_init(pkctx) <= 0)
|
|
|
|
goto err;
|
2015-11-30 09:25:36 +00:00
|
|
|
if (EVP_PKEY_CTX_set_signature_md(pkctx, EVP_MD_CTX_md(ctx)) <= 0)
|
2015-12-02 13:57:04 +00:00
|
|
|
goto err;
|
|
|
|
i = EVP_PKEY_verify(pkctx, sigbuf, siglen, m, m_len);
|
2015-01-22 03:40:55 +00:00
|
|
|
err:
|
2015-12-02 13:57:04 +00:00
|
|
|
EVP_PKEY_CTX_free(pkctx);
|
|
|
|
return i;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|