## Coverage Report

#### Created: 2023-09-23 17:42

    /libfido2/src/es256.c

    Line
    Count
    Source (jump to first uncovered line)
    1
    /*
    2
     * Copyright (c) 2018-2022 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/bn.h>
    9
    #include <openssl/ecdsa.h>
    10
    #include <openssl/obj_mac.h>
    11
    12
    #include "fido.h"
    13
    #include "fido/es256.h"
    14
    15
    #if OPENSSL_VERSION_NUMBER >= 0x30000000
    16
    30
    #define get0_EC_KEY(x)  EVP_PKEY_get0_EC_KEY((x))
    17
    #else
    18
    #define get0_EC_KEY(x)  EVP_PKEY_get0((x))
    19
    #endif
    20
    21
    static const int es256_nid = NID_X9_62_prime256v1;
    22
    23
    static int
    24
    decode_coord(const cbor_item_t *item, void *xy, size_t xy_len)
    25
    9.66k
    {
    26
    9.66k
            if (cbor_isa_bytestring(item) == false ||
    27
    9.66k
                cbor_bytestring_is_definite(item) == false ||
    28
    9.66k
                cbor_bytestring_length(item) != xy_len) {
    29
    101
                    fido_log_debug("%s: cbor type", __func__);
    30
    101
                    return (-1);
    31
    101
            }
    32
    33
    9.56k
            memcpy(xy, cbor_bytestring_handle(item), xy_len);
    34
    35
    9.56k
            return (0);
    36
    9.66k
    }
    37
    38
    static int
    39
    decode_pubkey_point(const cbor_item_t *key, const cbor_item_t *val, void *arg)
    40
    24.8k
    {
    41
    24.8k
            es256_pk_t *k = arg;
    42
    43
    24.8k
            if (cbor_isa_negint(key) == false ||
    44
    24.8k
                cbor_int_get_width(key) != CBOR_INT_8)
    45
    12.5k
                    return (0); /* ignore */
    46
    47
    12.3k
            switch (cbor_get_uint8(key)) {
    48
    4.93k
            case 1: /* x coordinate */
    49
    4.93k
                    return (decode_coord(val, &k->x, sizeof(k->x)));
    50
    4.73k
            case 2: /* y coordinate */
    51
    4.73k
                    return (decode_coord(val, &k->y, sizeof(k->y)));
    52
    12.3k
            }
    53
    54
    2.64k
            return (0); /* ignore */
    55
    12.3k
    }
    56
    57
    int
    58
    es256_pk_decode(const cbor_item_t *item, es256_pk_t *k)
    59
    5.04k
    {
    60
    5.04k
            if (cbor_isa_map(item) == false ||
    61
    5.04k
                cbor_map_is_definite(item) == false ||
    62
    5.04k
                cbor_map_iter(item, k, decode_pubkey_point) < 0) {
    63
    173
                    fido_log_debug("%s: cbor type", __func__);
    64
    173
                    return (-1);
    65
    173
            }
    66
    67
    4.86k
            return (0);
    68
    5.04k
    }
    69
    70
    cbor_item_t *
    71
    es256_pk_encode(const es256_pk_t *pk, int ecdh)
    72
    3.08k
    {
    73
    3.08k
            cbor_item_t             *item = NULL;
    74
    3.08k
            struct cbor_pair         argv[5];
    75
    3.08k
            int                      alg;
    76
    3.08k
            int                      ok = -1;
    77
    78
    3.08k
            memset(argv, 0, sizeof(argv));
    79
    80
    3.08k
            if ((item = cbor_new_definite_map(5)) == NULL)
    81
    13
                    goto fail;
    82
    83
            /* kty */
    84
    3.07k
            if ((argv[0].key = cbor_build_uint8(1)) == NULL ||
    85
    3.07k
                (argv[0].value = cbor_build_uint8(2)) == NULL ||
    86
    3.07k
                !cbor_map_add(item, argv[0]))
    87
    42
                    goto fail;
    88
    89
            /*
    90
             * "The COSEAlgorithmIdentifier used is -25 (ECDH-ES +
    91
             * HKDF-256) although this is NOT the algorithm actually
    92
             * used. Setting this to a different value may result in
    93
             * compatibility issues."
    94
             */
    95
    3.03k
            if (ecdh)
    96
    2.97k
                    alg = COSE_ECDH_ES256;
    97
    61
            else
    98
    61
                    alg = COSE_ES256;
    99
    100
            /* alg */
    101
    3.03k
            if ((argv[1].key = cbor_build_uint8(3)) == NULL ||
    102
    3.03k
                (argv[1].value = cbor_build_negint8((uint8_t)(-alg - 1))) == NULL ||
    103
    3.03k
                !cbor_map_add(item, argv[1]))
    104
    44
                    goto fail;
    105
    106
            /* crv */
    107
    2.98k
            if ((argv[2].key = cbor_build_negint8(0)) == NULL ||
    108
    2.98k
                (argv[2].value = cbor_build_uint8(1)) == NULL ||
    109
    2.98k
                !cbor_map_add(item, argv[2]))
    110
    51
                    goto fail;
    111
    112
            /* x */
    113
    2.93k
            if ((argv[3].key = cbor_build_negint8(1)) == NULL ||
    114
    2.93k
                (argv[3].value = cbor_build_bytestring(pk->x,
    115
    2.92k
                sizeof(pk->x))) == NULL || !cbor_map_add(item, argv[3]))
    116
    46
                    goto fail;
    117
    118
            /* y */
    119
    2.89k
            if ((argv[4].key = cbor_build_negint8(2)) == NULL ||
    120
    2.89k
                (argv[4].value = cbor_build_bytestring(pk->y,
    121
    2.88k
                sizeof(pk->y))) == NULL || !cbor_map_add(item, argv[4]))
    122
    45
                    goto fail;
    123
    124
    2.84k
            ok = 0;
    125
    3.08k
    fail:
    126
    3.08k
            if (ok < 0) {
    127
    241
                    if (item != NULL) {
    128
    228
                            cbor_decref(&item);
    129
    228
                            item = NULL;
    130
    228
                    }
    131
    241
            }
    132
    133
    18.5k
            for (size_t i = 0; i < 5; i++) {
    134
    15.4k
                    if (argv[i].key)
    135
    14.8k
                            cbor_decref(&argv[i].key);
    136
    15.4k
                    if (argv[i].value)
    137
    14.7k
                            cbor_decref(&argv[i].value);
    138
    15.4k
            }
    139
    140
    3.08k
            return (item);
    141
    2.84k
    }
    142
    143
    es256_sk_t *
    144
    es256_sk_new(void)
    145
    7.21k
    {
    146
    7.21k
            return (calloc(1, sizeof(es256_sk_t)));
    147
    7.21k
    }
    148
    149
    void
    150
    es256_sk_free(es256_sk_t **skp)
    151
    7.21k
    {
    152
    7.21k
            es256_sk_t *sk;
    153
    154
    7.21k
            if (skp == NULL || (sk = *skp) == NULL)
    155
    31
                    return;
    156
    157
    7.18k
            freezero(sk, sizeof(*sk));
    158
    7.18k
            *skp = NULL;
    159
    7.18k
    }
    160
    161
    es256_pk_t *
    162
    es256_pk_new(void)
    163
    14.2k
    {
    164
    14.2k
            return (calloc(1, sizeof(es256_pk_t)));
    165
    14.2k
    }
    166
    167
    void
    168
    es256_pk_free(es256_pk_t **pkp)
    169
    28.8k
    {
    170
    28.8k
            es256_pk_t *pk;
    171
    172
    28.8k
            if (pkp == NULL || (pk = *pkp) == NULL)
    173
    14.6k
                    return;
    174
    175
    14.1k
            freezero(pk, sizeof(*pk));
    176
    14.1k
            *pkp = NULL;
    177
    14.1k
    }
    178
    179
    int
    180
    es256_pk_from_ptr(es256_pk_t *pk, const void *ptr, size_t len)
    181
    521
    {
    182
    521
            const uint8_t   *p = ptr;
    183
    521
            EVP_PKEY        *pkey;
    184
    185
    521
            if (len < sizeof(*pk))
    186
    416
                    return (FIDO_ERR_INVALID_ARGUMENT);
    187
    188
    105
            if (len == sizeof(*pk) + 1 && *p == 0x04)
    189
    2
                    memcpy(pk, ++p, sizeof(*pk)); /* uncompressed format */
    190
    103
            else
    191
    103
                    memcpy(pk, ptr, sizeof(*pk)); /* libfido2 x||y format */
    192
    193
    105
            if ((pkey = es256_pk_to_EVP_PKEY(pk)) == NULL) {
    194
    73
                    fido_log_debug("%s: es256_pk_to_EVP_PKEY", __func__);
    195
    73
                    explicit_bzero(pk, sizeof(*pk));
    196
    73
                    return (FIDO_ERR_INVALID_ARGUMENT);
    197
    73
            }
    198
    199
    32
            EVP_PKEY_free(pkey);
    200
    201
    32
            return (FIDO_OK);
    202
    105
    }
    203
    204
    int
    205
    es256_pk_set_x(es256_pk_t *pk, const unsigned char *x)
    206
    61
    {
    207
    61
            memcpy(pk->x, x, sizeof(pk->x));
    208
    209
    61
            return (0);
    210
    61
    }
    211
    212
    int
    213
    es256_pk_set_y(es256_pk_t *pk, const unsigned char *y)
    214
    61
    {
    215
    61
            memcpy(pk->y, y, sizeof(pk->y));
    216
    217
    61
            return (0);
    218
    61
    }
    219
    220
    int
    221
    es256_sk_create(es256_sk_t *key)
    222
    7.15k
    {
    223
    7.15k
            EVP_PKEY_CTX    *pctx = NULL;
    224
    7.15k
            EVP_PKEY_CTX    *kctx = NULL;
    225
    7.15k
            EVP_PKEY        *p = NULL;
    226
    7.15k
            EVP_PKEY        *k = NULL;
    227
    7.15k
            const EC_KEY    *ec;
    228
    7.15k
            const BIGNUM    *d;
    229
    7.15k
            int              n;
    230
    7.15k
            int              ok = -1;
    231
    232
    7.15k
            if ((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) == NULL ||
    233
    7.15k
                EVP_PKEY_paramgen_init(pctx) <= 0 ||
    234
    7.15k
                EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, es256_nid) <= 0 ||
    235
    7.15k
                EVP_PKEY_paramgen(pctx, &p) <= 0) {
    236
    102
                    fido_log_debug("%s: EVP_PKEY_paramgen", __func__);
    237
    102
                    goto fail;
    238
    102
            }
    239
    240
    7.05k
            if ((kctx = EVP_PKEY_CTX_new(p, NULL)) == NULL ||
    241
    7.05k
                EVP_PKEY_keygen_init(kctx) <= 0 || EVP_PKEY_keygen(kctx, &k) <= 0) {
    242
    101
                    fido_log_debug("%s: EVP_PKEY_keygen", __func__);
    243
    101
                    goto fail;
    244
    101
            }
    245
    246
    6.95k
            if ((ec = EVP_PKEY_get0_EC_KEY(k)) == NULL ||
    247
    6.95k
                (d = EC_KEY_get0_private_key(ec)) == NULL ||
    248
    6.95k
                (n = BN_num_bytes(d)) < 0 || (size_t)n > sizeof(key->d) ||
    249
    6.95k
                (n = BN_bn2bin(d, key->d)) < 0 || (size_t)n > sizeof(key->d)) {
    250
    118
                    fido_log_debug("%s: EC_KEY_get0_private_key", __func__);
    251
    118
                    goto fail;
    252
    118
            }
    253
    254
    6.83k
            ok = 0;
    255
    7.15k
    fail:
    256
    7.15k
            if (p != NULL)
    257
    7.05k
                    EVP_PKEY_free(p);
    258
    7.15k
            if (k != NULL)
    259
    6.95k
                    EVP_PKEY_free(k);
    260
    7.15k
            if (pctx != NULL)
    261
    7.11k
                    EVP_PKEY_CTX_free(pctx);
    262
    7.15k
            if (kctx != NULL)
    263
    7.01k
                    EVP_PKEY_CTX_free(kctx);
    264
    265
    7.15k
            return (ok);
    266
    6.83k
    }
    267
    268
    EVP_PKEY *
    269
    es256_pk_to_EVP_PKEY(const es256_pk_t *k)
    270
    4.60k
    {
    271
    4.60k
            BN_CTX          *bnctx = NULL;
    272
    4.60k
            EC_KEY          *ec = NULL;
    273
    4.60k
            EC_POINT        *q = NULL;
    274
    4.60k
            EVP_PKEY        *pkey = NULL;
    275
    4.60k
            BIGNUM          *x = NULL;
    276
    4.60k
            BIGNUM          *y = NULL;
    277
    4.60k
            const EC_GROUP  *g = NULL;
    278
    4.60k
            int              ok = -1;
    279
    280
    4.60k
            if ((bnctx = BN_CTX_new()) == NULL)
    281
    23
                    goto fail;
    282
    283
    4.58k
            BN_CTX_start(bnctx);
    284
    285
    4.58k
            if ((x = BN_CTX_get(bnctx)) == NULL ||
    286
    4.58k
                (y = BN_CTX_get(bnctx)) == NULL)
    287
    46
                    goto fail;
    288
    289
    4.53k
            if (BN_bin2bn(k->x, sizeof(k->x), x) == NULL ||
    290
    4.53k
                BN_bin2bn(k->y, sizeof(k->y), y) == NULL) {
    291
    64
                    fido_log_debug("%s: BN_bin2bn", __func__);
    292
    64
                    goto fail;
    293
    64
            }
    294
    295
    4.47k
            if ((ec = EC_KEY_new_by_curve_name(es256_nid)) == NULL ||
    296
    4.47k
                (g = EC_KEY_get0_group(ec)) == NULL) {
    297
    43
                    fido_log_debug("%s: EC_KEY init", __func__);
    298
    43
                    goto fail;
    299
    43
            }
    300
    301
    4.42k
            if ((q = EC_POINT_new(g)) == NULL ||
    302
    4.42k
                EC_POINT_set_affine_coordinates_GFp(g, q, x, y, bnctx) == 0 ||
    303
    4.42k
                EC_KEY_set_public_key(ec, q) == 0) {
    304
    660
                    fido_log_debug("%s: EC_KEY_set_public_key", __func__);
    305
    660
                    goto fail;
    306
    660
            }
    307
    308
    3.76k
            if ((pkey = EVP_PKEY_new()) == NULL ||
    309
    3.76k
                EVP_PKEY_assign_EC_KEY(pkey, ec) == 0) {
    310
    37
                    fido_log_debug("%s: EVP_PKEY_assign_EC_KEY", __func__);
    311
    37
                    goto fail;
    312
    37
            }
    313
    314
    3.73k
            ec = NULL; /* at this point, ec belongs to evp */
    315
    316
    3.73k
            ok = 0;
    317
    4.60k
    fail:
    318
    4.60k
            if (bnctx != NULL) {
    319
    4.58k
                    BN_CTX_end(bnctx);
    320
    4.58k
                    BN_CTX_free(bnctx);
    321
    4.58k
            }
    322
    323
    4.60k
            if (ec != NULL)
    324
    714
                    EC_KEY_free(ec);
    325
    4.60k
            if (q != NULL)
    326
    4.40k
                    EC_POINT_free(q);
    327
    328
    4.60k
            if (ok < 0 && pkey != NULL) {
    329
    25
                    EVP_PKEY_free(pkey);
    330
    25
                    pkey = NULL;
    331
    25
            }
    332
    333
    4.60k
            return (pkey);
    334
    3.73k
    }
    335
    336
    int
    337
    es256_pk_from_EC_KEY(es256_pk_t *pk, const EC_KEY *ec)
    338
    6.70k
    {
    339
    6.70k
            BN_CTX          *bnctx = NULL;
    340
    6.70k
            BIGNUM          *x = NULL;
    341
    6.70k
            BIGNUM          *y = NULL;
    342
    6.70k
            const EC_POINT  *q = NULL;
    343
    6.70k
            EC_GROUP        *g = NULL;
    344
    6.70k
            size_t           dx;
    345
    6.70k
            size_t           dy;
    346
    6.70k
            int              ok = FIDO_ERR_INTERNAL;
    347
    6.70k
            int              nx;
    348
    6.70k
            int              ny;
    349
    350
    6.70k
            if ((q = EC_KEY_get0_public_key(ec)) == NULL ||
    351
    6.70k
                (g = EC_GROUP_new_by_curve_name(es256_nid)) == NULL ||
    352
    6.70k
                (bnctx = BN_CTX_new()) == NULL)
    353
    46
                    goto fail;
    354
    355
    6.66k
            BN_CTX_start(bnctx);
    356
    357
    6.66k
            if ((x = BN_CTX_get(bnctx)) == NULL ||
    358
    6.66k
                (y = BN_CTX_get(bnctx)) == NULL)
    359
    74
                    goto fail;
    360
    361
    6.58k
            if (EC_POINT_is_on_curve(g, q, bnctx) != 1) {
    362
    0
                    fido_log_debug("%s: EC_POINT_is_on_curve", __func__);
    363
    0
                    ok = FIDO_ERR_INVALID_ARGUMENT;
    364
    0
                    goto fail;
    365
    0
            }
    366
    367
    6.58k
            if (EC_POINT_get_affine_coordinates_GFp(g, q, x, y, bnctx) == 0 ||
    368
    6.58k
                (nx = BN_num_bytes(x)) < 0 || (size_t)nx > sizeof(pk->x) ||
    369
    6.58k
                (ny = BN_num_bytes(y)) < 0 || (size_t)ny > sizeof(pk->y)) {
    370
    34
                    fido_log_debug("%s: EC_POINT_get_affine_coordinates_GFp",
    371
    34
                        __func__);
    372
    34
                    goto fail;
    373
    34
            }
    374
    375
    6.55k
            dx = sizeof(pk->x) - (size_t)nx;
    376
    6.55k
            dy = sizeof(pk->y) - (size_t)ny;
    377
    378
    6.55k
            if ((nx = BN_bn2bin(x, pk->x + dx)) < 0 || (size_t)nx > sizeof(pk->x) ||
    379
    6.55k
                (ny = BN_bn2bin(y, pk->y + dy)) < 0 || (size_t)ny > sizeof(pk->y)) {
    380
    80
                    fido_log_debug("%s: BN_bn2bin", __func__);
    381
    80
                    goto fail;
    382
    80
            }
    383
    384
    6.47k
            ok = FIDO_OK;
    385
    6.70k
    fail:
    386
    6.70k
            EC_GROUP_free(g);
    387
    388
    6.70k
            if (bnctx != NULL) {
    389
    6.66k
                    BN_CTX_end(bnctx);
    390
    6.66k
                    BN_CTX_free(bnctx);
    391
    6.66k
            }
    392
    393
    6.70k
            return (ok);
    394
    6.47k
    }
    395
    396
    int
    397
    es256_pk_from_EVP_PKEY(es256_pk_t *pk, const EVP_PKEY *pkey)
    398
    30
    {
    399
    30
            const EC_KEY *ec;
    400
    401
    30
            if (EVP_PKEY_base_id(pkey) != EVP_PKEY_EC ||
    402
    30
                (ec = get0_EC_KEY(pkey)) == NULL)
    403
    3
                    return (FIDO_ERR_INVALID_ARGUMENT);
    404
    405
    27
            return (es256_pk_from_EC_KEY(pk, ec));
    406
    30
    }
    407
    408
    EVP_PKEY *
    409
    es256_sk_to_EVP_PKEY(const es256_sk_t *k)
    410
    3.64k
    {
    411
    3.64k
            BN_CTX          *bnctx = NULL;
    412
    3.64k
            EC_KEY          *ec = NULL;
    413
    3.64k
            EVP_PKEY        *pkey = NULL;
    414
    3.64k
            BIGNUM          *d = NULL;
    415
    3.64k
            int              ok = -1;
    416
    417
    3.64k
            if ((bnctx = BN_CTX_new()) == NULL)
    418
    12
                    goto fail;
    419
    420
    3.63k
            BN_CTX_start(bnctx);
    421
    422
    3.63k
            if ((d = BN_CTX_get(bnctx)) == NULL ||
    423
    3.63k
                BN_bin2bn(k->d, sizeof(k->d), d) == NULL) {
    424
    30
                    fido_log_debug("%s: BN_bin2bn", __func__);
    425
    30
                    goto fail;
    426
    30
            }
    427
    428
    3.60k
            if ((ec = EC_KEY_new_by_curve_name(es256_nid)) == NULL ||
    429
    3.60k
                EC_KEY_set_private_key(ec, d) == 0) {
    430
    16
                    fido_log_debug("%s: EC_KEY_set_private_key", __func__);
    431
    16
                    goto fail;
    432
    16
            }
    433
    434
    3.58k
            if ((pkey = EVP_PKEY_new()) == NULL ||
    435
    3.58k
                EVP_PKEY_assign_EC_KEY(pkey, ec) == 0) {
    436
    33
                    fido_log_debug("%s: EVP_PKEY_assign_EC_KEY", __func__);
    437
    33
                    goto fail;
    438
    33
            }
    439
    440
    3.55k
            ec = NULL; /* at this point, ec belongs to evp */
    441
    442
    3.55k
            ok = 0;
    443
    3.64k
    fail:
    444
    3.64k
            if (bnctx != NULL) {
    445
    3.63k
                    BN_CTX_end(bnctx);
    446
    3.63k
                    BN_CTX_free(bnctx);
    447
    3.63k
            }
    448
    449
    3.64k
            if (ec != NULL)
    450
    33
                    EC_KEY_free(ec);
    451
    452
    3.64k
            if (ok < 0 && pkey != NULL) {
    453
    19
                    EVP_PKEY_free(pkey);
    454
    19
                    pkey = NULL;
    455
    19
            }
    456
    457
    3.64k
            return (pkey);
    458
    3.55k
    }
    459
    460
    int
    461
    es256_derive_pk(const es256_sk_t *sk, es256_pk_t *pk)
    462
    6.83k
    {
    463
    6.83k
            BIGNUM          *d = NULL;
    464
    6.83k
            EC_KEY          *ec = NULL;
    465
    6.83k
            EC_POINT        *q = NULL;
    466
    6.83k
            const EC_GROUP  *g = NULL;
    467
    6.83k
            int              ok = -1;
    468
    469
    6.83k
            if ((d = BN_bin2bn(sk->d, (int)sizeof(sk->d), NULL)) == NULL ||
    470
    6.83k
                (ec = EC_KEY_new_by_curve_name(es256_nid)) == NULL ||
    471
    6.83k
                (g = EC_KEY_get0_group(ec)) == NULL ||
    472
    6.83k
                (q = EC_POINT_new(g)) == NULL) {
    473
    151
                    fido_log_debug("%s: get", __func__);
    474
    151
                    goto fail;
    475
    151
            }
    476
    477
    6.68k
            if (EC_POINT_mul(g, q, d, NULL, NULL, NULL) == 0 ||
    478
    6.68k
                EC_KEY_set_public_key(ec, q) == 0 ||
    479
    6.68k
                es256_pk_from_EC_KEY(pk, ec) != FIDO_OK) {
    480
    226
                    fido_log_debug("%s: set", __func__);
    481
    226
                    goto fail;
    482
    226
            }
    483
    484
    6.45k
            ok = 0;
    485
    6.83k
    fail:
    486
    6.83k
            if (d != NULL)
    487
    6.79k
                    BN_clear_free(d);
    488
    6.83k
            if (q != NULL)
    489
    6.68k
                    EC_POINT_free(q);
    490
    6.83k
            if (ec != NULL)
    491
    6.75k
                    EC_KEY_free(ec);
    492
    493
    6.83k
            return (ok);
    494
    6.45k
    }
    495
    496
    int
    497
    es256_verify_sig(const fido_blob_t *dgst, EVP_PKEY *pkey,
    498
        const fido_blob_t *sig)
    499
    44
    {
    500
    44
            EVP_PKEY_CTX    *pctx = NULL;
    501
    44
            int              ok = -1;
    502
    503
    44
            if (EVP_PKEY_base_id(pkey) != EVP_PKEY_EC) {
    504
    0
                    fido_log_debug("%s: EVP_PKEY_base_id", __func__);
    505
    0
                    goto fail;
    506
    0
            }
    507
    508
    44
            if ((pctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL ||
    509
    44
                EVP_PKEY_verify_init(pctx) != 1 ||
    510
    44
                EVP_PKEY_verify(pctx, sig->ptr, sig->len, dgst->ptr,
    511
    44
                dgst->len) != 1) {
    512
    44
                    fido_log_debug("%s: EVP_PKEY_verify", __func__);
    513
    44
                    goto fail;
    514
    44
            }
    515
    516
    0
            ok = 0;
    517
    44
    fail:
    518
    44
            EVP_PKEY_CTX_free(pctx);
    519
    520
    44
            return (ok);
    521
    0
    }
    522
    523
    int
    524
    es256_pk_verify_sig(const fido_blob_t *dgst, const es256_pk_t *pk,
    525
        const fido_blob_t *sig)
    526
    58
    {
    527
    58
            EVP_PKEY        *pkey;
    528
    58
            int              ok = -1;
    529
    530
    58
            if ((pkey = es256_pk_to_EVP_PKEY(pk)) == NULL ||
    531
    58
                es256_verify_sig(dgst, pkey, sig) < 0) {
    532
    58
                    fido_log_debug("%s: es256_verify_sig", __func__);
    533
    58
                    goto fail;
    534
    58
            }
    535
    536
    0
            ok = 0;
    537
    58
    fail:
    538
    58
            EVP_PKEY_free(pkey);
    539
    540
    58
            return (ok);
    541
    0
    }