From 8fc6b31117d7cfbbf06e7d98bf20cd69f2353360 Mon Sep 17 00:00:00 2001 From: tb Date: Mon, 4 Jul 2022 12:22:32 +0000 Subject: [PATCH] Prepare to provide DSA_meth_{get0,set1}_name() Also follow OpenSSL by making the name non-const to avoid ugly casting. Used by OpenSC's pkcs11-helper, as reported by Fabrice Fontaine in https://github.com/libressl-portable/openbsd/issues/130 ok jsing sthen --- lib/libcrypto/dsa/dsa.h | 6 +++++- lib/libcrypto/dsa/dsa_locl.h | 4 ++-- lib/libcrypto/dsa/dsa_meth.c | 33 ++++++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/lib/libcrypto/dsa/dsa.h b/lib/libcrypto/dsa/dsa.h index 2ee27d775f3..12b1faadf3d 100644 --- a/lib/libcrypto/dsa/dsa.h +++ b/lib/libcrypto/dsa/dsa.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa.h,v 1.36 2022/06/27 12:28:46 tb Exp $ */ +/* $OpenBSD: dsa.h,v 1.37 2022/07/04 12:22:32 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -222,6 +222,10 @@ ENGINE *DSA_get0_engine(DSA *d); DSA_METHOD *DSA_meth_new(const char *name, int flags); void DSA_meth_free(DSA_METHOD *meth); DSA_METHOD *DSA_meth_dup(const DSA_METHOD *meth); +#ifdef LIBRESSL_INTERNAL +const char *DSA_meth_get0_name(const DSA_METHOD *meth); +int DSA_meth_set1_name(DSA_METHOD *meth, const char *name); +#endif int DSA_meth_set_sign(DSA_METHOD *meth, DSA_SIG *(*sign)(const unsigned char *, int, DSA *)); int DSA_meth_set_finish(DSA_METHOD *meth, int (*finish)(DSA *)); diff --git a/lib/libcrypto/dsa/dsa_locl.h b/lib/libcrypto/dsa/dsa_locl.h index 299c67a6b90..f78ff818abb 100644 --- a/lib/libcrypto/dsa/dsa_locl.h +++ b/lib/libcrypto/dsa/dsa_locl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_locl.h,v 1.5 2022/01/14 08:29:06 tb Exp $ */ +/* $OpenBSD: dsa_locl.h,v 1.6 2022/07/04 12:22:32 tb Exp $ */ /* ==================================================================== * Copyright (c) 2007 The OpenSSL Project. All rights reserved. * @@ -63,7 +63,7 @@ struct DSA_SIG_st { } /* DSA_SIG */; struct dsa_method { - const char *name; + char *name; DSA_SIG *(*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa); int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); diff --git a/lib/libcrypto/dsa/dsa_meth.c b/lib/libcrypto/dsa/dsa_meth.c index cd232835ebd..2cb0426d430 100644 --- a/lib/libcrypto/dsa/dsa_meth.c +++ b/lib/libcrypto/dsa/dsa_meth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_meth.c,v 1.3 2022/05/07 10:31:54 tb Exp $ */ +/* $OpenBSD: dsa_meth.c,v 1.4 2022/07/04 12:22:32 tb Exp $ */ /* * Copyright (c) 2018 Theo Buehler * @@ -42,10 +42,11 @@ DSA_meth_new(const char *name, int flags) void DSA_meth_free(DSA_METHOD *meth) { - if (meth != NULL) { - free((char *)meth->name); - free(meth); - } + if (meth == NULL) + return + + free(meth->name); + free(meth); } DSA_METHOD * @@ -64,6 +65,28 @@ DSA_meth_dup(const DSA_METHOD *meth) return copy; } +const char * +DSA_meth_get0_name(const DSA_METHOD *meth) +{ + return meth->name; +} + +int +DSA_meth_set1_name(DSA_METHOD *meth, const char *name) +{ + char *new_name; + + if ((new_name = strdup(name)) == NULL) { + DSAerror(ERR_R_MALLOC_FAILURE); + return 0; + } + + free(meth->name); + meth->name = new_name; + + return 1; +} + int DSA_meth_set_sign(DSA_METHOD *meth, DSA_SIG *(*sign)(const unsigned char *, int, DSA *)) -- 2.20.1