]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_pmeth.c
Remove dependency from DSA
[openssl-gost/engine.git] / gost_pmeth.c
index e615d012936c29bd4ec75319ae9a2a7473af9ff1..ddbe1433ca6571f58e5853816e4edfea54d6e1f3 100644 (file)
@@ -151,6 +151,10 @@ static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
             return 0;
         }
         memcpy(pctx->shared_ukm, p2, (int)p1);
+        pctx->shared_ukm_size = p1;
+        return 1;
+    case EVP_PKEY_CTRL_CIPHER:
+        pctx->cipher_nid = p1;
         return 1;
     case EVP_PKEY_CTRL_PEER_KEY:
         if (p1 == 0 || p1 == 1) /* call from EVP_PKEY_derive_set_peer */
@@ -365,17 +369,17 @@ static int pkey_gost2012cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
 /* ----------- sign callbacks --------------------------------------*/
 /*
  * Packs signature according to Cryptopro rules
- * and frees up DSA_SIG structure
+ * and frees up ECDSA_SIG structure
  */
-int pack_sign_cp(DSA_SIG *s, int order, unsigned char *sig, size_t *siglen)
+int pack_sign_cp(ECDSA_SIG *s, int order, unsigned char *sig, size_t *siglen)
 {
     const BIGNUM *sig_r = NULL, *sig_s = NULL;
-    DSA_SIG_get0(s, &sig_r, &sig_s);
+    ECDSA_SIG_get0(s, &sig_r, &sig_s);
     *siglen = 2 * order;
     memset(sig, 0, *siglen);
     store_bignum(sig_s, sig, order);
     store_bignum(sig_r, sig + order, order);
-    DSA_SIG_free(s);
+    ECDSA_SIG_free(s);
     return 1;
 }
 
@@ -383,7 +387,7 @@ static int pkey_gost_ec_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
                                 size_t *siglen, const unsigned char *tbs,
                                 size_t tbs_len)
 {
-    DSA_SIG *unpacked_sig = NULL;
+    ECDSA_SIG *unpacked_sig = NULL;
     EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
     int order = 0;
 
@@ -417,19 +421,19 @@ static int pkey_gost_ec_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
 
 /* ------------------- verify callbacks ---------------------------*/
 /* Unpack signature according to cryptopro rules  */
-DSA_SIG *unpack_cp_signature(const unsigned char *sigbuf, size_t siglen)
+ECDSA_SIG *unpack_cp_signature(const unsigned char *sigbuf, size_t siglen)
 {
-    DSA_SIG *sig;
+    ECDSA_SIG *sig;
     BIGNUM *r = NULL, *s = NULL;
 
-    sig = DSA_SIG_new();
+    sig = ECDSA_SIG_new();
     if (sig == NULL) {
         GOSTerr(GOST_F_UNPACK_CP_SIGNATURE, ERR_R_MALLOC_FAILURE);
         return NULL;
     }
     s = BN_bin2bn(sigbuf, siglen / 2, NULL);
     r = BN_bin2bn(sigbuf + siglen / 2, siglen / 2, NULL);
-               DSA_SIG_set0(sig, r, s);
+               ECDSA_SIG_set0(sig, r, s);
     return sig;
 }
 
@@ -439,7 +443,7 @@ static int pkey_gost_ec_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
 {
     int ok = 0;
     EVP_PKEY *pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
-    DSA_SIG *s = (sig) ? unpack_cp_signature(sig, siglen) : NULL;
+    ECDSA_SIG *s = (sig) ? unpack_cp_signature(sig, siglen) : NULL;
     if (!s)
         return 0;
 #ifdef DEBUG_SIGN
@@ -451,7 +455,7 @@ static int pkey_gost_ec_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
 #endif
     if (pub_key)
         ok = gost_ec_verify(tbs, tbs_len, s, EVP_PKEY_get0(pub_key));
-    DSA_SIG_free(s);
+    ECDSA_SIG_free(s);
     return ok;
 }
 
@@ -556,8 +560,7 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
     case EVP_PKEY_CTRL_MD:
         {
             int nid = EVP_MD_type((const EVP_MD *)p2);
-            if (nid != NID_id_Gost28147_89_MAC && nid != NID_gost_mac_12
-                && nid != NID_magma_mac && nid != NID_grasshopper_mac) {
+            if (nid != NID_id_Gost28147_89_MAC && nid != NID_gost_mac_12) {
                 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
                         GOST_R_INVALID_DIGEST_TYPE);
                 return 0;
@@ -615,7 +618,6 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
         }
     case EVP_PKEY_CTRL_MAC_LEN:
         {
-                               /*TODO*/
             if (p1 < 1 || p1 > 8) {
 
                 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_SIZE);
@@ -747,8 +749,7 @@ static int pkey_gost_omac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2, si
         }
     case EVP_PKEY_CTRL_MAC_LEN:
         {
-                               /*TODO*/
-            if (p1 < 1 || p1 > 8) {
+            if (p1 < 1 || p1 > max_size) {
 
                 GOSTerr(GOST_F_PKEY_GOST_OMAC_CTRL, GOST_R_INVALID_MAC_SIZE);
                 return 0;