11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
51cb0ef41Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at
71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html
81cb0ef41Sopenharmony_ci */
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci/*
111cb0ef41Sopenharmony_ci * ECDH and ECDSA low level APIs are deprecated for public use, but still ok
121cb0ef41Sopenharmony_ci * for internal use.
131cb0ef41Sopenharmony_ci */
141cb0ef41Sopenharmony_ci#include "internal/deprecated.h"
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci#include <string.h>
171cb0ef41Sopenharmony_ci#include <openssl/ec.h>
181cb0ef41Sopenharmony_ci#ifndef FIPS_MODULE
191cb0ef41Sopenharmony_ci# include <openssl/engine.h>
201cb0ef41Sopenharmony_ci#endif
211cb0ef41Sopenharmony_ci#include <openssl/err.h>
221cb0ef41Sopenharmony_ci#include "ec_local.h"
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_cistatic const EC_KEY_METHOD openssl_ec_key_method = {
261cb0ef41Sopenharmony_ci    "OpenSSL EC_KEY method",
271cb0ef41Sopenharmony_ci    0,
281cb0ef41Sopenharmony_ci    0,0,0,0,0,0,
291cb0ef41Sopenharmony_ci    ossl_ec_key_gen,
301cb0ef41Sopenharmony_ci    ossl_ecdh_compute_key,
311cb0ef41Sopenharmony_ci    ossl_ecdsa_sign,
321cb0ef41Sopenharmony_ci    ossl_ecdsa_sign_setup,
331cb0ef41Sopenharmony_ci    ossl_ecdsa_sign_sig,
341cb0ef41Sopenharmony_ci    ossl_ecdsa_verify,
351cb0ef41Sopenharmony_ci    ossl_ecdsa_verify_sig
361cb0ef41Sopenharmony_ci};
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_cistatic const EC_KEY_METHOD *default_ec_key_meth = &openssl_ec_key_method;
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ciconst EC_KEY_METHOD *EC_KEY_OpenSSL(void)
411cb0ef41Sopenharmony_ci{
421cb0ef41Sopenharmony_ci    return &openssl_ec_key_method;
431cb0ef41Sopenharmony_ci}
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciconst EC_KEY_METHOD *EC_KEY_get_default_method(void)
461cb0ef41Sopenharmony_ci{
471cb0ef41Sopenharmony_ci    return default_ec_key_meth;
481cb0ef41Sopenharmony_ci}
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_civoid EC_KEY_set_default_method(const EC_KEY_METHOD *meth)
511cb0ef41Sopenharmony_ci{
521cb0ef41Sopenharmony_ci    if (meth == NULL)
531cb0ef41Sopenharmony_ci        default_ec_key_meth = &openssl_ec_key_method;
541cb0ef41Sopenharmony_ci    else
551cb0ef41Sopenharmony_ci        default_ec_key_meth = meth;
561cb0ef41Sopenharmony_ci}
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ciconst EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key)
591cb0ef41Sopenharmony_ci{
601cb0ef41Sopenharmony_ci    return key->meth;
611cb0ef41Sopenharmony_ci}
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ciint EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth)
641cb0ef41Sopenharmony_ci{
651cb0ef41Sopenharmony_ci    void (*finish)(EC_KEY *key) = key->meth->finish;
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci    if (finish != NULL)
681cb0ef41Sopenharmony_ci        finish(key);
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE)
711cb0ef41Sopenharmony_ci    ENGINE_finish(key->engine);
721cb0ef41Sopenharmony_ci    key->engine = NULL;
731cb0ef41Sopenharmony_ci#endif
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci    key->meth = meth;
761cb0ef41Sopenharmony_ci    if (meth->init != NULL)
771cb0ef41Sopenharmony_ci        return meth->init(key);
781cb0ef41Sopenharmony_ci    return 1;
791cb0ef41Sopenharmony_ci}
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ciEC_KEY *ossl_ec_key_new_method_int(OSSL_LIB_CTX *libctx, const char *propq,
821cb0ef41Sopenharmony_ci                                   ENGINE *engine)
831cb0ef41Sopenharmony_ci{
841cb0ef41Sopenharmony_ci    EC_KEY *ret = OPENSSL_zalloc(sizeof(*ret));
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ci    if (ret == NULL) {
871cb0ef41Sopenharmony_ci        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
881cb0ef41Sopenharmony_ci        return NULL;
891cb0ef41Sopenharmony_ci    }
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci    ret->libctx = libctx;
921cb0ef41Sopenharmony_ci    if (propq != NULL) {
931cb0ef41Sopenharmony_ci        ret->propq = OPENSSL_strdup(propq);
941cb0ef41Sopenharmony_ci        if (ret->propq == NULL) {
951cb0ef41Sopenharmony_ci            ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
961cb0ef41Sopenharmony_ci            goto err;
971cb0ef41Sopenharmony_ci        }
981cb0ef41Sopenharmony_ci    }
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci    ret->references = 1;
1011cb0ef41Sopenharmony_ci    ret->lock = CRYPTO_THREAD_lock_new();
1021cb0ef41Sopenharmony_ci    if (ret->lock == NULL) {
1031cb0ef41Sopenharmony_ci        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
1041cb0ef41Sopenharmony_ci        goto err;
1051cb0ef41Sopenharmony_ci    }
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ci    ret->meth = EC_KEY_get_default_method();
1081cb0ef41Sopenharmony_ci#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE)
1091cb0ef41Sopenharmony_ci    if (engine != NULL) {
1101cb0ef41Sopenharmony_ci        if (!ENGINE_init(engine)) {
1111cb0ef41Sopenharmony_ci            ERR_raise(ERR_LIB_EC, ERR_R_ENGINE_LIB);
1121cb0ef41Sopenharmony_ci            goto err;
1131cb0ef41Sopenharmony_ci        }
1141cb0ef41Sopenharmony_ci        ret->engine = engine;
1151cb0ef41Sopenharmony_ci    } else
1161cb0ef41Sopenharmony_ci        ret->engine = ENGINE_get_default_EC();
1171cb0ef41Sopenharmony_ci    if (ret->engine != NULL) {
1181cb0ef41Sopenharmony_ci        ret->meth = ENGINE_get_EC(ret->engine);
1191cb0ef41Sopenharmony_ci        if (ret->meth == NULL) {
1201cb0ef41Sopenharmony_ci            ERR_raise(ERR_LIB_EC, ERR_R_ENGINE_LIB);
1211cb0ef41Sopenharmony_ci            goto err;
1221cb0ef41Sopenharmony_ci        }
1231cb0ef41Sopenharmony_ci    }
1241cb0ef41Sopenharmony_ci#endif
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci    ret->version = 1;
1271cb0ef41Sopenharmony_ci    ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci/* No ex_data inside the FIPS provider */
1301cb0ef41Sopenharmony_ci#ifndef FIPS_MODULE
1311cb0ef41Sopenharmony_ci    if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) {
1321cb0ef41Sopenharmony_ci        goto err;
1331cb0ef41Sopenharmony_ci    }
1341cb0ef41Sopenharmony_ci#endif
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ci    if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {
1371cb0ef41Sopenharmony_ci        ERR_raise(ERR_LIB_EC, ERR_R_INIT_FAIL);
1381cb0ef41Sopenharmony_ci        goto err;
1391cb0ef41Sopenharmony_ci    }
1401cb0ef41Sopenharmony_ci    return ret;
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ci err:
1431cb0ef41Sopenharmony_ci    EC_KEY_free(ret);
1441cb0ef41Sopenharmony_ci    return NULL;
1451cb0ef41Sopenharmony_ci}
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ci#ifndef FIPS_MODULE
1481cb0ef41Sopenharmony_ciEC_KEY *EC_KEY_new_method(ENGINE *engine)
1491cb0ef41Sopenharmony_ci{
1501cb0ef41Sopenharmony_ci    return ossl_ec_key_new_method_int(NULL, NULL, engine);
1511cb0ef41Sopenharmony_ci}
1521cb0ef41Sopenharmony_ci#endif
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ciint ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
1551cb0ef41Sopenharmony_ci                     const EC_KEY *eckey,
1561cb0ef41Sopenharmony_ci                     void *(*KDF) (const void *in, size_t inlen, void *out,
1571cb0ef41Sopenharmony_ci                                   size_t *outlen))
1581cb0ef41Sopenharmony_ci{
1591cb0ef41Sopenharmony_ci    unsigned char *sec = NULL;
1601cb0ef41Sopenharmony_ci    size_t seclen;
1611cb0ef41Sopenharmony_ci    if (eckey->meth->compute_key == NULL) {
1621cb0ef41Sopenharmony_ci        ERR_raise(ERR_LIB_EC, EC_R_OPERATION_NOT_SUPPORTED);
1631cb0ef41Sopenharmony_ci        return 0;
1641cb0ef41Sopenharmony_ci    }
1651cb0ef41Sopenharmony_ci    if (outlen > INT_MAX) {
1661cb0ef41Sopenharmony_ci        ERR_raise(ERR_LIB_EC, EC_R_INVALID_OUTPUT_LENGTH);
1671cb0ef41Sopenharmony_ci        return 0;
1681cb0ef41Sopenharmony_ci    }
1691cb0ef41Sopenharmony_ci    if (!eckey->meth->compute_key(&sec, &seclen, pub_key, eckey))
1701cb0ef41Sopenharmony_ci        return 0;
1711cb0ef41Sopenharmony_ci    if (KDF != NULL) {
1721cb0ef41Sopenharmony_ci        KDF(sec, seclen, out, &outlen);
1731cb0ef41Sopenharmony_ci    } else {
1741cb0ef41Sopenharmony_ci        if (outlen > seclen)
1751cb0ef41Sopenharmony_ci            outlen = seclen;
1761cb0ef41Sopenharmony_ci        memcpy(out, sec, outlen);
1771cb0ef41Sopenharmony_ci    }
1781cb0ef41Sopenharmony_ci    OPENSSL_clear_free(sec, seclen);
1791cb0ef41Sopenharmony_ci    return outlen;
1801cb0ef41Sopenharmony_ci}
1811cb0ef41Sopenharmony_ci
1821cb0ef41Sopenharmony_ciEC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth)
1831cb0ef41Sopenharmony_ci{
1841cb0ef41Sopenharmony_ci    EC_KEY_METHOD *ret = OPENSSL_zalloc(sizeof(*meth));
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ci    if (ret == NULL)
1871cb0ef41Sopenharmony_ci        return NULL;
1881cb0ef41Sopenharmony_ci    if (meth != NULL)
1891cb0ef41Sopenharmony_ci        *ret = *meth;
1901cb0ef41Sopenharmony_ci    ret->flags |= EC_KEY_METHOD_DYNAMIC;
1911cb0ef41Sopenharmony_ci    return ret;
1921cb0ef41Sopenharmony_ci}
1931cb0ef41Sopenharmony_ci
1941cb0ef41Sopenharmony_civoid EC_KEY_METHOD_free(EC_KEY_METHOD *meth)
1951cb0ef41Sopenharmony_ci{
1961cb0ef41Sopenharmony_ci    if (meth->flags & EC_KEY_METHOD_DYNAMIC)
1971cb0ef41Sopenharmony_ci        OPENSSL_free(meth);
1981cb0ef41Sopenharmony_ci}
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_civoid EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth,
2011cb0ef41Sopenharmony_ci                            int (*init)(EC_KEY *key),
2021cb0ef41Sopenharmony_ci                            void (*finish)(EC_KEY *key),
2031cb0ef41Sopenharmony_ci                            int (*copy)(EC_KEY *dest, const EC_KEY *src),
2041cb0ef41Sopenharmony_ci                            int (*set_group)(EC_KEY *key, const EC_GROUP *grp),
2051cb0ef41Sopenharmony_ci                            int (*set_private)(EC_KEY *key,
2061cb0ef41Sopenharmony_ci                                               const BIGNUM *priv_key),
2071cb0ef41Sopenharmony_ci                            int (*set_public)(EC_KEY *key,
2081cb0ef41Sopenharmony_ci                                              const EC_POINT *pub_key))
2091cb0ef41Sopenharmony_ci{
2101cb0ef41Sopenharmony_ci    meth->init = init;
2111cb0ef41Sopenharmony_ci    meth->finish = finish;
2121cb0ef41Sopenharmony_ci    meth->copy = copy;
2131cb0ef41Sopenharmony_ci    meth->set_group = set_group;
2141cb0ef41Sopenharmony_ci    meth->set_private = set_private;
2151cb0ef41Sopenharmony_ci    meth->set_public = set_public;
2161cb0ef41Sopenharmony_ci}
2171cb0ef41Sopenharmony_ci
2181cb0ef41Sopenharmony_civoid EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth,
2191cb0ef41Sopenharmony_ci                              int (*keygen)(EC_KEY *key))
2201cb0ef41Sopenharmony_ci{
2211cb0ef41Sopenharmony_ci    meth->keygen = keygen;
2221cb0ef41Sopenharmony_ci}
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_civoid EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth,
2251cb0ef41Sopenharmony_ci                                   int (*ckey)(unsigned char **psec,
2261cb0ef41Sopenharmony_ci                                               size_t *pseclen,
2271cb0ef41Sopenharmony_ci                                               const EC_POINT *pub_key,
2281cb0ef41Sopenharmony_ci                                               const EC_KEY *ecdh))
2291cb0ef41Sopenharmony_ci{
2301cb0ef41Sopenharmony_ci    meth->compute_key = ckey;
2311cb0ef41Sopenharmony_ci}
2321cb0ef41Sopenharmony_ci
2331cb0ef41Sopenharmony_civoid EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth,
2341cb0ef41Sopenharmony_ci                            int (*sign)(int type, const unsigned char *dgst,
2351cb0ef41Sopenharmony_ci                                        int dlen, unsigned char *sig,
2361cb0ef41Sopenharmony_ci                                        unsigned int *siglen,
2371cb0ef41Sopenharmony_ci                                        const BIGNUM *kinv, const BIGNUM *r,
2381cb0ef41Sopenharmony_ci                                        EC_KEY *eckey),
2391cb0ef41Sopenharmony_ci                            int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
2401cb0ef41Sopenharmony_ci                                              BIGNUM **kinvp, BIGNUM **rp),
2411cb0ef41Sopenharmony_ci                            ECDSA_SIG *(*sign_sig)(const unsigned char *dgst,
2421cb0ef41Sopenharmony_ci                                                   int dgst_len,
2431cb0ef41Sopenharmony_ci                                                   const BIGNUM *in_kinv,
2441cb0ef41Sopenharmony_ci                                                   const BIGNUM *in_r,
2451cb0ef41Sopenharmony_ci                                                   EC_KEY *eckey))
2461cb0ef41Sopenharmony_ci{
2471cb0ef41Sopenharmony_ci    meth->sign = sign;
2481cb0ef41Sopenharmony_ci    meth->sign_setup = sign_setup;
2491cb0ef41Sopenharmony_ci    meth->sign_sig = sign_sig;
2501cb0ef41Sopenharmony_ci}
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_civoid EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth,
2531cb0ef41Sopenharmony_ci                              int (*verify)(int type, const unsigned
2541cb0ef41Sopenharmony_ci                                            char *dgst, int dgst_len,
2551cb0ef41Sopenharmony_ci                                            const unsigned char *sigbuf,
2561cb0ef41Sopenharmony_ci                                            int sig_len, EC_KEY *eckey),
2571cb0ef41Sopenharmony_ci                              int (*verify_sig)(const unsigned char *dgst,
2581cb0ef41Sopenharmony_ci                                                int dgst_len,
2591cb0ef41Sopenharmony_ci                                                const ECDSA_SIG *sig,
2601cb0ef41Sopenharmony_ci                                                EC_KEY *eckey))
2611cb0ef41Sopenharmony_ci{
2621cb0ef41Sopenharmony_ci    meth->verify = verify;
2631cb0ef41Sopenharmony_ci    meth->verify_sig = verify_sig;
2641cb0ef41Sopenharmony_ci}
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_civoid EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth,
2671cb0ef41Sopenharmony_ci                            int (**pinit)(EC_KEY *key),
2681cb0ef41Sopenharmony_ci                            void (**pfinish)(EC_KEY *key),
2691cb0ef41Sopenharmony_ci                            int (**pcopy)(EC_KEY *dest, const EC_KEY *src),
2701cb0ef41Sopenharmony_ci                            int (**pset_group)(EC_KEY *key,
2711cb0ef41Sopenharmony_ci                                               const EC_GROUP *grp),
2721cb0ef41Sopenharmony_ci                            int (**pset_private)(EC_KEY *key,
2731cb0ef41Sopenharmony_ci                                                 const BIGNUM *priv_key),
2741cb0ef41Sopenharmony_ci                            int (**pset_public)(EC_KEY *key,
2751cb0ef41Sopenharmony_ci                                                const EC_POINT *pub_key))
2761cb0ef41Sopenharmony_ci{
2771cb0ef41Sopenharmony_ci    if (pinit != NULL)
2781cb0ef41Sopenharmony_ci        *pinit = meth->init;
2791cb0ef41Sopenharmony_ci    if (pfinish != NULL)
2801cb0ef41Sopenharmony_ci        *pfinish = meth->finish;
2811cb0ef41Sopenharmony_ci    if (pcopy != NULL)
2821cb0ef41Sopenharmony_ci        *pcopy = meth->copy;
2831cb0ef41Sopenharmony_ci    if (pset_group != NULL)
2841cb0ef41Sopenharmony_ci        *pset_group = meth->set_group;
2851cb0ef41Sopenharmony_ci    if (pset_private != NULL)
2861cb0ef41Sopenharmony_ci        *pset_private = meth->set_private;
2871cb0ef41Sopenharmony_ci    if (pset_public != NULL)
2881cb0ef41Sopenharmony_ci        *pset_public = meth->set_public;
2891cb0ef41Sopenharmony_ci}
2901cb0ef41Sopenharmony_ci
2911cb0ef41Sopenharmony_civoid EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth,
2921cb0ef41Sopenharmony_ci                              int (**pkeygen)(EC_KEY *key))
2931cb0ef41Sopenharmony_ci{
2941cb0ef41Sopenharmony_ci    if (pkeygen != NULL)
2951cb0ef41Sopenharmony_ci        *pkeygen = meth->keygen;
2961cb0ef41Sopenharmony_ci}
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_civoid EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth,
2991cb0ef41Sopenharmony_ci                                   int (**pck)(unsigned char **pout,
3001cb0ef41Sopenharmony_ci                                               size_t *poutlen,
3011cb0ef41Sopenharmony_ci                                               const EC_POINT *pub_key,
3021cb0ef41Sopenharmony_ci                                               const EC_KEY *ecdh))
3031cb0ef41Sopenharmony_ci{
3041cb0ef41Sopenharmony_ci    if (pck != NULL)
3051cb0ef41Sopenharmony_ci        *pck = meth->compute_key;
3061cb0ef41Sopenharmony_ci}
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_civoid EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth,
3091cb0ef41Sopenharmony_ci                            int (**psign)(int type, const unsigned char *dgst,
3101cb0ef41Sopenharmony_ci                                          int dlen, unsigned char *sig,
3111cb0ef41Sopenharmony_ci                                          unsigned int *siglen,
3121cb0ef41Sopenharmony_ci                                          const BIGNUM *kinv, const BIGNUM *r,
3131cb0ef41Sopenharmony_ci                                          EC_KEY *eckey),
3141cb0ef41Sopenharmony_ci                            int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
3151cb0ef41Sopenharmony_ci                                                BIGNUM **kinvp, BIGNUM **rp),
3161cb0ef41Sopenharmony_ci                            ECDSA_SIG *(**psign_sig)(const unsigned char *dgst,
3171cb0ef41Sopenharmony_ci                                                     int dgst_len,
3181cb0ef41Sopenharmony_ci                                                     const BIGNUM *in_kinv,
3191cb0ef41Sopenharmony_ci                                                     const BIGNUM *in_r,
3201cb0ef41Sopenharmony_ci                                                     EC_KEY *eckey))
3211cb0ef41Sopenharmony_ci{
3221cb0ef41Sopenharmony_ci    if (psign != NULL)
3231cb0ef41Sopenharmony_ci        *psign = meth->sign;
3241cb0ef41Sopenharmony_ci    if (psign_setup != NULL)
3251cb0ef41Sopenharmony_ci        *psign_setup = meth->sign_setup;
3261cb0ef41Sopenharmony_ci    if (psign_sig != NULL)
3271cb0ef41Sopenharmony_ci        *psign_sig = meth->sign_sig;
3281cb0ef41Sopenharmony_ci}
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_civoid EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth,
3311cb0ef41Sopenharmony_ci                              int (**pverify)(int type, const unsigned
3321cb0ef41Sopenharmony_ci                                              char *dgst, int dgst_len,
3331cb0ef41Sopenharmony_ci                                              const unsigned char *sigbuf,
3341cb0ef41Sopenharmony_ci                                              int sig_len, EC_KEY *eckey),
3351cb0ef41Sopenharmony_ci                              int (**pverify_sig)(const unsigned char *dgst,
3361cb0ef41Sopenharmony_ci                                                  int dgst_len,
3371cb0ef41Sopenharmony_ci                                                  const ECDSA_SIG *sig,
3381cb0ef41Sopenharmony_ci                                                  EC_KEY *eckey))
3391cb0ef41Sopenharmony_ci{
3401cb0ef41Sopenharmony_ci    if (pverify != NULL)
3411cb0ef41Sopenharmony_ci        *pverify = meth->verify;
3421cb0ef41Sopenharmony_ci    if (pverify_sig != NULL)
3431cb0ef41Sopenharmony_ci        *pverify_sig = meth->verify_sig;
3441cb0ef41Sopenharmony_ci}
345