Updated to EVP_PKEY_METHOD code... still doesn't do much.
authorDr. Stephen Henson <steve@openssl.org>
Thu, 6 Apr 2006 17:32:43 +0000 (17:32 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Thu, 6 Apr 2006 17:32:43 +0000 (17:32 +0000)
crypto/evp/evp.h
crypto/evp/evp_err.c
crypto/evp/evp_locl.h
crypto/evp/pmeth_lib.c

index 7d16da8..58a9325 100644 (file)
@@ -902,6 +902,16 @@ void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
                void (*pkey_ctrl)(EVP_PKEY *pkey, int op,
                                                        long arg1, void *arg2));
 
+
+
+
+const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type, ENGINE *e);
+EVP_PKEY_CTX *EVP_PKEY_CTX_new(int ktype, ENGINE *e);
+void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx);
+int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
+                               int cmd, int p1, void *p2);
+
+
 /* BEGIN ERROR CODES */
 /* 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.
@@ -931,6 +941,7 @@ void ERR_load_EVP_strings(void);
 #define EVP_F_EVP_PKCS82PKEY_BROKEN                     136
 #define EVP_F_EVP_PKEY2PKCS8_BROKEN                     113
 #define EVP_F_EVP_PKEY_COPY_PARAMETERS                  103
+#define EVP_F_EVP_PKEY_CTX_CTRL                                 137
 #define EVP_F_EVP_PKEY_DECRYPT                          104
 #define EVP_F_EVP_PKEY_ENCRYPT                          105
 #define EVP_F_EVP_PKEY_GET1_DH                          119
@@ -957,6 +968,7 @@ void ERR_load_EVP_strings(void);
 #define EVP_R_BN_DECODE_ERROR                           112
 #define EVP_R_BN_PUBKEY_ERROR                           113
 #define EVP_R_CIPHER_PARAMETER_ERROR                    122
+#define EVP_R_COMMAND_NOT_SUPPORTED                     147
 #define EVP_R_CTRL_NOT_IMPLEMENTED                      132
 #define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED            133
 #define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH                 138
@@ -972,6 +984,7 @@ void ERR_load_EVP_strings(void);
 #define EVP_R_INITIALIZATION_ERROR                      134
 #define EVP_R_INPUT_NOT_INITIALIZED                     111
 #define EVP_R_INVALID_KEY_LENGTH                        130
+#define EVP_R_INVALID_OPERATION                                 148
 #define EVP_R_IV_TOO_LARGE                              102
 #define EVP_R_KEYGEN_FAILURE                            120
 #define EVP_R_METHOD_NOT_SUPPORTED                      144
@@ -979,6 +992,7 @@ void ERR_load_EVP_strings(void);
 #define EVP_R_NO_CIPHER_SET                             131
 #define EVP_R_NO_DIGEST_SET                             139
 #define EVP_R_NO_DSA_PARAMETERS                                 116
+#define EVP_R_NO_OPERATION_SET                          149
 #define EVP_R_NO_SIGN_FUNCTION_CONFIGURED               104
 #define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED             105
 #define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE                         117
index c312074..b37d99d 100644 (file)
@@ -90,6 +90,7 @@ static ERR_STRING_DATA EVP_str_functs[]=
 {ERR_FUNC(EVP_F_EVP_PKCS82PKEY_BROKEN),        "EVP_PKCS82PKEY_BROKEN"},
 {ERR_FUNC(EVP_F_EVP_PKEY2PKCS8_BROKEN),        "EVP_PKEY2PKCS8_broken"},
 {ERR_FUNC(EVP_F_EVP_PKEY_COPY_PARAMETERS),     "EVP_PKEY_copy_parameters"},
+{ERR_FUNC(EVP_F_EVP_PKEY_CTX_CTRL),    "EVP_PKEY_CTX_CTRL"},
 {ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT),     "EVP_PKEY_decrypt"},
 {ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT),     "EVP_PKEY_encrypt"},
 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_DH),     "EVP_PKEY_get1_DH"},
@@ -119,6 +120,7 @@ static ERR_STRING_DATA EVP_str_reasons[]=
 {ERR_REASON(EVP_R_BN_DECODE_ERROR)       ,"bn decode error"},
 {ERR_REASON(EVP_R_BN_PUBKEY_ERROR)       ,"bn pubkey error"},
 {ERR_REASON(EVP_R_CIPHER_PARAMETER_ERROR),"cipher parameter error"},
+{ERR_REASON(EVP_R_COMMAND_NOT_SUPPORTED) ,"command not supported"},
 {ERR_REASON(EVP_R_CTRL_NOT_IMPLEMENTED)  ,"ctrl not implemented"},
 {ERR_REASON(EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED),"ctrl operation not implemented"},
 {ERR_REASON(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH),"data not multiple of block length"},
@@ -134,6 +136,7 @@ static ERR_STRING_DATA EVP_str_reasons[]=
 {ERR_REASON(EVP_R_INITIALIZATION_ERROR)  ,"initialization error"},
 {ERR_REASON(EVP_R_INPUT_NOT_INITIALIZED) ,"input not initialized"},
 {ERR_REASON(EVP_R_INVALID_KEY_LENGTH)    ,"invalid key length"},
+{ERR_REASON(EVP_R_INVALID_OPERATION)     ,"invalid operation"},
 {ERR_REASON(EVP_R_IV_TOO_LARGE)          ,"iv too large"},
 {ERR_REASON(EVP_R_KEYGEN_FAILURE)        ,"keygen failure"},
 {ERR_REASON(EVP_R_METHOD_NOT_SUPPORTED)  ,"method not supported"},
@@ -141,6 +144,7 @@ static ERR_STRING_DATA EVP_str_reasons[]=
 {ERR_REASON(EVP_R_NO_CIPHER_SET)         ,"no cipher set"},
 {ERR_REASON(EVP_R_NO_DIGEST_SET)         ,"no digest set"},
 {ERR_REASON(EVP_R_NO_DSA_PARAMETERS)     ,"no dsa parameters"},
+{ERR_REASON(EVP_R_NO_OPERATION_SET)      ,"no operation set"},
 {ERR_REASON(EVP_R_NO_SIGN_FUNCTION_CONFIGURED),"no sign function configured"},
 {ERR_REASON(EVP_R_NO_VERIFY_FUNCTION_CONFIGURED),"no verify function configured"},
 {ERR_REASON(EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE),"pkcs8 unknown broken type"},
index af02514..e405368 100644 (file)
@@ -262,6 +262,8 @@ struct evp_pkey_ctx_st
 struct evp_pkey_method_st
        {
        int pkey_id;
+       int flags;
+       int (*init)(EVP_PKEY_CTX *ctx);
        int (*paramgen_init)(EVP_PKEY_CTX *ctx);
        int (*paramgen)(EVP_PKEY *key, EVP_PKEY_CTX *ctx);
 
index 1830ea1..3a854f0 100644 (file)
@@ -60,6 +60,7 @@
 #include <stdlib.h>
 #include <openssl/objects.h>
 #include "cryptlib.h"
+#include <openssl/evp.h>
 #include "evp_locl.h"
 
 STACK *app_pkey_methods = NULL;
@@ -112,35 +113,58 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_new(int ktype, ENGINE *e)
        ret->pkey = NULL;
        ret->data = NULL;
 
+       if (pmeth->init)
+               {
+               if (pmeth->init(ret) <= 0)
+                       {
+                       EVP_PKEY_CTX_free(ret);
+                       return NULL;
+                       }
+               }
+
        return ret;
        }
 
+void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
+       {
+       if (ctx->pmeth && ctx->pmeth->cleanup)
+               ctx->pmeth->cleanup(ctx);
+       if (ctx->pkey)
+               EVP_PKEY_free(ctx->pkey);
+       OPENSSL_free(ctx);
+       }
+
 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
                                int cmd, int p1, void *p2)
        {
+       int ret;
        if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl)
+               {
+               EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
                return -2;
+               }
        if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
                return -1;
 
        if (ctx->operation == EVP_PKEY_OP_UNDEFINED)
                {
-               /* Not initialized */
+               EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET);
                return -1;
                }
 
        if ((optype != -1) && (ctx->operation != optype))
                {
-               /* Invalid operation type */
+               EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION);
                return -1;
                }
 
-       return ctx->pmeth->ctrl(ctx, cmd, p1, p2);
-
-       }
-
+       ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
 
+       if (ret == -2)
+               EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
 
+       return ret;
 
+       }