From a517f7fcdc85000b682b91d4cb2ab602f6f7d050 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Sat, 2 Apr 2016 19:41:41 +0100 Subject: [PATCH] Various DSA opacity fixups Numerous fixups based on feedback of the DSA opacity changes. Reviewed-by: Richard Levitte Reviewed-by: Stephen Henson --- crypto/dsa/dsa_meth.c | 68 ++++++----------------------------- crypto/engine/eng_cryptodev.c | 2 +- doc/crypto/DSA_get0_pqg.pod | 10 +++--- doc/crypto/DSA_meth_new.pod | 37 +++++++++++-------- engines/e_capi.c | 16 +++++---- include/openssl/dsa.h | 6 ++-- util/libcrypto.num | 4 +-- 7 files changed, 54 insertions(+), 89 deletions(-) diff --git a/crypto/dsa/dsa_meth.c b/crypto/dsa/dsa_meth.c index ed4df5413c..237f555c08 100644 --- a/crypto/dsa/dsa_meth.c +++ b/crypto/dsa/dsa_meth.c @@ -1,55 +1,9 @@ -/* ==================================================================== - * Copyright (c) 2016 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 - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@OpenSSL.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). - * +/* + * Licensed under the OpenSSL licenses, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.openssl.org/source/license.html + * or in the file LICENSE in the source distribution. */ #include "dsa_locl.h" @@ -76,26 +30,26 @@ void DSA_meth_free(DSA_METHOD *dsam) } } -DSA_METHOD *DSA_meth_dup(const DSA_METHOD *meth) +DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam) { DSA_METHOD *ret; ret = OPENSSL_malloc(sizeof(DSA_METHOD)); if (ret != NULL) { - memcpy(ret, meth, sizeof(*meth)); - ret->name = OPENSSL_strdup(meth->name); + memcpy(ret, dsam, sizeof(*dsam)); + ret->name = OPENSSL_strdup(dsam->name); } return ret; } -const char *DSA_meth_get_name(const DSA_METHOD *dsam) +const char *DSA_meth_get0_name(const DSA_METHOD *dsam) { return dsam->name; } -int DSA_meth_set_name(DSA_METHOD *dsam, const char *name) +int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name) { OPENSSL_free(dsam->name); dsam->name = OPENSSL_strdup(name); diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c index 00828702db..bb2ce9efa9 100644 --- a/crypto/engine/eng_cryptodev.c +++ b/crypto/engine/eng_cryptodev.c @@ -1682,7 +1682,7 @@ void engine_load_cryptodev_internal(void) #ifndef OPENSSL_NO_DSA cryptodev_dsa = DSA_meth_dup(DSA_OpenSSL()); if (cryptodev_dsa != NULL) { - DSA_meth_set_name(cryptodev_dsa, "cryptodev DSA method"); + DSA_meth_set1_name(cryptodev_dsa, "cryptodev DSA method"); DSA_meth_set_flags(cryptodev_dsa, 0); if (ENGINE_set_DSA(engine, cryptodev_dsa)) { if (cryptodev_asymfeat & CRF_DSA_SIGN) diff --git a/doc/crypto/DSA_get0_pqg.pod b/doc/crypto/DSA_get0_pqg.pod index fc79cfdebe..1c835f0128 100644 --- a/doc/crypto/DSA_get0_pqg.pod +++ b/doc/crypto/DSA_get0_pqg.pod @@ -2,7 +2,7 @@ =head1 NAME -DSA_get0_pqg, DSA_set0_pgg, DSA_get0_key, DSA_set0_key, DSA_clear_flags, +DSA_get0_pqg, DSA_set0_pqg, DSA_get0_key, DSA_set0_key, DSA_clear_flags, DSA_test_flags, DSA_set_flags, DSA_get0_engine - Routines for getting and setting data in a DSA object @@ -52,7 +52,7 @@ been called. DSA_set_flags() sets the flags in the B parameter on the DSA object. Multiple flags can be passed in one go (bitwise ORed together). Any flags that are already set are left set. DSA_test_flags() tests to see whether the flags -passed in the B parameter are currently set in the DSA object. Multple +passed in the B parameter are currently set in the DSA object. Multiple flags can be tested in one go. All flags that are currently set are returned, or zero if none of the flags are set. DSA_clear_flags() clears the specified flags within the DSA object. @@ -71,9 +71,9 @@ has been set. =head1 SEE ALSO -L, L, L, L, -L, L, L, L, L, -L, L +L, L, L, L, +L, L, L, L, +L, L, L =head1 HISTORY diff --git a/doc/crypto/DSA_meth_new.pod b/doc/crypto/DSA_meth_new.pod index 278008d8c0..5799ffa605 100644 --- a/doc/crypto/DSA_meth_new.pod +++ b/doc/crypto/DSA_meth_new.pod @@ -2,25 +2,25 @@ =head1 NAME -DSA_meth_new, DSA_meth_free, DSA_meth_dup, DSA_meth_get_name, DSA_meth_set_name, -DSA_meth_get_flags, DSA_meth_set_flags, DSA_meth_get_app_data, -DSA_meth_set_app_data, DSA_meth_get_sign, DSA_meth_set_sign, -DSA_meth_get_sign_setup, DSA_meth_set_sign_setup, DSA_meth_get_verify, -DSA_meth_set_verify, DSA_meth_get_mod_exp, DSA_meth_set_mod_exp, -DSA_meth_get_bn_mod_exp, DSA_meth_set_bn_mod_exp, DSA_meth_get_init, -DSA_meth_set_init, DSA_meth_get_finish, DSA_meth_set_finish, +DSA_meth_new, DSA_meth_free, DSA_meth_dup, DSA_meth_get0_name, +DSA_meth_set1_name, DSA_meth_get_flags, DSA_meth_set_flags, +DSA_meth_get_app_data, DSA_meth_set_app_data, DSA_meth_get_sign, +DSA_meth_set_sign, DSA_meth_get_sign_setup, DSA_meth_set_sign_setup, +DSA_meth_get_verify, DSA_meth_set_verify, DSA_meth_get_mod_exp, +DSA_meth_set_mod_exp, DSA_meth_get_bn_mod_exp, DSA_meth_set_bn_mod_exp, +DSA_meth_get_init, DSA_meth_set_init, DSA_meth_get_finish, DSA_meth_set_finish, DSA_meth_get_paramgen, DSA_meth_set_paramgen, DSA_meth_get_keygen, DSA_meth_set_keygen - Routines to build up DSA methods =head1 SYNOPSIS - #include + #include DSA_METHOD *DSA_meth_new(const char *name, int flags); void DSA_meth_free(DSA_METHOD *dsam); DSA_METHOD *DSA_meth_dup(const DSA_METHOD *meth); - const char *DSA_meth_get_name(const DSA_METHOD *dsam); - int DSA_meth_set_name(DSA_METHOD *dsam, const char *name); + const char *DSA_meth_get0_name(const DSA_METHOD *dsam); + int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name); int DSA_meth_get_flags(DSA_METHOD *dsam); int DSA_meth_set_flags(DSA_METHOD *dsam, int flags); void *DSA_meth_get_app_data(const DSA_METHOD *dsam); @@ -83,6 +83,12 @@ existing one, but with some differences. DSA_meth_free() destroys a B structure and frees up any memory associated with it. +DSA_meth_get0_name() will return a pointer to the name of this DSA_METHOD. This +is a pointer to the internal name string and so should not be freed by the +caller. DSA_meth_set1_name() sets the name of the DSA_METHOD to B. The +string is duplicated and the copy is stored in the DSA_METHOD structure, so the +caller remains responsible for freeing the memory associated with the name. + DSA_meth_get_flags() returns the current value of the flags associated with this DSA_METHOD. DSA_meth_set_flags() provides the ability to set these flags. @@ -155,20 +161,21 @@ for the function has the same meaning as for DSA_generate_key(). DSA_meth_new() and DSA_meth_dup() return the newly allocated DSA_METHOD object or NULL on failure. -DSA_meth_get_name() and DSA_meth_get_flags() return the name and flags +DSA_meth_get0_name() and DSA_meth_get_flags() return the name and flags associated with the DSA_METHOD respectively. All other DSA_meth_get_*() functions return the appropriate function pointer that has been set in the DSA_METHOD, or NULL if no such pointer has yet been set. -All DSA_meth_set_*() functions return 1 on success or 0 on failure. +DSA_meth_set1_name() and all DSA_meth_set_*() functions return 1 on success or +0 on failure. =head1 SEE ALSO -L, L, L, L, -L, L, L, L, L, -L, L +L, L, L, L, +L, L, L, L, +L, L, L =head1 HISTORY diff --git a/engines/e_capi.c b/engines/e_capi.c index 0c7b68c949..4cec2f411c 100644 --- a/engines/e_capi.c +++ b/engines/e_capi.c @@ -476,12 +476,16 @@ static int capi_init(ENGINE *e) /* Setup DSA Method */ dsa_capi_idx = DSA_get_ex_new_index(0, NULL, NULL, NULL, 0); ossl_dsa_meth = DSA_OpenSSL(); - DSA_meth_set_sign(capi_dsa_method, capi_dsa_do_sign); - DSA_meth_set_verify(capi_dsa_method, DSA_meth_get_verify(ossl_dsa_meth)); - DSA_meth_set_finish(capi_dsa_method, capi_dsa_free); - DSA_meth_set_mod_exp(capi_dsa_method, DSA_meth_get_mod_exp(ossl_dsa_meth)); - DSA_meth_set_bn_mod_exp(capi_dsa_method, - DSA_meth_get_bn_mod_exp(ossl_dsa_meth)); + if ( !DSA_meth_set_sign(capi_dsa_method, capi_dsa_do_sign) + || !DSA_meth_set_verify(capi_dsa_method, + DSA_meth_get_verify(ossl_dsa_meth)) + || !DSA_meth_set_finish(capi_dsa_method, capi_dsa_free) + || !DSA_meth_set_mod_exp(capi_dsa_method, + DSA_meth_get_mod_exp(ossl_dsa_meth)) + || !DSA_meth_set_bn_mod_exp(capi_dsa_method, + DSA_meth_get_bn_mod_exp(ossl_dsa_meth))) { + goto memerr; + } } ctx = capi_ctx_new(); diff --git a/include/openssl/dsa.h b/include/openssl/dsa.h index 910a46a405..bbe0902a53 100644 --- a/include/openssl/dsa.h +++ b/include/openssl/dsa.h @@ -227,9 +227,9 @@ ENGINE *DSA_get0_engine(DSA *d); DSA_METHOD *DSA_meth_new(const char *name, int flags); void DSA_meth_free(DSA_METHOD *dsam); -DSA_METHOD *DSA_meth_dup(const DSA_METHOD *meth); -const char *DSA_meth_get_name(const DSA_METHOD *dsam); -int DSA_meth_set_name(DSA_METHOD *dsam, const char *name); +DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam); +const char *DSA_meth_get0_name(const DSA_METHOD *dsam); +int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name); int DSA_meth_get_flags(DSA_METHOD *dsam); int DSA_meth_set_flags(DSA_METHOD *dsam, int flags); void *DSA_meth_get_app_data(const DSA_METHOD *dsam); diff --git a/util/libcrypto.num b/util/libcrypto.num index 8e1102d0ff..53ba2786d5 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -4097,13 +4097,13 @@ DSA_get0_pqg 3962 1_1_0 EXIST::FUNCTION:DSA DSA_meth_get_app_data 3963 1_1_0 EXIST::FUNCTION:DSA DSA_meth_get_keygen 3964 1_1_0 EXIST::FUNCTION:DSA DSA_clear_flags 3965 1_1_0 EXIST::FUNCTION:DSA -DSA_meth_get_name 3966 1_1_0 EXIST::FUNCTION:DSA +DSA_meth_get0_name 3966 1_1_0 EXIST::FUNCTION:DSA DSA_meth_get_paramgen 3967 1_1_0 EXIST::FUNCTION:DSA DSA_meth_get_sign 3968 1_1_0 EXIST::FUNCTION:DSA DSA_meth_set_paramgen 3969 1_1_0 EXIST::FUNCTION:DSA DSA_test_flags 3970 1_1_0 EXIST::FUNCTION:DSA DSA_meth_set_app_data 3971 1_1_0 EXIST::FUNCTION:DSA -DSA_meth_set_name 3972 1_1_0 EXIST::FUNCTION:DSA +DSA_meth_set1_name 3972 1_1_0 EXIST::FUNCTION:DSA DSA_get0_key 3973 1_1_0 EXIST::FUNCTION:DSA DSA_meth_get_mod_exp 3974 1_1_0 EXIST::FUNCTION:DSA DSA_set0_pqg 3975 1_1_0 EXIST::FUNCTION:DSA -- 2.34.1