diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/Makefile | 10 | ||||
| -rw-r--r-- | src/lib/libcrypto/Symbols.list | 13 | ||||
| -rw-r--r-- | src/lib/libcrypto/crypto.h | 3 | ||||
| -rw-r--r-- | src/lib/libcrypto/ec/ec.h | 31 | ||||
| -rw-r--r-- | src/lib/libcrypto/ec/ec_key.c | 91 | ||||
| -rw-r--r-- | src/lib/libcrypto/ec/ec_kmeth.c | 272 | ||||
| -rw-r--r-- | src/lib/libcrypto/ec/ec_lcl.h | 30 | ||||
| -rw-r--r-- | src/lib/libcrypto/ecdsa/ecdsa.h | 22 | ||||
| -rw-r--r-- | src/lib/libcrypto/ecdsa/ecs_locl.h | 10 | ||||
| -rw-r--r-- | src/lib/libcrypto/ecdsa/ecs_ossl.c | 39 | ||||
| -rw-r--r-- | src/lib/libcrypto/ecdsa/ecs_sign.c | 38 | ||||
| -rw-r--r-- | src/lib/libcrypto/engine/eng_fat.c | 11 | ||||
| -rw-r--r-- | src/lib/libcrypto/engine/eng_int.h | 3 | ||||
| -rw-r--r-- | src/lib/libcrypto/engine/eng_list.c | 5 | ||||
| -rw-r--r-- | src/lib/libcrypto/engine/engine.h | 14 | ||||
| -rw-r--r-- | src/lib/libcrypto/engine/tb_eckey.c | 123 |
16 files changed, 659 insertions, 56 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile index 8e39d92ab4..66f511761b 100644 --- a/src/lib/libcrypto/Makefile +++ b/src/lib/libcrypto/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.30 2018/11/11 06:53:31 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.31 2019/01/19 01:07:00 tb Exp $ |
| 2 | 2 | ||
| 3 | LIB= crypto | 3 | LIB= crypto |
| 4 | LIBREBUILD=y | 4 | LIBREBUILD=y |
| @@ -31,6 +31,10 @@ CFLAGS+= -I${LCRYPTO_SRC} | |||
| 31 | CFLAGS+= -I${LCRYPTO_SRC}/asn1 -I${LCRYPTO_SRC}/bn -I${LCRYPTO_SRC}/evp | 31 | CFLAGS+= -I${LCRYPTO_SRC}/asn1 -I${LCRYPTO_SRC}/bn -I${LCRYPTO_SRC}/evp |
| 32 | CFLAGS+= -I${LCRYPTO_SRC}/modes | 32 | CFLAGS+= -I${LCRYPTO_SRC}/modes |
| 33 | 33 | ||
| 34 | # XXX FIXME ecdsa and ec should be merged | ||
| 35 | CFLAGS+= -I${LCRYPTO_SRC}/ecdsa | ||
| 36 | CFLAGS+= -I${LCRYPTO_SRC}/ec | ||
| 37 | |||
| 34 | VERSION_SCRIPT= Symbols.map | 38 | VERSION_SCRIPT= Symbols.map |
| 35 | SYMBOL_LIST= ${.CURDIR}/Symbols.list | 39 | SYMBOL_LIST= ${.CURDIR}/Symbols.list |
| 36 | 40 | ||
| @@ -125,7 +129,7 @@ SRCS+= dso_openssl.c | |||
| 125 | # ec/ | 129 | # ec/ |
| 126 | SRCS+= ec_lib.c ecp_smpl.c ecp_mont.c ecp_nist.c ec_cvt.c ec_mult.c | 130 | SRCS+= ec_lib.c ecp_smpl.c ecp_mont.c ecp_nist.c ec_cvt.c ec_mult.c |
| 127 | SRCS+= ec_err.c ec_curve.c ec_check.c ec_print.c ec_asn1.c ec_key.c | 131 | SRCS+= ec_err.c ec_curve.c ec_check.c ec_print.c ec_asn1.c ec_key.c |
| 128 | SRCS+= ec2_smpl.c ec2_mult.c ec_ameth.c ec_pmeth.c eck_prn.c | 132 | SRCS+= ec2_smpl.c ec2_mult.c ec_ameth.c ec_pmeth.c ec_kmeth.c eck_prn.c |
| 129 | SRCS+= ecp_nistp224.c ecp_nistp256.c ecp_nistp521.c ecp_nistputil.c | 133 | SRCS+= ecp_nistp224.c ecp_nistp256.c ecp_nistp521.c ecp_nistputil.c |
| 130 | SRCS+= ecp_oct.c ec2_oct.c ec_oct.c | 134 | SRCS+= ecp_oct.c ec2_oct.c ec_oct.c |
| 131 | 135 | ||
| @@ -139,7 +143,7 @@ SRCS+= ecs_lib.c ecs_asn1.c ecs_ossl.c ecs_sign.c ecs_vrf.c ecs_err.c | |||
| 139 | SRCS+= eng_err.c eng_lib.c eng_list.c eng_init.c eng_ctrl.c | 143 | SRCS+= eng_err.c eng_lib.c eng_list.c eng_init.c eng_ctrl.c |
| 140 | SRCS+= eng_table.c eng_pkey.c eng_fat.c eng_all.c | 144 | SRCS+= eng_table.c eng_pkey.c eng_fat.c eng_all.c |
| 141 | SRCS+= tb_rsa.c tb_dsa.c tb_ecdsa.c tb_dh.c tb_ecdh.c tb_rand.c tb_store.c | 145 | SRCS+= tb_rsa.c tb_dsa.c tb_ecdsa.c tb_dh.c tb_ecdh.c tb_rand.c tb_store.c |
| 142 | SRCS+= tb_cipher.c tb_digest.c tb_pkmeth.c tb_asnmth.c | 146 | SRCS+= tb_cipher.c tb_digest.c tb_pkmeth.c tb_asnmth.c tb_eckey.c |
| 143 | SRCS+= eng_openssl.c eng_cnf.c eng_dyn.c | 147 | SRCS+= eng_openssl.c eng_cnf.c eng_dyn.c |
| 144 | # XXX unnecessary? handled in EVP now... | 148 | # XXX unnecessary? handled in EVP now... |
| 145 | # SRCS+= eng_aesni.c # local addition | 149 | # SRCS+= eng_aesni.c # local addition |
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list index c4b78dbef2..2734fed62a 100644 --- a/src/lib/libcrypto/Symbols.list +++ b/src/lib/libcrypto/Symbols.list | |||
| @@ -955,6 +955,13 @@ EC_GROUP_set_curve_name | |||
| 955 | EC_GROUP_set_generator | 955 | EC_GROUP_set_generator |
| 956 | EC_GROUP_set_point_conversion_form | 956 | EC_GROUP_set_point_conversion_form |
| 957 | EC_GROUP_set_seed | 957 | EC_GROUP_set_seed |
| 958 | EC_KEY_METHOD_free | ||
| 959 | EC_KEY_METHOD_get_init | ||
| 960 | EC_KEY_METHOD_get_sign | ||
| 961 | EC_KEY_METHOD_new | ||
| 962 | EC_KEY_METHOD_set_init | ||
| 963 | EC_KEY_METHOD_set_sign | ||
| 964 | EC_KEY_OpenSSL | ||
| 958 | EC_KEY_check_key | 965 | EC_KEY_check_key |
| 959 | EC_KEY_clear_flags | 966 | EC_KEY_clear_flags |
| 960 | EC_KEY_copy | 967 | EC_KEY_copy |
| @@ -965,9 +972,12 @@ EC_KEY_get0_group | |||
| 965 | EC_KEY_get0_private_key | 972 | EC_KEY_get0_private_key |
| 966 | EC_KEY_get0_public_key | 973 | EC_KEY_get0_public_key |
| 967 | EC_KEY_get_conv_form | 974 | EC_KEY_get_conv_form |
| 975 | EC_KEY_get_default_method | ||
| 968 | EC_KEY_get_enc_flags | 976 | EC_KEY_get_enc_flags |
| 977 | EC_KEY_get_ex_data | ||
| 969 | EC_KEY_get_flags | 978 | EC_KEY_get_flags |
| 970 | EC_KEY_get_key_method_data | 979 | EC_KEY_get_key_method_data |
| 980 | EC_KEY_get_method | ||
| 971 | EC_KEY_insert_key_method_data | 981 | EC_KEY_insert_key_method_data |
| 972 | EC_KEY_new | 982 | EC_KEY_new |
| 973 | EC_KEY_new_by_curve_name | 983 | EC_KEY_new_by_curve_name |
| @@ -976,9 +986,12 @@ EC_KEY_print | |||
| 976 | EC_KEY_print_fp | 986 | EC_KEY_print_fp |
| 977 | EC_KEY_set_asn1_flag | 987 | EC_KEY_set_asn1_flag |
| 978 | EC_KEY_set_conv_form | 988 | EC_KEY_set_conv_form |
| 989 | EC_KEY_set_default_method | ||
| 979 | EC_KEY_set_enc_flags | 990 | EC_KEY_set_enc_flags |
| 991 | EC_KEY_set_ex_data | ||
| 980 | EC_KEY_set_flags | 992 | EC_KEY_set_flags |
| 981 | EC_KEY_set_group | 993 | EC_KEY_set_group |
| 994 | EC_KEY_set_method | ||
| 982 | EC_KEY_set_private_key | 995 | EC_KEY_set_private_key |
| 983 | EC_KEY_set_public_key | 996 | EC_KEY_set_public_key |
| 984 | EC_KEY_set_public_key_affine_coordinates | 997 | EC_KEY_set_public_key_affine_coordinates |
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h index 8d549da8b5..7de8abb437 100644 --- a/src/lib/libcrypto/crypto.h +++ b/src/lib/libcrypto/crypto.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: crypto.h,v 1.49 2018/11/11 16:32:28 bcook Exp $ */ | 1 | /* $OpenBSD: crypto.h,v 1.50 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -286,6 +286,7 @@ DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS) | |||
| 286 | #define CRYPTO_EX_INDEX_ECDH 13 | 286 | #define CRYPTO_EX_INDEX_ECDH 13 |
| 287 | #define CRYPTO_EX_INDEX_COMP 14 | 287 | #define CRYPTO_EX_INDEX_COMP 14 |
| 288 | #define CRYPTO_EX_INDEX_STORE 15 | 288 | #define CRYPTO_EX_INDEX_STORE 15 |
| 289 | #define CRYPTO_EX_INDEX_EC_KEY 16 | ||
| 289 | 290 | ||
| 290 | /* Dynamically assigned indexes start from this value (don't use directly, use | 291 | /* Dynamically assigned indexes start from this value (don't use directly, use |
| 291 | * via CRYPTO_ex_data_new_class). */ | 292 | * via CRYPTO_ex_data_new_class). */ |
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h index d9df48603a..1173459dae 100644 --- a/src/lib/libcrypto/ec/ec.h +++ b/src/lib/libcrypto/ec/ec.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ec.h,v 1.13 2018/05/19 10:37:02 tb Exp $ */ | 1 | /* $OpenBSD: ec.h,v 1.14 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Originally written by Bodo Moeller for the OpenSSL project. | 3 | * Originally written by Bodo Moeller for the OpenSSL project. |
| 4 | */ | 4 | */ |
| @@ -705,6 +705,7 @@ int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off); | |||
| 705 | /********************************************************************/ | 705 | /********************************************************************/ |
| 706 | 706 | ||
| 707 | typedef struct ec_key_st EC_KEY; | 707 | typedef struct ec_key_st EC_KEY; |
| 708 | typedef struct ec_key_method_st EC_KEY_METHOD; | ||
| 708 | 709 | ||
| 709 | /* some values for the encoding_flag */ | 710 | /* some values for the encoding_flag */ |
| 710 | #define EC_PKEY_NO_PARAMETERS 0x001 | 711 | #define EC_PKEY_NO_PARAMETERS 0x001 |
| @@ -945,6 +946,34 @@ int ECParameters_print_fp(FILE *fp, const EC_KEY *key); | |||
| 945 | */ | 946 | */ |
| 946 | int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); | 947 | int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); |
| 947 | 948 | ||
| 949 | #define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \ | ||
| 950 | CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef) | ||
| 951 | int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg); | ||
| 952 | void *EC_KEY_get_ex_data(const EC_KEY *key, int idx); | ||
| 953 | |||
| 954 | const EC_KEY_METHOD *EC_KEY_OpenSSL(void); | ||
| 955 | const EC_KEY_METHOD *EC_KEY_get_default_method(void); | ||
| 956 | void EC_KEY_set_default_method(const EC_KEY_METHOD *meth); | ||
| 957 | const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key); | ||
| 958 | int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth); | ||
| 959 | EC_KEY *EC_KEY_new_method(ENGINE *engine); | ||
| 960 | EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth); | ||
| 961 | void EC_KEY_METHOD_free(EC_KEY_METHOD *meth); | ||
| 962 | void EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth, | ||
| 963 | int (*init)(EC_KEY *key), | ||
| 964 | void (*finish)(EC_KEY *key), | ||
| 965 | int (*copy)(EC_KEY *dest, const EC_KEY *src), | ||
| 966 | int (*set_group)(EC_KEY *key, const EC_GROUP *grp), | ||
| 967 | int (*set_private)(EC_KEY *key, const BIGNUM *priv_key), | ||
| 968 | int (*set_public)(EC_KEY *key, const EC_POINT *pub_key)); | ||
| 969 | void EC_KEY_METHOD_get_init(EC_KEY_METHOD *meth, | ||
| 970 | int (**pinit)(EC_KEY *key), | ||
| 971 | void (**pfinish)(EC_KEY *key), | ||
| 972 | int (**pcopy)(EC_KEY *dest, const EC_KEY *src), | ||
| 973 | int (**pset_group)(EC_KEY *key, const EC_GROUP *grp), | ||
| 974 | int (**pset_private)(EC_KEY *key, const BIGNUM *priv_key), | ||
| 975 | int (**pset_public)(EC_KEY *key, const EC_POINT *pub_key)); | ||
| 976 | |||
| 948 | EC_KEY *ECParameters_dup(EC_KEY *key); | 977 | EC_KEY *ECParameters_dup(EC_KEY *key); |
| 949 | 978 | ||
| 950 | #ifndef __cplusplus | 979 | #ifndef __cplusplus |
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c index fcdf461d20..f57e078c7f 100644 --- a/src/lib/libcrypto/ec/ec_key.c +++ b/src/lib/libcrypto/ec/ec_key.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ec_key.c,v 1.22 2018/11/09 23:39:45 tb Exp $ */ | 1 | /* $OpenBSD: ec_key.c,v 1.23 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
| 4 | */ | 4 | */ |
| @@ -65,30 +65,18 @@ | |||
| 65 | 65 | ||
| 66 | #include <openssl/opensslconf.h> | 66 | #include <openssl/opensslconf.h> |
| 67 | 67 | ||
| 68 | #ifndef OPENSSL_NO_ENGINE | ||
| 69 | #include <openssl/engine.h> | ||
| 70 | #endif | ||
| 71 | #include <openssl/err.h> | ||
| 72 | |||
| 68 | #include "bn_lcl.h" | 73 | #include "bn_lcl.h" |
| 69 | #include "ec_lcl.h" | 74 | #include "ec_lcl.h" |
| 70 | #include <openssl/err.h> | ||
| 71 | 75 | ||
| 72 | EC_KEY * | 76 | EC_KEY * |
| 73 | EC_KEY_new(void) | 77 | EC_KEY_new(void) |
| 74 | { | 78 | { |
| 75 | EC_KEY *ret; | 79 | return EC_KEY_new_method(NULL); |
| 76 | |||
| 77 | ret = malloc(sizeof(EC_KEY)); | ||
| 78 | if (ret == NULL) { | ||
| 79 | ECerror(ERR_R_MALLOC_FAILURE); | ||
| 80 | return (NULL); | ||
| 81 | } | ||
| 82 | ret->version = 1; | ||
| 83 | ret->flags = 0; | ||
| 84 | ret->group = NULL; | ||
| 85 | ret->pub_key = NULL; | ||
| 86 | ret->priv_key = NULL; | ||
| 87 | ret->enc_flag = 0; | ||
| 88 | ret->conv_form = POINT_CONVERSION_UNCOMPRESSED; | ||
| 89 | ret->references = 1; | ||
| 90 | ret->method_data = NULL; | ||
| 91 | return (ret); | ||
| 92 | } | 80 | } |
| 93 | 81 | ||
| 94 | EC_KEY * | 82 | EC_KEY * |
| @@ -102,6 +90,11 @@ EC_KEY_new_by_curve_name(int nid) | |||
| 102 | EC_KEY_free(ret); | 90 | EC_KEY_free(ret); |
| 103 | return NULL; | 91 | return NULL; |
| 104 | } | 92 | } |
| 93 | if (ret->meth->set_group != NULL && | ||
| 94 | ret->meth->set_group(ret, ret->group) == 0) { | ||
| 95 | EC_KEY_free(ret); | ||
| 96 | return NULL; | ||
| 97 | } | ||
| 105 | return ret; | 98 | return ret; |
| 106 | } | 99 | } |
| 107 | 100 | ||
| @@ -117,6 +110,14 @@ EC_KEY_free(EC_KEY * r) | |||
| 117 | if (i > 0) | 110 | if (i > 0) |
| 118 | return; | 111 | return; |
| 119 | 112 | ||
| 113 | if (r->meth != NULL && r->meth->finish != NULL) | ||
| 114 | r->meth->finish(r); | ||
| 115 | |||
| 116 | #ifndef OPENSSL_NO_ENGINE | ||
| 117 | ENGINE_finish(r->engine); | ||
| 118 | #endif | ||
| 119 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data); | ||
| 120 | |||
| 120 | EC_GROUP_free(r->group); | 121 | EC_GROUP_free(r->group); |
| 121 | EC_POINT_free(r->pub_key); | 122 | EC_POINT_free(r->pub_key); |
| 122 | BN_clear_free(r->priv_key); | 123 | BN_clear_free(r->priv_key); |
| @@ -135,6 +136,15 @@ EC_KEY_copy(EC_KEY * dest, const EC_KEY * src) | |||
| 135 | ECerror(ERR_R_PASSED_NULL_PARAMETER); | 136 | ECerror(ERR_R_PASSED_NULL_PARAMETER); |
| 136 | return NULL; | 137 | return NULL; |
| 137 | } | 138 | } |
| 139 | if (src->meth != dest->meth) { | ||
| 140 | if (dest->meth != NULL && dest->meth->finish != NULL) | ||
| 141 | dest->meth->finish(dest); | ||
| 142 | #ifndef OPENSSL_NO_ENGINE | ||
| 143 | if (ENGINE_finish(dest->engine) == 0) | ||
| 144 | return 0; | ||
| 145 | dest->engine = NULL; | ||
| 146 | #endif | ||
| 147 | } | ||
| 138 | /* copy the parameters */ | 148 | /* copy the parameters */ |
| 139 | if (src->group) { | 149 | if (src->group) { |
| 140 | const EC_METHOD *meth = EC_GROUP_method_of(src->group); | 150 | const EC_METHOD *meth = EC_GROUP_method_of(src->group); |
| @@ -184,14 +194,32 @@ EC_KEY_copy(EC_KEY * dest, const EC_KEY * src) | |||
| 184 | dest->version = src->version; | 194 | dest->version = src->version; |
| 185 | dest->flags = src->flags; | 195 | dest->flags = src->flags; |
| 186 | 196 | ||
| 197 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_EC_KEY, &dest->ex_data, | ||
| 198 | &((EC_KEY *)src)->ex_data)) /* XXX const */ | ||
| 199 | return NULL; | ||
| 200 | |||
| 201 | if (src->meth != dest->meth) { | ||
| 202 | #ifndef OPENSSL_NO_ENGINE | ||
| 203 | if (src->engine != NULL && ENGINE_init(src->engine) == 0) | ||
| 204 | return 0; | ||
| 205 | dest->engine = src->engine; | ||
| 206 | #endif | ||
| 207 | dest->meth = src->meth; | ||
| 208 | } | ||
| 209 | |||
| 210 | if (src->meth != NULL && src->meth->copy != NULL && | ||
| 211 | src->meth->copy(dest, src) == 0) | ||
| 212 | return 0; | ||
| 213 | |||
| 187 | return dest; | 214 | return dest; |
| 188 | } | 215 | } |
| 189 | 216 | ||
| 190 | EC_KEY * | 217 | EC_KEY * |
| 191 | EC_KEY_dup(const EC_KEY * ec_key) | 218 | EC_KEY_dup(const EC_KEY * ec_key) |
| 192 | { | 219 | { |
| 193 | EC_KEY *ret = EC_KEY_new(); | 220 | EC_KEY *ret; |
| 194 | if (ret == NULL) | 221 | |
| 222 | if ((ret = EC_KEY_new_method(ec_key->engine)) == NULL) | ||
| 195 | return NULL; | 223 | return NULL; |
| 196 | if (EC_KEY_copy(ret, ec_key) == NULL) { | 224 | if (EC_KEY_copy(ret, ec_key) == NULL) { |
| 197 | EC_KEY_free(ret); | 225 | EC_KEY_free(ret); |
| @@ -207,6 +235,18 @@ EC_KEY_up_ref(EC_KEY * r) | |||
| 207 | return ((i > 1) ? 1 : 0); | 235 | return ((i > 1) ? 1 : 0); |
| 208 | } | 236 | } |
| 209 | 237 | ||
| 238 | int | ||
| 239 | EC_KEY_set_ex_data(EC_KEY *r, int idx, void *arg) | ||
| 240 | { | ||
| 241 | return CRYPTO_set_ex_data(&r->ex_data, idx, arg); | ||
| 242 | } | ||
| 243 | |||
| 244 | void * | ||
| 245 | EC_KEY_get_ex_data(const EC_KEY *r, int idx) | ||
| 246 | { | ||
| 247 | return CRYPTO_get_ex_data(&r->ex_data, idx); | ||
| 248 | } | ||
| 249 | |||
| 210 | int | 250 | int |
| 211 | EC_KEY_generate_key(EC_KEY *eckey) | 251 | EC_KEY_generate_key(EC_KEY *eckey) |
| 212 | { | 252 | { |
| @@ -407,6 +447,9 @@ EC_KEY_get0_group(const EC_KEY * key) | |||
| 407 | int | 447 | int |
| 408 | EC_KEY_set_group(EC_KEY * key, const EC_GROUP * group) | 448 | EC_KEY_set_group(EC_KEY * key, const EC_GROUP * group) |
| 409 | { | 449 | { |
| 450 | if (key->meth->set_group != NULL && | ||
| 451 | key->meth->set_group(key, group) == 0) | ||
| 452 | return 0; | ||
| 410 | EC_GROUP_free(key->group); | 453 | EC_GROUP_free(key->group); |
| 411 | key->group = EC_GROUP_dup(group); | 454 | key->group = EC_GROUP_dup(group); |
| 412 | return (key->group == NULL) ? 0 : 1; | 455 | return (key->group == NULL) ? 0 : 1; |
| @@ -421,6 +464,9 @@ EC_KEY_get0_private_key(const EC_KEY * key) | |||
| 421 | int | 464 | int |
| 422 | EC_KEY_set_private_key(EC_KEY * key, const BIGNUM * priv_key) | 465 | EC_KEY_set_private_key(EC_KEY * key, const BIGNUM * priv_key) |
| 423 | { | 466 | { |
| 467 | if (key->meth->set_private != NULL && | ||
| 468 | key->meth->set_private(key, priv_key) == 0) | ||
| 469 | return 0; | ||
| 424 | BN_clear_free(key->priv_key); | 470 | BN_clear_free(key->priv_key); |
| 425 | key->priv_key = BN_dup(priv_key); | 471 | key->priv_key = BN_dup(priv_key); |
| 426 | return (key->priv_key == NULL) ? 0 : 1; | 472 | return (key->priv_key == NULL) ? 0 : 1; |
| @@ -435,6 +481,9 @@ EC_KEY_get0_public_key(const EC_KEY * key) | |||
| 435 | int | 481 | int |
| 436 | EC_KEY_set_public_key(EC_KEY * key, const EC_POINT * pub_key) | 482 | EC_KEY_set_public_key(EC_KEY * key, const EC_POINT * pub_key) |
| 437 | { | 483 | { |
| 484 | if (key->meth->set_public != NULL && | ||
| 485 | key->meth->set_public(key, pub_key) == 0) | ||
| 486 | return 0; | ||
| 438 | EC_POINT_free(key->pub_key); | 487 | EC_POINT_free(key->pub_key); |
| 439 | key->pub_key = EC_POINT_dup(pub_key, key->group); | 488 | key->pub_key = EC_POINT_dup(pub_key, key->group); |
| 440 | return (key->pub_key == NULL) ? 0 : 1; | 489 | return (key->pub_key == NULL) ? 0 : 1; |
diff --git a/src/lib/libcrypto/ec/ec_kmeth.c b/src/lib/libcrypto/ec/ec_kmeth.c new file mode 100644 index 0000000000..b714c62236 --- /dev/null +++ b/src/lib/libcrypto/ec/ec_kmeth.c | |||
| @@ -0,0 +1,272 @@ | |||
| 1 | /* | ||
| 2 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2015 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | */ | ||
| 53 | |||
| 54 | #include <openssl/ec.h> | ||
| 55 | #ifndef OPENSSL_NO_ENGINE | ||
| 56 | #include <openssl/engine.h> | ||
| 57 | #endif | ||
| 58 | #include <openssl/err.h> | ||
| 59 | |||
| 60 | #include "ec_lcl.h" | ||
| 61 | #include "ecs_locl.h" | ||
| 62 | |||
| 63 | static const EC_KEY_METHOD openssl_ec_key_method = { | ||
| 64 | .name = "OpenSSL EC_KEY method", | ||
| 65 | .flags = 0, | ||
| 66 | |||
| 67 | .init = NULL, | ||
| 68 | .finish = NULL, | ||
| 69 | .copy = NULL, | ||
| 70 | |||
| 71 | .set_group = NULL, | ||
| 72 | .set_private = NULL, | ||
| 73 | .set_public = NULL, | ||
| 74 | |||
| 75 | .sign = ossl_ecdsa_sign, | ||
| 76 | .sign_setup = ossl_ecdsa_sign_setup, | ||
| 77 | .sign_sig = ossl_ecdsa_sign_sig, | ||
| 78 | }; | ||
| 79 | |||
| 80 | const EC_KEY_METHOD *default_ec_key_meth = &openssl_ec_key_method; | ||
| 81 | |||
| 82 | const EC_KEY_METHOD * | ||
| 83 | EC_KEY_OpenSSL(void) | ||
| 84 | { | ||
| 85 | return &openssl_ec_key_method; | ||
| 86 | } | ||
| 87 | |||
| 88 | const EC_KEY_METHOD * | ||
| 89 | EC_KEY_get_default_method(void) | ||
| 90 | { | ||
| 91 | return default_ec_key_meth; | ||
| 92 | } | ||
| 93 | |||
| 94 | void | ||
| 95 | EC_KEY_set_default_method(const EC_KEY_METHOD *meth) | ||
| 96 | { | ||
| 97 | if (meth == NULL) | ||
| 98 | default_ec_key_meth = &openssl_ec_key_method; | ||
| 99 | else | ||
| 100 | default_ec_key_meth = meth; | ||
| 101 | } | ||
| 102 | |||
| 103 | const EC_KEY_METHOD * | ||
| 104 | EC_KEY_get_method(const EC_KEY *key) | ||
| 105 | { | ||
| 106 | return key->meth; | ||
| 107 | } | ||
| 108 | |||
| 109 | int | ||
| 110 | EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth) | ||
| 111 | { | ||
| 112 | void (*finish)(EC_KEY *key) = key->meth->finish; | ||
| 113 | |||
| 114 | if (finish != NULL) | ||
| 115 | finish(key); | ||
| 116 | |||
| 117 | #ifndef OPENSSL_NO_ENGINE | ||
| 118 | ENGINE_finish(key->engine); | ||
| 119 | key->engine = NULL; | ||
| 120 | #endif | ||
| 121 | |||
| 122 | key->meth = meth; | ||
| 123 | if (meth->init != NULL) | ||
| 124 | return meth->init(key); | ||
| 125 | return 1; | ||
| 126 | } | ||
| 127 | |||
| 128 | EC_KEY * | ||
| 129 | EC_KEY_new_method(ENGINE *engine) | ||
| 130 | { | ||
| 131 | EC_KEY *ret; | ||
| 132 | |||
| 133 | if ((ret = calloc(1, sizeof(EC_KEY))) == NULL) { | ||
| 134 | ECerror(ERR_R_MALLOC_FAILURE); | ||
| 135 | return NULL; | ||
| 136 | } | ||
| 137 | ret->meth = EC_KEY_get_default_method(); | ||
| 138 | #ifndef OPENSSL_NO_ENGINE | ||
| 139 | if (engine != NULL) { | ||
| 140 | if (!ENGINE_init(engine)) { | ||
| 141 | ECerror(ERR_R_ENGINE_LIB); | ||
| 142 | goto err; | ||
| 143 | } | ||
| 144 | ret->engine = engine; | ||
| 145 | } else | ||
| 146 | ret->engine = ENGINE_get_default_EC(); | ||
| 147 | if (ret->engine) { | ||
| 148 | ret->meth = ENGINE_get_EC(ret->engine); | ||
| 149 | if (ret->meth == NULL) { | ||
| 150 | ECerror(ERR_R_ENGINE_LIB); | ||
| 151 | goto err; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | #endif | ||
| 155 | ret->version = 1; | ||
| 156 | ret->flags = 0; | ||
| 157 | ret->group = NULL; | ||
| 158 | ret->pub_key = NULL; | ||
| 159 | ret->priv_key = NULL; | ||
| 160 | ret->enc_flag = 0; | ||
| 161 | ret->conv_form = POINT_CONVERSION_UNCOMPRESSED; | ||
| 162 | ret->references = 1; | ||
| 163 | ret->method_data = NULL; | ||
| 164 | |||
| 165 | if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data)) | ||
| 166 | goto err; | ||
| 167 | if (ret->meth->init != NULL && ret->meth->init(ret) == 0) | ||
| 168 | goto err; | ||
| 169 | |||
| 170 | return ret; | ||
| 171 | |||
| 172 | err: | ||
| 173 | EC_KEY_free(ret); | ||
| 174 | return NULL; | ||
| 175 | } | ||
| 176 | |||
| 177 | EC_KEY_METHOD * | ||
| 178 | EC_KEY_METHOD_new(const EC_KEY_METHOD *meth) | ||
| 179 | { | ||
| 180 | EC_KEY_METHOD *ret; | ||
| 181 | |||
| 182 | if ((ret = malloc(sizeof(*meth))) == NULL) | ||
| 183 | return NULL; | ||
| 184 | if (meth != NULL) | ||
| 185 | *ret = *meth; | ||
| 186 | ret->flags |= EC_KEY_METHOD_DYNAMIC; | ||
| 187 | return ret; | ||
| 188 | } | ||
| 189 | |||
| 190 | void | ||
| 191 | EC_KEY_METHOD_free(EC_KEY_METHOD *meth) | ||
| 192 | { | ||
| 193 | if (meth == NULL) | ||
| 194 | return; | ||
| 195 | if (meth->flags & EC_KEY_METHOD_DYNAMIC) | ||
| 196 | free(meth); | ||
| 197 | } | ||
| 198 | |||
| 199 | void | ||
| 200 | EC_KEY_METHOD_get_init(EC_KEY_METHOD *meth, | ||
| 201 | int (**pinit)(EC_KEY *key), | ||
| 202 | void (**pfinish)(EC_KEY *key), | ||
| 203 | int (**pcopy)(EC_KEY *dest, const EC_KEY *src), | ||
| 204 | int (**pset_group)(EC_KEY *key, const EC_GROUP *grp), | ||
| 205 | int (**pset_private)(EC_KEY *key, const BIGNUM *priv_key), | ||
| 206 | int (**pset_public)(EC_KEY *key, const EC_POINT *pub_key)) | ||
| 207 | { | ||
| 208 | if (pinit != NULL) | ||
| 209 | *pinit = meth->init; | ||
| 210 | if (pfinish != NULL) | ||
| 211 | *pfinish = meth->finish; | ||
| 212 | if (pcopy != NULL) | ||
| 213 | *pcopy = meth->copy; | ||
| 214 | if (pset_group != NULL) | ||
| 215 | *pset_group = meth->set_group; | ||
| 216 | if (pset_private != NULL) | ||
| 217 | *pset_private = meth->set_private; | ||
| 218 | if (pset_public != NULL) | ||
| 219 | *pset_public = meth->set_public; | ||
| 220 | } | ||
| 221 | |||
| 222 | void | ||
| 223 | EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth, | ||
| 224 | int (*init)(EC_KEY *key), | ||
| 225 | void (*finish)(EC_KEY *key), | ||
| 226 | int (*copy)(EC_KEY *dest, const EC_KEY *src), | ||
| 227 | int (*set_group)(EC_KEY *key, const EC_GROUP *grp), | ||
| 228 | int (*set_private)(EC_KEY *key, const BIGNUM *priv_key), | ||
| 229 | int (*set_public)(EC_KEY *key, const EC_POINT *pub_key)) | ||
| 230 | { | ||
| 231 | meth->init = init; | ||
| 232 | meth->finish = finish; | ||
| 233 | meth->copy = copy; | ||
| 234 | meth->set_group = set_group; | ||
| 235 | meth->set_private = set_private; | ||
| 236 | meth->set_public = set_public; | ||
| 237 | } | ||
| 238 | |||
| 239 | void | ||
| 240 | EC_KEY_METHOD_get_sign(EC_KEY_METHOD *meth, | ||
| 241 | int (**psign)(int type, const unsigned char *dgst, | ||
| 242 | int dlen, unsigned char *sig, unsigned int *siglen, | ||
| 243 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey), | ||
| 244 | int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | ||
| 245 | BIGNUM **kinvp, BIGNUM **rp), | ||
| 246 | ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, | ||
| 247 | int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, | ||
| 248 | EC_KEY *eckey)) | ||
| 249 | { | ||
| 250 | if (psign != NULL) | ||
| 251 | *psign = meth->sign; | ||
| 252 | if (psign_setup != NULL) | ||
| 253 | *psign_setup = meth->sign_setup; | ||
| 254 | if (psign_sig != NULL) | ||
| 255 | *psign_sig = meth->sign_sig; | ||
| 256 | } | ||
| 257 | |||
| 258 | void | ||
| 259 | EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth, | ||
| 260 | int (*sign)(int type, const unsigned char *dgst, | ||
| 261 | int dlen, unsigned char *sig, unsigned int *siglen, | ||
| 262 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey), | ||
| 263 | int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | ||
| 264 | BIGNUM **kinvp, BIGNUM **rp), | ||
| 265 | ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, | ||
| 266 | int dgst_len, const BIGNUM *in_kinv, | ||
| 267 | const BIGNUM *in_r, EC_KEY *eckey)) | ||
| 268 | { | ||
| 269 | meth->sign = sign; | ||
| 270 | meth->sign_setup = sign_setup; | ||
| 271 | meth->sign_sig = sign_sig; | ||
| 272 | } | ||
diff --git a/src/lib/libcrypto/ec/ec_lcl.h b/src/lib/libcrypto/ec/ec_lcl.h index c177246f36..cff0892e89 100644 --- a/src/lib/libcrypto/ec/ec_lcl.h +++ b/src/lib/libcrypto/ec/ec_lcl.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ec_lcl.h,v 1.11 2018/11/05 20:18:21 tb Exp $ */ | 1 | /* $OpenBSD: ec_lcl.h,v 1.12 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Originally written by Bodo Moeller for the OpenSSL project. | 3 | * Originally written by Bodo Moeller for the OpenSSL project. |
| 4 | */ | 4 | */ |
| @@ -73,6 +73,7 @@ | |||
| 73 | 73 | ||
| 74 | #include <openssl/obj_mac.h> | 74 | #include <openssl/obj_mac.h> |
| 75 | #include <openssl/ec.h> | 75 | #include <openssl/ec.h> |
| 76 | #include <openssl/ecdsa.h> | ||
| 76 | #include <openssl/bn.h> | 77 | #include <openssl/bn.h> |
| 77 | 78 | ||
| 78 | __BEGIN_HIDDEN_DECLS | 79 | __BEGIN_HIDDEN_DECLS |
| @@ -245,6 +246,9 @@ struct ec_group_st { | |||
| 245 | } /* EC_GROUP */; | 246 | } /* EC_GROUP */; |
| 246 | 247 | ||
| 247 | struct ec_key_st { | 248 | struct ec_key_st { |
| 249 | const EC_KEY_METHOD *meth; | ||
| 250 | ENGINE *engine; | ||
| 251 | |||
| 248 | int version; | 252 | int version; |
| 249 | 253 | ||
| 250 | EC_GROUP *group; | 254 | EC_GROUP *group; |
| @@ -259,6 +263,7 @@ struct ec_key_st { | |||
| 259 | int flags; | 263 | int flags; |
| 260 | 264 | ||
| 261 | EC_EXTRA_DATA *method_data; | 265 | EC_EXTRA_DATA *method_data; |
| 266 | CRYPTO_EX_DATA ex_data; | ||
| 262 | } /* EC_KEY */; | 267 | } /* EC_KEY */; |
| 263 | 268 | ||
| 264 | /* Basically a 'mixin' for extra data, but available for EC_GROUPs/EC_KEYs only | 269 | /* Basically a 'mixin' for extra data, but available for EC_GROUPs/EC_KEYs only |
| @@ -441,6 +446,29 @@ int ec_GFp_nistp256_have_precompute_mult(const EC_GROUP *group); | |||
| 441 | const EC_METHOD *EC_GFp_nistz256_method(void); | 446 | const EC_METHOD *EC_GFp_nistz256_method(void); |
| 442 | #endif | 447 | #endif |
| 443 | 448 | ||
| 449 | /* EC_METHOD definitions */ | ||
| 450 | |||
| 451 | struct ec_key_method_st { | ||
| 452 | const char *name; | ||
| 453 | int32_t flags; | ||
| 454 | int (*init)(EC_KEY *key); | ||
| 455 | void (*finish)(EC_KEY *key); | ||
| 456 | int (*copy)(EC_KEY *dest, const EC_KEY *src); | ||
| 457 | int (*set_group)(EC_KEY *key, const EC_GROUP *grp); | ||
| 458 | int (*set_private)(EC_KEY *key, const BIGNUM *priv_key); | ||
| 459 | int (*set_public)(EC_KEY *key, const EC_POINT *pub_key); | ||
| 460 | int (*sign)(int type, const unsigned char *dgst, int dlen, unsigned char | ||
| 461 | *sig, unsigned int *siglen, const BIGNUM *kinv, | ||
| 462 | const BIGNUM *r, EC_KEY *eckey); | ||
| 463 | int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, | ||
| 464 | BIGNUM **rp); | ||
| 465 | ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, int dgst_len, | ||
| 466 | const BIGNUM *in_kinv, const BIGNUM *in_r, | ||
| 467 | EC_KEY *eckey); | ||
| 468 | } /* EC_KEY_METHOD */; | ||
| 469 | |||
| 470 | #define EC_KEY_METHOD_DYNAMIC 1 | ||
| 471 | |||
| 444 | /* method functions in ecp_nistp521.c */ | 472 | /* method functions in ecp_nistp521.c */ |
| 445 | int ec_GFp_nistp521_group_init(EC_GROUP *group); | 473 | int ec_GFp_nistp521_group_init(EC_GROUP *group); |
| 446 | int ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *n, BN_CTX *); | 474 | int ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *n, BN_CTX *); |
diff --git a/src/lib/libcrypto/ecdsa/ecdsa.h b/src/lib/libcrypto/ecdsa/ecdsa.h index 9c53230a88..12d6677ce3 100644 --- a/src/lib/libcrypto/ecdsa/ecdsa.h +++ b/src/lib/libcrypto/ecdsa/ecdsa.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ecdsa.h,v 1.5 2018/03/17 15:24:44 tb Exp $ */ | 1 | /* $OpenBSD: ecdsa.h,v 1.6 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /** | 2 | /** |
| 3 | * \file crypto/ecdsa/ecdsa.h Include file for the OpenSSL ECDSA functions | 3 | * \file crypto/ecdsa/ecdsa.h Include file for the OpenSSL ECDSA functions |
| 4 | * \author Written by Nils Larsch for the OpenSSL project | 4 | * \author Written by Nils Larsch for the OpenSSL project |
| @@ -269,6 +269,26 @@ int ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg); | |||
| 269 | void *ECDSA_get_ex_data(EC_KEY *d, int idx); | 269 | void *ECDSA_get_ex_data(EC_KEY *d, int idx); |
| 270 | 270 | ||
| 271 | 271 | ||
| 272 | /* XXX should be in ec.h, but needs ECDSA_SIG */ | ||
| 273 | void EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth, | ||
| 274 | int (*sign)(int type, const unsigned char *dgst, | ||
| 275 | int dlen, unsigned char *sig, unsigned int *siglen, | ||
| 276 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey), | ||
| 277 | int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | ||
| 278 | BIGNUM **kinvp, BIGNUM **rp), | ||
| 279 | ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, | ||
| 280 | int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, | ||
| 281 | EC_KEY *eckey)); | ||
| 282 | void EC_KEY_METHOD_get_sign(EC_KEY_METHOD *meth, | ||
| 283 | int (**psign)(int type, const unsigned char *dgst, | ||
| 284 | int dlen, unsigned char *sig, unsigned int *siglen, | ||
| 285 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey), | ||
| 286 | int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | ||
| 287 | BIGNUM **kinvp, BIGNUM **rp), | ||
| 288 | ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, | ||
| 289 | int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, | ||
| 290 | EC_KEY *eckey)); | ||
| 291 | |||
| 272 | /* BEGIN ERROR CODES */ | 292 | /* BEGIN ERROR CODES */ |
| 273 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 293 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
| 274 | * made after this point may be overwritten when the script is next run. | 294 | * made after this point may be overwritten when the script is next run. |
diff --git a/src/lib/libcrypto/ecdsa/ecs_locl.h b/src/lib/libcrypto/ecdsa/ecs_locl.h index 94e8874332..0a9f17908b 100644 --- a/src/lib/libcrypto/ecdsa/ecs_locl.h +++ b/src/lib/libcrypto/ecdsa/ecs_locl.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ecs_locl.h,v 1.5 2016/12/21 15:49:29 jsing Exp $ */ | 1 | /* $OpenBSD: ecs_locl.h,v 1.6 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Nils Larsch for the OpenSSL project | 3 | * Written by Nils Larsch for the OpenSSL project |
| 4 | */ | 4 | */ |
| @@ -81,6 +81,14 @@ typedef struct ecdsa_data_st { | |||
| 81 | */ | 81 | */ |
| 82 | ECDSA_DATA *ecdsa_check(EC_KEY *eckey); | 82 | ECDSA_DATA *ecdsa_check(EC_KEY *eckey); |
| 83 | 83 | ||
| 84 | int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, | ||
| 85 | BIGNUM **rp); | ||
| 86 | int ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen, | ||
| 87 | unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, | ||
| 88 | const BIGNUM *r, EC_KEY *eckey); | ||
| 89 | ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len, | ||
| 90 | const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey); | ||
| 91 | |||
| 84 | __END_HIDDEN_DECLS | 92 | __END_HIDDEN_DECLS |
| 85 | 93 | ||
| 86 | #endif /* HEADER_ECS_LOCL_H */ | 94 | #endif /* HEADER_ECS_LOCL_H */ |
diff --git a/src/lib/libcrypto/ecdsa/ecs_ossl.c b/src/lib/libcrypto/ecdsa/ecs_ossl.c index 87d80642df..4e05cb9aac 100644 --- a/src/lib/libcrypto/ecdsa/ecs_ossl.c +++ b/src/lib/libcrypto/ecdsa/ecs_ossl.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ecs_ossl.c,v 1.16 2018/07/10 21:36:02 tb Exp $ */ | 1 | /* $OpenBSD: ecs_ossl.c,v 1.17 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Nils Larsch for the OpenSSL project | 3 | * Written by Nils Larsch for the OpenSSL project |
| 4 | */ | 4 | */ |
| @@ -111,6 +111,21 @@ ecdsa_prepare_digest(const unsigned char *dgst, int dgst_len, BIGNUM *order, | |||
| 111 | return 1; | 111 | return 1; |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | int | ||
| 115 | ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, | ||
| 116 | unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey) | ||
| 117 | { | ||
| 118 | ECDSA_SIG *s; | ||
| 119 | |||
| 120 | if ((s = ECDSA_do_sign_ex(dgst, dlen, kinv, r, eckey)) == NULL) { | ||
| 121 | *siglen = 0; | ||
| 122 | return 0; | ||
| 123 | } | ||
| 124 | *siglen = i2d_ECDSA_SIG(s, &sig); | ||
| 125 | ECDSA_SIG_free(s); | ||
| 126 | return 1; | ||
| 127 | } | ||
| 128 | |||
| 114 | static int | 129 | static int |
| 115 | ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | 130 | ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) |
| 116 | { | 131 | { |
| @@ -234,6 +249,16 @@ ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | |||
| 234 | return (ret); | 249 | return (ret); |
| 235 | } | 250 | } |
| 236 | 251 | ||
| 252 | /* replace w/ ecdsa_sign_setup() when ECDSA_METHOD gets removed */ | ||
| 253 | int | ||
| 254 | ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | ||
| 255 | { | ||
| 256 | ECDSA_DATA *ecdsa; | ||
| 257 | |||
| 258 | if ((ecdsa = ecdsa_check(eckey)) == NULL) | ||
| 259 | return 0; | ||
| 260 | return ecdsa->meth->ecdsa_sign_setup(eckey, ctx_in, kinvp, rp); | ||
| 261 | } | ||
| 237 | 262 | ||
| 238 | static ECDSA_SIG * | 263 | static ECDSA_SIG * |
| 239 | ecdsa_do_sign(const unsigned char *dgst, int dgst_len, | 264 | ecdsa_do_sign(const unsigned char *dgst, int dgst_len, |
| @@ -384,6 +409,18 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len, | |||
| 384 | return ret; | 409 | return ret; |
| 385 | } | 410 | } |
| 386 | 411 | ||
| 412 | /* replace w/ ecdsa_do_sign() when ECDSA_METHOD gets removed */ | ||
| 413 | ECDSA_SIG * | ||
| 414 | ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len, | ||
| 415 | const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey) | ||
| 416 | { | ||
| 417 | ECDSA_DATA *ecdsa; | ||
| 418 | |||
| 419 | if ((ecdsa = ecdsa_check(eckey)) == NULL) | ||
| 420 | return NULL; | ||
| 421 | return ecdsa->meth->ecdsa_do_sign(dgst, dgst_len, in_kinv, in_r, eckey); | ||
| 422 | } | ||
| 423 | |||
| 387 | static int | 424 | static int |
| 388 | ecdsa_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, | 425 | ecdsa_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, |
| 389 | EC_KEY *eckey) | 426 | EC_KEY *eckey) |
diff --git a/src/lib/libcrypto/ecdsa/ecs_sign.c b/src/lib/libcrypto/ecdsa/ecs_sign.c index 029a0cb562..5beb853b94 100644 --- a/src/lib/libcrypto/ecdsa/ecs_sign.c +++ b/src/lib/libcrypto/ecdsa/ecs_sign.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ecs_sign.c,v 1.6 2015/02/08 13:35:07 jsing Exp $ */ | 1 | /* $OpenBSD: ecs_sign.c,v 1.7 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -55,11 +55,13 @@ | |||
| 55 | 55 | ||
| 56 | #include <openssl/opensslconf.h> | 56 | #include <openssl/opensslconf.h> |
| 57 | 57 | ||
| 58 | #include "ecs_locl.h" | ||
| 59 | #ifndef OPENSSL_NO_ENGINE | 58 | #ifndef OPENSSL_NO_ENGINE |
| 60 | #include <openssl/engine.h> | 59 | #include <openssl/engine.h> |
| 61 | #endif | 60 | #endif |
| 62 | 61 | ||
| 62 | #include "ecs_locl.h" | ||
| 63 | #include "ec_lcl.h" | ||
| 64 | |||
| 63 | ECDSA_SIG * | 65 | ECDSA_SIG * |
| 64 | ECDSA_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) | 66 | ECDSA_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) |
| 65 | { | 67 | { |
| @@ -70,11 +72,10 @@ ECDSA_SIG * | |||
| 70 | ECDSA_do_sign_ex(const unsigned char *dgst, int dlen, const BIGNUM *kinv, | 72 | ECDSA_do_sign_ex(const unsigned char *dgst, int dlen, const BIGNUM *kinv, |
| 71 | const BIGNUM *rp, EC_KEY *eckey) | 73 | const BIGNUM *rp, EC_KEY *eckey) |
| 72 | { | 74 | { |
| 73 | ECDSA_DATA *ecdsa = ecdsa_check(eckey); | 75 | if (eckey->meth->sign_sig != NULL) |
| 74 | 76 | return eckey->meth->sign_sig(dgst, dlen, kinv, rp, eckey); | |
| 75 | if (ecdsa == NULL) | 77 | ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); |
| 76 | return NULL; | 78 | return 0; |
| 77 | return ecdsa->meth->ecdsa_do_sign(dgst, dlen, kinv, rp, eckey); | ||
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | int | 81 | int |
| @@ -88,24 +89,17 @@ int | |||
| 88 | ECDSA_sign_ex(int type, const unsigned char *dgst, int dlen, unsigned char *sig, | 89 | ECDSA_sign_ex(int type, const unsigned char *dgst, int dlen, unsigned char *sig, |
| 89 | unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey) | 90 | unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey) |
| 90 | { | 91 | { |
| 91 | ECDSA_SIG *s; | 92 | if (eckey->meth->sign != NULL) |
| 92 | 93 | return eckey->meth->sign(type, dgst, dlen, sig, siglen, kinv, r, eckey); | |
| 93 | s = ECDSA_do_sign_ex(dgst, dlen, kinv, r, eckey); | 94 | ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); |
| 94 | if (s == NULL) { | 95 | return 0; |
| 95 | *siglen = 0; | ||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | *siglen = i2d_ECDSA_SIG(s, &sig); | ||
| 99 | ECDSA_SIG_free(s); | ||
| 100 | return 1; | ||
| 101 | } | 96 | } |
| 102 | 97 | ||
| 103 | int | 98 | int |
| 104 | ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | 99 | ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) |
| 105 | { | 100 | { |
| 106 | ECDSA_DATA *ecdsa = ecdsa_check(eckey); | 101 | if (eckey->meth->sign_setup != NULL) |
| 107 | 102 | return eckey->meth->sign_setup(eckey, ctx_in, kinvp, rp); | |
| 108 | if (ecdsa == NULL) | 103 | ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); |
| 109 | return 0; | 104 | return 0; |
| 110 | return ecdsa->meth->ecdsa_sign_setup(eckey, ctx_in, kinvp, rp); | ||
| 111 | } | 105 | } |
diff --git a/src/lib/libcrypto/engine/eng_fat.c b/src/lib/libcrypto/engine/eng_fat.c index c97695a7d3..baf1a54883 100644 --- a/src/lib/libcrypto/engine/eng_fat.c +++ b/src/lib/libcrypto/engine/eng_fat.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: eng_fat.c,v 1.16 2017/01/29 17:49:23 beck Exp $ */ | 1 | /* $OpenBSD: eng_fat.c,v 1.17 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -93,6 +93,10 @@ ENGINE_set_default(ENGINE *e, unsigned int flags) | |||
| 93 | if ((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e)) | 93 | if ((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e)) |
| 94 | return 0; | 94 | return 0; |
| 95 | #endif | 95 | #endif |
| 96 | #ifndef OPENSSL_NO_EC | ||
| 97 | if ((flags & ENGINE_METHOD_EC) && !ENGINE_set_default_EC(e)) | ||
| 98 | return 0; | ||
| 99 | #endif | ||
| 96 | if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) | 100 | if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) |
| 97 | return 0; | 101 | return 0; |
| 98 | if ((flags & ENGINE_METHOD_PKEY_METHS) && | 102 | if ((flags & ENGINE_METHOD_PKEY_METHS) && |
| @@ -123,6 +127,8 @@ int_def_cb(const char *alg, int len, void *arg) | |||
| 123 | *pflags |= ENGINE_METHOD_ECDSA; | 127 | *pflags |= ENGINE_METHOD_ECDSA; |
| 124 | else if (!strncmp(alg, "DH", len)) | 128 | else if (!strncmp(alg, "DH", len)) |
| 125 | *pflags |= ENGINE_METHOD_DH; | 129 | *pflags |= ENGINE_METHOD_DH; |
| 130 | else if (strncmp(alg, "EC", len) == 0) | ||
| 131 | *pflags |= ENGINE_METHOD_EC; | ||
| 126 | else if (!strncmp(alg, "RAND", len)) | 132 | else if (!strncmp(alg, "RAND", len)) |
| 127 | *pflags |= ENGINE_METHOD_RAND; | 133 | *pflags |= ENGINE_METHOD_RAND; |
| 128 | else if (!strncmp(alg, "CIPHERS", len)) | 134 | else if (!strncmp(alg, "CIPHERS", len)) |
| @@ -174,6 +180,9 @@ ENGINE_register_complete(ENGINE *e) | |||
| 174 | #ifndef OPENSSL_NO_ECDSA | 180 | #ifndef OPENSSL_NO_ECDSA |
| 175 | ENGINE_register_ECDSA(e); | 181 | ENGINE_register_ECDSA(e); |
| 176 | #endif | 182 | #endif |
| 183 | #ifndef OPENSSL_NO_EC | ||
| 184 | ENGINE_register_EC(e); | ||
| 185 | #endif | ||
| 177 | ENGINE_register_RAND(e); | 186 | ENGINE_register_RAND(e); |
| 178 | ENGINE_register_pkey_meths(e); | 187 | ENGINE_register_pkey_meths(e); |
| 179 | return 1; | 188 | return 1; |
diff --git a/src/lib/libcrypto/engine/eng_int.h b/src/lib/libcrypto/engine/eng_int.h index dbb639949d..298c0e327f 100644 --- a/src/lib/libcrypto/engine/eng_int.h +++ b/src/lib/libcrypto/engine/eng_int.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: eng_int.h,v 1.9 2016/12/21 15:49:29 jsing Exp $ */ | 1 | /* $OpenBSD: eng_int.h,v 1.10 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL |
| 3 | * project 2000. | 3 | * project 2000. |
| 4 | */ | 4 | */ |
| @@ -159,6 +159,7 @@ struct engine_st { | |||
| 159 | const DH_METHOD *dh_meth; | 159 | const DH_METHOD *dh_meth; |
| 160 | const ECDH_METHOD *ecdh_meth; | 160 | const ECDH_METHOD *ecdh_meth; |
| 161 | const ECDSA_METHOD *ecdsa_meth; | 161 | const ECDSA_METHOD *ecdsa_meth; |
| 162 | const EC_KEY_METHOD *ec_meth; | ||
| 162 | const RAND_METHOD *rand_meth; | 163 | const RAND_METHOD *rand_meth; |
| 163 | const STORE_METHOD *store_meth; | 164 | const STORE_METHOD *store_meth; |
| 164 | /* Cipher handling is via this callback */ | 165 | /* Cipher handling is via this callback */ |
diff --git a/src/lib/libcrypto/engine/eng_list.c b/src/lib/libcrypto/engine/eng_list.c index 134866d2c6..b29b4102e4 100644 --- a/src/lib/libcrypto/engine/eng_list.c +++ b/src/lib/libcrypto/engine/eng_list.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: eng_list.c,v 1.23 2018/08/24 19:25:31 tb Exp $ */ | 1 | /* $OpenBSD: eng_list.c,v 1.24 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL |
| 3 | * project 2000. | 3 | * project 2000. |
| 4 | */ | 4 | */ |
| @@ -316,6 +316,9 @@ engine_cpy(ENGINE *dest, const ENGINE *src) | |||
| 316 | #ifndef OPENSSL_NO_ECDSA | 316 | #ifndef OPENSSL_NO_ECDSA |
| 317 | dest->ecdsa_meth = src->ecdsa_meth; | 317 | dest->ecdsa_meth = src->ecdsa_meth; |
| 318 | #endif | 318 | #endif |
| 319 | #ifndef OPENSSL_NO_EC | ||
| 320 | dest->ec_meth = src->ec_meth; | ||
| 321 | #endif | ||
| 319 | dest->rand_meth = src->rand_meth; | 322 | dest->rand_meth = src->rand_meth; |
| 320 | dest->store_meth = src->store_meth; | 323 | dest->store_meth = src->store_meth; |
| 321 | dest->ciphers = src->ciphers; | 324 | dest->ciphers = src->ciphers; |
diff --git a/src/lib/libcrypto/engine/engine.h b/src/lib/libcrypto/engine/engine.h index 0f603feaaf..dc14be8e38 100644 --- a/src/lib/libcrypto/engine/engine.h +++ b/src/lib/libcrypto/engine/engine.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: engine.h,v 1.32 2018/11/11 06:41:28 bcook Exp $ */ | 1 | /* $OpenBSD: engine.h,v 1.33 2019/01/19 01:07:00 tb Exp $ */ |
| 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL |
| 3 | * project 2000. | 3 | * project 2000. |
| 4 | */ | 4 | */ |
| @@ -87,6 +87,9 @@ | |||
| 87 | #ifndef OPENSSL_NO_ECDSA | 87 | #ifndef OPENSSL_NO_ECDSA |
| 88 | #include <openssl/ecdsa.h> | 88 | #include <openssl/ecdsa.h> |
| 89 | #endif | 89 | #endif |
| 90 | #ifndef OPENSSL_NO_EC | ||
| 91 | #include <openssl/ec.h> | ||
| 92 | #endif | ||
| 90 | #include <openssl/ui.h> | 93 | #include <openssl/ui.h> |
| 91 | #include <openssl/err.h> | 94 | #include <openssl/err.h> |
| 92 | #endif | 95 | #endif |
| @@ -112,6 +115,7 @@ extern "C" { | |||
| 112 | #define ENGINE_METHOD_STORE (unsigned int)0x0100 | 115 | #define ENGINE_METHOD_STORE (unsigned int)0x0100 |
| 113 | #define ENGINE_METHOD_PKEY_METHS (unsigned int)0x0200 | 116 | #define ENGINE_METHOD_PKEY_METHS (unsigned int)0x0200 |
| 114 | #define ENGINE_METHOD_PKEY_ASN1_METHS (unsigned int)0x0400 | 117 | #define ENGINE_METHOD_PKEY_ASN1_METHS (unsigned int)0x0400 |
| 118 | #define ENGINE_METHOD_EC (unsigned int)0x0800 | ||
| 115 | /* Obvious all-or-nothing cases. */ | 119 | /* Obvious all-or-nothing cases. */ |
| 116 | #define ENGINE_METHOD_ALL (unsigned int)0xFFFF | 120 | #define ENGINE_METHOD_ALL (unsigned int)0xFFFF |
| 117 | #define ENGINE_METHOD_NONE (unsigned int)0x0000 | 121 | #define ENGINE_METHOD_NONE (unsigned int)0x0000 |
| @@ -353,6 +357,10 @@ int ENGINE_register_ECDSA(ENGINE *e); | |||
| 353 | void ENGINE_unregister_ECDSA(ENGINE *e); | 357 | void ENGINE_unregister_ECDSA(ENGINE *e); |
| 354 | void ENGINE_register_all_ECDSA(void); | 358 | void ENGINE_register_all_ECDSA(void); |
| 355 | 359 | ||
| 360 | int ENGINE_register_EC(ENGINE *e); | ||
| 361 | void ENGINE_unregister_EC(ENGINE *e); | ||
| 362 | void ENGINE_register_all_EC(void); | ||
| 363 | |||
| 356 | int ENGINE_register_DH(ENGINE *e); | 364 | int ENGINE_register_DH(ENGINE *e); |
| 357 | void ENGINE_unregister_DH(ENGINE *e); | 365 | void ENGINE_unregister_DH(ENGINE *e); |
| 358 | void ENGINE_register_all_DH(void); | 366 | void ENGINE_register_all_DH(void); |
| @@ -447,6 +455,7 @@ int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); | |||
| 447 | int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); | 455 | int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); |
| 448 | int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth); | 456 | int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth); |
| 449 | int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth); | 457 | int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth); |
| 458 | int ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ec_meth); | ||
| 450 | int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); | 459 | int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); |
| 451 | int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); | 460 | int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); |
| 452 | int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth); | 461 | int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth); |
| @@ -486,6 +495,7 @@ const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); | |||
| 486 | const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); | 495 | const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); |
| 487 | const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e); | 496 | const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e); |
| 488 | const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e); | 497 | const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e); |
| 498 | const EC_KEY_METHOD *ENGINE_get_EC(const ENGINE *e); | ||
| 489 | const DH_METHOD *ENGINE_get_DH(const ENGINE *e); | 499 | const DH_METHOD *ENGINE_get_DH(const ENGINE *e); |
| 490 | const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); | 500 | const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); |
| 491 | const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e); | 501 | const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e); |
| @@ -553,6 +563,7 @@ ENGINE *ENGINE_get_default_RSA(void); | |||
| 553 | ENGINE *ENGINE_get_default_DSA(void); | 563 | ENGINE *ENGINE_get_default_DSA(void); |
| 554 | ENGINE *ENGINE_get_default_ECDH(void); | 564 | ENGINE *ENGINE_get_default_ECDH(void); |
| 555 | ENGINE *ENGINE_get_default_ECDSA(void); | 565 | ENGINE *ENGINE_get_default_ECDSA(void); |
| 566 | ENGINE *ENGINE_get_default_EC(void); | ||
| 556 | ENGINE *ENGINE_get_default_DH(void); | 567 | ENGINE *ENGINE_get_default_DH(void); |
| 557 | ENGINE *ENGINE_get_default_RAND(void); | 568 | ENGINE *ENGINE_get_default_RAND(void); |
| 558 | /* These functions can be used to get a functional reference to perform | 569 | /* These functions can be used to get a functional reference to perform |
| @@ -572,6 +583,7 @@ int ENGINE_set_default_string(ENGINE *e, const char *def_list); | |||
| 572 | int ENGINE_set_default_DSA(ENGINE *e); | 583 | int ENGINE_set_default_DSA(ENGINE *e); |
| 573 | int ENGINE_set_default_ECDH(ENGINE *e); | 584 | int ENGINE_set_default_ECDH(ENGINE *e); |
| 574 | int ENGINE_set_default_ECDSA(ENGINE *e); | 585 | int ENGINE_set_default_ECDSA(ENGINE *e); |
| 586 | int ENGINE_set_default_EC(ENGINE *e); | ||
| 575 | int ENGINE_set_default_DH(ENGINE *e); | 587 | int ENGINE_set_default_DH(ENGINE *e); |
| 576 | int ENGINE_set_default_RAND(ENGINE *e); | 588 | int ENGINE_set_default_RAND(ENGINE *e); |
| 577 | int ENGINE_set_default_ciphers(ENGINE *e); | 589 | int ENGINE_set_default_ciphers(ENGINE *e); |
diff --git a/src/lib/libcrypto/engine/tb_eckey.c b/src/lib/libcrypto/engine/tb_eckey.c new file mode 100644 index 0000000000..dd30815788 --- /dev/null +++ b/src/lib/libcrypto/engine/tb_eckey.c | |||
| @@ -0,0 +1,123 @@ | |||
| 1 | /* ==================================================================== | ||
| 2 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * | ||
| 8 | * 1. Redistributions of source code must retain the above copyright | ||
| 9 | * notice, this list of conditions and the following disclaimer. | ||
| 10 | * | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in | ||
| 13 | * the documentation and/or other materials provided with the | ||
| 14 | * distribution. | ||
| 15 | * | ||
| 16 | * 3. All advertising materials mentioning features or use of this | ||
| 17 | * software must display the following acknowledgment: | ||
| 18 | * "This product includes software developed by the OpenSSL Project | ||
| 19 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 20 | * | ||
| 21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 22 | * endorse or promote products derived from this software without | ||
| 23 | * prior written permission. For written permission, please contact | ||
| 24 | * licensing@OpenSSL.org. | ||
| 25 | * | ||
| 26 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 27 | * nor may "OpenSSL" appear in their names without prior written | ||
| 28 | * permission of the OpenSSL Project. | ||
| 29 | * | ||
| 30 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 31 | * acknowledgment: | ||
| 32 | * "This product includes software developed by the OpenSSL Project | ||
| 33 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 34 | * | ||
| 35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 46 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 47 | * ==================================================================== | ||
| 48 | * | ||
| 49 | * This product includes cryptographic software written by Eric Young | ||
| 50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 51 | * Hudson (tjh@cryptsoft.com). | ||
| 52 | * | ||
| 53 | */ | ||
| 54 | |||
| 55 | #include "eng_int.h" | ||
| 56 | |||
| 57 | static ENGINE_TABLE *ec_table = NULL; | ||
| 58 | static const int dummy_nid = 1; | ||
| 59 | |||
| 60 | void | ||
| 61 | ENGINE_unregister_EC(ENGINE *e) | ||
| 62 | { | ||
| 63 | engine_table_unregister(&ec_table, e); | ||
| 64 | } | ||
| 65 | |||
| 66 | static void | ||
| 67 | engine_unregister_all_EC(void) | ||
| 68 | { | ||
| 69 | engine_table_cleanup(&ec_table); | ||
| 70 | } | ||
| 71 | |||
| 72 | int | ||
| 73 | ENGINE_register_EC(ENGINE *e) | ||
| 74 | { | ||
| 75 | if (e->ec_meth) | ||
| 76 | return engine_table_register(&ec_table, | ||
| 77 | engine_unregister_all_EC, e, &dummy_nid, 1, 0); | ||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | void | ||
| 82 | ENGINE_register_all_EC(void) | ||
| 83 | { | ||
| 84 | ENGINE *e; | ||
| 85 | |||
| 86 | for (e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e)) | ||
| 87 | ENGINE_register_EC(e); | ||
| 88 | } | ||
| 89 | |||
| 90 | int | ||
| 91 | ENGINE_set_default_EC(ENGINE *e) | ||
| 92 | { | ||
| 93 | if (e->ec_meth != NULL) | ||
| 94 | return engine_table_register(&ec_table, | ||
| 95 | engine_unregister_all_EC, e, &dummy_nid, 1, 1); | ||
| 96 | return 1; | ||
| 97 | } | ||
| 98 | |||
| 99 | /* | ||
| 100 | * Exposed API function to get a functional reference from the implementation | ||
| 101 | * table (ie. try to get a functional reference from the tabled structural | ||
| 102 | * references). | ||
| 103 | */ | ||
| 104 | ENGINE * | ||
| 105 | ENGINE_get_default_EC(void) | ||
| 106 | { | ||
| 107 | return engine_table_select(&ec_table, dummy_nid); | ||
| 108 | } | ||
| 109 | |||
| 110 | /* Obtains an EC_KEY implementation from an ENGINE functional reference */ | ||
| 111 | const EC_KEY_METHOD * | ||
| 112 | ENGINE_get_EC(const ENGINE *e) | ||
| 113 | { | ||
| 114 | return e->ec_meth; | ||
| 115 | } | ||
| 116 | |||
| 117 | /* Sets an EC_KEY implementation in an ENGINE structure */ | ||
| 118 | int | ||
| 119 | ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ec_meth) | ||
| 120 | { | ||
| 121 | e->ec_meth = ec_meth; | ||
| 122 | return 1; | ||
| 123 | } | ||
