summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/gost/gostr341001_ameth.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/gost/gostr341001_ameth.c')
-rw-r--r--src/lib/libcrypto/gost/gostr341001_ameth.c59
1 files changed, 25 insertions, 34 deletions
diff --git a/src/lib/libcrypto/gost/gostr341001_ameth.c b/src/lib/libcrypto/gost/gostr341001_ameth.c
index bb569ea846..b6958c77d5 100644
--- a/src/lib/libcrypto/gost/gostr341001_ameth.c
+++ b/src/lib/libcrypto/gost/gostr341001_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gostr341001_ameth.c,v 1.10 2016/10/19 16:49:11 jsing Exp $ */ 1/* $OpenBSD: gostr341001_ameth.c,v 1.11 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
@@ -86,8 +86,7 @@ decode_gost01_algor_params(EVP_PKEY *pkey, const unsigned char **p, int len)
86 86
87 gkp = d2i_GOST_KEY_PARAMS(NULL, p, len); 87 gkp = d2i_GOST_KEY_PARAMS(NULL, p, len);
88 if (gkp == NULL) { 88 if (gkp == NULL) {
89 GOSTerr(GOST_F_DECODE_GOST01_ALGOR_PARAMS, 89 GOSTerror(GOST_R_BAD_PKEY_PARAMETERS_FORMAT);
90 GOST_R_BAD_PKEY_PARAMETERS_FORMAT);
91 return 0; 90 return 0;
92 } 91 }
93 param_nid = OBJ_obj2nid(gkp->key_params); 92 param_nid = OBJ_obj2nid(gkp->key_params);
@@ -125,8 +124,7 @@ encode_gost01_algor_params(const EVP_PKEY *key)
125 int pkey_param_nid = NID_undef; 124 int pkey_param_nid = NID_undef;
126 125
127 if (params == NULL || gkp == NULL) { 126 if (params == NULL || gkp == NULL) {
128 GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS, 127 GOSTerror(ERR_R_MALLOC_FAILURE);
129 ERR_R_MALLOC_FAILURE);
130 ASN1_STRING_free(params); 128 ASN1_STRING_free(params);
131 params = NULL; 129 params = NULL;
132 goto err; 130 goto err;
@@ -139,8 +137,7 @@ encode_gost01_algor_params(const EVP_PKEY *key)
139 /*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid); */ 137 /*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid); */
140 params->length = i2d_GOST_KEY_PARAMS(gkp, &params->data); 138 params->length = i2d_GOST_KEY_PARAMS(gkp, &params->data);
141 if (params->length <= 0) { 139 if (params->length <= 0) {
142 GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS, 140 GOSTerror(ERR_R_MALLOC_FAILURE);
143 ERR_R_MALLOC_FAILURE);
144 ASN1_STRING_free(params); 141 ASN1_STRING_free(params);
145 params = NULL; 142 params = NULL;
146 goto err; 143 goto err;
@@ -206,8 +203,7 @@ pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub)
206 (void)EVP_PKEY_assign_GOST(pk, NULL); 203 (void)EVP_PKEY_assign_GOST(pk, NULL);
207 X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg); 204 X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg);
208 if (ptype != V_ASN1_SEQUENCE) { 205 if (ptype != V_ASN1_SEQUENCE) {
209 GOSTerr(GOST_F_PUB_DECODE_GOST01, 206 GOSTerror(GOST_R_BAD_KEY_PARAMETERS_FORMAT);
210 GOST_R_BAD_KEY_PARAMETERS_FORMAT);
211 return 0; 207 return 0;
212 } 208 }
213 p = pval->data; 209 p = pval->data;
@@ -216,7 +212,7 @@ pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub)
216 212
217 octet = d2i_ASN1_OCTET_STRING(NULL, &pubkey_buf, pub_len); 213 octet = d2i_ASN1_OCTET_STRING(NULL, &pubkey_buf, pub_len);
218 if (octet == NULL) { 214 if (octet == NULL) {
219 GOSTerr(GOST_F_PUB_DECODE_GOST01, ERR_R_MALLOC_FAILURE); 215 GOSTerror(ERR_R_MALLOC_FAILURE);
220 return 0; 216 return 0;
221 } 217 }
222 len = octet->length / 2; 218 len = octet->length / 2;
@@ -228,7 +224,7 @@ pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub)
228 224
229 ret = GOST_KEY_set_public_key_affine_coordinates(pk->pkey.gost, X, Y); 225 ret = GOST_KEY_set_public_key_affine_coordinates(pk->pkey.gost, X, Y);
230 if (ret == 0) 226 if (ret == 0)
231 GOSTerr(GOST_F_PUB_DECODE_GOST01, ERR_R_EC_LIB); 227 GOSTerror(ERR_R_EC_LIB);
232 228
233 BN_free(X); 229 BN_free(X);
234 BN_free(Y); 230 BN_free(Y);
@@ -263,19 +259,19 @@ pub_encode_gost01(X509_PUBKEY *pub, const EVP_PKEY *pk)
263 259
264 pub_key = GOST_KEY_get0_public_key(ec); 260 pub_key = GOST_KEY_get0_public_key(ec);
265 if (pub_key == NULL) { 261 if (pub_key == NULL) {
266 GOSTerr(GOST_F_PUB_ENCODE_GOST01, GOST_R_PUBLIC_KEY_UNDEFINED); 262 GOSTerror(GOST_R_PUBLIC_KEY_UNDEFINED);
267 goto err; 263 goto err;
268 } 264 }
269 265
270 octet = ASN1_OCTET_STRING_new(); 266 octet = ASN1_OCTET_STRING_new();
271 if (octet == NULL) { 267 if (octet == NULL) {
272 GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_MALLOC_FAILURE); 268 GOSTerror(ERR_R_MALLOC_FAILURE);
273 goto err; 269 goto err;
274 } 270 }
275 271
276 ret = ASN1_STRING_set(octet, NULL, 2 * key_size); 272 ret = ASN1_STRING_set(octet, NULL, 2 * key_size);
277 if (ret == 0) { 273 if (ret == 0) {
278 GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_INTERNAL_ERROR); 274 GOSTerror(ERR_R_INTERNAL_ERROR);
279 goto err; 275 goto err;
280 } 276 }
281 277
@@ -284,13 +280,13 @@ pub_encode_gost01(X509_PUBKEY *pub, const EVP_PKEY *pk)
284 X = BN_new(); 280 X = BN_new();
285 Y = BN_new(); 281 Y = BN_new();
286 if (X == NULL || Y == NULL) { 282 if (X == NULL || Y == NULL) {
287 GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_MALLOC_FAILURE); 283 GOSTerror(ERR_R_MALLOC_FAILURE);
288 goto err; 284 goto err;
289 } 285 }
290 286
291 if (EC_POINT_get_affine_coordinates_GFp(GOST_KEY_get0_group(ec), 287 if (EC_POINT_get_affine_coordinates_GFp(GOST_KEY_get0_group(ec),
292 pub_key, X, Y, NULL) == 0) { 288 pub_key, X, Y, NULL) == 0) {
293 GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_EC_LIB); 289 GOSTerror(ERR_R_EC_LIB);
294 goto err; 290 goto err;
295 } 291 }
296 292
@@ -340,7 +336,7 @@ pub_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx)
340 const EC_GROUP *group; 336 const EC_GROUP *group;
341 337
342 if (ctx == NULL) { 338 if (ctx == NULL) {
343 GOSTerr(GOST_F_PUB_PRINT_GOST01, ERR_R_MALLOC_FAILURE); 339 GOSTerror(ERR_R_MALLOC_FAILURE);
344 return 0; 340 return 0;
345 } 341 }
346 BN_CTX_start(ctx); 342 BN_CTX_start(ctx);
@@ -352,7 +348,7 @@ pub_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx)
352 group = GOST_KEY_get0_group(pkey->pkey.gost); 348 group = GOST_KEY_get0_group(pkey->pkey.gost);
353 if (EC_POINT_get_affine_coordinates_GFp(group, pubkey, X, Y, 349 if (EC_POINT_get_affine_coordinates_GFp(group, pubkey, X, Y,
354 ctx) == 0) { 350 ctx) == 0) {
355 GOSTerr(GOST_F_PUB_PRINT_GOST01, ERR_R_EC_LIB); 351 GOSTerror(ERR_R_EC_LIB);
356 goto err; 352 goto err;
357 } 353 }
358 if (BIO_indent(out, indent, 128) == 0) 354 if (BIO_indent(out, indent, 128) == 0)
@@ -416,8 +412,7 @@ priv_decode_gost01(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
416 (void)EVP_PKEY_assign_GOST(pk, NULL); 412 (void)EVP_PKEY_assign_GOST(pk, NULL);
417 X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg); 413 X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg);
418 if (ptype != V_ASN1_SEQUENCE) { 414 if (ptype != V_ASN1_SEQUENCE) {
419 GOSTerr(GOST_F_PUB_DECODE_GOST01, 415 GOSTerror(GOST_R_BAD_KEY_PARAMETERS_FORMAT);
420 GOST_R_BAD_KEY_PARAMETERS_FORMAT);
421 return 0; 416 return 0;
422 } 417 }
423 p = pval->data; 418 p = pval->data;
@@ -432,7 +427,7 @@ priv_decode_gost01(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
432 d2i_ASN1_OCTET_STRING(NULL, &p, priv_len); 427 d2i_ASN1_OCTET_STRING(NULL, &p, priv_len);
433 428
434 if (s == NULL || s->length != 32) { 429 if (s == NULL || s->length != 32) {
435 GOSTerr(GOST_F_PRIV_DECODE_GOST01, EVP_R_DECODE_ERROR); 430 GOSTerror(EVP_R_DECODE_ERROR);
436 ASN1_STRING_free(s); 431 ASN1_STRING_free(s);
437 return 0; 432 return 0;
438 } 433 }
@@ -448,7 +443,7 @@ priv_decode_gost01(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
448 ret = ((pk_num = ASN1_INTEGER_to_BN(priv_key, NULL)) != NULL); 443 ret = ((pk_num = ASN1_INTEGER_to_BN(priv_key, NULL)) != NULL);
449 ASN1_INTEGER_free(priv_key); 444 ASN1_INTEGER_free(priv_key);
450 if (ret == 0) { 445 if (ret == 0) {
451 GOSTerr(GOST_F_PRIV_DECODE_GOST01, EVP_R_DECODE_ERROR); 446 GOSTerror(EVP_R_DECODE_ERROR);
452 return 0; 447 return 0;
453 } 448 }
454 } 449 }
@@ -533,7 +528,7 @@ param_decode_gost01(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
533 528
534 /* Compatibility */ 529 /* Compatibility */
535 if (d2i_ASN1_OBJECT(&obj, pder, derlen) == NULL) { 530 if (d2i_ASN1_OBJECT(&obj, pder, derlen) == NULL) {
536 GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE); 531 GOSTerror(ERR_R_MALLOC_FAILURE);
537 return 0; 532 return 0;
538 } 533 }
539 nid = OBJ_obj2nid(obj); 534 nid = OBJ_obj2nid(obj);
@@ -541,20 +536,19 @@ param_decode_gost01(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
541 536
542 ec = GOST_KEY_new(); 537 ec = GOST_KEY_new();
543 if (ec == NULL) { 538 if (ec == NULL) {
544 GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE); 539 GOSTerror(ERR_R_MALLOC_FAILURE);
545 return 0; 540 return 0;
546 } 541 }
547 group = EC_GROUP_new_by_curve_name(nid); 542 group = EC_GROUP_new_by_curve_name(nid);
548 if (group == NULL) { 543 if (group == NULL) {
549 GOSTerr(GOST_F_PARAM_DECODE_GOST01, 544 GOSTerror(EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
550 EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
551 GOST_KEY_free(ec); 545 GOST_KEY_free(ec);
552 return 0; 546 return 0;
553 } 547 }
554 548
555 EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE); 549 EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
556 if (GOST_KEY_set_group(ec, group) == 0) { 550 if (GOST_KEY_set_group(ec, group) == 0) {
557 GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_EC_LIB); 551 GOSTerror(ERR_R_EC_LIB);
558 EC_GROUP_free(group); 552 EC_GROUP_free(group);
559 GOST_KEY_free(ec); 553 GOST_KEY_free(ec);
560 return 0; 554 return 0;
@@ -562,7 +556,7 @@ param_decode_gost01(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
562 EC_GROUP_free(group); 556 EC_GROUP_free(group);
563 if (GOST_KEY_set_digest(ec, 557 if (GOST_KEY_set_digest(ec,
564 NID_id_GostR3411_94_CryptoProParamSet) == 0) { 558 NID_id_GostR3411_94_CryptoProParamSet) == 0) {
565 GOSTerr(GOST_F_PARAM_DECODE_GOST01, GOST_R_INVALID_DIGEST_TYPE); 559 GOSTerror(GOST_R_INVALID_DIGEST_TYPE);
566 GOST_KEY_free(ec); 560 GOST_KEY_free(ec);
567 return 0; 561 return 0;
568 } 562 }
@@ -594,20 +588,17 @@ param_copy_gost01(EVP_PKEY *to, const EVP_PKEY *from)
594 int ret = 1; 588 int ret = 1;
595 589
596 if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to)) { 590 if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to)) {
597 GOSTerr(GOST_F_PARAM_COPY_GOST01, 591 GOSTerror(GOST_R_INCOMPATIBLE_ALGORITHMS);
598 GOST_R_INCOMPATIBLE_ALGORITHMS);
599 return 0; 592 return 0;
600 } 593 }
601 if (efrom == NULL) { 594 if (efrom == NULL) {
602 GOSTerr(GOST_F_PARAM_COPY_GOST01, 595 GOSTerror(GOST_R_KEY_PARAMETERS_MISSING);
603 GOST_R_KEY_PARAMETERS_MISSING);
604 return 0; 596 return 0;
605 } 597 }
606 if (eto == NULL) { 598 if (eto == NULL) {
607 eto = GOST_KEY_new(); 599 eto = GOST_KEY_new();
608 if (eto == NULL) { 600 if (eto == NULL) {
609 GOSTerr(GOST_F_PARAM_COPY_GOST01, 601 GOSTerror(ERR_R_MALLOC_FAILURE);
610 ERR_R_MALLOC_FAILURE);
611 return 0; 602 return 0;
612 } 603 }
613 if (EVP_PKEY_assign(to, EVP_PKEY_base_id(from), eto) == 0) { 604 if (EVP_PKEY_assign(to, EVP_PKEY_base_id(from), eto) == 0) {