1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* Copyright (c) 2021 Yubico AB. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <openssl/rsa.h>
#include <openssl/obj_mac.h>
#include "fido.h"
#if defined(__GNUC__)
#define PRAGMA(s) _Pragma(s)
#else
#define PRAGMA(s)
#endif
static EVP_MD *
rs1_get_EVP_MD(void)
{
PRAGMA("GCC diagnostic push")
PRAGMA("GCC diagnostic ignored \"-Wcast-qual\"")
return ((EVP_MD *)EVP_sha1());
PRAGMA("GCC diagnostic pop")
}
int
rs1_verify_sig(const fido_blob_t *dgst, EVP_PKEY *pkey,
const fido_blob_t *sig)
{
EVP_PKEY_CTX *pctx = NULL;
EVP_MD *md = NULL;
int ok = -1;
if (EVP_PKEY_base_id(pkey) != EVP_PKEY_RSA) {
fido_log_debug("%s: EVP_PKEY_base_id", __func__);
goto fail;
}
if ((md = rs1_get_EVP_MD()) == NULL) {
fido_log_debug("%s: rs1_get_EVP_MD", __func__);
goto fail;
}
if ((pctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL ||
EVP_PKEY_verify_init(pctx) != 1 ||
EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PADDING) != 1 ||
EVP_PKEY_CTX_set_signature_md(pctx, md) != 1) {
fido_log_debug("%s: EVP_PKEY_CTX", __func__);
goto fail;
}
if (EVP_PKEY_verify(pctx, sig->ptr, sig->len, dgst->ptr,
dgst->len) != 1) {
fido_log_debug("%s: EVP_PKEY_verify", __func__);
goto fail;
}
ok = 0;
fail:
EVP_PKEY_CTX_free(pctx);
return (ok);
}
|