pkey_gost_mac_keygen: check for NULL after allocating keydata
[openssl.git] / engines / ccgost / gost_pmeth.c
index 0bd08e93010018eda42cb1450d786af83451879b..7ccae8657e672a90f6fb03f44e6132a5d3a8ed66 100644 (file)
@@ -86,9 +86,19 @@ static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
                }
                break;
 
+               case EVP_PKEY_CTRL_GET_MD:
+               *(const EVP_MD **)p2 = pctx->md;
+               return 1;
+
                case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
                case EVP_PKEY_CTRL_PKCS7_DECRYPT:
                case EVP_PKEY_CTRL_PKCS7_SIGN:
+               case EVP_PKEY_CTRL_DIGESTINIT:
+#ifndef OPENSSL_NO_CMS         
+               case EVP_PKEY_CTRL_CMS_ENCRYPT:
+               case EVP_PKEY_CTRL_CMS_DECRYPT:
+               case EVP_PKEY_CTRL_CMS_SIGN:
+#endif         
                        return 1;
 
                case EVP_PKEY_CTRL_GOST_PARAMSET:
@@ -96,6 +106,11 @@ static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
                        return 1;
                case EVP_PKEY_CTRL_SET_IV:
                        pctx->shared_ukm=OPENSSL_malloc((int)p1);
+                       if (pctx->shared_ukm == NULL)
+                               {
+                               GOSTerr(GOST_F_PKEY_GOST_CTRL, ERR_R_MALLOC_FAILURE);
+                               return 0;
+                               }
                        memcpy(pctx->shared_ukm,p2,(int) p1);
                        return 1;
                case EVP_PKEY_CTRL_PEER_KEY:
@@ -458,6 +473,10 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
                }
                break;
 
+               case EVP_PKEY_CTRL_GET_MD:
+               *(const EVP_MD **)p2 = data->md;
+               return 1;
+
                case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
                case EVP_PKEY_CTRL_PKCS7_DECRYPT:
                case EVP_PKEY_CTRL_PKCS7_SIGN:
@@ -543,6 +562,8 @@ static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
                        return 0;
                }
                keydata = OPENSSL_malloc(32);
+               if (keydata == NULL)
+                       return 0;
                memcpy(keydata,data->key,32);
                EVP_PKEY_assign(pkey, NID_id_Gost28147_89_MAC, keydata);
                return 1;