modes/modes_lcl.h: make it indent-friendly.
[oweals/openssl.git] / engines / ccgost / gost_pmeth.c
index 2861d383272d227598ea3e52ac8e88e8b5f2acb1..4520387fc8a7d07824d494ebf6f37e560b6e59f8 100644 (file)
@@ -10,6 +10,7 @@
 #include <openssl/evp.h>
 #include <openssl/objects.h>
 #include <openssl/ec.h>
+#include <openssl/err.h>
 #include <openssl/x509v3.h> /*For string_to_hex */
 #include <stdlib.h>
 #include <string.h>
@@ -86,9 +87,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,9 +107,21 @@ 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:
+                       if (p1 == 0 || p1 == 1) /* call from EVP_PKEY_derive_set_peer */
+                               return 1;
+                       if (p1 == 2)            /* TLS: peer key used? */
+                               return pctx->peer_key_used;
+                       if (p1 == 3)            /* TLS: peer key used! */
+                               return (pctx->peer_key_used = 1);
+                       return -2;
                }
        return -2;
        }
@@ -116,7 +139,7 @@ static int pkey_gost_ctrl94_str(EVP_PKEY_CTX *ctx,
                        }
                if (strlen(value) == 1)
                        {
-                       switch(toupper(value[0]))
+                       switch(toupper((unsigned char)value[0]))
                                {
                                case 'A':
                                        param_nid = NID_id_GostR3410_94_CryptoPro_A_ParamSet;
@@ -135,9 +158,9 @@ static int pkey_gost_ctrl94_str(EVP_PKEY_CTX *ctx,
                                        break;
                                }
                        }
-               else if ((strlen(value) == 2) && (toupper(value[0]) == 'X'))
+               else if ((strlen(value) == 2) && (toupper((unsigned char)value[0]) == 'X'))
                        {
-                       switch (toupper(value[1]))
+                       switch (toupper((unsigned char)value[1]))
                                {
                                case 'A':
                                        param_nid = NID_id_GostR3410_94_CryptoPro_XchA_ParamSet;
@@ -191,7 +214,7 @@ static int pkey_gost_ctrl01_str(EVP_PKEY_CTX *ctx,
                        }
                if (strlen(value) == 1)
                        {
-                       switch(toupper(value[0]))
+                       switch(toupper((unsigned char)value[0]))
                                {
                                case 'A':
                                        param_nid = NID_id_GostR3410_2001_CryptoPro_A_ParamSet;
@@ -210,9 +233,9 @@ static int pkey_gost_ctrl01_str(EVP_PKEY_CTX *ctx,
                                        break;
                                }
                        }
-               else if ((strlen(value) == 2) && (toupper(value[0]) == 'X'))
+               else if ((strlen(value) == 2) && (toupper((unsigned char)value[0]) == 'X'))
                        {
-                       switch (toupper(value[1]))
+                       switch (toupper((unsigned char)value[1]))
                                {
                                case 'A':
                                        param_nid = NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet;
@@ -451,6 +474,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:
@@ -514,6 +541,7 @@ static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx,
                                {
                                GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
                                        GOST_R_INVALID_MAC_KEY_LENGTH);
+                               OPENSSL_free(keybuf);
                                return 0;       
                                }
                        ret= pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
@@ -535,6 +563,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;
@@ -611,4 +641,3 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth,int flags)
        
        return 1;
        }
-