New function EVP_PKEY_asn1_copy(). Use default MD if type param is NULL.
authorDr. Stephen Henson <steve@openssl.org>
Tue, 15 May 2007 23:52:03 +0000 (23:52 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Tue, 15 May 2007 23:52:03 +0000 (23:52 +0000)
crypto/asn1/ameth_lib.c
crypto/evp/evp.h
crypto/evp/evp_err.c
crypto/evp/m_sigver.c
crypto/hmac/hm_ameth.c

index 92e8d59ca61eee968b00abbe8599dfe0afd92c3b..13129bcd7f215be3868cf70319e7dd26e6f9edd6 100644 (file)
@@ -301,7 +301,7 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
                if (!ameth->pem_str)
                        goto err;
                }
-       
+
        ameth->pub_decode = 0;
        ameth->pub_encode = 0;
        ameth->pub_cmp = 0;
@@ -336,6 +336,37 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
 
        }
 
+void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, 
+                       const EVP_PKEY_ASN1_METHOD *src)
+       {
+
+       dst->pub_decode = src->pub_decode;
+       dst->pub_encode = src->pub_encode;
+       dst->pub_cmp = src->pub_cmp;
+       dst->pub_print = src->pub_print;
+
+       dst->priv_decode = src->priv_decode;
+       dst->priv_encode = src->priv_encode;
+       dst->priv_print = src->priv_print;
+
+       dst->old_priv_encode = src->old_priv_encode;
+       dst->old_priv_decode = src->old_priv_decode;
+
+       dst->pkey_size = src->pkey_size;
+       dst->pkey_bits = src->pkey_bits;
+
+       dst->param_decode = src->param_decode;
+       dst->param_encode = src->param_encode;
+       dst->param_missing = src->param_missing;
+       dst->param_copy = src->param_copy;
+       dst->param_cmp = src->param_cmp;
+       dst->param_print = src->param_print;
+
+       dst->pkey_free = src->pkey_free;
+       dst->pkey_ctrl = src->pkey_ctrl;
+
+       }
+
 void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
        {
        if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC))
index 428300e000ed690b3fb6a68f5a2b3253ccc01e3a..6c65f5a677ff47480272993753b8b687b34a6461 100644 (file)
@@ -941,6 +941,8 @@ int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id, int *ppkey_flags,
 
 EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
                                        const char *pem_str, const char *info);
+void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, 
+                       const EVP_PKEY_ASN1_METHOD *src);
 void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth);
 void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
                int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub),
@@ -1156,6 +1158,7 @@ void ERR_load_EVP_strings(void);
 #define EVP_F_AES_INIT_KEY                              133
 #define EVP_F_CAMELLIA_INIT_KEY                                 159
 #define EVP_F_D2I_PKEY                                  100
+#define EVP_F_DO_SIGVER_INIT                            161
 #define EVP_F_DSAPKEY2PKCS8                             134
 #define EVP_F_DSA_PKEY2PKCS8                            135
 #define EVP_F_ECDSA_PKEY2PKCS8                          129
@@ -1249,6 +1252,7 @@ void ERR_load_EVP_strings(void);
 #define EVP_R_METHOD_NOT_SUPPORTED                      144
 #define EVP_R_MISSING_PARAMETERS                        103
 #define EVP_R_NO_CIPHER_SET                             131
+#define EVP_R_NO_DEFAULT_DIGEST                                 158
 #define EVP_R_NO_DIGEST_SET                             139
 #define EVP_R_NO_DSA_PARAMETERS                                 116
 #define EVP_R_NO_KEY_SET                                154
@@ -1273,7 +1277,6 @@ void ERR_load_EVP_strings(void);
 #define EVP_R_UNSUPPORTED_SALT_TYPE                     126
 #define EVP_R_WRONG_FINAL_BLOCK_LENGTH                  109
 #define EVP_R_WRONG_PUBLIC_KEY_TYPE                     110
-#define EVP_R_SEED_KEY_SETUP_FAILED                     162
 
 #ifdef  __cplusplus
 }
index a93056828ec90f7cf6c6bd1e4936cc75213a71c8..25a8ad7cdcb9c3e269b9e3da5abb942382ae2ff2 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/evp/evp_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -73,6 +73,7 @@ static ERR_STRING_DATA EVP_str_functs[]=
 {ERR_FUNC(EVP_F_AES_INIT_KEY), "AES_INIT_KEY"},
 {ERR_FUNC(EVP_F_CAMELLIA_INIT_KEY),    "CAMELLIA_INIT_KEY"},
 {ERR_FUNC(EVP_F_D2I_PKEY),     "D2I_PKEY"},
+{ERR_FUNC(EVP_F_DO_SIGVER_INIT),       "DO_SIGVER_INIT"},
 {ERR_FUNC(EVP_F_DSAPKEY2PKCS8),        "DSAPKEY2PKCS8"},
 {ERR_FUNC(EVP_F_DSA_PKEY2PKCS8),       "DSA_PKEY2PKCS8"},
 {ERR_FUNC(EVP_F_ECDSA_PKEY2PKCS8),     "ECDSA_PKEY2PKCS8"},
@@ -169,6 +170,7 @@ static ERR_STRING_DATA EVP_str_reasons[]=
 {ERR_REASON(EVP_R_METHOD_NOT_SUPPORTED)  ,"method not supported"},
 {ERR_REASON(EVP_R_MISSING_PARAMETERS)    ,"missing parameters"},
 {ERR_REASON(EVP_R_NO_CIPHER_SET)         ,"no cipher set"},
+{ERR_REASON(EVP_R_NO_DEFAULT_DIGEST)     ,"no default digest"},
 {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_KEY_SET)            ,"no key set"},
index 8fdfe61b3f478071194f906ee5894431864bfa81..e12f85f69f740327995fc98b648684bfd579864e 100644 (file)
@@ -71,6 +71,20 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
                ctx->pctx = EVP_PKEY_CTX_new(pkey, e);
        if (ctx->pctx == NULL)
                return 0;
+
+       if (type == NULL)
+               {
+               int def_nid;
+               if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) > 0)
+                       type = EVP_get_digestbynid(def_nid);
+               }
+
+       if (type == NULL)
+               {
+               EVPerr(EVP_F_DO_SIGVER_INIT, EVP_R_NO_DEFAULT_DIGEST);
+               return 0;
+               }
+
        if (ver)
                {
                if (ctx->pctx->pmeth->verifyctx_init)
index 204bdb2492d0e6bef217e11e9c923f0be106a546..0b05923ba1a224f7c83f1d212c861e260b499bed 100644 (file)
@@ -84,6 +84,19 @@ static void hmac_key_free(EVP_PKEY *pkey)
        }
 
 
+static int hmac_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
+       {
+       switch (op)
+               {
+               case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+               *(int *)arg2 = NID_sha1;
+               return 1;
+
+               default:
+               return -2;
+               }
+       }
+
 #ifdef HMAC_TEST_PRIVATE_KEY_FORMAT
 /* A bogus private key format for test purposes. This is simply the
  * HMAC key with "HMAC PRIVATE KEY" in the headers. When enabled the
@@ -143,7 +156,7 @@ const EVP_PKEY_ASN1_METHOD hmac_asn1_meth =
        0,0,0,0,0,0,
 
        hmac_key_free,
-       0,
+       hmac_pkey_ctrl,
 #ifdef HMAC_TEST_PRIVATE_KEY_FORMAT
        old_hmac_decode,
        old_hmac_encode