]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Allow to pass mac_size via -macopt
authorDmitry Belyavskiy <beldmit@gmail.com>
Sun, 3 Jan 2016 14:30:05 +0000 (17:30 +0300)
committerDmitry Belyavskiy <beldmit@gmail.com>
Sun, 3 Jan 2016 14:30:05 +0000 (17:30 +0300)
e_gost_err.c
e_gost_err.h
gost_lcl.h
gost_pmeth.c

index 488e0e977ef9a6a7852912ac00e972d1e067240a..baaeb44ec7aebeac60076bf65a96bb87b65f139e 100644 (file)
@@ -98,6 +98,8 @@ static ERR_STRING_DATA GOST_str_functs[] = {
     {ERR_FUNC(GOST_F_PKEY_GOST_MAC_CTRL), "PKEY_GOST_MAC_CTRL"},
     {ERR_FUNC(GOST_F_PKEY_GOST_MAC_CTRL_STR), "PKEY_GOST_MAC_CTRL_STR"},
     {ERR_FUNC(GOST_F_PKEY_GOST_MAC_KEYGEN), "PKEY_GOST_MAC_KEYGEN"},
+    {ERR_FUNC(GOST_F_PKEY_GOST_MAC_SIGNCTX_INIT),
+     "PKEY_GOST_MAC_SIGNCTX_INIT"},
     {ERR_FUNC(GOST_F_PRINT_GOST_EC_PUB), "PRINT_GOST_EC_PUB"},
     {ERR_FUNC(GOST_F_PRIV_DECODE_GOST), "PRIV_DECODE_GOST"},
     {ERR_FUNC(GOST_F_PUB_DECODE_GOST_EC), "PUB_DECODE_GOST_EC"},
index c62471343d9b361c63037f1d1f77cfa0b8230919..e8a5f2877ba63740014a0ae5f8f09037ad3adeae 100644 (file)
@@ -64,9 +64,9 @@ extern "C" {
  * The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
  */
-    void ERR_load_GOST_strings(void);
-    void ERR_unload_GOST_strings(void);
-    void ERR_GOST_error(int function, int reason, char *file, int line);
+void ERR_load_GOST_strings(void);
+void ERR_unload_GOST_strings(void);
+void ERR_GOST_error(int function, int reason, char *file, int line);
 # define GOSTerr(f,r) ERR_GOST_error((f),(r),__FILE__,__LINE__)
 
 /* Error codes for the GOST functions. */
@@ -98,6 +98,7 @@ extern "C" {
 # define GOST_F_PKEY_GOST_MAC_CTRL                        123
 # define GOST_F_PKEY_GOST_MAC_CTRL_STR                    124
 # define GOST_F_PKEY_GOST_MAC_KEYGEN                      125
+# define GOST_F_PKEY_GOST_MAC_SIGNCTX_INIT                132
 # define GOST_F_PRINT_GOST_EC_PUB                         126
 # define GOST_F_PRIV_DECODE_GOST                          127
 # define GOST_F_PUB_DECODE_GOST_EC                        128
@@ -138,7 +139,7 @@ extern "C" {
 # define GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND            126
 # define GOST_R_UNSUPPORTED_PARAMETER_SET                 127
 
-# ifdef  __cplusplus
+#ifdef  __cplusplus
 }
-# endif
+#endif
 #endif
index b089eb2a476d08f6d79e1d35adcbc890f78ab892..bb18ff1122aa5bc10826012d62806db92a272c50 100644 (file)
@@ -80,6 +80,7 @@ struct gost_mac_pmeth_data {
 struct gost_mac_key {
     int mac_param_nid;
     unsigned char key[32];
+    short int mac_size;
 };
 /* GOST-specific ASN1 structures */
 
index de35388de63f6c01322e742c458570e974ed874f..2d580ae1d9228d0e264e0eb1d328db6c0aa400f5 100644 (file)
@@ -478,6 +478,7 @@ static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
         struct gost_mac_key *key = EVP_PKEY_get0(pkey);
         if (key) {
             data->mac_param_nid = key->mac_param_nid;
+                                               data->mac_size      = key->mac_size;
         }
     }
 
@@ -546,14 +547,6 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
         {
             struct gost_cipher_info *param = p2;
             data->mac_param_nid = param->nid;
-            struct gost_mac_key *key = NULL;
-            EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
-            if (pkey) {
-                key = EVP_PKEY_get0(pkey);
-                if (key) {
-                    key->mac_param_nid = param->nid;
-                }
-            }
             return 1;
         }
     case EVP_PKEY_CTRL_DIGESTINIT:
@@ -665,6 +658,7 @@ static int pkey_gost_mac_keygen_base(EVP_PKEY_CTX *ctx,
         return 0;
     memcpy(keydata->key, data->key, 32);
     keydata->mac_param_nid = data->mac_param_nid;
+               keydata->mac_size      = data->mac_size;
     EVP_PKEY_assign(pkey, mac_nid, keydata);
     return 1;
 }
@@ -681,6 +675,18 @@ static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
 
 static int pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
 {
+    struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
+
+               if (data == NULL) {
+                       pkey_gost_mac_init(ctx);
+               }
+
+    data = EVP_PKEY_CTX_get_data(ctx);
+    if (!data) {
+        GOSTerr(GOST_F_PKEY_GOST_MAC_SIGNCTX_INIT, GOST_R_MAC_KEY_NOT_SET);
+        return 0;
+    }
+
     return 1;
 }