Make {RSA,DSA,DH}_new_method obtain and release an ENGINE
authorDr. Stephen Henson <steve@openssl.org>
Sat, 9 Mar 2002 18:25:03 +0000 (18:25 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sat, 9 Mar 2002 18:25:03 +0000 (18:25 +0000)
functional reference in all cases.

crypto/dh/dh.h
crypto/dh/dh_err.c
crypto/dh/dh_lib.c
crypto/dsa/dsa.h
crypto/dsa/dsa_err.c
crypto/dsa/dsa_lib.c
crypto/rsa/rsa_lib.c

index 9bc1d31..15cf70d 100644 (file)
@@ -195,7 +195,7 @@ void ERR_load_DH_strings(void);
 #define DH_F_DH_COMPUTE_KEY                             102
 #define DH_F_DH_GENERATE_KEY                            103
 #define DH_F_DH_GENERATE_PARAMETERS                     104
-#define DH_F_DH_NEW                                     105
+#define DH_F_DH_NEW_METHOD                              105
 
 /* Reason codes. */
 #define DH_R_NO_PRIVATE_VALUE                           100
index 86764a3..2257793 100644 (file)
@@ -71,7 +71,7 @@ static ERR_STRING_DATA DH_str_functs[]=
 {ERR_PACK(0,DH_F_DH_COMPUTE_KEY,0),    "DH_compute_key"},
 {ERR_PACK(0,DH_F_DH_GENERATE_KEY,0),   "DH_generate_key"},
 {ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0),    "DH_generate_parameters"},
-{ERR_PACK(0,DH_F_DH_NEW,0),    "DH_new"},
+{ERR_PACK(0,DH_F_DH_NEW_METHOD,0),     "DH_new_method"},
 {0,NULL}
        };
 
index 367c19d..7adf48e 100644 (file)
@@ -107,20 +107,29 @@ DH *DH_new_method(ENGINE *engine)
        ret=(DH *)OPENSSL_malloc(sizeof(DH));
        if (ret == NULL)
                {
-               DHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE);
+               DHerr(DH_F_DH_NEW_METHOD,ERR_R_MALLOC_FAILURE);
                return(NULL);
                }
 
        ret->meth = DH_get_default_method();
-       ret->engine = engine;
-       if(!ret->engine)
+       if (engine)
+               {
+               if (!ENGINE_init(engine))
+                       {
+                       DSAerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);
+                       OPENSSL_free(ret);
+                       return NULL;
+                       }
+               ret->engine = engine;
+               }
+       else
                ret->engine = ENGINE_get_default_DH();
        if(ret->engine)
                {
                ret->meth = ENGINE_get_DH(ret->engine);
                if(!ret->meth)
                        {
-                       DHerr(DH_F_DH_NEW,ERR_R_ENGINE_LIB);
+                       DHerr(DH_F_DH_NEW_METHOD,ERR_R_ENGINE_LIB);
                        ENGINE_finish(ret->engine);
                        OPENSSL_free(ret);
                        return NULL;
@@ -145,6 +154,8 @@ DH *DH_new_method(ENGINE *engine)
        CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
        if ((ret->meth->init != NULL) && !ret->meth->init(ret))
                {
+               if (ret->engine)
+                       ENGINE_finish(ret->engine);
                CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
                OPENSSL_free(ret);
                ret=NULL;
index 1ddc37f..9b3baad 100644 (file)
@@ -230,7 +230,7 @@ void ERR_load_DSA_strings(void);
 #define DSA_F_DSAPARAMS_PRINT_FP                        101
 #define DSA_F_DSA_DO_SIGN                               112
 #define DSA_F_DSA_DO_VERIFY                             113
-#define DSA_F_DSA_NEW                                   103
+#define DSA_F_DSA_NEW_METHOD                            103
 #define DSA_F_DSA_PRINT                                         104
 #define DSA_F_DSA_PRINT_FP                              105
 #define DSA_F_DSA_SIGN                                  106
index 2956c36..79aa4ff 100644 (file)
@@ -71,7 +71,7 @@ static ERR_STRING_DATA DSA_str_functs[]=
 {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0),       "DSAparams_print_fp"},
 {ERR_PACK(0,DSA_F_DSA_DO_SIGN,0),      "DSA_do_sign"},
 {ERR_PACK(0,DSA_F_DSA_DO_VERIFY,0),    "DSA_do_verify"},
-{ERR_PACK(0,DSA_F_DSA_NEW,0),  "DSA_new"},
+{ERR_PACK(0,DSA_F_DSA_NEW_METHOD,0),   "DSA_new_method"},
 {ERR_PACK(0,DSA_F_DSA_PRINT,0),        "DSA_print"},
 {ERR_PACK(0,DSA_F_DSA_PRINT_FP,0),     "DSA_print_fp"},
 {ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"},
index 900e009..da2cdfa 100644 (file)
@@ -110,19 +110,28 @@ DSA *DSA_new_method(ENGINE *engine)
        ret=(DSA *)OPENSSL_malloc(sizeof(DSA));
        if (ret == NULL)
                {
-               DSAerr(DSA_F_DSA_NEW,ERR_R_MALLOC_FAILURE);
+               DSAerr(DSA_F_DSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
                return(NULL);
                }
        ret->meth = DSA_get_default_method();
-       ret->engine = engine;
-       if(!ret->engine)
+       if (engine)
+               {
+               if (!ENGINE_init(engine))
+                       {
+                       DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
+                       OPENSSL_free(ret);
+                       return NULL;
+                       }
+               ret->engine = engine;
+               }
+       else
                ret->engine = ENGINE_get_default_DSA();
        if(ret->engine)
                {
                ret->meth = ENGINE_get_DSA(ret->engine);
                if(!ret->meth)
                        {
-                       DSAerr(DSA_F_DSA_NEW,
+                       DSAerr(DSA_F_DSA_NEW_METHOD,
                                ERR_R_ENGINE_LIB);
                        ENGINE_finish(ret->engine);
                        OPENSSL_free(ret);
@@ -149,6 +158,8 @@ DSA *DSA_new_method(ENGINE *engine)
        CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
        if ((ret->meth->init != NULL) && !ret->meth->init(ret))
                {
+               if (ret->engine)
+                       ENGINE_finish(ret->engine);
                CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
                OPENSSL_free(ret);
                ret=NULL;
index 3856ea5..9323574 100644 (file)
@@ -130,8 +130,17 @@ RSA *RSA_new_method(ENGINE *engine)
                }
 
        ret->meth = RSA_get_default_method();
-       ret->engine = engine;
-       if(!ret->engine)
+       if (engine)
+               {
+               if (!ENGINE_init(engine))
+                       {
+                       RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);
+                       OPENSSL_free(ret);
+                       return NULL;
+                       }
+               ret->engine = engine;
+               }
+       else
                ret->engine = ENGINE_get_default_RSA();
        if(ret->engine)
                {
@@ -166,6 +175,8 @@ RSA *RSA_new_method(ENGINE *engine)
        CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
        if ((ret->meth->init != NULL) && !ret->meth->init(ret))
                {
+               if (ret->engine)
+                       ENGINE_finish(ret->engine);
                CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
                OPENSSL_free(ret);
                ret=NULL;