diff options
Diffstat (limited to 'src/lib/libcrypto/ec/ec_kmeth.c')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_kmeth.c | 328 |
1 files changed, 0 insertions, 328 deletions
diff --git a/src/lib/libcrypto/ec/ec_kmeth.c b/src/lib/libcrypto/ec/ec_kmeth.c deleted file mode 100644 index 43661f2c13..0000000000 --- a/src/lib/libcrypto/ec/ec_kmeth.c +++ /dev/null | |||
| @@ -1,328 +0,0 @@ | |||
| 1 | /* $OpenBSD: ec_kmeth.c,v 1.16 2024/11/16 10:32:08 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 4 | * project. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 2015 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * licensing@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | */ | ||
| 54 | |||
| 55 | #include <openssl/ec.h> | ||
| 56 | #include <openssl/err.h> | ||
| 57 | |||
| 58 | #include "bn_local.h" | ||
| 59 | #include "ec_local.h" | ||
| 60 | #include "ecdsa_local.h" | ||
| 61 | |||
| 62 | const EC_KEY_METHOD * | ||
| 63 | EC_KEY_get_method(const EC_KEY *key) | ||
| 64 | { | ||
| 65 | return key->meth; | ||
| 66 | } | ||
| 67 | LCRYPTO_ALIAS(EC_KEY_get_method); | ||
| 68 | |||
| 69 | int | ||
| 70 | EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth) | ||
| 71 | { | ||
| 72 | void (*finish)(EC_KEY *key) = key->meth->finish; | ||
| 73 | |||
| 74 | if (finish != NULL) | ||
| 75 | finish(key); | ||
| 76 | |||
| 77 | key->meth = meth; | ||
| 78 | if (meth->init != NULL) | ||
| 79 | return meth->init(key); | ||
| 80 | return 1; | ||
| 81 | } | ||
| 82 | LCRYPTO_ALIAS(EC_KEY_set_method); | ||
| 83 | |||
| 84 | EC_KEY * | ||
| 85 | EC_KEY_new_method(ENGINE *engine) | ||
| 86 | { | ||
| 87 | EC_KEY *ret; | ||
| 88 | |||
| 89 | if ((ret = calloc(1, sizeof(EC_KEY))) == NULL) { | ||
| 90 | ECerror(ERR_R_MALLOC_FAILURE); | ||
| 91 | return NULL; | ||
| 92 | } | ||
| 93 | ret->meth = EC_KEY_get_default_method(); | ||
| 94 | ret->version = 1; | ||
| 95 | ret->flags = 0; | ||
| 96 | ret->group = NULL; | ||
| 97 | ret->pub_key = NULL; | ||
| 98 | ret->priv_key = NULL; | ||
| 99 | ret->enc_flag = 0; | ||
| 100 | ret->conv_form = POINT_CONVERSION_UNCOMPRESSED; | ||
| 101 | ret->references = 1; | ||
| 102 | |||
| 103 | if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) | ||
| 104 | goto err; | ||
| 105 | if (ret->meth->init != NULL && ret->meth->init(ret) == 0) | ||
| 106 | goto err; | ||
| 107 | |||
| 108 | return ret; | ||
| 109 | |||
| 110 | err: | ||
| 111 | EC_KEY_free(ret); | ||
| 112 | return NULL; | ||
| 113 | } | ||
| 114 | LCRYPTO_ALIAS(EC_KEY_new_method); | ||
| 115 | |||
| 116 | EC_KEY_METHOD * | ||
| 117 | EC_KEY_METHOD_new(const EC_KEY_METHOD *meth) | ||
| 118 | { | ||
| 119 | EC_KEY_METHOD *ret; | ||
| 120 | |||
| 121 | if ((ret = calloc(1, sizeof(*meth))) == NULL) | ||
| 122 | return NULL; | ||
| 123 | if (meth != NULL) | ||
| 124 | *ret = *meth; | ||
| 125 | ret->flags |= EC_KEY_METHOD_DYNAMIC; | ||
| 126 | return ret; | ||
| 127 | } | ||
| 128 | LCRYPTO_ALIAS(EC_KEY_METHOD_new); | ||
| 129 | |||
| 130 | void | ||
| 131 | EC_KEY_METHOD_free(EC_KEY_METHOD *meth) | ||
| 132 | { | ||
| 133 | if (meth == NULL) | ||
| 134 | return; | ||
| 135 | if (meth->flags & EC_KEY_METHOD_DYNAMIC) | ||
| 136 | free(meth); | ||
| 137 | } | ||
| 138 | LCRYPTO_ALIAS(EC_KEY_METHOD_free); | ||
| 139 | |||
| 140 | void | ||
| 141 | EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth, | ||
| 142 | int (*init)(EC_KEY *key), | ||
| 143 | void (*finish)(EC_KEY *key), | ||
| 144 | int (*copy)(EC_KEY *dest, const EC_KEY *src), | ||
| 145 | int (*set_group)(EC_KEY *key, const EC_GROUP *grp), | ||
| 146 | int (*set_private)(EC_KEY *key, const BIGNUM *priv_key), | ||
| 147 | int (*set_public)(EC_KEY *key, const EC_POINT *pub_key)) | ||
| 148 | { | ||
| 149 | meth->init = init; | ||
| 150 | meth->finish = finish; | ||
| 151 | meth->copy = copy; | ||
| 152 | meth->set_group = set_group; | ||
| 153 | meth->set_private = set_private; | ||
| 154 | meth->set_public = set_public; | ||
| 155 | } | ||
| 156 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_init); | ||
| 157 | |||
| 158 | void | ||
| 159 | EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth, int (*keygen)(EC_KEY *key)) | ||
| 160 | { | ||
| 161 | meth->keygen = keygen; | ||
| 162 | } | ||
| 163 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_keygen); | ||
| 164 | |||
| 165 | void | ||
| 166 | EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth, | ||
| 167 | int (*ckey)(unsigned char **out, size_t *out_len, const EC_POINT *pub_key, | ||
| 168 | const EC_KEY *ecdh)) | ||
| 169 | { | ||
| 170 | meth->compute_key = ckey; | ||
| 171 | } | ||
| 172 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_compute_key); | ||
| 173 | |||
| 174 | void | ||
| 175 | EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth, | ||
| 176 | int (*sign)(int type, const unsigned char *dgst, | ||
| 177 | int dlen, unsigned char *sig, unsigned int *siglen, | ||
| 178 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey), | ||
| 179 | int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | ||
| 180 | BIGNUM **kinvp, BIGNUM **rp), | ||
| 181 | ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, | ||
| 182 | int dgst_len, const BIGNUM *in_kinv, | ||
| 183 | const BIGNUM *in_r, EC_KEY *eckey)) | ||
| 184 | { | ||
| 185 | meth->sign = sign; | ||
| 186 | meth->sign_setup = sign_setup; | ||
| 187 | meth->sign_sig = sign_sig; | ||
| 188 | } | ||
| 189 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_sign); | ||
| 190 | |||
| 191 | void | ||
| 192 | EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth, | ||
| 193 | int (*verify)(int type, const unsigned char *dgst, int dgst_len, | ||
| 194 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey), | ||
| 195 | int (*verify_sig)(const unsigned char *dgst, int dgst_len, | ||
| 196 | const ECDSA_SIG *sig, EC_KEY *eckey)) | ||
| 197 | { | ||
| 198 | meth->verify = verify; | ||
| 199 | meth->verify_sig = verify_sig; | ||
| 200 | } | ||
| 201 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_verify); | ||
| 202 | |||
| 203 | |||
| 204 | void | ||
| 205 | EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth, | ||
| 206 | int (**pinit)(EC_KEY *key), | ||
| 207 | void (**pfinish)(EC_KEY *key), | ||
| 208 | int (**pcopy)(EC_KEY *dest, const EC_KEY *src), | ||
| 209 | int (**pset_group)(EC_KEY *key, const EC_GROUP *grp), | ||
| 210 | int (**pset_private)(EC_KEY *key, const BIGNUM *priv_key), | ||
| 211 | int (**pset_public)(EC_KEY *key, const EC_POINT *pub_key)) | ||
| 212 | { | ||
| 213 | if (pinit != NULL) | ||
| 214 | *pinit = meth->init; | ||
| 215 | if (pfinish != NULL) | ||
| 216 | *pfinish = meth->finish; | ||
| 217 | if (pcopy != NULL) | ||
| 218 | *pcopy = meth->copy; | ||
| 219 | if (pset_group != NULL) | ||
| 220 | *pset_group = meth->set_group; | ||
| 221 | if (pset_private != NULL) | ||
| 222 | *pset_private = meth->set_private; | ||
| 223 | if (pset_public != NULL) | ||
| 224 | *pset_public = meth->set_public; | ||
| 225 | } | ||
| 226 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_init); | ||
| 227 | |||
| 228 | void | ||
| 229 | EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth, | ||
| 230 | int (**pkeygen)(EC_KEY *key)) | ||
| 231 | { | ||
| 232 | if (pkeygen != NULL) | ||
| 233 | *pkeygen = meth->keygen; | ||
| 234 | } | ||
| 235 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_keygen); | ||
| 236 | |||
| 237 | void | ||
| 238 | EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth, | ||
| 239 | int (**pck)(unsigned char **out, size_t *out_len, const EC_POINT *pub_key, | ||
| 240 | const EC_KEY *ecdh)) | ||
| 241 | { | ||
| 242 | if (pck != NULL) | ||
| 243 | *pck = meth->compute_key; | ||
| 244 | } | ||
| 245 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_compute_key); | ||
| 246 | |||
| 247 | void | ||
| 248 | EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth, | ||
| 249 | int (**psign)(int type, const unsigned char *dgst, | ||
| 250 | int dlen, unsigned char *sig, unsigned int *siglen, | ||
| 251 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey), | ||
| 252 | int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | ||
| 253 | BIGNUM **kinvp, BIGNUM **rp), | ||
| 254 | ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, | ||
| 255 | int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, | ||
| 256 | EC_KEY *eckey)) | ||
| 257 | { | ||
| 258 | if (psign != NULL) | ||
| 259 | *psign = meth->sign; | ||
| 260 | if (psign_setup != NULL) | ||
| 261 | *psign_setup = meth->sign_setup; | ||
| 262 | if (psign_sig != NULL) | ||
| 263 | *psign_sig = meth->sign_sig; | ||
| 264 | } | ||
| 265 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_sign); | ||
| 266 | |||
| 267 | void | ||
| 268 | EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth, | ||
| 269 | int (**pverify)(int type, const unsigned char *dgst, int dgst_len, | ||
| 270 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey), | ||
| 271 | int (**pverify_sig)(const unsigned char *dgst, int dgst_len, | ||
| 272 | const ECDSA_SIG *sig, EC_KEY *eckey)) | ||
| 273 | { | ||
| 274 | if (pverify != NULL) | ||
| 275 | *pverify = meth->verify; | ||
| 276 | if (pverify_sig != NULL) | ||
| 277 | *pverify_sig = meth->verify_sig; | ||
| 278 | } | ||
| 279 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_verify); | ||
| 280 | |||
| 281 | static const EC_KEY_METHOD openssl_ec_key_method = { | ||
| 282 | .name = "OpenSSL EC_KEY method", | ||
| 283 | .flags = 0, | ||
| 284 | |||
| 285 | .init = NULL, | ||
| 286 | .finish = NULL, | ||
| 287 | .copy = NULL, | ||
| 288 | |||
| 289 | .set_group = NULL, | ||
| 290 | .set_private = NULL, | ||
| 291 | .set_public = NULL, | ||
| 292 | |||
| 293 | .keygen = ec_key_gen, | ||
| 294 | .compute_key = ecdh_compute_key, | ||
| 295 | |||
| 296 | .sign = ecdsa_sign, | ||
| 297 | .sign_setup = ecdsa_sign_setup, | ||
| 298 | .sign_sig = ecdsa_sign_sig, | ||
| 299 | |||
| 300 | .verify = ecdsa_verify, | ||
| 301 | .verify_sig = ecdsa_verify_sig, | ||
| 302 | }; | ||
| 303 | |||
| 304 | const EC_KEY_METHOD * | ||
| 305 | EC_KEY_OpenSSL(void) | ||
| 306 | { | ||
| 307 | return &openssl_ec_key_method; | ||
| 308 | } | ||
| 309 | LCRYPTO_ALIAS(EC_KEY_OpenSSL); | ||
| 310 | |||
| 311 | const EC_KEY_METHOD *default_ec_key_meth = &openssl_ec_key_method; | ||
| 312 | |||
| 313 | const EC_KEY_METHOD * | ||
| 314 | EC_KEY_get_default_method(void) | ||
| 315 | { | ||
| 316 | return default_ec_key_meth; | ||
| 317 | } | ||
| 318 | LCRYPTO_ALIAS(EC_KEY_get_default_method); | ||
| 319 | |||
| 320 | void | ||
| 321 | EC_KEY_set_default_method(const EC_KEY_METHOD *meth) | ||
| 322 | { | ||
| 323 | if (meth == NULL) | ||
| 324 | default_ec_key_meth = &openssl_ec_key_method; | ||
| 325 | else | ||
| 326 | default_ec_key_meth = meth; | ||
| 327 | } | ||
| 328 | LCRYPTO_ALIAS(EC_KEY_set_default_method); | ||
