]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_ec_keyx.c
Remove duplicates
[openssl-gost/engine.git] / gost_ec_keyx.c
index 2dd0d3ad11939bb797ed93e69cc8b56f1187e8a9..7043347b584381a9faaf3104fd7b00c043eef712 100644 (file)
@@ -8,6 +8,7 @@
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
 #include <openssl/evp.h>
+#include <openssl/err.h>
 #include <openssl/rand.h>
 #include <string.h>
 #include <openssl/objects.h>
@@ -35,7 +36,7 @@ static int VKO_compute_key(unsigned char *shared_key, size_t shared_key_size,
         half_len = buf_len >> 1;
 
     if (!ctx) {
-        GOSTerr(GOST_F_VKO_COMPUTE_KEY, GOST_R_NO_MEMORY);
+        GOSTerr(GOST_F_VKO_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);
         return 0;
     }
     BN_CTX_start(ctx);
@@ -43,7 +44,7 @@ static int VKO_compute_key(unsigned char *shared_key, size_t shared_key_size,
     databuf = OPENSSL_malloc(buf_len);
     hashbuf = OPENSSL_malloc(buf_len);
     if (!databuf || !hashbuf) {
-        GOSTerr(GOST_F_VKO_COMPUTE_KEY, GOST_R_MALLOC_FAILURE);
+        GOSTerr(GOST_F_VKO_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);
         goto err;
     }
 
@@ -60,7 +61,11 @@ static int VKO_compute_key(unsigned char *shared_key, size_t shared_key_size,
     Y = BN_CTX_get(ctx);
     EC_GROUP_get_order(EC_KEY_get0_group(priv_key), order, ctx);
     BN_mod_mul(p, key, UKM, order, ctx);
-    EC_POINT_mul(EC_KEY_get0_group(priv_key), pnt, NULL, pub_key, p, ctx);
+    if (!EC_POINT_mul
+        (EC_KEY_get0_group(priv_key), pnt, NULL, pub_key, p, ctx)) {
+        GOSTerr(GOST_F_VKO_COMPUTE_KEY, GOST_R_ERROR_POINT_MUL);
+        goto err;
+    }
     EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(priv_key),
                                         pnt, X, Y, ctx);
     /*
@@ -163,8 +168,7 @@ int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
     } else if (out) {
 
         if (RAND_bytes(ukm, 8) <= 0) {
-            GOSTerr(GOST_F_PKEY_GOST_ECCP_ENCRYPT,
-                    GOST_R_RANDOM_GENERATOR_FAILURE);
+            GOSTerr(GOST_F_PKEY_GOST_ECCP_ENCRYPT, GOST_R_RNG_ERROR);
             return 0;
         }
     }
@@ -189,7 +193,7 @@ int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
     }
     if (!get_gost_engine_param(GOST_PARAM_CRYPT_PARAMS)
         && param == gost_cipher_list) {
-        param = gost_cipher_list + 1;
+        param = gost_cipher_list;
     }
     if (out) {
         int dgst_nid = NID_undef;
@@ -229,7 +233,7 @@ int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
     }
     ASN1_OBJECT_free(gkt->key_agreement_info->cipher);
     gkt->key_agreement_info->cipher = OBJ_nid2obj(param->nid);
-    if (key_is_ephemeral && sec_key)
+    if (key_is_ephemeral)
         EVP_PKEY_free(sec_key);
     if (!key_is_ephemeral) {
         /* Set control "public key from client certificate used" */
@@ -244,7 +248,7 @@ int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
     GOST_KEY_TRANSPORT_free(gkt);
     return ret;
  err:
-    if (key_is_ephemeral && sec_key)
+    if (key_is_ephemeral)
         EVP_PKEY_free(sec_key);
     GOST_KEY_TRANSPORT_free(gkt);
     return -1;
@@ -331,9 +335,7 @@ int pkey_GOST_ECcp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
 
     ret = 1;
  err:
-    if (eph_key)
-        EVP_PKEY_free(eph_key);
-    if (gkt)
-        GOST_KEY_TRANSPORT_free(gkt);
+    EVP_PKEY_free(eph_key);
+    GOST_KEY_TRANSPORT_free(gkt);
     return ret;
 }