]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_ec_sign.c
Explicitely setting cofactor
[openssl-gost/engine.git] / gost_ec_sign.c
index 2c04ed756e2600b86fa197dbc97b5afe21e8d207..2deb09324b50d15a50caaba367362d5f83a496b4 100644 (file)
@@ -74,7 +74,7 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid)
     R3410_ec_params *params = gost_nid2params(nid);
     EC_GROUP *grp = NULL;
     EC_POINT *P = NULL;
-    BIGNUM *p = NULL, *q = NULL, *a = NULL, *b = NULL, *x = NULL, *y = NULL;
+    BIGNUM *p = NULL, *q = NULL, *a = NULL, *b = NULL, *x = NULL, *y = NULL, *cofactor = NULL;
     BN_CTX *ctx;
     int ok = 0;
 
@@ -95,14 +95,16 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid)
     x = BN_CTX_get(ctx);
     y = BN_CTX_get(ctx);
     q = BN_CTX_get(ctx);
-    if (!p || !a || !b || !x || !y || !q) {
+               cofactor = BN_CTX_get(ctx);
+    if (!p || !a || !b || !x || !y || !q || !cofactor) {
         GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_MALLOC_FAILURE);
         goto end;
     }
 
     if (!BN_hex2bn(&p, params->p)
         || !BN_hex2bn(&a, params->a)
-        || !BN_hex2bn(&b, params->b)) {
+        || !BN_hex2bn(&b, params->b)
+                               || !BN_hex2bn(&cofactor, params->cofactor) ) {
         GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR);
         goto end;
     }
@@ -127,7 +129,7 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid)
         goto end;
     }
 
-    if (!EC_GROUP_set_generator(grp, P, q, NULL)) {
+    if (!EC_GROUP_set_generator(grp, P, q, cofactor)) {
         GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR);
         goto end;
     }
@@ -276,13 +278,13 @@ DSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey)
     }
     while (BN_is_zero(s));
 
-    DSA_SIG_get0(&new_r, &new_s, newsig);
     new_s = BN_dup(s);
     new_r = BN_dup(r);
     if (!new_s || !new_r) {
         GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE);
         goto err;
     }
+    DSA_SIG_set0(newsig, new_r, new_s);
 
     ret = newsig;
  err:
@@ -310,7 +312,7 @@ int gost_ec_verify(const unsigned char *dgst, int dgst_len,
     BIGNUM *order;
     BIGNUM *md = NULL, *e = NULL, *R = NULL, *v = NULL,
         *z1 = NULL, *z2 = NULL;
-    BIGNUM *sig_s = NULL, *sig_r = NULL;
+    const BIGNUM *sig_s = NULL, *sig_r = NULL;
     BIGNUM *X = NULL, *tmp = NULL;
     EC_POINT *C = NULL;
     const EC_POINT *pub_key = NULL;
@@ -343,7 +345,7 @@ int gost_ec_verify(const unsigned char *dgst, int dgst_len,
         goto err;
     }
 
-    DSA_SIG_get0(&sig_r, &sig_s, sig);
+    DSA_SIG_get0(sig, &sig_r, &sig_s);
 
     if (BN_is_zero(sig_s) || BN_is_zero(sig_r) ||
         (BN_cmp(sig_s, order) >= 1) || (BN_cmp(sig_r, order) >= 1)) {