diff options
author | jsing <> | 2015-09-13 10:46:20 +0000 |
---|---|---|
committer | jsing <> | 2015-09-13 10:46:20 +0000 |
commit | 3a5b89dade4c6af7e3c236a45cd4575df392c731 (patch) | |
tree | 817bacc9b22fc4c0e55887238cb20046856e27ec /src/lib | |
parent | 0fe34ffb19fc905de54d80200f12c5b3d7d14926 (diff) | |
download | openbsd-3a5b89dade4c6af7e3c236a45cd4575df392c731.tar.gz openbsd-3a5b89dade4c6af7e3c236a45cd4575df392c731.tar.bz2 openbsd-3a5b89dade4c6af7e3c236a45cd4575df392c731.zip |
Lob a style(9) grenade in here.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/ecdh/ecdh.h | 17 | ||||
-rw-r--r-- | src/lib/libcrypto/ecdh/ech_err.c | 49 | ||||
-rw-r--r-- | src/lib/libcrypto/ecdh/ech_key.c | 11 | ||||
-rw-r--r-- | src/lib/libcrypto/ecdh/ech_lib.c | 133 | ||||
-rw-r--r-- | src/lib/libcrypto/ecdh/ech_locl.h | 11 | ||||
-rw-r--r-- | src/lib/libcrypto/ecdh/ech_ossl.c | 136 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ecdh/ecdh.h | 17 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ecdh/ech_err.c | 49 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ecdh/ech_key.c | 11 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ecdh/ech_lib.c | 133 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ecdh/ech_locl.h | 11 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ecdh/ech_ossl.c | 136 |
12 files changed, 352 insertions, 362 deletions
diff --git a/src/lib/libcrypto/ecdh/ecdh.h b/src/lib/libcrypto/ecdh/ecdh.h index c8c6920aa2..3bcb8b045e 100644 --- a/src/lib/libcrypto/ecdh/ecdh.h +++ b/src/lib/libcrypto/ecdh/ecdh.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecdh.h,v 1.2 2014/06/12 15:49:29 deraadt Exp $ */ | 1 | /* $OpenBSD: ecdh.h,v 1.3 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -21,7 +21,7 @@ | |||
21 | * are met: | 21 | * are met: |
22 | * | 22 | * |
23 | * 1. Redistributions of source code must retain the above copyright | 23 | * 1. Redistributions of source code must retain the above copyright |
24 | * notice, this list of conditions and the following disclaimer. | 24 | * notice, this list of conditions and the following disclaimer. |
25 | * | 25 | * |
26 | * 2. Redistributions in binary form must reproduce the above copyright | 26 | * 2. Redistributions in binary form must reproduce the above copyright |
27 | * notice, this list of conditions and the following disclaimer in | 27 | * notice, this list of conditions and the following disclaimer in |
@@ -87,15 +87,16 @@ extern "C" { | |||
87 | 87 | ||
88 | const ECDH_METHOD *ECDH_OpenSSL(void); | 88 | const ECDH_METHOD *ECDH_OpenSSL(void); |
89 | 89 | ||
90 | void ECDH_set_default_method(const ECDH_METHOD *); | 90 | void ECDH_set_default_method(const ECDH_METHOD *); |
91 | const ECDH_METHOD *ECDH_get_default_method(void); | 91 | const ECDH_METHOD *ECDH_get_default_method(void); |
92 | int ECDH_set_method(EC_KEY *, const ECDH_METHOD *); | 92 | int ECDH_set_method(EC_KEY *, const ECDH_METHOD *); |
93 | 93 | ||
94 | int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, | 94 | int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, |
95 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | 95 | EC_KEY *ecdh, |
96 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | ||
96 | 97 | ||
97 | int ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new | 98 | int ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new |
98 | *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | 99 | *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); |
99 | int ECDH_set_ex_data(EC_KEY *d, int idx, void *arg); | 100 | int ECDH_set_ex_data(EC_KEY *d, int idx, void *arg); |
100 | void *ECDH_get_ex_data(EC_KEY *d, int idx); | 101 | void *ECDH_get_ex_data(EC_KEY *d, int idx); |
101 | 102 | ||
diff --git a/src/lib/libcrypto/ecdh/ech_err.c b/src/lib/libcrypto/ecdh/ech_err.c index 6b417a255d..2899b573c3 100644 --- a/src/lib/libcrypto/ecdh/ech_err.c +++ b/src/lib/libcrypto/ecdh/ech_err.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ech_err.c,v 1.3 2014/07/10 22:45:57 jsing Exp $ */ | 1 | /* $OpenBSD: ech_err.c,v 1.4 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -71,33 +71,30 @@ | |||
71 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ECDH,func,0) | 71 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ECDH,func,0) |
72 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECDH,0,reason) | 72 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECDH,0,reason) |
73 | 73 | ||
74 | static ERR_STRING_DATA ECDH_str_functs[]= | 74 | static ERR_STRING_DATA ECDH_str_functs[]= { |
75 | { | 75 | {ERR_FUNC(ECDH_F_ECDH_CHECK), "ECDH_CHECK"}, |
76 | {ERR_FUNC(ECDH_F_ECDH_CHECK), "ECDH_CHECK"}, | 76 | {ERR_FUNC(ECDH_F_ECDH_COMPUTE_KEY), "ECDH_compute_key"}, |
77 | {ERR_FUNC(ECDH_F_ECDH_COMPUTE_KEY), "ECDH_compute_key"}, | 77 | {ERR_FUNC(ECDH_F_ECDH_DATA_NEW_METHOD), "ECDH_DATA_new_method"}, |
78 | {ERR_FUNC(ECDH_F_ECDH_DATA_NEW_METHOD), "ECDH_DATA_new_method"}, | 78 | {0, NULL} |
79 | {0,NULL} | 79 | }; |
80 | }; | ||
81 | 80 | ||
82 | static ERR_STRING_DATA ECDH_str_reasons[]= | 81 | static ERR_STRING_DATA ECDH_str_reasons[]= { |
83 | { | 82 | {ERR_REASON(ECDH_R_KDF_FAILED) , "KDF failed"}, |
84 | {ERR_REASON(ECDH_R_KDF_FAILED) ,"KDF failed"}, | 83 | {ERR_REASON(ECDH_R_NON_FIPS_METHOD) , "non fips method"}, |
85 | {ERR_REASON(ECDH_R_NON_FIPS_METHOD) ,"non fips method"}, | 84 | {ERR_REASON(ECDH_R_NO_PRIVATE_VALUE) , "no private value"}, |
86 | {ERR_REASON(ECDH_R_NO_PRIVATE_VALUE) ,"no private value"}, | 85 | {ERR_REASON(ECDH_R_POINT_ARITHMETIC_FAILURE), "point arithmetic failure"}, |
87 | {ERR_REASON(ECDH_R_POINT_ARITHMETIC_FAILURE),"point arithmetic failure"}, | 86 | {0, NULL} |
88 | {0,NULL} | 87 | }; |
89 | }; | ||
90 | 88 | ||
91 | #endif | 89 | #endif |
92 | 90 | ||
93 | void ERR_load_ECDH_strings(void) | 91 | void |
94 | { | 92 | ERR_load_ECDH_strings(void) |
93 | { | ||
95 | #ifndef OPENSSL_NO_ERR | 94 | #ifndef OPENSSL_NO_ERR |
96 | 95 | if (ERR_func_error_string(ECDH_str_functs[0].error) == NULL) { | |
97 | if (ERR_func_error_string(ECDH_str_functs[0].error) == NULL) | 96 | ERR_load_strings(0, ECDH_str_functs); |
98 | { | 97 | ERR_load_strings(0, ECDH_str_reasons); |
99 | ERR_load_strings(0,ECDH_str_functs); | ||
100 | ERR_load_strings(0,ECDH_str_reasons); | ||
101 | } | ||
102 | #endif | ||
103 | } | 98 | } |
99 | #endif | ||
100 | } | ||
diff --git a/src/lib/libcrypto/ecdh/ech_key.c b/src/lib/libcrypto/ecdh/ech_key.c index b0bba7f826..9a8091fe19 100644 --- a/src/lib/libcrypto/ecdh/ech_key.c +++ b/src/lib/libcrypto/ecdh/ech_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ech_key.c,v 1.2 2014/06/12 15:49:29 deraadt Exp $ */ | 1 | /* $OpenBSD: ech_key.c,v 1.3 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -21,7 +21,7 @@ | |||
21 | * are met: | 21 | * are met: |
22 | * | 22 | * |
23 | * 1. Redistributions of source code must retain the above copyright | 23 | * 1. Redistributions of source code must retain the above copyright |
24 | * notice, this list of conditions and the following disclaimer. | 24 | * notice, this list of conditions and the following disclaimer. |
25 | * | 25 | * |
26 | * 2. Redistributions in binary form must reproduce the above copyright | 26 | * 2. Redistributions in binary form must reproduce the above copyright |
27 | * notice, this list of conditions and the following disclaimer in | 27 | * notice, this list of conditions and the following disclaimer in |
@@ -69,9 +69,10 @@ | |||
69 | 69 | ||
70 | #include "ech_locl.h" | 70 | #include "ech_locl.h" |
71 | 71 | ||
72 | int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, | 72 | int |
73 | EC_KEY *eckey, | 73 | ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, |
74 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) | 74 | EC_KEY *eckey, |
75 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) | ||
75 | { | 76 | { |
76 | ECDH_DATA *ecdh = ecdh_check(eckey); | 77 | ECDH_DATA *ecdh = ecdh_check(eckey); |
77 | if (ecdh == NULL) | 78 | if (ecdh == NULL) |
diff --git a/src/lib/libcrypto/ecdh/ech_lib.c b/src/lib/libcrypto/ecdh/ech_lib.c index 58dddf638f..579dfc4b4f 100644 --- a/src/lib/libcrypto/ecdh/ech_lib.c +++ b/src/lib/libcrypto/ecdh/ech_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ech_lib.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */ | 1 | /* $OpenBSD: ech_lib.c,v 1.10 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -21,7 +21,7 @@ | |||
21 | * are met: | 21 | * are met: |
22 | * | 22 | * |
23 | * 1. Redistributions of source code must retain the above copyright | 23 | * 1. Redistributions of source code must retain the above copyright |
24 | * notice, this list of conditions and the following disclaimer. | 24 | * notice, this list of conditions and the following disclaimer. |
25 | * | 25 | * |
26 | * 2. Redistributions in binary form must reproduce the above copyright | 26 | * 2. Redistributions in binary form must reproduce the above copyright |
27 | * notice, this list of conditions and the following disclaimer in | 27 | * notice, this list of conditions and the following disclaimer in |
@@ -83,22 +83,24 @@ static void *ecdh_data_new(void); | |||
83 | static void *ecdh_data_dup(void *); | 83 | static void *ecdh_data_dup(void *); |
84 | static void ecdh_data_free(void *); | 84 | static void ecdh_data_free(void *); |
85 | 85 | ||
86 | void ECDH_set_default_method(const ECDH_METHOD *meth) | 86 | void |
87 | { | 87 | ECDH_set_default_method(const ECDH_METHOD *meth) |
88 | { | ||
88 | default_ECDH_method = meth; | 89 | default_ECDH_method = meth; |
89 | } | 90 | } |
90 | 91 | ||
91 | const ECDH_METHOD *ECDH_get_default_method(void) | 92 | const ECDH_METHOD * |
92 | { | 93 | ECDH_get_default_method(void) |
93 | if(!default_ECDH_method) | 94 | { |
94 | { | 95 | if (!default_ECDH_method) { |
95 | default_ECDH_method = ECDH_OpenSSL(); | 96 | default_ECDH_method = ECDH_OpenSSL(); |
96 | } | ||
97 | return default_ECDH_method; | ||
98 | } | 97 | } |
98 | return default_ECDH_method; | ||
99 | } | ||
99 | 100 | ||
100 | int ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth) | 101 | int |
101 | { | 102 | ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth) |
103 | { | ||
102 | ECDH_DATA *ecdh; | 104 | ECDH_DATA *ecdh; |
103 | 105 | ||
104 | ecdh = ecdh_check(eckey); | 106 | ecdh = ecdh_check(eckey); |
@@ -107,26 +109,25 @@ int ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth) | |||
107 | return 0; | 109 | return 0; |
108 | 110 | ||
109 | #ifndef OPENSSL_NO_ENGINE | 111 | #ifndef OPENSSL_NO_ENGINE |
110 | if (ecdh->engine) | 112 | if (ecdh->engine) { |
111 | { | ||
112 | ENGINE_finish(ecdh->engine); | 113 | ENGINE_finish(ecdh->engine); |
113 | ecdh->engine = NULL; | 114 | ecdh->engine = NULL; |
114 | } | ||
115 | #endif | ||
116 | ecdh->meth = meth; | ||
117 | return 1; | ||
118 | } | 115 | } |
116 | #endif | ||
117 | ecdh->meth = meth; | ||
118 | return 1; | ||
119 | } | ||
119 | 120 | ||
120 | static ECDH_DATA *ECDH_DATA_new_method(ENGINE *engine) | 121 | static ECDH_DATA * |
121 | { | 122 | ECDH_DATA_new_method(ENGINE *engine) |
123 | { | ||
122 | ECDH_DATA *ret; | 124 | ECDH_DATA *ret; |
123 | 125 | ||
124 | ret = malloc(sizeof(ECDH_DATA)); | 126 | ret = malloc(sizeof(ECDH_DATA)); |
125 | if (ret == NULL) | 127 | if (ret == NULL) { |
126 | { | ||
127 | ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE); | 128 | ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE); |
128 | return(NULL); | 129 | return (NULL); |
129 | } | 130 | } |
130 | 131 | ||
131 | ret->init = NULL; | 132 | ret->init = NULL; |
132 | 133 | ||
@@ -135,30 +136,30 @@ static ECDH_DATA *ECDH_DATA_new_method(ENGINE *engine) | |||
135 | #ifndef OPENSSL_NO_ENGINE | 136 | #ifndef OPENSSL_NO_ENGINE |
136 | if (!ret->engine) | 137 | if (!ret->engine) |
137 | ret->engine = ENGINE_get_default_ECDH(); | 138 | ret->engine = ENGINE_get_default_ECDH(); |
138 | if (ret->engine) | 139 | if (ret->engine) { |
139 | { | ||
140 | ret->meth = ENGINE_get_ECDH(ret->engine); | 140 | ret->meth = ENGINE_get_ECDH(ret->engine); |
141 | if (!ret->meth) | 141 | if (!ret->meth) { |
142 | { | ||
143 | ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_ENGINE_LIB); | 142 | ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_ENGINE_LIB); |
144 | ENGINE_finish(ret->engine); | 143 | ENGINE_finish(ret->engine); |
145 | free(ret); | 144 | free(ret); |
146 | return NULL; | 145 | return NULL; |
147 | } | ||
148 | } | 146 | } |
147 | } | ||
149 | #endif | 148 | #endif |
150 | 149 | ||
151 | ret->flags = ret->meth->flags; | 150 | ret->flags = ret->meth->flags; |
152 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ECDH, ret, &ret->ex_data); | 151 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ECDH, ret, &ret->ex_data); |
153 | return(ret); | 152 | return (ret); |
154 | } | 153 | } |
155 | 154 | ||
156 | static void *ecdh_data_new(void) | 155 | static void * |
157 | { | 156 | ecdh_data_new(void) |
157 | { | ||
158 | return (void *)ECDH_DATA_new_method(NULL); | 158 | return (void *)ECDH_DATA_new_method(NULL); |
159 | } | 159 | } |
160 | 160 | ||
161 | static void *ecdh_data_dup(void *data) | 161 | static void * |
162 | ecdh_data_dup(void *data) | ||
162 | { | 163 | { |
163 | ECDH_DATA *r = (ECDH_DATA *)data; | 164 | ECDH_DATA *r = (ECDH_DATA *)data; |
164 | 165 | ||
@@ -169,8 +170,9 @@ static void *ecdh_data_dup(void *data) | |||
169 | return (void *)ecdh_data_new(); | 170 | return (void *)ecdh_data_new(); |
170 | } | 171 | } |
171 | 172 | ||
172 | void ecdh_data_free(void *data) | 173 | void |
173 | { | 174 | ecdh_data_free(void *data) |
175 | { | ||
174 | ECDH_DATA *r = (ECDH_DATA *)data; | 176 | ECDH_DATA *r = (ECDH_DATA *)data; |
175 | 177 | ||
176 | #ifndef OPENSSL_NO_ENGINE | 178 | #ifndef OPENSSL_NO_ENGINE |
@@ -183,56 +185,57 @@ void ecdh_data_free(void *data) | |||
183 | explicit_bzero((void *)r, sizeof(ECDH_DATA)); | 185 | explicit_bzero((void *)r, sizeof(ECDH_DATA)); |
184 | 186 | ||
185 | free(r); | 187 | free(r); |
186 | } | 188 | } |
187 | 189 | ||
188 | ECDH_DATA *ecdh_check(EC_KEY *key) | 190 | ECDH_DATA * |
189 | { | 191 | ecdh_check(EC_KEY *key) |
192 | { | ||
190 | ECDH_DATA *ecdh_data; | 193 | ECDH_DATA *ecdh_data; |
191 | 194 | ||
192 | void *data = EC_KEY_get_key_method_data(key, ecdh_data_dup, | 195 | void *data = EC_KEY_get_key_method_data(key, ecdh_data_dup, |
193 | ecdh_data_free, ecdh_data_free); | 196 | ecdh_data_free, ecdh_data_free); |
194 | if (data == NULL) | 197 | if (data == NULL) { |
195 | { | ||
196 | ecdh_data = (ECDH_DATA *)ecdh_data_new(); | 198 | ecdh_data = (ECDH_DATA *)ecdh_data_new(); |
197 | if (ecdh_data == NULL) | 199 | if (ecdh_data == NULL) |
198 | return NULL; | 200 | return NULL; |
199 | data = EC_KEY_insert_key_method_data(key, (void *)ecdh_data, | 201 | data = EC_KEY_insert_key_method_data(key, (void *)ecdh_data, |
200 | ecdh_data_dup, ecdh_data_free, ecdh_data_free); | 202 | ecdh_data_dup, ecdh_data_free, ecdh_data_free); |
201 | if (data != NULL) | 203 | if (data != NULL) { |
202 | { | ||
203 | /* Another thread raced us to install the key_method | 204 | /* Another thread raced us to install the key_method |
204 | * data and won. */ | 205 | * data and won. */ |
205 | ecdh_data_free(ecdh_data); | 206 | ecdh_data_free(ecdh_data); |
206 | ecdh_data = (ECDH_DATA *)data; | 207 | ecdh_data = (ECDH_DATA *)data; |
207 | } | 208 | } |
208 | } | 209 | } else |
209 | else | ||
210 | ecdh_data = (ECDH_DATA *)data; | 210 | ecdh_data = (ECDH_DATA *)data; |
211 | 211 | ||
212 | return ecdh_data; | 212 | return ecdh_data; |
213 | } | 213 | } |
214 | 214 | ||
215 | int ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 215 | int |
216 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 216 | ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
217 | { | 217 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) |
218 | { | ||
218 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ECDH, argl, argp, | 219 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ECDH, argl, argp, |
219 | new_func, dup_func, free_func); | 220 | new_func, dup_func, free_func); |
220 | } | 221 | } |
221 | 222 | ||
222 | int ECDH_set_ex_data(EC_KEY *d, int idx, void *arg) | 223 | int |
223 | { | 224 | ECDH_set_ex_data(EC_KEY *d, int idx, void *arg) |
225 | { | ||
224 | ECDH_DATA *ecdh; | 226 | ECDH_DATA *ecdh; |
225 | ecdh = ecdh_check(d); | 227 | ecdh = ecdh_check(d); |
226 | if (ecdh == NULL) | 228 | if (ecdh == NULL) |
227 | return 0; | 229 | return 0; |
228 | return(CRYPTO_set_ex_data(&ecdh->ex_data,idx,arg)); | 230 | return (CRYPTO_set_ex_data(&ecdh->ex_data, idx, arg)); |
229 | } | 231 | } |
230 | 232 | ||
231 | void *ECDH_get_ex_data(EC_KEY *d, int idx) | 233 | void * |
232 | { | 234 | ECDH_get_ex_data(EC_KEY *d, int idx) |
235 | { | ||
233 | ECDH_DATA *ecdh; | 236 | ECDH_DATA *ecdh; |
234 | ecdh = ecdh_check(d); | 237 | ecdh = ecdh_check(d); |
235 | if (ecdh == NULL) | 238 | if (ecdh == NULL) |
236 | return NULL; | 239 | return NULL; |
237 | return(CRYPTO_get_ex_data(&ecdh->ex_data,idx)); | 240 | return (CRYPTO_get_ex_data(&ecdh->ex_data, idx)); |
238 | } | 241 | } |
diff --git a/src/lib/libcrypto/ecdh/ech_locl.h b/src/lib/libcrypto/ecdh/ech_locl.h index 077c7dab95..8338007393 100644 --- a/src/lib/libcrypto/ecdh/ech_locl.h +++ b/src/lib/libcrypto/ecdh/ech_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ech_locl.h,v 1.3 2015/02/07 13:19:15 doug Exp $ */ | 1 | /* $OpenBSD: ech_locl.h,v 1.4 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -62,14 +62,13 @@ | |||
62 | extern "C" { | 62 | extern "C" { |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | struct ecdh_method | 65 | struct ecdh_method { |
66 | { | ||
67 | const char *name; | 66 | const char *name; |
68 | int (*compute_key)(void *key, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, | 67 | int (*compute_key)(void *key, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, |
69 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | 68 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); |
70 | int flags; | 69 | int flags; |
71 | char *app_data; | 70 | char *app_data; |
72 | }; | 71 | }; |
73 | 72 | ||
74 | /* If this flag is set the ECDH method is FIPS compliant and can be used | 73 | /* If this flag is set the ECDH method is FIPS compliant and can be used |
75 | * in FIPS mode. This is set in the validated module method. If an | 74 | * in FIPS mode. This is set in the validated module method. If an |
diff --git a/src/lib/libcrypto/ecdh/ech_ossl.c b/src/lib/libcrypto/ecdh/ech_ossl.c index 4fae7cacfd..f05db87f78 100644 --- a/src/lib/libcrypto/ecdh/ech_ossl.c +++ b/src/lib/libcrypto/ecdh/ech_ossl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ech_ossl.c,v 1.9 2015/02/09 15:49:22 jsing Exp $ */ | 1 | /* $OpenBSD: ech_ossl.c,v 1.10 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -21,7 +21,7 @@ | |||
21 | * are met: | 21 | * are met: |
22 | * | 22 | * |
23 | * 1. Redistributions of source code must retain the above copyright | 23 | * 1. Redistributions of source code must retain the above copyright |
24 | * notice, this list of conditions and the following disclaimer. | 24 | * notice, this list of conditions and the following disclaimer. |
25 | * | 25 | * |
26 | * 2. Redistributions in binary form must reproduce the above copyright | 26 | * 2. Redistributions in binary form must reproduce the above copyright |
27 | * notice, this list of conditions and the following disclaimer in | 27 | * notice, this list of conditions and the following disclaimer in |
@@ -80,18 +80,19 @@ | |||
80 | #include "ech_locl.h" | 80 | #include "ech_locl.h" |
81 | 81 | ||
82 | static int ecdh_compute_key(void *out, size_t len, const EC_POINT *pub_key, | 82 | static int ecdh_compute_key(void *out, size_t len, const EC_POINT *pub_key, |
83 | EC_KEY *ecdh, | 83 | EC_KEY *ecdh, |
84 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | 84 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); |
85 | 85 | ||
86 | static ECDH_METHOD openssl_ecdh_meth = { | 86 | static ECDH_METHOD openssl_ecdh_meth = { |
87 | .name = "OpenSSL ECDH method", | 87 | .name = "OpenSSL ECDH method", |
88 | .compute_key = ecdh_compute_key | 88 | .compute_key = ecdh_compute_key |
89 | }; | 89 | }; |
90 | 90 | ||
91 | const ECDH_METHOD *ECDH_OpenSSL(void) | 91 | const ECDH_METHOD * |
92 | { | 92 | ECDH_OpenSSL(void) |
93 | { | ||
93 | return &openssl_ecdh_meth; | 94 | return &openssl_ecdh_meth; |
94 | } | 95 | } |
95 | 96 | ||
96 | 97 | ||
97 | /* This implementation is based on the following primitives in the IEEE 1363 standard: | 98 | /* This implementation is based on the following primitives in the IEEE 1363 standard: |
@@ -99,114 +100,107 @@ const ECDH_METHOD *ECDH_OpenSSL(void) | |||
99 | * - ECSVDP-DH | 100 | * - ECSVDP-DH |
100 | * Finally an optional KDF is applied. | 101 | * Finally an optional KDF is applied. |
101 | */ | 102 | */ |
102 | static int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, | 103 | static int |
103 | EC_KEY *ecdh, | 104 | ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, |
104 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) | 105 | EC_KEY *ecdh, |
105 | { | 106 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) |
107 | { | ||
106 | BN_CTX *ctx; | 108 | BN_CTX *ctx; |
107 | EC_POINT *tmp=NULL; | 109 | EC_POINT *tmp = NULL; |
108 | BIGNUM *x=NULL, *y=NULL; | 110 | BIGNUM *x = NULL, *y = NULL; |
109 | const BIGNUM *priv_key; | 111 | const BIGNUM *priv_key; |
110 | const EC_GROUP* group; | 112 | const EC_GROUP* group; |
111 | int ret= -1; | 113 | int ret = -1; |
112 | size_t buflen, len; | 114 | size_t buflen, len; |
113 | unsigned char *buf=NULL; | 115 | unsigned char *buf = NULL; |
114 | 116 | ||
115 | if (outlen > INT_MAX) | 117 | if (outlen > INT_MAX) { |
116 | { | ||
117 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); /* sort of, anyway */ | 118 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); /* sort of, anyway */ |
118 | return -1; | 119 | return -1; |
119 | } | 120 | } |
120 | 121 | ||
121 | if ((ctx = BN_CTX_new()) == NULL) goto err; | 122 | if ((ctx = BN_CTX_new()) == NULL) |
123 | goto err; | ||
122 | BN_CTX_start(ctx); | 124 | BN_CTX_start(ctx); |
123 | if ((x = BN_CTX_get(ctx)) == NULL) | 125 | if ((x = BN_CTX_get(ctx)) == NULL) |
124 | goto err; | 126 | goto err; |
125 | if ((y = BN_CTX_get(ctx)) == NULL) | 127 | if ((y = BN_CTX_get(ctx)) == NULL) |
126 | goto err; | 128 | goto err; |
127 | 129 | ||
128 | priv_key = EC_KEY_get0_private_key(ecdh); | 130 | priv_key = EC_KEY_get0_private_key(ecdh); |
129 | if (priv_key == NULL) | 131 | if (priv_key == NULL) { |
130 | { | 132 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_NO_PRIVATE_VALUE); |
131 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_NO_PRIVATE_VALUE); | ||
132 | goto err; | 133 | goto err; |
133 | } | 134 | } |
134 | 135 | ||
135 | group = EC_KEY_get0_group(ecdh); | 136 | group = EC_KEY_get0_group(ecdh); |
136 | if ((tmp=EC_POINT_new(group)) == NULL) | 137 | if ((tmp = EC_POINT_new(group)) == NULL) { |
137 | { | 138 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); |
138 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); | ||
139 | goto err; | 139 | goto err; |
140 | } | 140 | } |
141 | 141 | ||
142 | if (!EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx)) | 142 | if (!EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx)) { |
143 | { | 143 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, |
144 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | 144 | ECDH_R_POINT_ARITHMETIC_FAILURE); |
145 | goto err; | 145 | goto err; |
146 | } | 146 | } |
147 | 147 | ||
148 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) | 148 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == |
149 | { | 149 | NID_X9_62_prime_field) { |
150 | if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, y, ctx)) | 150 | if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, y, |
151 | { | 151 | ctx)) { |
152 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | 152 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, |
153 | ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
153 | goto err; | 154 | goto err; |
154 | } | ||
155 | } | 155 | } |
156 | } | ||
156 | #ifndef OPENSSL_NO_EC2M | 157 | #ifndef OPENSSL_NO_EC2M |
157 | else | 158 | else { |
158 | { | 159 | if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y, |
159 | if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y, ctx)) | 160 | ctx)) { |
160 | { | 161 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, |
161 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | 162 | ECDH_R_POINT_ARITHMETIC_FAILURE); |
162 | goto err; | 163 | goto err; |
163 | } | ||
164 | } | 164 | } |
165 | } | ||
165 | #endif | 166 | #endif |
166 | 167 | ||
167 | buflen = (EC_GROUP_get_degree(group) + 7)/8; | 168 | buflen = (EC_GROUP_get_degree(group) + 7)/8; |
168 | len = BN_num_bytes(x); | 169 | len = BN_num_bytes(x); |
169 | if (len > buflen) | 170 | if (len > buflen) { |
170 | { | 171 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR); |
171 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_INTERNAL_ERROR); | ||
172 | goto err; | 172 | goto err; |
173 | } | 173 | } |
174 | if ((buf = malloc(buflen)) == NULL) | 174 | if ((buf = malloc(buflen)) == NULL) { |
175 | { | 175 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); |
176 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); | ||
177 | goto err; | 176 | goto err; |
178 | } | 177 | } |
179 | 178 | ||
180 | memset(buf, 0, buflen - len); | 179 | memset(buf, 0, buflen - len); |
181 | if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) | 180 | if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) { |
182 | { | 181 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); |
183 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
184 | goto err; | 182 | goto err; |
185 | } | 183 | } |
186 | 184 | ||
187 | if (KDF != 0) | 185 | if (KDF != 0) { |
188 | { | 186 | if (KDF(buf, buflen, out, &outlen) == NULL) { |
189 | if (KDF(buf, buflen, out, &outlen) == NULL) | 187 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KDF_FAILED); |
190 | { | ||
191 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_KDF_FAILED); | ||
192 | goto err; | 188 | goto err; |
193 | } | ||
194 | ret = outlen; | ||
195 | } | 189 | } |
196 | else | 190 | ret = outlen; |
197 | { | 191 | } else { |
198 | /* no KDF, just copy as much as we can */ | 192 | /* no KDF, just copy as much as we can */ |
199 | if (outlen > buflen) | 193 | if (outlen > buflen) |
200 | outlen = buflen; | 194 | outlen = buflen; |
201 | memcpy(out, buf, outlen); | 195 | memcpy(out, buf, outlen); |
202 | ret = outlen; | 196 | ret = outlen; |
203 | } | 197 | } |
204 | 198 | ||
205 | err: | 199 | err: |
206 | EC_POINT_free(tmp); | 200 | EC_POINT_free(tmp); |
207 | if (ctx) | 201 | if (ctx) |
208 | BN_CTX_end(ctx); | 202 | BN_CTX_end(ctx); |
209 | BN_CTX_free(ctx); | 203 | BN_CTX_free(ctx); |
210 | free(buf); | 204 | free(buf); |
211 | return(ret); | 205 | return (ret); |
212 | } | 206 | } |
diff --git a/src/lib/libssl/src/crypto/ecdh/ecdh.h b/src/lib/libssl/src/crypto/ecdh/ecdh.h index c8c6920aa2..3bcb8b045e 100644 --- a/src/lib/libssl/src/crypto/ecdh/ecdh.h +++ b/src/lib/libssl/src/crypto/ecdh/ecdh.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecdh.h,v 1.2 2014/06/12 15:49:29 deraadt Exp $ */ | 1 | /* $OpenBSD: ecdh.h,v 1.3 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -21,7 +21,7 @@ | |||
21 | * are met: | 21 | * are met: |
22 | * | 22 | * |
23 | * 1. Redistributions of source code must retain the above copyright | 23 | * 1. Redistributions of source code must retain the above copyright |
24 | * notice, this list of conditions and the following disclaimer. | 24 | * notice, this list of conditions and the following disclaimer. |
25 | * | 25 | * |
26 | * 2. Redistributions in binary form must reproduce the above copyright | 26 | * 2. Redistributions in binary form must reproduce the above copyright |
27 | * notice, this list of conditions and the following disclaimer in | 27 | * notice, this list of conditions and the following disclaimer in |
@@ -87,15 +87,16 @@ extern "C" { | |||
87 | 87 | ||
88 | const ECDH_METHOD *ECDH_OpenSSL(void); | 88 | const ECDH_METHOD *ECDH_OpenSSL(void); |
89 | 89 | ||
90 | void ECDH_set_default_method(const ECDH_METHOD *); | 90 | void ECDH_set_default_method(const ECDH_METHOD *); |
91 | const ECDH_METHOD *ECDH_get_default_method(void); | 91 | const ECDH_METHOD *ECDH_get_default_method(void); |
92 | int ECDH_set_method(EC_KEY *, const ECDH_METHOD *); | 92 | int ECDH_set_method(EC_KEY *, const ECDH_METHOD *); |
93 | 93 | ||
94 | int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, | 94 | int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, |
95 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | 95 | EC_KEY *ecdh, |
96 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | ||
96 | 97 | ||
97 | int ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new | 98 | int ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new |
98 | *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | 99 | *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); |
99 | int ECDH_set_ex_data(EC_KEY *d, int idx, void *arg); | 100 | int ECDH_set_ex_data(EC_KEY *d, int idx, void *arg); |
100 | void *ECDH_get_ex_data(EC_KEY *d, int idx); | 101 | void *ECDH_get_ex_data(EC_KEY *d, int idx); |
101 | 102 | ||
diff --git a/src/lib/libssl/src/crypto/ecdh/ech_err.c b/src/lib/libssl/src/crypto/ecdh/ech_err.c index 6b417a255d..2899b573c3 100644 --- a/src/lib/libssl/src/crypto/ecdh/ech_err.c +++ b/src/lib/libssl/src/crypto/ecdh/ech_err.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ech_err.c,v 1.3 2014/07/10 22:45:57 jsing Exp $ */ | 1 | /* $OpenBSD: ech_err.c,v 1.4 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -71,33 +71,30 @@ | |||
71 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ECDH,func,0) | 71 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ECDH,func,0) |
72 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECDH,0,reason) | 72 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECDH,0,reason) |
73 | 73 | ||
74 | static ERR_STRING_DATA ECDH_str_functs[]= | 74 | static ERR_STRING_DATA ECDH_str_functs[]= { |
75 | { | 75 | {ERR_FUNC(ECDH_F_ECDH_CHECK), "ECDH_CHECK"}, |
76 | {ERR_FUNC(ECDH_F_ECDH_CHECK), "ECDH_CHECK"}, | 76 | {ERR_FUNC(ECDH_F_ECDH_COMPUTE_KEY), "ECDH_compute_key"}, |
77 | {ERR_FUNC(ECDH_F_ECDH_COMPUTE_KEY), "ECDH_compute_key"}, | 77 | {ERR_FUNC(ECDH_F_ECDH_DATA_NEW_METHOD), "ECDH_DATA_new_method"}, |
78 | {ERR_FUNC(ECDH_F_ECDH_DATA_NEW_METHOD), "ECDH_DATA_new_method"}, | 78 | {0, NULL} |
79 | {0,NULL} | 79 | }; |
80 | }; | ||
81 | 80 | ||
82 | static ERR_STRING_DATA ECDH_str_reasons[]= | 81 | static ERR_STRING_DATA ECDH_str_reasons[]= { |
83 | { | 82 | {ERR_REASON(ECDH_R_KDF_FAILED) , "KDF failed"}, |
84 | {ERR_REASON(ECDH_R_KDF_FAILED) ,"KDF failed"}, | 83 | {ERR_REASON(ECDH_R_NON_FIPS_METHOD) , "non fips method"}, |
85 | {ERR_REASON(ECDH_R_NON_FIPS_METHOD) ,"non fips method"}, | 84 | {ERR_REASON(ECDH_R_NO_PRIVATE_VALUE) , "no private value"}, |
86 | {ERR_REASON(ECDH_R_NO_PRIVATE_VALUE) ,"no private value"}, | 85 | {ERR_REASON(ECDH_R_POINT_ARITHMETIC_FAILURE), "point arithmetic failure"}, |
87 | {ERR_REASON(ECDH_R_POINT_ARITHMETIC_FAILURE),"point arithmetic failure"}, | 86 | {0, NULL} |
88 | {0,NULL} | 87 | }; |
89 | }; | ||
90 | 88 | ||
91 | #endif | 89 | #endif |
92 | 90 | ||
93 | void ERR_load_ECDH_strings(void) | 91 | void |
94 | { | 92 | ERR_load_ECDH_strings(void) |
93 | { | ||
95 | #ifndef OPENSSL_NO_ERR | 94 | #ifndef OPENSSL_NO_ERR |
96 | 95 | if (ERR_func_error_string(ECDH_str_functs[0].error) == NULL) { | |
97 | if (ERR_func_error_string(ECDH_str_functs[0].error) == NULL) | 96 | ERR_load_strings(0, ECDH_str_functs); |
98 | { | 97 | ERR_load_strings(0, ECDH_str_reasons); |
99 | ERR_load_strings(0,ECDH_str_functs); | ||
100 | ERR_load_strings(0,ECDH_str_reasons); | ||
101 | } | ||
102 | #endif | ||
103 | } | 98 | } |
99 | #endif | ||
100 | } | ||
diff --git a/src/lib/libssl/src/crypto/ecdh/ech_key.c b/src/lib/libssl/src/crypto/ecdh/ech_key.c index b0bba7f826..9a8091fe19 100644 --- a/src/lib/libssl/src/crypto/ecdh/ech_key.c +++ b/src/lib/libssl/src/crypto/ecdh/ech_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ech_key.c,v 1.2 2014/06/12 15:49:29 deraadt Exp $ */ | 1 | /* $OpenBSD: ech_key.c,v 1.3 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -21,7 +21,7 @@ | |||
21 | * are met: | 21 | * are met: |
22 | * | 22 | * |
23 | * 1. Redistributions of source code must retain the above copyright | 23 | * 1. Redistributions of source code must retain the above copyright |
24 | * notice, this list of conditions and the following disclaimer. | 24 | * notice, this list of conditions and the following disclaimer. |
25 | * | 25 | * |
26 | * 2. Redistributions in binary form must reproduce the above copyright | 26 | * 2. Redistributions in binary form must reproduce the above copyright |
27 | * notice, this list of conditions and the following disclaimer in | 27 | * notice, this list of conditions and the following disclaimer in |
@@ -69,9 +69,10 @@ | |||
69 | 69 | ||
70 | #include "ech_locl.h" | 70 | #include "ech_locl.h" |
71 | 71 | ||
72 | int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, | 72 | int |
73 | EC_KEY *eckey, | 73 | ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, |
74 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) | 74 | EC_KEY *eckey, |
75 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) | ||
75 | { | 76 | { |
76 | ECDH_DATA *ecdh = ecdh_check(eckey); | 77 | ECDH_DATA *ecdh = ecdh_check(eckey); |
77 | if (ecdh == NULL) | 78 | if (ecdh == NULL) |
diff --git a/src/lib/libssl/src/crypto/ecdh/ech_lib.c b/src/lib/libssl/src/crypto/ecdh/ech_lib.c index 58dddf638f..579dfc4b4f 100644 --- a/src/lib/libssl/src/crypto/ecdh/ech_lib.c +++ b/src/lib/libssl/src/crypto/ecdh/ech_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ech_lib.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */ | 1 | /* $OpenBSD: ech_lib.c,v 1.10 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -21,7 +21,7 @@ | |||
21 | * are met: | 21 | * are met: |
22 | * | 22 | * |
23 | * 1. Redistributions of source code must retain the above copyright | 23 | * 1. Redistributions of source code must retain the above copyright |
24 | * notice, this list of conditions and the following disclaimer. | 24 | * notice, this list of conditions and the following disclaimer. |
25 | * | 25 | * |
26 | * 2. Redistributions in binary form must reproduce the above copyright | 26 | * 2. Redistributions in binary form must reproduce the above copyright |
27 | * notice, this list of conditions and the following disclaimer in | 27 | * notice, this list of conditions and the following disclaimer in |
@@ -83,22 +83,24 @@ static void *ecdh_data_new(void); | |||
83 | static void *ecdh_data_dup(void *); | 83 | static void *ecdh_data_dup(void *); |
84 | static void ecdh_data_free(void *); | 84 | static void ecdh_data_free(void *); |
85 | 85 | ||
86 | void ECDH_set_default_method(const ECDH_METHOD *meth) | 86 | void |
87 | { | 87 | ECDH_set_default_method(const ECDH_METHOD *meth) |
88 | { | ||
88 | default_ECDH_method = meth; | 89 | default_ECDH_method = meth; |
89 | } | 90 | } |
90 | 91 | ||
91 | const ECDH_METHOD *ECDH_get_default_method(void) | 92 | const ECDH_METHOD * |
92 | { | 93 | ECDH_get_default_method(void) |
93 | if(!default_ECDH_method) | 94 | { |
94 | { | 95 | if (!default_ECDH_method) { |
95 | default_ECDH_method = ECDH_OpenSSL(); | 96 | default_ECDH_method = ECDH_OpenSSL(); |
96 | } | ||
97 | return default_ECDH_method; | ||
98 | } | 97 | } |
98 | return default_ECDH_method; | ||
99 | } | ||
99 | 100 | ||
100 | int ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth) | 101 | int |
101 | { | 102 | ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth) |
103 | { | ||
102 | ECDH_DATA *ecdh; | 104 | ECDH_DATA *ecdh; |
103 | 105 | ||
104 | ecdh = ecdh_check(eckey); | 106 | ecdh = ecdh_check(eckey); |
@@ -107,26 +109,25 @@ int ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth) | |||
107 | return 0; | 109 | return 0; |
108 | 110 | ||
109 | #ifndef OPENSSL_NO_ENGINE | 111 | #ifndef OPENSSL_NO_ENGINE |
110 | if (ecdh->engine) | 112 | if (ecdh->engine) { |
111 | { | ||
112 | ENGINE_finish(ecdh->engine); | 113 | ENGINE_finish(ecdh->engine); |
113 | ecdh->engine = NULL; | 114 | ecdh->engine = NULL; |
114 | } | ||
115 | #endif | ||
116 | ecdh->meth = meth; | ||
117 | return 1; | ||
118 | } | 115 | } |
116 | #endif | ||
117 | ecdh->meth = meth; | ||
118 | return 1; | ||
119 | } | ||
119 | 120 | ||
120 | static ECDH_DATA *ECDH_DATA_new_method(ENGINE *engine) | 121 | static ECDH_DATA * |
121 | { | 122 | ECDH_DATA_new_method(ENGINE *engine) |
123 | { | ||
122 | ECDH_DATA *ret; | 124 | ECDH_DATA *ret; |
123 | 125 | ||
124 | ret = malloc(sizeof(ECDH_DATA)); | 126 | ret = malloc(sizeof(ECDH_DATA)); |
125 | if (ret == NULL) | 127 | if (ret == NULL) { |
126 | { | ||
127 | ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE); | 128 | ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE); |
128 | return(NULL); | 129 | return (NULL); |
129 | } | 130 | } |
130 | 131 | ||
131 | ret->init = NULL; | 132 | ret->init = NULL; |
132 | 133 | ||
@@ -135,30 +136,30 @@ static ECDH_DATA *ECDH_DATA_new_method(ENGINE *engine) | |||
135 | #ifndef OPENSSL_NO_ENGINE | 136 | #ifndef OPENSSL_NO_ENGINE |
136 | if (!ret->engine) | 137 | if (!ret->engine) |
137 | ret->engine = ENGINE_get_default_ECDH(); | 138 | ret->engine = ENGINE_get_default_ECDH(); |
138 | if (ret->engine) | 139 | if (ret->engine) { |
139 | { | ||
140 | ret->meth = ENGINE_get_ECDH(ret->engine); | 140 | ret->meth = ENGINE_get_ECDH(ret->engine); |
141 | if (!ret->meth) | 141 | if (!ret->meth) { |
142 | { | ||
143 | ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_ENGINE_LIB); | 142 | ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_ENGINE_LIB); |
144 | ENGINE_finish(ret->engine); | 143 | ENGINE_finish(ret->engine); |
145 | free(ret); | 144 | free(ret); |
146 | return NULL; | 145 | return NULL; |
147 | } | ||
148 | } | 146 | } |
147 | } | ||
149 | #endif | 148 | #endif |
150 | 149 | ||
151 | ret->flags = ret->meth->flags; | 150 | ret->flags = ret->meth->flags; |
152 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ECDH, ret, &ret->ex_data); | 151 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ECDH, ret, &ret->ex_data); |
153 | return(ret); | 152 | return (ret); |
154 | } | 153 | } |
155 | 154 | ||
156 | static void *ecdh_data_new(void) | 155 | static void * |
157 | { | 156 | ecdh_data_new(void) |
157 | { | ||
158 | return (void *)ECDH_DATA_new_method(NULL); | 158 | return (void *)ECDH_DATA_new_method(NULL); |
159 | } | 159 | } |
160 | 160 | ||
161 | static void *ecdh_data_dup(void *data) | 161 | static void * |
162 | ecdh_data_dup(void *data) | ||
162 | { | 163 | { |
163 | ECDH_DATA *r = (ECDH_DATA *)data; | 164 | ECDH_DATA *r = (ECDH_DATA *)data; |
164 | 165 | ||
@@ -169,8 +170,9 @@ static void *ecdh_data_dup(void *data) | |||
169 | return (void *)ecdh_data_new(); | 170 | return (void *)ecdh_data_new(); |
170 | } | 171 | } |
171 | 172 | ||
172 | void ecdh_data_free(void *data) | 173 | void |
173 | { | 174 | ecdh_data_free(void *data) |
175 | { | ||
174 | ECDH_DATA *r = (ECDH_DATA *)data; | 176 | ECDH_DATA *r = (ECDH_DATA *)data; |
175 | 177 | ||
176 | #ifndef OPENSSL_NO_ENGINE | 178 | #ifndef OPENSSL_NO_ENGINE |
@@ -183,56 +185,57 @@ void ecdh_data_free(void *data) | |||
183 | explicit_bzero((void *)r, sizeof(ECDH_DATA)); | 185 | explicit_bzero((void *)r, sizeof(ECDH_DATA)); |
184 | 186 | ||
185 | free(r); | 187 | free(r); |
186 | } | 188 | } |
187 | 189 | ||
188 | ECDH_DATA *ecdh_check(EC_KEY *key) | 190 | ECDH_DATA * |
189 | { | 191 | ecdh_check(EC_KEY *key) |
192 | { | ||
190 | ECDH_DATA *ecdh_data; | 193 | ECDH_DATA *ecdh_data; |
191 | 194 | ||
192 | void *data = EC_KEY_get_key_method_data(key, ecdh_data_dup, | 195 | void *data = EC_KEY_get_key_method_data(key, ecdh_data_dup, |
193 | ecdh_data_free, ecdh_data_free); | 196 | ecdh_data_free, ecdh_data_free); |
194 | if (data == NULL) | 197 | if (data == NULL) { |
195 | { | ||
196 | ecdh_data = (ECDH_DATA *)ecdh_data_new(); | 198 | ecdh_data = (ECDH_DATA *)ecdh_data_new(); |
197 | if (ecdh_data == NULL) | 199 | if (ecdh_data == NULL) |
198 | return NULL; | 200 | return NULL; |
199 | data = EC_KEY_insert_key_method_data(key, (void *)ecdh_data, | 201 | data = EC_KEY_insert_key_method_data(key, (void *)ecdh_data, |
200 | ecdh_data_dup, ecdh_data_free, ecdh_data_free); | 202 | ecdh_data_dup, ecdh_data_free, ecdh_data_free); |
201 | if (data != NULL) | 203 | if (data != NULL) { |
202 | { | ||
203 | /* Another thread raced us to install the key_method | 204 | /* Another thread raced us to install the key_method |
204 | * data and won. */ | 205 | * data and won. */ |
205 | ecdh_data_free(ecdh_data); | 206 | ecdh_data_free(ecdh_data); |
206 | ecdh_data = (ECDH_DATA *)data; | 207 | ecdh_data = (ECDH_DATA *)data; |
207 | } | 208 | } |
208 | } | 209 | } else |
209 | else | ||
210 | ecdh_data = (ECDH_DATA *)data; | 210 | ecdh_data = (ECDH_DATA *)data; |
211 | 211 | ||
212 | return ecdh_data; | 212 | return ecdh_data; |
213 | } | 213 | } |
214 | 214 | ||
215 | int ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 215 | int |
216 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 216 | ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
217 | { | 217 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) |
218 | { | ||
218 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ECDH, argl, argp, | 219 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ECDH, argl, argp, |
219 | new_func, dup_func, free_func); | 220 | new_func, dup_func, free_func); |
220 | } | 221 | } |
221 | 222 | ||
222 | int ECDH_set_ex_data(EC_KEY *d, int idx, void *arg) | 223 | int |
223 | { | 224 | ECDH_set_ex_data(EC_KEY *d, int idx, void *arg) |
225 | { | ||
224 | ECDH_DATA *ecdh; | 226 | ECDH_DATA *ecdh; |
225 | ecdh = ecdh_check(d); | 227 | ecdh = ecdh_check(d); |
226 | if (ecdh == NULL) | 228 | if (ecdh == NULL) |
227 | return 0; | 229 | return 0; |
228 | return(CRYPTO_set_ex_data(&ecdh->ex_data,idx,arg)); | 230 | return (CRYPTO_set_ex_data(&ecdh->ex_data, idx, arg)); |
229 | } | 231 | } |
230 | 232 | ||
231 | void *ECDH_get_ex_data(EC_KEY *d, int idx) | 233 | void * |
232 | { | 234 | ECDH_get_ex_data(EC_KEY *d, int idx) |
235 | { | ||
233 | ECDH_DATA *ecdh; | 236 | ECDH_DATA *ecdh; |
234 | ecdh = ecdh_check(d); | 237 | ecdh = ecdh_check(d); |
235 | if (ecdh == NULL) | 238 | if (ecdh == NULL) |
236 | return NULL; | 239 | return NULL; |
237 | return(CRYPTO_get_ex_data(&ecdh->ex_data,idx)); | 240 | return (CRYPTO_get_ex_data(&ecdh->ex_data, idx)); |
238 | } | 241 | } |
diff --git a/src/lib/libssl/src/crypto/ecdh/ech_locl.h b/src/lib/libssl/src/crypto/ecdh/ech_locl.h index 077c7dab95..8338007393 100644 --- a/src/lib/libssl/src/crypto/ecdh/ech_locl.h +++ b/src/lib/libssl/src/crypto/ecdh/ech_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ech_locl.h,v 1.3 2015/02/07 13:19:15 doug Exp $ */ | 1 | /* $OpenBSD: ech_locl.h,v 1.4 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -62,14 +62,13 @@ | |||
62 | extern "C" { | 62 | extern "C" { |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | struct ecdh_method | 65 | struct ecdh_method { |
66 | { | ||
67 | const char *name; | 66 | const char *name; |
68 | int (*compute_key)(void *key, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, | 67 | int (*compute_key)(void *key, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, |
69 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | 68 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); |
70 | int flags; | 69 | int flags; |
71 | char *app_data; | 70 | char *app_data; |
72 | }; | 71 | }; |
73 | 72 | ||
74 | /* If this flag is set the ECDH method is FIPS compliant and can be used | 73 | /* If this flag is set the ECDH method is FIPS compliant and can be used |
75 | * in FIPS mode. This is set in the validated module method. If an | 74 | * in FIPS mode. This is set in the validated module method. If an |
diff --git a/src/lib/libssl/src/crypto/ecdh/ech_ossl.c b/src/lib/libssl/src/crypto/ecdh/ech_ossl.c index 4fae7cacfd..f05db87f78 100644 --- a/src/lib/libssl/src/crypto/ecdh/ech_ossl.c +++ b/src/lib/libssl/src/crypto/ecdh/ech_ossl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ech_ossl.c,v 1.9 2015/02/09 15:49:22 jsing Exp $ */ | 1 | /* $OpenBSD: ech_ossl.c,v 1.10 2015/09/13 10:46:20 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -21,7 +21,7 @@ | |||
21 | * are met: | 21 | * are met: |
22 | * | 22 | * |
23 | * 1. Redistributions of source code must retain the above copyright | 23 | * 1. Redistributions of source code must retain the above copyright |
24 | * notice, this list of conditions and the following disclaimer. | 24 | * notice, this list of conditions and the following disclaimer. |
25 | * | 25 | * |
26 | * 2. Redistributions in binary form must reproduce the above copyright | 26 | * 2. Redistributions in binary form must reproduce the above copyright |
27 | * notice, this list of conditions and the following disclaimer in | 27 | * notice, this list of conditions and the following disclaimer in |
@@ -80,18 +80,19 @@ | |||
80 | #include "ech_locl.h" | 80 | #include "ech_locl.h" |
81 | 81 | ||
82 | static int ecdh_compute_key(void *out, size_t len, const EC_POINT *pub_key, | 82 | static int ecdh_compute_key(void *out, size_t len, const EC_POINT *pub_key, |
83 | EC_KEY *ecdh, | 83 | EC_KEY *ecdh, |
84 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | 84 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); |
85 | 85 | ||
86 | static ECDH_METHOD openssl_ecdh_meth = { | 86 | static ECDH_METHOD openssl_ecdh_meth = { |
87 | .name = "OpenSSL ECDH method", | 87 | .name = "OpenSSL ECDH method", |
88 | .compute_key = ecdh_compute_key | 88 | .compute_key = ecdh_compute_key |
89 | }; | 89 | }; |
90 | 90 | ||
91 | const ECDH_METHOD *ECDH_OpenSSL(void) | 91 | const ECDH_METHOD * |
92 | { | 92 | ECDH_OpenSSL(void) |
93 | { | ||
93 | return &openssl_ecdh_meth; | 94 | return &openssl_ecdh_meth; |
94 | } | 95 | } |
95 | 96 | ||
96 | 97 | ||
97 | /* This implementation is based on the following primitives in the IEEE 1363 standard: | 98 | /* This implementation is based on the following primitives in the IEEE 1363 standard: |
@@ -99,114 +100,107 @@ const ECDH_METHOD *ECDH_OpenSSL(void) | |||
99 | * - ECSVDP-DH | 100 | * - ECSVDP-DH |
100 | * Finally an optional KDF is applied. | 101 | * Finally an optional KDF is applied. |
101 | */ | 102 | */ |
102 | static int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, | 103 | static int |
103 | EC_KEY *ecdh, | 104 | ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, |
104 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) | 105 | EC_KEY *ecdh, |
105 | { | 106 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) |
107 | { | ||
106 | BN_CTX *ctx; | 108 | BN_CTX *ctx; |
107 | EC_POINT *tmp=NULL; | 109 | EC_POINT *tmp = NULL; |
108 | BIGNUM *x=NULL, *y=NULL; | 110 | BIGNUM *x = NULL, *y = NULL; |
109 | const BIGNUM *priv_key; | 111 | const BIGNUM *priv_key; |
110 | const EC_GROUP* group; | 112 | const EC_GROUP* group; |
111 | int ret= -1; | 113 | int ret = -1; |
112 | size_t buflen, len; | 114 | size_t buflen, len; |
113 | unsigned char *buf=NULL; | 115 | unsigned char *buf = NULL; |
114 | 116 | ||
115 | if (outlen > INT_MAX) | 117 | if (outlen > INT_MAX) { |
116 | { | ||
117 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); /* sort of, anyway */ | 118 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); /* sort of, anyway */ |
118 | return -1; | 119 | return -1; |
119 | } | 120 | } |
120 | 121 | ||
121 | if ((ctx = BN_CTX_new()) == NULL) goto err; | 122 | if ((ctx = BN_CTX_new()) == NULL) |
123 | goto err; | ||
122 | BN_CTX_start(ctx); | 124 | BN_CTX_start(ctx); |
123 | if ((x = BN_CTX_get(ctx)) == NULL) | 125 | if ((x = BN_CTX_get(ctx)) == NULL) |
124 | goto err; | 126 | goto err; |
125 | if ((y = BN_CTX_get(ctx)) == NULL) | 127 | if ((y = BN_CTX_get(ctx)) == NULL) |
126 | goto err; | 128 | goto err; |
127 | 129 | ||
128 | priv_key = EC_KEY_get0_private_key(ecdh); | 130 | priv_key = EC_KEY_get0_private_key(ecdh); |
129 | if (priv_key == NULL) | 131 | if (priv_key == NULL) { |
130 | { | 132 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_NO_PRIVATE_VALUE); |
131 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_NO_PRIVATE_VALUE); | ||
132 | goto err; | 133 | goto err; |
133 | } | 134 | } |
134 | 135 | ||
135 | group = EC_KEY_get0_group(ecdh); | 136 | group = EC_KEY_get0_group(ecdh); |
136 | if ((tmp=EC_POINT_new(group)) == NULL) | 137 | if ((tmp = EC_POINT_new(group)) == NULL) { |
137 | { | 138 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); |
138 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); | ||
139 | goto err; | 139 | goto err; |
140 | } | 140 | } |
141 | 141 | ||
142 | if (!EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx)) | 142 | if (!EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx)) { |
143 | { | 143 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, |
144 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | 144 | ECDH_R_POINT_ARITHMETIC_FAILURE); |
145 | goto err; | 145 | goto err; |
146 | } | 146 | } |
147 | 147 | ||
148 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) | 148 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == |
149 | { | 149 | NID_X9_62_prime_field) { |
150 | if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, y, ctx)) | 150 | if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, y, |
151 | { | 151 | ctx)) { |
152 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | 152 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, |
153 | ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
153 | goto err; | 154 | goto err; |
154 | } | ||
155 | } | 155 | } |
156 | } | ||
156 | #ifndef OPENSSL_NO_EC2M | 157 | #ifndef OPENSSL_NO_EC2M |
157 | else | 158 | else { |
158 | { | 159 | if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y, |
159 | if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y, ctx)) | 160 | ctx)) { |
160 | { | 161 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, |
161 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | 162 | ECDH_R_POINT_ARITHMETIC_FAILURE); |
162 | goto err; | 163 | goto err; |
163 | } | ||
164 | } | 164 | } |
165 | } | ||
165 | #endif | 166 | #endif |
166 | 167 | ||
167 | buflen = (EC_GROUP_get_degree(group) + 7)/8; | 168 | buflen = (EC_GROUP_get_degree(group) + 7)/8; |
168 | len = BN_num_bytes(x); | 169 | len = BN_num_bytes(x); |
169 | if (len > buflen) | 170 | if (len > buflen) { |
170 | { | 171 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR); |
171 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_INTERNAL_ERROR); | ||
172 | goto err; | 172 | goto err; |
173 | } | 173 | } |
174 | if ((buf = malloc(buflen)) == NULL) | 174 | if ((buf = malloc(buflen)) == NULL) { |
175 | { | 175 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); |
176 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); | ||
177 | goto err; | 176 | goto err; |
178 | } | 177 | } |
179 | 178 | ||
180 | memset(buf, 0, buflen - len); | 179 | memset(buf, 0, buflen - len); |
181 | if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) | 180 | if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) { |
182 | { | 181 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); |
183 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
184 | goto err; | 182 | goto err; |
185 | } | 183 | } |
186 | 184 | ||
187 | if (KDF != 0) | 185 | if (KDF != 0) { |
188 | { | 186 | if (KDF(buf, buflen, out, &outlen) == NULL) { |
189 | if (KDF(buf, buflen, out, &outlen) == NULL) | 187 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KDF_FAILED); |
190 | { | ||
191 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_KDF_FAILED); | ||
192 | goto err; | 188 | goto err; |
193 | } | ||
194 | ret = outlen; | ||
195 | } | 189 | } |
196 | else | 190 | ret = outlen; |
197 | { | 191 | } else { |
198 | /* no KDF, just copy as much as we can */ | 192 | /* no KDF, just copy as much as we can */ |
199 | if (outlen > buflen) | 193 | if (outlen > buflen) |
200 | outlen = buflen; | 194 | outlen = buflen; |
201 | memcpy(out, buf, outlen); | 195 | memcpy(out, buf, outlen); |
202 | ret = outlen; | 196 | ret = outlen; |
203 | } | 197 | } |
204 | 198 | ||
205 | err: | 199 | err: |
206 | EC_POINT_free(tmp); | 200 | EC_POINT_free(tmp); |
207 | if (ctx) | 201 | if (ctx) |
208 | BN_CTX_end(ctx); | 202 | BN_CTX_end(ctx); |
209 | BN_CTX_free(ctx); | 203 | BN_CTX_free(ctx); |
210 | free(buf); | 204 | free(buf); |
211 | return(ret); | 205 | return (ret); |
212 | } | 206 | } |