summaryrefslogtreecommitdiffstats
path: root/lib/libcrypto/rsa/rsa_meth.c
diff options
context:
space:
mode:
authortb <tb@openbsd.org>2018-03-17 15:12:56 +0000
committertb <tb@openbsd.org>2018-03-17 15:12:56 +0000
commit7a0262ffcb2672030d13bdb1cdc12316f67655ee (patch)
tree5dfaf110275dfd3b0da471b155f8aa16e92447ab /lib/libcrypto/rsa/rsa_meth.c
parentMake BIO_meth_get_write() public. Omission spotted by schwarze. (diff)
downloadwireguard-openbsd-7a0262ffcb2672030d13bdb1cdc12316f67655ee.tar.xz
wireguard-openbsd-7a0262ffcb2672030d13bdb1cdc12316f67655ee.zip
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/libcrypto/rsa/rsa_meth.c')
-rw-r--r--lib/libcrypto/rsa/rsa_meth.c86
1 files changed, 86 insertions, 0 deletions
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;
+}