diff options
Diffstat (limited to 'src/lib/libcrypto/gost/gostr341001_key.c')
-rw-r--r-- | src/lib/libcrypto/gost/gostr341001_key.c | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/lib/libcrypto/gost/gostr341001_key.c b/src/lib/libcrypto/gost/gostr341001_key.c index 894a189e3b..0a42a15378 100644 --- a/src/lib/libcrypto/gost/gostr341001_key.c +++ b/src/lib/libcrypto/gost/gostr341001_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: gostr341001_key.c,v 1.6 2015/09/10 15:56:25 jsing Exp $ */ | 1 | /* $OpenBSD: gostr341001_key.c,v 1.7 2017/01/29 17:49:23 beck Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> |
4 | * Copyright (c) 2005-2006 Cryptocom LTD | 4 | * Copyright (c) 2005-2006 Cryptocom LTD |
@@ -78,7 +78,7 @@ GOST_KEY_new(void) | |||
78 | 78 | ||
79 | ret = malloc(sizeof(GOST_KEY)); | 79 | ret = malloc(sizeof(GOST_KEY)); |
80 | if (ret == NULL) { | 80 | if (ret == NULL) { |
81 | GOSTerr(GOST_F_GOST_KEY_NEW, ERR_R_MALLOC_FAILURE); | 81 | GOSTerror(ERR_R_MALLOC_FAILURE); |
82 | return (NULL); | 82 | return (NULL); |
83 | } | 83 | } |
84 | ret->group = NULL; | 84 | ret->group = NULL; |
@@ -118,11 +118,11 @@ GOST_KEY_check_key(const GOST_KEY *key) | |||
118 | EC_POINT *point = NULL; | 118 | EC_POINT *point = NULL; |
119 | 119 | ||
120 | if (key == NULL || key->group == NULL || key->pub_key == NULL) { | 120 | if (key == NULL || key->group == NULL || key->pub_key == NULL) { |
121 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER); | 121 | GOSTerror(ERR_R_PASSED_NULL_PARAMETER); |
122 | return 0; | 122 | return 0; |
123 | } | 123 | } |
124 | if (EC_POINT_is_at_infinity(key->group, key->pub_key) != 0) { | 124 | if (EC_POINT_is_at_infinity(key->group, key->pub_key) != 0) { |
125 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_POINT_AT_INFINITY); | 125 | GOSTerror(EC_R_POINT_AT_INFINITY); |
126 | goto err; | 126 | goto err; |
127 | } | 127 | } |
128 | if ((ctx = BN_CTX_new()) == NULL) | 128 | if ((ctx = BN_CTX_new()) == NULL) |
@@ -132,23 +132,23 @@ GOST_KEY_check_key(const GOST_KEY *key) | |||
132 | 132 | ||
133 | /* testing whether the pub_key is on the elliptic curve */ | 133 | /* testing whether the pub_key is on the elliptic curve */ |
134 | if (EC_POINT_is_on_curve(key->group, key->pub_key, ctx) == 0) { | 134 | if (EC_POINT_is_on_curve(key->group, key->pub_key, ctx) == 0) { |
135 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE); | 135 | GOSTerror(EC_R_POINT_IS_NOT_ON_CURVE); |
136 | goto err; | 136 | goto err; |
137 | } | 137 | } |
138 | /* testing whether pub_key * order is the point at infinity */ | 138 | /* testing whether pub_key * order is the point at infinity */ |
139 | if ((order = BN_new()) == NULL) | 139 | if ((order = BN_new()) == NULL) |
140 | goto err; | 140 | goto err; |
141 | if (EC_GROUP_get_order(key->group, order, ctx) == 0) { | 141 | if (EC_GROUP_get_order(key->group, order, ctx) == 0) { |
142 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER); | 142 | GOSTerror(EC_R_INVALID_GROUP_ORDER); |
143 | goto err; | 143 | goto err; |
144 | } | 144 | } |
145 | if (EC_POINT_mul(key->group, point, NULL, key->pub_key, order, | 145 | if (EC_POINT_mul(key->group, point, NULL, key->pub_key, order, |
146 | ctx) == 0) { | 146 | ctx) == 0) { |
147 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_EC_LIB); | 147 | GOSTerror(ERR_R_EC_LIB); |
148 | goto err; | 148 | goto err; |
149 | } | 149 | } |
150 | if (EC_POINT_is_at_infinity(key->group, point) == 0) { | 150 | if (EC_POINT_is_at_infinity(key->group, point) == 0) { |
151 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_WRONG_ORDER); | 151 | GOSTerror(EC_R_WRONG_ORDER); |
152 | goto err; | 152 | goto err; |
153 | } | 153 | } |
154 | /* | 154 | /* |
@@ -157,17 +157,16 @@ GOST_KEY_check_key(const GOST_KEY *key) | |||
157 | */ | 157 | */ |
158 | if (key->priv_key != NULL) { | 158 | if (key->priv_key != NULL) { |
159 | if (BN_cmp(key->priv_key, order) >= 0) { | 159 | if (BN_cmp(key->priv_key, order) >= 0) { |
160 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_WRONG_ORDER); | 160 | GOSTerror(EC_R_WRONG_ORDER); |
161 | goto err; | 161 | goto err; |
162 | } | 162 | } |
163 | if (EC_POINT_mul(key->group, point, key->priv_key, NULL, NULL, | 163 | if (EC_POINT_mul(key->group, point, key->priv_key, NULL, NULL, |
164 | ctx) == 0) { | 164 | ctx) == 0) { |
165 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_EC_LIB); | 165 | GOSTerror(ERR_R_EC_LIB); |
166 | goto err; | 166 | goto err; |
167 | } | 167 | } |
168 | if (EC_POINT_cmp(key->group, point, key->pub_key, ctx) != 0) { | 168 | if (EC_POINT_cmp(key->group, point, key->pub_key, ctx) != 0) { |
169 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, | 169 | GOSTerror(EC_R_INVALID_PRIVATE_KEY); |
170 | EC_R_INVALID_PRIVATE_KEY); | ||
171 | goto err; | 170 | goto err; |
172 | } | 171 | } |
173 | } | 172 | } |
@@ -188,8 +187,7 @@ GOST_KEY_set_public_key_affine_coordinates(GOST_KEY *key, BIGNUM *x, BIGNUM *y) | |||
188 | int ok = 0; | 187 | int ok = 0; |
189 | 188 | ||
190 | if (key == NULL || key->group == NULL || x == NULL || y == NULL) { | 189 | if (key == NULL || key->group == NULL || x == NULL || y == NULL) { |
191 | GOSTerr(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, | 190 | GOSTerror(ERR_R_PASSED_NULL_PARAMETER); |
192 | ERR_R_PASSED_NULL_PARAMETER); | ||
193 | return 0; | 191 | return 0; |
194 | } | 192 | } |
195 | ctx = BN_CTX_new(); | 193 | ctx = BN_CTX_new(); |
@@ -215,8 +213,7 @@ GOST_KEY_set_public_key_affine_coordinates(GOST_KEY *key, BIGNUM *x, BIGNUM *y) | |||
215 | * out of range. | 213 | * out of range. |
216 | */ | 214 | */ |
217 | if (BN_cmp(x, tx) != 0 || BN_cmp(y, ty) != 0) { | 215 | if (BN_cmp(x, tx) != 0 || BN_cmp(y, ty) != 0) { |
218 | GOSTerr(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, | 216 | GOSTerror(EC_R_COORDINATES_OUT_OF_RANGE); |
219 | EC_R_COORDINATES_OUT_OF_RANGE); | ||
220 | goto err; | 217 | goto err; |
221 | } | 218 | } |
222 | if (GOST_KEY_set_public_key(key, point) == 0) | 219 | if (GOST_KEY_set_public_key(key, point) == 0) |