## Coverage Report

#### Created: 2025-03-01 02:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)

    /libfido2/src/rs1.c

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