]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_ec_sign.c
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / gost_ec_sign.c
index e4800a461d1452d77991619010567fbef6ad3875..a825dbabac64e0a6eb1dfa077954ba10ee14a1de 100644 (file)
@@ -58,6 +58,27 @@ static R3410_ec_params *gost_nid2params(int nid)
     return NULL;
 }
 
+void free_cached_groups()
+{
+    R3410_ec_params *params;
+
+    /* Search nid in 2012 paramset */
+    params = R3410_2012_512_paramset;
+    while (params->nid != NID_undef) {
+       EC_GROUP_free(params->group);
+       params->group = NULL;
+        params++;
+    }
+
+    /* Search nid in 2001 paramset */
+    params = R3410_2001_paramset;
+    while (params->nid != NID_undef) {
+       EC_GROUP_free(params->group);
+       params->group = NULL;
+        params++;
+    }
+}
+
 /*
  * Fills EC_KEY structure hidden in the app_data field of DSA structure
  * with parameter information, extracted from parameter array in
@@ -73,7 +94,7 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid)
     EC_POINT *P = NULL;
     BIGNUM *p = NULL, *q = NULL, *a = NULL, *b = NULL, *x = NULL, *y =
         NULL, *cofactor = NULL;
-    BN_CTX *ctx;
+    BN_CTX *ctx = NULL;
     int ok = 0;
 
     if (!eckey || !params) {
@@ -81,6 +102,15 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid)
         return 0;
     }
 
+    if (params->group) {
+        EC_GROUP_set_curve_name(params->group, nid);
+        if (!EC_KEY_set_group(eckey, params->group)) {
+            GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR);
+            goto end;
+        }
+        return 1;
+    }
+
     if (!(ctx = BN_CTX_new())) {
         GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_MALLOC_FAILURE);
         return 0;
@@ -132,16 +162,14 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid)
         goto end;
     }
     EC_GROUP_set_curve_name(grp, nid);
+    params->group = grp;
     if (!EC_KEY_set_group(eckey, grp)) {
         GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR);
         goto end;
     }
     ok = 1;
  end:
-    if (P)
-        EC_POINT_free(P);
-    if (grp)
-        EC_GROUP_free(grp);
+    EC_POINT_free(P);
     BN_CTX_end(ctx);
     BN_CTX_free(ctx);
     return ok;
@@ -337,10 +365,10 @@ int gost_ec_verify(const unsigned char *dgst, int dgst_len,
     ECDSA_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)) {
+        BN_is_negative(sig_s) || BN_is_negative(sig_r) ||
+        BN_ucmp(sig_s, order) >= 0 || BN_ucmp(sig_r, order) >= 0) {
         GOSTerr(GOST_F_GOST_EC_VERIFY, GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);
         goto err;
-
     }
 
     OPENSSL_assert(dgst_len == 32 || dgst_len == 64);