1 /**********************************************************************
3 * Copyright (c) 2005-2013 Cryptocom LTD *
4 * This file is distributed under the same license as OpenSSL *
6 * Implementation of GOST R 34.10-2001 *
7 * Requires OpenSSL 1.0.0+ for compilation *
8 **********************************************************************/
11 #include <openssl/rand.h>
12 #include <openssl/ecdsa.h>
13 #include <openssl/err.h>
14 #include "e_gost_err.h"
17 void dump_signature(const char *message, const unsigned char *buffer,
19 void dump_dsa_sig(const char *message, ECDSA_SIG *sig);
22 # define dump_signature(a,b,c)
23 # define dump_dsa_sig(a,b)
26 static R3410_ec_params *gost_nid2params(int nid)
28 R3410_ec_params *params;
30 /* Map tc26-2012 256-bit parameters to cp-2001 parameters */
32 case NID_id_tc26_gost_3410_2012_256_paramSetB:
33 nid = NID_id_GostR3410_2001_CryptoPro_A_ParamSet;
35 case NID_id_tc26_gost_3410_2012_256_paramSetC:
36 nid = NID_id_GostR3410_2001_CryptoPro_B_ParamSet;
38 case NID_id_tc26_gost_3410_2012_256_paramSetD:
39 nid = NID_id_GostR3410_2001_CryptoPro_C_ParamSet;
42 /* Search nid in 2012 paramset */
43 params = R3410_2012_512_paramset;
44 while (params->nid != NID_undef) {
45 if (params->nid == nid)
50 /* Search nid in 2001 paramset */
51 params = R3410_2001_paramset;
52 while (params->nid != NID_undef) {
53 if (params->nid == nid)
62 * Fills EC_KEY structure hidden in the app_data field of DSA structure
63 * with parameter information, extracted from parameter array in
66 * Also fils DSA->q field with copy of EC_GROUP order field to make
67 * DSA_size function work
69 int fill_GOST_EC_params(EC_KEY *eckey, int nid)
71 R3410_ec_params *params = gost_nid2params(nid);
74 BIGNUM *p = NULL, *q = NULL, *a = NULL, *b = NULL, *x = NULL, *y =
75 NULL, *cofactor = NULL;
79 if (!eckey || !params) {
80 GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, GOST_R_UNSUPPORTED_PARAMETER_SET);
84 if (!(ctx = BN_CTX_new())) {
85 GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_MALLOC_FAILURE);
96 cofactor = BN_CTX_get(ctx);
97 if (!p || !a || !b || !x || !y || !q || !cofactor) {
98 GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_MALLOC_FAILURE);
102 if (!BN_hex2bn(&p, params->p)
103 || !BN_hex2bn(&a, params->a)
104 || !BN_hex2bn(&b, params->b)
105 || !BN_hex2bn(&cofactor, params->cofactor)) {
106 GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR);
110 grp = EC_GROUP_new_curve_GFp(p, a, b, ctx);
112 GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_MALLOC_FAILURE);
116 P = EC_POINT_new(grp);
118 GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_MALLOC_FAILURE);
122 if (!BN_hex2bn(&x, params->x)
123 || !BN_hex2bn(&y, params->y)
124 || !EC_POINT_set_affine_coordinates(grp, P, x, y, ctx)
125 || !BN_hex2bn(&q, params->q)) {
126 GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR);
130 if (!EC_GROUP_set_generator(grp, P, q, cofactor)) {
131 GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR);
134 EC_GROUP_set_curve_name(grp, nid);
135 if (!EC_KEY_set_group(eckey, grp)) {
136 GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR);
151 * Computes gost_ec signature as ECDSA_SIG structure
154 ECDSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey)
156 ECDSA_SIG *newsig = NULL, *ret = NULL;
158 BIGNUM *order = NULL;
159 const EC_GROUP *group;
160 const BIGNUM *priv_key;
161 BIGNUM *r = NULL, *s = NULL, *X = NULL, *tmp = NULL, *tmp2 = NULL,
162 *k = NULL, *e = NULL;
164 BIGNUM *new_r = NULL, *new_s = NULL;
169 OPENSSL_assert(dgst != NULL && eckey != NULL);
171 if (!(ctx = BN_CTX_secure_new())) {
172 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE);
177 OPENSSL_assert(dlen == 32 || dlen == 64);
178 md = BN_lebin2bn(dgst, dlen, NULL);
179 newsig = ECDSA_SIG_new();
180 if (!newsig || !md) {
181 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE);
184 group = EC_KEY_get0_group(eckey);
186 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_INTERNAL_ERROR);
189 order = BN_CTX_get(ctx);
190 if (!order || !EC_GROUP_get_order(group, order, ctx)) {
191 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_INTERNAL_ERROR);
194 priv_key = EC_KEY_get0_private_key(eckey);
196 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_INTERNAL_ERROR);
200 if (!e || !BN_mod(e, md, order, ctx)) {
201 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_INTERNAL_ERROR);
205 fprintf(stderr, "digest as bignum=");
206 BN_print_fp(stderr, md);
207 fprintf(stderr, "\ndigest mod q=");
208 BN_print_fp(stderr, e);
209 fprintf(stderr, "\n");
215 C = EC_POINT_new(group);
217 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE);
223 if (!BN_rand_range(k, order)) {
224 GOSTerr(GOST_F_GOST_EC_SIGN, GOST_R_RNG_ERROR);
227 if (!gost_ec_point_mul(group, C, k, NULL, NULL, ctx)) {
228 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_EC_LIB);
236 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE);
239 if (!EC_POINT_get_affine_coordinates(group, C, X, NULL, ctx)) {
240 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_EC_LIB);
244 if (!BN_nnmod(r, X, order, ctx)) {
245 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_INTERNAL_ERROR);
249 while (BN_is_zero(r));
250 /* s = (r*priv_key+k*e) mod order */
252 tmp = BN_CTX_get(ctx);
254 tmp2 = BN_CTX_get(ctx);
257 if (!tmp || !tmp2 || !s) {
258 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE);
262 if (!BN_mod_mul(tmp, priv_key, r, order, ctx)
263 || !BN_mod_mul(tmp2, k, e, order, ctx)
264 || !BN_mod_add(s, tmp, tmp2, order, ctx)) {
265 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_INTERNAL_ERROR);
269 while (BN_is_zero(s));
273 if (!new_s || !new_r) {
274 GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE);
277 ECDSA_SIG_set0(newsig, new_r, new_s);
287 if (!ret && newsig) {
288 ECDSA_SIG_free(newsig);
294 * Verifies gost ec signature
297 int gost_ec_verify(const unsigned char *dgst, int dgst_len,
298 ECDSA_SIG *sig, EC_KEY *ec)
301 const EC_GROUP *group = (ec) ? EC_KEY_get0_group(ec) : NULL;
303 BIGNUM *md = NULL, *e = NULL, *R = NULL, *v = NULL, *z1 = NULL, *z2 = NULL;
304 const BIGNUM *sig_s = NULL, *sig_r = NULL;
305 BIGNUM *X = NULL, *tmp = NULL;
307 const EC_POINT *pub_key = NULL;
310 OPENSSL_assert(dgst != NULL && sig != NULL && group != NULL);
312 if (!(ctx = BN_CTX_new())) {
313 GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_MALLOC_FAILURE);
318 order = BN_CTX_get(ctx);
320 z1 = BN_CTX_get(ctx);
321 z2 = BN_CTX_get(ctx);
322 tmp = BN_CTX_get(ctx);
326 if (!order || !e || !z1 || !z2 || !tmp || !X || !R || !v) {
327 GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_MALLOC_FAILURE);
331 pub_key = EC_KEY_get0_public_key(ec);
332 if (!pub_key || !EC_GROUP_get_order(group, order, ctx)) {
333 GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_INTERNAL_ERROR);
337 ECDSA_SIG_get0(sig, &sig_r, &sig_s);
339 if (BN_is_zero(sig_s) || BN_is_zero(sig_r) ||
340 (BN_cmp(sig_s, order) >= 1) || (BN_cmp(sig_r, order) >= 1)) {
341 GOSTerr(GOST_F_GOST_EC_VERIFY, GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);
346 OPENSSL_assert(dgst_len == 32 || dgst_len == 64);
347 md = BN_lebin2bn(dgst, dgst_len, NULL);
348 if (!md || !BN_mod(e, md, order, ctx)) {
349 GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_INTERNAL_ERROR);
353 fprintf(stderr, "digest as bignum: ");
354 BN_print_fp(stderr, md);
355 fprintf(stderr, "\ndigest mod q: ");
356 BN_print_fp(stderr, e);
358 if (BN_is_zero(e) && !BN_one(e)) {
359 GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_INTERNAL_ERROR);
362 v = BN_mod_inverse(v, e, order, ctx);
363 if (!v || !BN_mod_mul(z1, sig_s, v, order, ctx)
364 || !BN_sub(tmp, order, sig_r)
365 || !BN_mod_mul(z2, tmp, v, order, ctx)) {
366 GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_INTERNAL_ERROR);
370 fprintf(stderr, "\nInverted digest value: ");
371 BN_print_fp(stderr, v);
372 fprintf(stderr, "\nz1: ");
373 BN_print_fp(stderr, z1);
374 fprintf(stderr, "\nz2: ");
375 BN_print_fp(stderr, z2);
377 C = EC_POINT_new(group);
379 GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_MALLOC_FAILURE);
382 if (!gost_ec_point_mul(group, C, z1, pub_key, z2, ctx)) {
383 GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_EC_LIB);
386 if (!EC_POINT_get_affine_coordinates(group, C, X, NULL, ctx)) {
387 GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_EC_LIB);
390 if (!BN_mod(R, X, order, ctx)) {
391 GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_INTERNAL_ERROR);
395 fprintf(stderr, "\nX=");
396 BN_print_fp(stderr, X);
397 fprintf(stderr, "\nX mod q=");
398 BN_print_fp(stderr, R);
399 fprintf(stderr, "\n");
401 if (BN_cmp(R, sig_r) != 0) {
402 GOSTerr(GOST_F_GOST_EC_VERIFY, GOST_R_SIGNATURE_MISMATCH);
417 * Computes GOST R 34.10-2001 public key
418 * or GOST R 34.10-2012 public key
421 int gost_ec_compute_public(EC_KEY *ec)
423 const EC_GROUP *group = (ec) ? EC_KEY_get0_group(ec) : NULL;
424 EC_POINT *pub_key = NULL;
425 const BIGNUM *priv_key = NULL;
430 GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, GOST_R_KEY_IS_NOT_INITIALIZED);
434 ctx = BN_CTX_secure_new();
436 GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, ERR_R_MALLOC_FAILURE);
441 priv_key = EC_KEY_get0_private_key(ec);
443 GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, ERR_R_EC_LIB);
447 pub_key = EC_POINT_new(group);
449 GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, ERR_R_MALLOC_FAILURE);
453 if (!gost_ec_point_mul(group, pub_key, priv_key, NULL, NULL, ctx)) {
454 GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, ERR_R_EC_LIB);
457 if (!EC_KEY_set_public_key(ec, pub_key)) {
458 GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, ERR_R_EC_LIB);
464 EC_POINT_free(pub_key);
470 int gost_ec_point_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,
471 const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx)
473 if (group == NULL || r == NULL || ctx == NULL)
476 if (m != NULL && n != NULL) {
480 switch(EC_GROUP_get_curve_name(group)) {
481 case NID_id_GostR3410_2001_CryptoPro_A_ParamSet:
482 case NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet:
483 case NID_id_tc26_gost_3410_2012_256_paramSetB:
484 return point_mul_two_id_GostR3410_2001_CryptoPro_A_ParamSet(group, r, n, q, m, ctx);
485 case NID_id_GostR3410_2001_CryptoPro_B_ParamSet:
486 case NID_id_tc26_gost_3410_2012_256_paramSetC:
487 return point_mul_two_id_GostR3410_2001_CryptoPro_B_ParamSet(group, r, n, q, m, ctx);
488 case NID_id_GostR3410_2001_CryptoPro_C_ParamSet:
489 case NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet:
490 case NID_id_tc26_gost_3410_2012_256_paramSetD:
491 return point_mul_two_id_GostR3410_2001_CryptoPro_C_ParamSet(group, r, n, q, m, ctx);
492 case NID_id_GostR3410_2001_TestParamSet:
493 return point_mul_two_id_GostR3410_2001_TestParamSet(group, r, n, q, m, ctx);
494 case NID_id_tc26_gost_3410_2012_256_paramSetA:
495 return point_mul_two_id_tc26_gost_3410_2012_256_paramSetA(group, r, n, q, m, ctx);
496 case NID_id_tc26_gost_3410_2012_512_paramSetA:
497 return point_mul_two_id_tc26_gost_3410_2012_512_paramSetA(group, r, n, q, m, ctx);
498 case NID_id_tc26_gost_3410_2012_512_paramSetB:
499 return point_mul_two_id_tc26_gost_3410_2012_512_paramSetB(group, r, n, q, m, ctx);
500 case NID_id_tc26_gost_3410_2012_512_paramSetC:
501 return point_mul_two_id_tc26_gost_3410_2012_512_paramSetC(group, r, n, q, m, ctx);
503 return EC_POINT_mul(group, r, n, q, m, ctx);
505 } else if (n != NULL) {
507 switch(EC_GROUP_get_curve_name(group)) {
508 case NID_id_GostR3410_2001_CryptoPro_A_ParamSet:
509 case NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet:
510 case NID_id_tc26_gost_3410_2012_256_paramSetB:
511 return point_mul_g_id_GostR3410_2001_CryptoPro_A_ParamSet(group, r, n, ctx);
512 case NID_id_GostR3410_2001_CryptoPro_B_ParamSet:
513 case NID_id_tc26_gost_3410_2012_256_paramSetC:
514 return point_mul_g_id_GostR3410_2001_CryptoPro_B_ParamSet(group, r, n, ctx);
515 case NID_id_GostR3410_2001_CryptoPro_C_ParamSet:
516 case NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet:
517 case NID_id_tc26_gost_3410_2012_256_paramSetD:
518 return point_mul_g_id_GostR3410_2001_CryptoPro_C_ParamSet(group, r, n, ctx);
519 case NID_id_GostR3410_2001_TestParamSet:
520 return point_mul_g_id_GostR3410_2001_TestParamSet(group, r, n, ctx);
521 case NID_id_tc26_gost_3410_2012_256_paramSetA:
522 return point_mul_g_id_tc26_gost_3410_2012_256_paramSetA(group, r, n, ctx);
523 case NID_id_tc26_gost_3410_2012_512_paramSetA:
524 return point_mul_g_id_tc26_gost_3410_2012_512_paramSetA(group, r, n, ctx);
525 case NID_id_tc26_gost_3410_2012_512_paramSetB:
526 return point_mul_g_id_tc26_gost_3410_2012_512_paramSetB(group, r, n, ctx);
527 case NID_id_tc26_gost_3410_2012_512_paramSetC:
528 return point_mul_g_id_tc26_gost_3410_2012_512_paramSetC(group, r, n, ctx);
530 return EC_POINT_mul(group, r, n, q, m, ctx);
532 } else if (m != NULL) {
536 switch(EC_GROUP_get_curve_name(group)) {
537 case NID_id_GostR3410_2001_CryptoPro_A_ParamSet:
538 case NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet:
539 case NID_id_tc26_gost_3410_2012_256_paramSetB:
540 return point_mul_id_GostR3410_2001_CryptoPro_A_ParamSet(group, r, q, m, ctx);
541 case NID_id_GostR3410_2001_CryptoPro_B_ParamSet:
542 case NID_id_tc26_gost_3410_2012_256_paramSetC:
543 return point_mul_id_GostR3410_2001_CryptoPro_B_ParamSet(group, r, q, m, ctx);
544 case NID_id_GostR3410_2001_CryptoPro_C_ParamSet:
545 case NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet:
546 case NID_id_tc26_gost_3410_2012_256_paramSetD:
547 return point_mul_id_GostR3410_2001_CryptoPro_C_ParamSet(group, r, q, m, ctx);
548 case NID_id_GostR3410_2001_TestParamSet:
549 return point_mul_id_GostR3410_2001_TestParamSet(group, r, q, m, ctx);
550 case NID_id_tc26_gost_3410_2012_256_paramSetA:
551 return point_mul_id_tc26_gost_3410_2012_256_paramSetA(group, r, q, m, ctx);
552 case NID_id_tc26_gost_3410_2012_512_paramSetA:
553 return point_mul_id_tc26_gost_3410_2012_512_paramSetA(group, r, q, m, ctx);
554 case NID_id_tc26_gost_3410_2012_512_paramSetB:
555 return point_mul_id_tc26_gost_3410_2012_512_paramSetB(group, r, q, m, ctx);
556 case NID_id_tc26_gost_3410_2012_512_paramSetC:
557 return point_mul_id_tc26_gost_3410_2012_512_paramSetC(group, r, q, m, ctx);
559 return EC_POINT_mul(group, r, n, q, m, ctx);
567 * Generates GOST R 34.10-2001
568 * or GOST R 34.10-2012 keypair
571 int gost_ec_keygen(EC_KEY *ec)
573 BIGNUM *order = NULL, *d = NULL;
574 const EC_GROUP *group = (ec) ? EC_KEY_get0_group(ec) : NULL;
578 GOSTerr(GOST_F_GOST_EC_KEYGEN, ERR_R_INTERNAL_ERROR);
585 GOSTerr(GOST_F_GOST_EC_KEYGEN, ERR_R_MALLOC_FAILURE);
589 if (!EC_GROUP_get_order(group, order, NULL)) {
590 GOSTerr(GOST_F_GOST_EC_KEYGEN, ERR_R_INTERNAL_ERROR);
595 if (!BN_rand_range(d, order)) {
596 GOSTerr(GOST_F_GOST_EC_KEYGEN, GOST_R_RNG_ERROR);
600 while (BN_is_zero(d));
602 if (!EC_KEY_set_private_key(ec, d)) {
603 GOSTerr(GOST_F_GOST_EC_KEYGEN, ERR_R_INTERNAL_ERROR);
614 return (ok) ? gost_ec_compute_public(ec) : 0;
617 int gost_ec_oct2point(const EC_GROUP *group, EC_POINT *point,
618 const unsigned char *buf, size_t len)
622 size_t field_len, enc_len;
626 GOSTerr(GOST_F_GOST_EC_OCT2POINT, EC_R_BUFFER_TOO_SMALL);
630 field_len = (EC_GROUP_get_degree(group) + 7) / 8;
631 enc_len = 2 * field_len;
633 if (len != enc_len) {
634 GOSTerr(GOST_F_GOST_EC_OCT2POINT, EC_R_INVALID_ENCODING);
649 if (!EC_GROUP_get_curve(group, p, NULL, NULL, NULL))
652 if (!BN_lebin2bn(buf, field_len, x))
654 if (BN_ucmp(x, p) >= 0) {
655 GOSTerr(GOST_F_GOST_EC_OCT2POINT, EC_R_INVALID_ENCODING);
659 if (!BN_lebin2bn(buf + field_len, field_len, y))
661 if (BN_ucmp(y, p) >= 0) {
662 GOSTerr(GOST_F_GOST_EC_OCT2POINT, EC_R_INVALID_ENCODING);
667 * EC_POINT_set_affine_coordinates is responsible for checking that
668 * the point is on the curve.
670 if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
682 size_t gost_ec_point2oct(const EC_GROUP *group, const EC_POINT *point,
683 unsigned char *buf, size_t len)
691 field_len = (EC_GROUP_get_degree(group) + 7) / 8;
696 GOSTerr(GOST_F_GOST_EC_POINT2OCT, EC_R_BUFFER_TOO_SMALL);
711 if (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx))
714 if (BN_bn2lebinpad(x, buf, field_len) != field_len
715 || BN_bn2lebinpad(y, buf + field_len, field_len) != field_len)
731 size_t gost_ec_key2buf(const EC_KEY *key, unsigned char **pbuf)
735 const EC_GROUP *grp = NULL;
736 const EC_POINT *pkey = NULL;
738 pkey = EC_KEY_get0_public_key(key);
739 grp = EC_KEY_get0_group(key);
741 if(pkey == NULL || grp == NULL)
744 len = gost_ec_point2oct(grp, pkey, NULL, 0);
747 if ((buf = OPENSSL_malloc(len)) == NULL) {
748 GOSTerr(GOST_F_GOST_EC_KEY2BUF, ERR_R_MALLOC_FAILURE);
751 len = gost_ec_point2oct(grp, pkey, buf, len);
760 int gost_ec_oct2key(EC_KEY *key, const unsigned char *buf, size_t len)
762 const EC_GROUP *group = NULL;
763 const EC_POINT *pub_key = NULL;
764 EC_POINT *point = NULL;
767 if (key == NULL || (group = EC_KEY_get0_group(key)) == NULL)
770 if ((pub_key = EC_KEY_get0_public_key(key)) == NULL) {
771 if((point = EC_POINT_new(group)) == NULL ||
772 !EC_KEY_set_public_key(key, point))
774 pub_key = EC_KEY_get0_public_key(key);
777 if (gost_ec_oct2point(group, (EC_POINT *)pub_key, buf, len) == 0)
784 EC_POINT_free(point);