summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2018-03-17 15:12:57 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2018-03-17 15:12:57 +0000
commitb5075b3edbe2a1ca80b70ca3f8fe9582c1a8706e (patch)
tree04328a422d5c5fdfb5510c8bd8ca55a8527d62b3 /lib
parentfbd46f72258f69264df4a52c9538a94acd89b1b8 (diff)
Provide RSA_meth_{dup,free,new,set_{finish,priv_{dec,enc}}}()
Note that these functions return NULL in out-of-memory situations, but contrary to OpenSSL's versions they do not set an error. ok jsing
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/Makefile4
-rw-r--r--lib/libcrypto/Symbols.list6
-rw-r--r--lib/libcrypto/rsa/rsa.h11
-rw-r--r--lib/libcrypto/rsa/rsa_meth.c86
4 files changed, 104 insertions, 3 deletions
diff --git a/lib/libcrypto/Makefile b/lib/libcrypto/Makefile
index 85e6b0ee8d3..18c7c0608ab 100644
--- a/lib/libcrypto/Makefile
+++ b/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.24 2018/02/17 13:57:14 tb Exp $
+# $OpenBSD: Makefile,v 1.25 2018/03/17 15:12:56 tb Exp $
LIB= crypto
LIBREBUILD=y
@@ -227,7 +227,7 @@ SRCS+= rmd_dgst.c rmd_one.c
SRCS+= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c
SRCS+= rsa_pk1.c rsa_none.c rsa_oaep.c rsa_chk.c
SRCS+= rsa_pss.c rsa_x931.c rsa_asn1.c rsa_depr.c rsa_ameth.c rsa_prn.c
-SRCS+= rsa_pmeth.c rsa_crpt.c
+SRCS+= rsa_pmeth.c rsa_crpt.c rsa_meth.c
# sha/
SRCS+= sha1dgst.c sha1_one.c sha256.c sha512.c
diff --git a/lib/libcrypto/Symbols.list b/lib/libcrypto/Symbols.list
index 07f938f6bed..7cb78c4dafe 100644
--- a/lib/libcrypto/Symbols.list
+++ b/lib/libcrypto/Symbols.list
@@ -2263,6 +2263,12 @@ RSA_get_default_method
RSA_get_ex_data
RSA_get_ex_new_index
RSA_get_method
+RSA_meth_dup
+RSA_meth_free
+RSA_meth_new
+RSA_meth_set_finish
+RSA_meth_set_priv_dec
+RSA_meth_set_priv_enc
RSA_new
RSA_new_method
RSA_padding_add_PKCS1_OAEP
diff --git a/lib/libcrypto/rsa/rsa.h b/lib/libcrypto/rsa/rsa.h
index 65a643f4c6d..23929aafb91 100644
--- a/lib/libcrypto/rsa/rsa.h
+++ b/lib/libcrypto/rsa/rsa.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rsa.h,v 1.37 2018/02/20 17:42:32 tb Exp $ */
+/* $OpenBSD: rsa.h,v 1.38 2018/03/17 15:12:56 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -430,6 +430,15 @@ RSA *RSAPrivateKey_dup(RSA *rsa);
*/
#define RSA_FLAG_CHECKED 0x0800
+RSA_METHOD *RSA_meth_new(const char *name, int flags);
+void RSA_meth_free(RSA_METHOD *meth);
+RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
+int RSA_meth_set_priv_enc(RSA_METHOD *meth, int (*priv_enc)(int flen,
+ const unsigned char *from, unsigned char *to, RSA *rsa, int padding));
+int RSA_meth_set_priv_dec(RSA_METHOD *meth, int (*priv_dec)(int flen,
+ const unsigned char *from, unsigned char *to, RSA *rsa, int padding));
+int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish)(RSA *rsa));
+
/* BEGIN ERROR CODES */
/* The following lines are auto generated by the script mkerr.pl. Any changes
* made after this point may be overwritten when the script is next run.
diff --git a/lib/libcrypto/rsa/rsa_meth.c b/lib/libcrypto/rsa/rsa_meth.c
new file mode 100644
index 00000000000..0e52799a384
--- /dev/null
+++ b/lib/libcrypto/rsa/rsa_meth.c
@@ -0,0 +1,86 @@
+/* $OpenBSD: rsa_meth.c,v 1.1 2018/03/17 15:12:56 tb Exp $ */
+/*
+ * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <openssl/err.h>
+#include <openssl/rsa.h>
+
+RSA_METHOD *
+RSA_meth_new(const char *name, int flags)
+{
+ RSA_METHOD *meth;
+
+ if ((meth = calloc(1, sizeof(*meth))) == NULL)
+ return NULL;
+ if ((meth->name = strdup(name)) == NULL) {
+ free(meth);
+ return NULL;
+ }
+ meth->flags = flags;
+
+ return meth;
+}
+
+void
+RSA_meth_free(RSA_METHOD *meth)
+{
+ if (meth != NULL) {
+ free((char *)meth->name);
+ free(meth);
+ }
+}
+
+RSA_METHOD *
+RSA_meth_dup(const RSA_METHOD *meth)
+{
+ RSA_METHOD *copy;
+
+ if ((copy = calloc(1, sizeof(*copy))) == NULL)
+ return NULL;
+ memcpy(copy, meth, sizeof(*copy));
+ if ((copy->name = strdup(meth->name)) == NULL) {
+ free(copy);
+ return NULL;
+ }
+
+ return copy;
+}
+
+int
+RSA_meth_set_priv_enc(RSA_METHOD *meth, int (*priv_enc)(int flen,
+ const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
+{
+ meth->rsa_priv_enc = priv_enc;
+ return 1;
+}
+
+int
+RSA_meth_set_priv_dec(RSA_METHOD *meth, int (*priv_dec)(int flen,
+ const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
+{
+ meth->rsa_priv_dec = priv_dec;
+ return 1;
+}
+
+int
+RSA_meth_set_finish(RSA_METHOD *meth, int (*finish)(RSA *rsa))
+{
+ meth->finish = finish;
+ return 1;
+}