aboutsummaryrefslogtreecommitdiff
path: root/net/strongswan/patches/0904-gmpdh-Plugin-that-implements-gmp-DH-functions-in-an-.patch
blob: 8aa72b35093f340443c53aea82813f36f4085501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
From 9f60c2ea6394facac55b90ef66466e1b9edef2a9 Mon Sep 17 00:00:00 2001
From: Noel Kuntze <noel.kuntze@thermi.consulting>
Date: Mon, 12 Jul 2021 01:34:23 +0200
Subject: [PATCH 904/904] gmpdh: Plugin that implements gmp DH functions in an
 extra plugin. Links and uses gmp plugin source and header files. Patch taken
 verbatim from openwrt package sources.

---
 configure.ac                                  |   4 +
 src/libstrongswan/Makefile.am                 |   7 ++
 src/libstrongswan/plugins/gmpdh/Makefile.am   |  19 ++++
 .../plugins/gmpdh/gmpdh_plugin.c              | 101 ++++++++++++++++++
 .../plugins/gmpdh/gmpdh_plugin.h              |  42 ++++++++
 5 files changed, 173 insertions(+)
 create mode 100644 src/libstrongswan/plugins/gmpdh/Makefile.am
 create mode 100644 src/libstrongswan/plugins/gmpdh/gmpdh_plugin.c
 create mode 100644 src/libstrongswan/plugins/gmpdh/gmpdh_plugin.h

--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,7 @@ ARG_DISBL_SET([fips-prf],       [disable
 ARG_DISBL_SET([gcm],            [disable the GCM AEAD wrapper crypto plugin.])
 ARG_ENABL_SET([gcrypt],         [enables the libgcrypt plugin.])
 ARG_DISBL_SET([gmp],            [disable GNU MP (libgmp) based crypto implementation plugin.])
+ARG_DISBL_SET([gmpdh],          [disable GNU MP (libgmp) based static-linked crypto DH minimal implementation plugin.])
 ARG_DISBL_SET([curve25519],     [disable Curve25519 Diffie-Hellman plugin.])
 ARG_DISBL_SET([hmac],           [disable HMAC crypto implementation plugin.])
 ARG_DISBL_SET([kdf],            [disable KDF (prf+) implementation plugin.])
@@ -1574,6 +1575,7 @@ ADD_PLUGIN([pkcs8],                [s ch
 ADD_PLUGIN([af-alg],               [s charon pki scripts medsrv attest nm cmd aikgen])
 ADD_PLUGIN([fips-prf],             [s charon nm cmd])
 ADD_PLUGIN([gmp],                  [s charon pki scripts manager medsrv attest nm cmd aikgen fuzz])
+ADD_PLUGIN([gmpdh],                [s charon pki scripts manager medsrv attest nm cmd aikgen])
 ADD_PLUGIN([curve25519],           [s charon pki scripts nm cmd])
 ADD_PLUGIN([agent],                [s charon nm cmd])
 ADD_PLUGIN([keychain],             [s charon cmd])
@@ -1716,6 +1718,7 @@ AM_CONDITIONAL(USE_SHA3, test x$sha3 = x
 AM_CONDITIONAL(USE_MGF1, test x$mgf1 = xtrue)
 AM_CONDITIONAL(USE_FIPS_PRF, test x$fips_prf = xtrue)
 AM_CONDITIONAL(USE_GMP, test x$gmp = xtrue)
+AM_CONDITIONAL(USE_GMPDH, test x$gmpdh = xtrue)
 AM_CONDITIONAL(USE_CURVE25519, test x$curve25519 = xtrue)
 AM_CONDITIONAL(USE_RDRAND, test x$rdrand = xtrue)
 AM_CONDITIONAL(USE_AESNI, test x$aesni = xtrue)
@@ -1997,6 +2000,7 @@ AC_CONFIG_FILES([
 	src/libstrongswan/plugins/mgf1/Makefile
 	src/libstrongswan/plugins/fips_prf/Makefile
 	src/libstrongswan/plugins/gmp/Makefile
+	src/libstrongswan/plugins/gmpdh/Makefile
 	src/libstrongswan/plugins/curve25519/Makefile
 	src/libstrongswan/plugins/rdrand/Makefile
 	src/libstrongswan/plugins/aesni/Makefile
--- a/src/libstrongswan/Makefile.am
+++ b/src/libstrongswan/Makefile.am
@@ -357,6 +357,13 @@ if MONOLITHIC
 endif
 endif
 
+if USE_GMPDH
+  SUBDIRS += plugins/gmpdh
+if MONOLITHIC
+  libstrongswan_la_LIBADD += plugins/gmpdh/libstrongswan-gmpdh.la
+endif
+endif
+
 if USE_CURVE25519
   SUBDIRS += plugins/curve25519
 if MONOLITHIC
--- /dev/null
+++ b/src/libstrongswan/plugins/gmpdh/Makefile.am
@@ -0,0 +1,19 @@
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/src/libstrongswan
+
+AM_CFLAGS = \
+	$(PLUGIN_CFLAGS)
+
+if MONOLITHIC
+noinst_LTLIBRARIES = libstrongswan-gmpdh.la
+else
+plugin_LTLIBRARIES = libstrongswan-gmpdh.la
+endif
+
+libstrongswan_gmpdh_la_SOURCES = \
+	gmpdh_plugin.h gmpdh_plugin.c \
+	../gmp/gmp_diffie_hellman.c ../gmp/gmp_diffie_hellman.h
+
+
+libstrongswan_gmpdh_la_LDFLAGS = -module -avoid-version -Wl,-Bstatic -Wl,-lgmp -Wl,-Bdynamic -Wl,--as-needed $(FPIC)
+libstrongswan_gmpdh_la_LIBADD  =
--- /dev/null
+++ b/src/libstrongswan/plugins/gmpdh/gmpdh_plugin.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2008-2009 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "gmpdh_plugin.h"
+
+#include <library.h>
+#include "../gmp/gmp_diffie_hellman.h"
+
+typedef struct private_gmpdh_plugin_t private_gmpdh_plugin_t;
+
+/**
+ * private data of gmp_plugin
+ */
+struct private_gmpdh_plugin_t {
+
+	/**
+	 * public functions
+	 */
+	gmpdh_plugin_t public;
+};
+
+METHOD(plugin_t, get_name, char*,
+	private_gmpdh_plugin_t *this)
+{
+	return "gmpdh";
+}
+
+METHOD(plugin_t, get_features, int,
+	private_gmpdh_plugin_t *this, plugin_feature_t *features[])
+{
+	static plugin_feature_t f[] = {
+		/* DH groups */
+		PLUGIN_REGISTER(KE, gmp_diffie_hellman_create),
+			PLUGIN_PROVIDE(KE, MODP_2048_BIT),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+			PLUGIN_PROVIDE(KE, MODP_2048_224),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+			PLUGIN_PROVIDE(KE, MODP_2048_256),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+			PLUGIN_PROVIDE(KE, MODP_1536_BIT),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+			PLUGIN_PROVIDE(KE, MODP_3072_BIT),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+			PLUGIN_PROVIDE(KE, MODP_4096_BIT),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+			PLUGIN_PROVIDE(KE, MODP_6144_BIT),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+			PLUGIN_PROVIDE(KE, MODP_8192_BIT),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+			PLUGIN_PROVIDE(KE, MODP_1024_BIT),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+			PLUGIN_PROVIDE(KE, MODP_1024_160),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+			PLUGIN_PROVIDE(KE, MODP_768_BIT),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+		PLUGIN_REGISTER(KE, gmp_diffie_hellman_create_custom),
+			PLUGIN_PROVIDE(KE, MODP_CUSTOM),
+				PLUGIN_DEPENDS(RNG, RNG_STRONG),
+	};
+	*features = f;
+	return countof(f);
+}
+
+METHOD(plugin_t, destroy, void,
+	private_gmpdh_plugin_t *this)
+{
+	free(this);
+}
+
+/*
+ * see header file
+ */
+plugin_t *gmpdh_plugin_create()
+{
+	private_gmpdh_plugin_t *this;
+
+	INIT(this,
+		.public = {
+			.plugin = {
+				.get_name = _get_name,
+				.get_features = _get_features,
+				.destroy = _destroy,
+			},
+		},
+	);
+
+	return &this->public.plugin;
+}
+
--- /dev/null
+++ b/src/libstrongswan/plugins/gmpdh/gmpdh_plugin.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2008 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup gmpdh_p gmpdh
+ * @ingroup plugins
+ *
+ * @defgroup gmpdh_plugin gmpdh_plugin
+ * @{ @ingroup gmpdh_p
+ */
+
+#ifndef GMPDH_PLUGIN_H_
+#define GMPDH_PLUGIN_H_
+
+#include <plugins/plugin.h>
+
+typedef struct gmpdh_plugin_t gmpdh_plugin_t;
+
+/**
+ * Plugin implementing asymmetric crypto algorithms using the GNU MP library.
+ */
+struct gmpdh_plugin_t {
+
+	/**
+	 * implements plugin interface
+	 */
+	plugin_t plugin;
+};
+
+#endif /** GMPDH_PLUGIN_H_ @}*/