]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Let's wrap old and new key enncryption together
authorDmitry Belyavskiy <beldmit@gmail.com>
Tue, 4 Sep 2018 14:02:57 +0000 (17:02 +0300)
committerDmitry Belyavskiy <beldmit@gmail.com>
Tue, 4 Sep 2018 14:02:57 +0000 (17:02 +0300)
e_gost_err.c
e_gost_err.h
gost.txt
gost_ec_keyx.c
gost_lcl.h
gost_pmeth.c

index 0bc085642587f3698c12bef38824a168e4148cc8..c93a434058cf5acbedb6b532d9668b0b4b639f79 100644 (file)
@@ -53,6 +53,7 @@ static ERR_STRING_DATA GOST_str_functs[] = {
     {ERR_PACK(0, GOST_F_PKEY_GOST2018_DECRYPT, 0), "pkey_gost2018_decrypt"},
     {ERR_PACK(0, GOST_F_PKEY_GOST2018_ENCRYPT, 0), "pkey_gost2018_encrypt"},
     {ERR_PACK(0, GOST_F_PKEY_GOST_CTRL, 0), "pkey_gost_ctrl"},
+    {ERR_PACK(0, GOST_F_PKEY_GOST_DECRYPT, 0), "pkey_gost_decrypt"},
     {ERR_PACK(0, GOST_F_PKEY_GOST_ECCP_DECRYPT, 0), "pkey_GOST_ECcp_decrypt"},
     {ERR_PACK(0, GOST_F_PKEY_GOST_ECCP_ENCRYPT, 0), "pkey_GOST_ECcp_encrypt"},
     {ERR_PACK(0, GOST_F_PKEY_GOST_EC_CTRL_STR_256, 0),
@@ -60,6 +61,7 @@ static ERR_STRING_DATA GOST_str_functs[] = {
     {ERR_PACK(0, GOST_F_PKEY_GOST_EC_CTRL_STR_512, 0),
      "pkey_gost_ec_ctrl_str_512"},
     {ERR_PACK(0, GOST_F_PKEY_GOST_EC_DERIVE, 0), "pkey_gost_ec_derive"},
+    {ERR_PACK(0, GOST_F_PKEY_GOST_ENCRYPT, 0), "pkey_gost_encrypt"},
     {ERR_PACK(0, GOST_F_PKEY_GOST_GRASSHOPPER_MAC_SIGNCTX_INIT, 0),
      "pkey_gost_grasshopper_mac_signctx_init"},
     {ERR_PACK(0, GOST_F_PKEY_GOST_MAC_CTRL, 0), "pkey_gost_mac_ctrl"},
index 90c3b4139f9f782e1706ec720572c74fe72aa8c0..39b3da2c087aeab347a7bef489dde9178332b6fe 100644 (file)
@@ -60,11 +60,13 @@ void ERR_GOST_error(int function, int reason, char *file, int line);
 # define GOST_F_PKEY_GOST2018_DECRYPT                     150
 # define GOST_F_PKEY_GOST2018_ENCRYPT                     151
 # define GOST_F_PKEY_GOST_CTRL                            122
+# define GOST_F_PKEY_GOST_DECRYPT                         153
 # define GOST_F_PKEY_GOST_ECCP_DECRYPT                    123
 # define GOST_F_PKEY_GOST_ECCP_ENCRYPT                    124
 # define GOST_F_PKEY_GOST_EC_CTRL_STR_256                 125
 # define GOST_F_PKEY_GOST_EC_CTRL_STR_512                 126
 # define GOST_F_PKEY_GOST_EC_DERIVE                       127
+# define GOST_F_PKEY_GOST_ENCRYPT                         152
 # define GOST_F_PKEY_GOST_GRASSHOPPER_MAC_SIGNCTX_INIT    141
 # define GOST_F_PKEY_GOST_MAC_CTRL                        128
 # define GOST_F_PKEY_GOST_MAC_CTRL_STR                    129
index 540b755cab293cffe442c595f2dae04cd3f52a63..a0cb8ab4257860df4e60090bf6352fd64c9899d2 100644 (file)
--- a/gost.txt
+++ b/gost.txt
@@ -40,11 +40,13 @@ GOST_F_PKEY_GOST2012_PARAMGEN:121:pkey_gost2012_paramgen
 GOST_F_PKEY_GOST2018_DECRYPT:150:pkey_gost2018_decrypt
 GOST_F_PKEY_GOST2018_ENCRYPT:151:pkey_gost2018_encrypt
 GOST_F_PKEY_GOST_CTRL:122:pkey_gost_ctrl
+GOST_F_PKEY_GOST_DECRYPT:153:pkey_gost_decrypt
 GOST_F_PKEY_GOST_ECCP_DECRYPT:123:pkey_GOST_ECcp_decrypt
 GOST_F_PKEY_GOST_ECCP_ENCRYPT:124:pkey_GOST_ECcp_encrypt
 GOST_F_PKEY_GOST_EC_CTRL_STR_256:125:pkey_gost_ec_ctrl_str_256
 GOST_F_PKEY_GOST_EC_CTRL_STR_512:126:pkey_gost_ec_ctrl_str_512
 GOST_F_PKEY_GOST_EC_DERIVE:127:pkey_gost_ec_derive
+GOST_F_PKEY_GOST_ENCRYPT:152:pkey_gost_encrypt
 GOST_F_PKEY_GOST_GRASSHOPPER_MAC_SIGNCTX_INIT:141:\
        pkey_gost_grasshopper_mac_signctx_init
 GOST_F_PKEY_GOST_MAC_CTRL:128:pkey_gost_mac_ctrl
index 1e17f8356030e6d26b04e3f78bc611e53a42b196..409d8e19e07a480c2bb545fe4cdc12b3d62589c0 100644 (file)
@@ -229,7 +229,7 @@ int pkey_gost_ec_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
  * Implementation of GOST2001/12 key transport, cryptopro variation
  */
 
-int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
+static int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
                            size_t *out_len, const unsigned char *key,
                            size_t key_len)
 {
@@ -346,7 +346,7 @@ int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
  * EVP_PKEY_METHOD callback decrypt
  * Implementation of GOST2018 key transport
  */
-int pkey_gost2018_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
+static int pkey_gost2018_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
                           size_t *out_len, const unsigned char *key,
                           size_t key_len)
 {
@@ -435,11 +435,25 @@ int pkey_gost2018_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
     return ret;
 }
 
+int pkey_gost_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
+                      size_t *out_len, const unsigned char *key, size_t key_len)
+{
+    struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(pctx);
+    if (data->shared_ukm == NULL || data->shared_ukm_size == 8)
+        return pkey_GOST_ECcp_encrypt(pctx, out, out_len, key, key_len);
+    else if (data->shared_ukm_size == 32)
+        return pkey_gost2018_encrypt(pctx, out, out_len, key, key_len);
+    else {
+        GOSTerr(GOST_F_PKEY_GOST_ENCRYPT, ERR_R_INTERNAL_ERROR);
+        return -1;
+    }
+}
+
 /*
  * EVP_PKEY_METHOD callback decrypt
  * Implementation of GOST2001/12 key transport, cryptopro variation
  */
-int pkey_GOST_ECcp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
+static int pkey_GOST_ECcp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
                            size_t *key_len, const unsigned char *in,
                            size_t in_len)
 {
@@ -528,7 +542,7 @@ int pkey_GOST_ECcp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
  * EVP_PKEY_METHOD callback decrypt
  * Implementation of GOST2018 key transport
  */
-int pkey_gost2018_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
+static int pkey_gost2018_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
                           size_t *key_len, const unsigned char *in,
                           size_t in_len)
 {
@@ -593,3 +607,17 @@ int pkey_gost2018_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
     PSKeyTransport_gost_free(pst);
     return ret;
 }
+
+int pkey_gost_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
+                      size_t *key_len, const unsigned char *in, size_t in_len)
+{
+    struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(pctx);
+    if (data->shared_ukm == NULL || data->shared_ukm_size == 8)
+        return pkey_GOST_ECcp_decrypt(pctx, key, key_len, in, in_len);
+    else if (data->shared_ukm_size == 32)
+        return pkey_gost2018_decrypt(pctx, key, key_len, in, in_len);
+    else {
+        GOSTerr(GOST_F_PKEY_GOST_DECRYPT, ERR_R_INTERNAL_ERROR);
+        return -1;
+    }
+}
index 9b0fa1c1dcbabcb96b73ee5ced3528c25412fd98..cc1672c9249152069132041334c3cc9020a5a87a 100644 (file)
@@ -248,11 +248,11 @@ void inc_counter(unsigned char *buffer, size_t buf_len);
 # define EVP_MD_CTRL_MAC_LEN (EVP_MD_CTRL_ALG_CTRL+5)
 /* EVP_PKEY_METHOD key encryption callbacks */
 /* From gost_ec_keyx.c */
-int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out,
+int pkey_gost_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out,
                            size_t *outlen, const unsigned char *key,
                            size_t key_len);
 
-int pkey_GOST_ECcp_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out,
+int pkey_gost_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out,
                            size_t *outlen, const unsigned char *in,
                            size_t in_len);
 /* derive functions */
index ddbe1433ca6571f58e5853816e4edfea54d6e1f3..00cda702dd01eae44f889969d3acd973d4dc4178 100644 (file)
@@ -954,8 +954,8 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags)
 
         EVP_PKEY_meth_set_encrypt(*pmeth,
                                   pkey_gost_encrypt_init,
-                                  pkey_GOST_ECcp_encrypt);
-        EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
+                                  pkey_gost_encrypt);
+        EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_gost_decrypt);
         EVP_PKEY_meth_set_derive(*pmeth,
                                  pkey_gost_derive_init, pkey_gost_ec_derive);
         EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init,
@@ -971,8 +971,8 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags)
 
         EVP_PKEY_meth_set_encrypt(*pmeth,
                                   pkey_gost_encrypt_init,
-                                  pkey_GOST_ECcp_encrypt);
-        EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
+                                  pkey_gost_encrypt);
+        EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_gost_decrypt);
         EVP_PKEY_meth_set_derive(*pmeth,
                                  pkey_gost_derive_init, pkey_gost_ec_derive);
         EVP_PKEY_meth_set_paramgen(*pmeth,
@@ -989,8 +989,8 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags)
 
         EVP_PKEY_meth_set_encrypt(*pmeth,
                                   pkey_gost_encrypt_init,
-                                  pkey_GOST_ECcp_encrypt);
-        EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
+                                  pkey_gost_encrypt);
+        EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_gost_decrypt);
         EVP_PKEY_meth_set_derive(*pmeth,
                                  pkey_gost_derive_init, pkey_gost_ec_derive);
         EVP_PKEY_meth_set_paramgen(*pmeth,