summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2022-07-04 12:22:33 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2022-07-04 12:22:33 +0000
commit7fa55026a6ae6123ae181d0b6dc3b4d57220aac1 (patch)
tree76e88836efa4f9a78ab25c4bdb83c4293ccfe6a8
parent1249a0c227a676a7d6485ccd149f834d75e85a37 (diff)
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
-rw-r--r--lib/libcrypto/dsa/dsa.h6
-rw-r--r--lib/libcrypto/dsa/dsa_locl.h4
-rw-r--r--lib/libcrypto/dsa/dsa_meth.c33
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 <tb@openbsd.org>
*
@@ -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 *))