summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2018-03-17 15:19:12 +0000
committertb <>2018-03-17 15:19:12 +0000
commitff154a0391cfcee220c90f520739c6f08f97c2aa (patch)
treeb098ccdac17cb9ccf01e46859b80d5ce671af779 /src
parent47bd2696f108ed72a37c309a2c1d049aeee2c89d (diff)
downloadopenbsd-ff154a0391cfcee220c90f520739c6f08f97c2aa.tar.gz
openbsd-ff154a0391cfcee220c90f520739c6f08f97c2aa.tar.bz2
openbsd-ff154a0391cfcee220c90f520739c6f08f97c2aa.zip
Add DSA_meth_{dup,free,new,set_{finish,sign}}()
As in RSA_meth_*, note that these functions return NULL in out-of-memory situations, but they do not set an error explicitly. ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/Makefile3
-rw-r--r--src/lib/libcrypto/Symbols.list5
-rw-r--r--src/lib/libcrypto/dsa/dsa.h9
-rw-r--r--src/lib/libcrypto/dsa/dsa_meth.c78
4 files changed, 93 insertions, 2 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile
index 18c7c0608a..4817a4c260 100644
--- a/src/lib/libcrypto/Makefile
+++ b/src/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.25 2018/03/17 15:12:56 tb Exp $ 1# $OpenBSD: Makefile,v 1.26 2018/03/17 15:19:12 tb Exp $
2 2
3LIB= crypto 3LIB= crypto
4LIBREBUILD=y 4LIBREBUILD=y
@@ -117,6 +117,7 @@ SRCS+= dh_ameth.c dh_pmeth.c dh_prn.c
117# dsa/ 117# dsa/
118SRCS+= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c 118SRCS+= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c
119SRCS+= dsa_err.c dsa_ossl.c dsa_depr.c dsa_ameth.c dsa_pmeth.c dsa_prn.c 119SRCS+= dsa_err.c dsa_ossl.c dsa_depr.c dsa_ameth.c dsa_pmeth.c dsa_prn.c
120SRCS+= dsa_meth.c
120 121
121# dso/ 122# dso/
122SRCS+= dso_dlfcn.c dso_err.c dso_lib.c dso_null.c 123SRCS+= dso_dlfcn.c dso_err.c dso_lib.c dso_null.c
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list
index 7cb78c4daf..6777e8cc13 100644
--- a/src/lib/libcrypto/Symbols.list
+++ b/src/lib/libcrypto/Symbols.list
@@ -831,6 +831,11 @@ DSA_get0_pqg
831DSA_get_default_method 831DSA_get_default_method
832DSA_get_ex_data 832DSA_get_ex_data
833DSA_get_ex_new_index 833DSA_get_ex_new_index
834DSA_meth_dup
835DSA_meth_free
836DSA_meth_new
837DSA_meth_set_finish
838DSA_meth_set_sign
834DSA_new 839DSA_new
835DSA_new_method 840DSA_new_method
836DSA_print 841DSA_print
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
index 8fe7c668b2..61bfc2b466 100644
--- a/src/lib/libcrypto/dsa/dsa.h
+++ b/src/lib/libcrypto/dsa/dsa.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa.h,v 1.29 2018/02/20 17:52:27 tb Exp $ */ 1/* $OpenBSD: dsa.h,v 1.30 2018/03/17 15:19:12 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -269,6 +269,13 @@ int DSA_test_flags(const DSA *d, int flags);
269void DSA_set_flags(DSA *d, int flags); 269void DSA_set_flags(DSA *d, int flags);
270ENGINE *DSA_get0_engine(DSA *d); 270ENGINE *DSA_get0_engine(DSA *d);
271 271
272DSA_METHOD *DSA_meth_new(const char *name, int flags);
273void DSA_meth_free(DSA_METHOD *meth);
274DSA_METHOD *DSA_meth_dup(const DSA_METHOD *meth);
275int DSA_meth_set_sign(DSA_METHOD *meth,
276 DSA_SIG *(*sign)(const unsigned char *, int, DSA *));
277int DSA_meth_set_finish(DSA_METHOD *meth, int (*finish)(DSA *));
278
272#define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \ 279#define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \
273 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ 280 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \
274 EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL) 281 EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL)
diff --git a/src/lib/libcrypto/dsa/dsa_meth.c b/src/lib/libcrypto/dsa/dsa_meth.c
new file mode 100644
index 0000000000..e6f043f830
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa_meth.c
@@ -0,0 +1,78 @@
1/* $OpenBSD: dsa_meth.c,v 1.1 2018/03/17 15:19:12 tb Exp $ */
2/*
3 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdlib.h>
19#include <string.h>
20
21#include <openssl/dsa.h>
22#include <openssl/err.h>
23
24DSA_METHOD *
25DSA_meth_new(const char *name, int flags)
26{
27 DSA_METHOD *meth;
28
29 if ((meth = calloc(1, sizeof(*meth))) == NULL)
30 return NULL;
31 if ((meth->name = strdup(name)) == NULL) {
32 free(meth);
33 return NULL;
34 }
35 meth->flags = flags;
36
37 return meth;
38}
39
40void
41DSA_meth_free(DSA_METHOD *meth)
42{
43 if (meth != NULL) {
44 free((char *)meth->name);
45 free(meth);
46 }
47}
48
49DSA_METHOD *
50DSA_meth_dup(const DSA_METHOD *meth)
51{
52 DSA_METHOD *copy;
53
54 if ((copy = calloc(1, sizeof(*copy))) == NULL)
55 return NULL;
56 memcpy(copy, meth, sizeof(*copy));
57 if ((copy->name = strdup(meth->name)) == NULL) {
58 free(copy);
59 return NULL;
60 }
61
62 return copy;
63}
64
65int
66DSA_meth_set_sign(DSA_METHOD *meth,
67 DSA_SIG *(*sign)(const unsigned char *, int, DSA *))
68{
69 meth->dsa_do_sign = sign;
70 return 1;
71}
72
73int
74DSA_meth_set_finish(DSA_METHOD *meth, int (*finish)(DSA *))
75{
76 meth->finish = finish;
77 return 1;
78}