]> granicus.if.org Git - openssl/commitdiff
Add functions to set ECDSA_METHOD structure.
authorDr. Stephen Henson <steve@openssl.org>
Tue, 17 Sep 2013 23:50:15 +0000 (00:50 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Wed, 18 Sep 2013 00:23:40 +0000 (01:23 +0100)
Add various functions to allocate and set the fields of an ECDSA_METHOD
structure.
(cherry picked from commit 94c2f77a62be7079ab1893ab14b18a30157c4532)

CHANGES
crypto/ecdsa/ecdsa.h
crypto/ecdsa/ecs_err.c
crypto/ecdsa/ecs_lib.c
crypto/ecdsa/ecs_locl.h

diff --git a/CHANGES b/CHANGES
index c8e3813f6108ab1a66f1c5a257678e51872bbd31..b175fbd8c4f8471991d708728a0cc5d89ae878b4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,10 @@
 
  Changes between 1.0.1e and 1.0.2 [xx XXX xxxx]
 
+  *) Add functions to allocate and set the fields of an ECDSA_METHOD
+     structure.
+     [Douglas E. Engert, Steve Henson]
+
   *) Add option SSL_OP_SAFARI_ECDHE_ECDSA_BUG (part of SSL_OP_ALL) which
      avoids preferring ECDHE-ECDSA ciphers when the client appears to be
      Safari on OS X.  Safari on OS X 10.8..10.8.3 advertises support for
index 7fb5254b62e61f2bd6a1002140b0d34a1dc8d938..418b218d1297d423a131e7890ca67f45bc737efe 100644 (file)
@@ -229,6 +229,59 @@ int          ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg);
 void     *ECDSA_get_ex_data(EC_KEY *d, int idx);
 
 
+/** Allocates and initialize a ECDSA_METHOD structure
+ *  \param ecdsa_method pointer to ECDSA_METHOD to copy.  (May be NULL)
+ *  \return pointer to a ECDSA_METHOD structure or NULL if an error occurred
+ */
+
+ECDSA_METHOD *ECDSA_METHOD_new(ECDSA_METHOD *ecdsa_method);
+
+/** frees a ECDSA_METHOD structure
+ *  \param  ecdsa_method  pointer to the ECDSA_METHOD structure
+ */
+void ECDSA_METHOD_free(ECDSA_METHOD *ecdsa_method);
+
+/**  Set the ECDSA_do_sign function in the ECDSA_METHOD
+ *   \param  ecdsa_method  pointer to existing ECDSA_METHOD
+ *   \param  ecdsa_do_sign a funtion of type ECDSA_do_sign
+ */
+
+void ECDSA_METHOD_set_sign(ECDSA_METHOD *ecdsa_method,
+        ECDSA_SIG *(*ecdsa_do_sign)(const unsigned char *dgst, int dgst_len,
+                const BIGNUM *inv, const BIGNUM *rp, EC_KEY *eckey));
+
+/**  Set the  ECDSA_sign_setup function in the ECDSA_METHOD
+ *   \param  ecdsa_method  pointer to existing ECDSA_METHOD
+ *   \param  ecdsa_sign_setup a funtion of type ECDSA_sign_setup
+ */
+
+void ECDSA_METHOD_set_sign_setup(ECDSA_METHOD *ecdsa_method,
+        int (*ecdsa_sign_setup)(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv,
+                BIGNUM **r));
+
+/**  Set the ECDSA_do_verify function in the ECDSA_METHOD
+ *   \param  ecdsa_method  pointer to existing ECDSA_METHOD
+ *   \param  ecdsa_do_verify a funtion of type ECDSA_do_verify
+ */
+
+void ECDSA_METHOD_set_verify(ECDSA_METHOD *ecdsa_method,
+        int (*ecdsa_do_verify)(const unsigned char *dgst, int dgst_len,
+                const ECDSA_SIG *sig, EC_KEY *eckey));
+
+void ECDSA_METHOD_set_flags(ECDSA_METHOD *ecdsa_method, int flags);
+
+/**  Set the flags field in the ECDSA_METHOD
+ *   \param  ecdsa_method  pointer to existing ECDSA_METHOD
+ *   \param  flags flags value to set
+ */
+
+void ECDSA_METHOD_set_name(ECDSA_METHOD *ecdsa_method, char *name);
+
+/**  Set the name field in the ECDSA_METHOD
+ *   \param  ecdsa_method  pointer to existing ECDSA_METHOD
+ *   \param  name name to set
+ */
+
 /* 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.
@@ -242,6 +295,7 @@ void ERR_load_ECDSA_strings(void);
 #define ECDSA_F_ECDSA_DATA_NEW_METHOD                   100
 #define ECDSA_F_ECDSA_DO_SIGN                           101
 #define ECDSA_F_ECDSA_DO_VERIFY                                 102
+#define ECDSA_F_ECDSA_METHOD_NEW                        105
 #define ECDSA_F_ECDSA_SIGN_SETUP                        103
 
 /* Reason codes. */
index 81542e6d15394939f98f03974d0374e3d68a1441..e866b1f6a1675f5180af852b5e438fc6b7657456 100644 (file)
@@ -74,6 +74,7 @@ static ERR_STRING_DATA ECDSA_str_functs[]=
 {ERR_FUNC(ECDSA_F_ECDSA_DATA_NEW_METHOD),      "ECDSA_DATA_NEW_METHOD"},
 {ERR_FUNC(ECDSA_F_ECDSA_DO_SIGN),      "ECDSA_do_sign"},
 {ERR_FUNC(ECDSA_F_ECDSA_DO_VERIFY),    "ECDSA_do_verify"},
+{ERR_FUNC(ECDSA_F_ECDSA_METHOD_NEW),   "ECDSA_METHOD_new"},
 {ERR_FUNC(ECDSA_F_ECDSA_SIGN_SETUP),   "ECDSA_sign_setup"},
 {0,NULL}
        };
index 814a6bf40465ab7acc83797bcf9735a0b544543c..0d79469201a8c78e693a957cb0b86cc10eed5384 100644 (file)
@@ -283,3 +283,68 @@ void *ECDSA_get_ex_data(EC_KEY *d, int idx)
                return NULL;
        return(CRYPTO_get_ex_data(&ecdsa->ex_data,idx));
 }
+
+ECDSA_METHOD *ECDSA_METHOD_new(ECDSA_METHOD *ecdsa_meth)
+       {
+       ECDSA_METHOD  *ret;
+
+       ret = OPENSSL_malloc(sizeof(ECDSA_METHOD));
+       if (ret == NULL)
+               {
+               ECDSAerr(ECDSA_F_ECDSA_METHOD_NEW, ERR_R_MALLOC_FAILURE);
+               return NULL;
+               }
+
+       if (ecdsa_meth)
+               *ret = *ecdsa_meth;
+       else
+               {
+               ret->ecdsa_sign_setup = 0;
+               ret->ecdsa_do_sign = 0;
+               ret->ecdsa_do_verify = 0;
+               ret->name = NULL;
+               ret->flags = 0;
+               }
+       ret->flags |= ECDSA_METHOD_FLAG_ALLOCATED;
+       return ret;
+       }
+
+
+void ECDSA_METHOD_set_sign(ECDSA_METHOD *ecdsa_method,
+       ECDSA_SIG *(*ecdsa_do_sign)(const unsigned char *dgst, int dgst_len,
+               const BIGNUM *inv, const BIGNUM *rp, EC_KEY *eckey))
+       {
+       ecdsa_method->ecdsa_do_sign = ecdsa_do_sign;
+       }
+
+void ECDSA_METHOD_set_sign_setup(ECDSA_METHOD *ecdsa_method,
+       int (*ecdsa_sign_setup)(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv,
+               BIGNUM **r))
+       {
+       ecdsa_method->ecdsa_sign_setup = ecdsa_sign_setup;
+       }
+
+void ECDSA_METHOD_set_verify(ECDSA_METHOD *ecdsa_method,
+       int (*ecdsa_do_verify)(const unsigned char *dgst, int dgst_len,
+               const ECDSA_SIG *sig, EC_KEY *eckey))
+       {
+       ecdsa_method->ecdsa_do_verify = ecdsa_do_verify;
+       }
+
+void ECDSA_METHOD_set_flags(ECDSA_METHOD *ecdsa_method, int flags)
+       {
+       ecdsa_method->flags = flags | ECDSA_METHOD_FLAG_ALLOCATED;
+       }
+
+void ECDSA_METHOD_set_name(ECDSA_METHOD *ecdsa_method, char *name)
+       {
+       ecdsa_method->name = name;
+       }
+
+void ECDSA_METHOD_free(ECDSA_METHOD *ecdsa_method)
+       {
+       if (ecdsa_method->flags & ECDSA_METHOD_FLAG_ALLOCATED)
+               OPENSSL_free(ecdsa_method);
+       }
+
+
index cb3be13cfc307025266aff78f47099ff0b5c7971..810def12e8d6a30b73336a6a0d05d132f74f975d 100644 (file)
@@ -82,6 +82,11 @@ struct ecdsa_method
        char *app_data;
        };
 
+/* The ECDSA_METHOD was allocated and can be freed */
+
+#define ECDSA_METHOD_FLAG_ALLOCATED 0x2
+
+
 /* If this flag is set the ECDSA method is FIPS compliant and can be used
  * in FIPS mode. This is set in the validated module method. If an
  * application sets this flag in its own methods it is its responsibility