]>
Commit | Line | Data |
---|---|---|
5a212462 | 1 | /* |
4333b89f | 2 | * Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved. |
5a212462 | 3 | * |
48f4ad77 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5a212462 NT |
5 | * this file except in compliance with the License. You can obtain a copy |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
8 | */ | |
9 | ||
10 | /* Internal EC functions for other submodules: not for application use */ | |
11 | ||
ae4186b0 DMSP |
12 | #ifndef OSSL_CRYPTO_EC_H |
13 | # define OSSL_CRYPTO_EC_H | |
80ce21fe F |
14 | # pragma once |
15 | ||
5a212462 | 16 | # include <openssl/opensslconf.h> |
565b3399 RL |
17 | # include <openssl/evp.h> |
18 | ||
32ab57cb SL |
19 | int ossl_ec_curve_name2nid(const char *name); |
20 | const char *ossl_ec_curve_nid2nist_int(int nid); | |
21 | int ossl_ec_curve_nist2nid_int(const char *name); | |
565b3399 | 22 | int evp_pkey_ctx_set_ec_param_enc_prov(EVP_PKEY_CTX *ctx, int param_enc); |
5a212462 NT |
23 | |
24 | # ifndef OPENSSL_NO_EC | |
0abae163 | 25 | # include <openssl/core.h> |
5a212462 | 26 | # include <openssl/ec.h> |
5b5eea4b | 27 | # include "crypto/types.h" |
5a212462 NT |
28 | |
29 | /*- | |
30 | * Computes the multiplicative inverse of x in the range | |
31 | * [1,EC_GROUP::order), where EC_GROUP::order is the cardinality of the | |
32 | * subgroup generated by the generator G: | |
33 | * | |
34 | * res := x^(-1) (mod EC_GROUP::order). | |
35 | * | |
36 | * This function expects the following two conditions to hold: | |
37 | * - the EC_GROUP order is prime, and | |
38 | * - x is included in the range [1, EC_GROUP::order). | |
39 | * | |
40 | * This function returns 1 on success, 0 on error. | |
41 | * | |
42 | * If the EC_GROUP order is even, this function explicitly returns 0 as | |
43 | * an error. | |
44 | * In case any of the two conditions stated above is not satisfied, | |
45 | * the correctness of its output is not guaranteed, even if the return | |
46 | * value could still be 1 (as primality testing and a conditional modular | |
47 | * reduction round on the input can be omitted by the underlying | |
48 | * implementations for better SCA properties on regular input values). | |
49 | */ | |
32ab57cb SL |
50 | __owur int ossl_ec_group_do_inverse_ord(const EC_GROUP *group, BIGNUM *res, |
51 | const BIGNUM *x, BN_CTX *ctx); | |
5a212462 | 52 | |
ffd89124 AS |
53 | /*- |
54 | * ECDH Key Derivation Function as defined in ANSI X9.63 | |
55 | */ | |
32ab57cb SL |
56 | int ossl_ecdh_kdf_X9_63(unsigned char *out, size_t outlen, |
57 | const unsigned char *Z, size_t Zlen, | |
58 | const unsigned char *sinfo, size_t sinfolen, | |
59 | const EVP_MD *md, OSSL_LIB_CTX *libctx, | |
60 | const char *propq); | |
ffd89124 | 61 | |
32ab57cb SL |
62 | int ossl_ec_key_public_check(const EC_KEY *eckey, BN_CTX *ctx); |
63 | int ossl_ec_key_public_check_quick(const EC_KEY *eckey, BN_CTX *ctx); | |
64 | int ossl_ec_key_private_check(const EC_KEY *eckey); | |
65 | int ossl_ec_key_pairwise_check(const EC_KEY *eckey, BN_CTX *ctx); | |
66 | OSSL_LIB_CTX *ossl_ec_key_get_libctx(const EC_KEY *eckey); | |
67 | const char *ossl_ec_key_get0_propq(const EC_KEY *eckey); | |
68 | void ossl_ec_key_set0_libctx(EC_KEY *key, OSSL_LIB_CTX *libctx); | |
0abae163 RL |
69 | |
70 | /* Backend support */ | |
32ab57cb SL |
71 | int ossl_ec_group_todata(const EC_GROUP *group, OSSL_PARAM_BLD *tmpl, |
72 | OSSL_PARAM params[], OSSL_LIB_CTX *libctx, | |
73 | const char *propq, | |
74 | BN_CTX *bnctx, unsigned char **genbuf); | |
75 | int ossl_ec_group_fromdata(EC_KEY *ec, const OSSL_PARAM params[]); | |
76 | int ossl_ec_group_set_params(EC_GROUP *group, const OSSL_PARAM params[]); | |
77 | int ossl_ec_key_fromdata(EC_KEY *ecx, const OSSL_PARAM params[], | |
78 | int include_private); | |
79 | int ossl_ec_key_otherparams_fromdata(EC_KEY *ec, const OSSL_PARAM params[]); | |
b247113c | 80 | int ossl_ec_key_is_foreign(const EC_KEY *ec); |
b4f447c0 | 81 | EC_KEY *ossl_ec_key_dup(const EC_KEY *key, int selection); |
8c7c1c84 | 82 | int ossl_x509_algor_is_sm2(const X509_ALGOR *palg); |
cf333799 RL |
83 | EC_KEY *ossl_ec_key_param_from_x509_algor(const X509_ALGOR *palg, |
84 | OSSL_LIB_CTX *libctx, | |
85 | const char *propq); | |
86 | EC_KEY *ossl_ec_key_from_pkcs8(const PKCS8_PRIV_KEY_INFO *p8inf, | |
87 | OSSL_LIB_CTX *libctx, const char *propq); | |
88 | ||
32ab57cb SL |
89 | int ossl_ec_set_ecdh_cofactor_mode(EC_KEY *ec, int mode); |
90 | int ossl_ec_encoding_name2id(const char *name); | |
91 | int ossl_ec_encoding_param2id(const OSSL_PARAM *p, int *id); | |
92 | int ossl_ec_pt_format_name2id(const char *name); | |
93 | int ossl_ec_pt_format_param2id(const OSSL_PARAM *p, int *id); | |
94 | char *ossl_ec_pt_format_id2name(int id); | |
5b5eea4b | 95 | |
32ab57cb SL |
96 | char *ossl_ec_check_group_type_id2name(int flags); |
97 | int ossl_ec_set_check_group_type_from_name(EC_KEY *ec, const char *name); | |
0abae163 | 98 | |
5a212462 NT |
99 | # endif /* OPENSSL_NO_EC */ |
100 | #endif |