You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
7.6 KiB

  1. From 9f60c2ea6394facac55b90ef66466e1b9edef2a9 Mon Sep 17 00:00:00 2001
  2. From: Noel Kuntze <noel.kuntze@thermi.consulting>
  3. Date: Mon, 12 Jul 2021 01:34:23 +0200
  4. Subject: [PATCH 904/904] gmpdh: Plugin that implements gmp DH functions in an
  5. extra plugin. Links and uses gmp plugin source and header files. Patch taken
  6. verbatim from openwrt package sources.
  7. ---
  8. configure.ac | 4 +
  9. src/libstrongswan/Makefile.am | 7 ++
  10. src/libstrongswan/plugins/gmpdh/Makefile.am | 19 ++++
  11. .../plugins/gmpdh/gmpdh_plugin.c | 101 ++++++++++++++++++
  12. .../plugins/gmpdh/gmpdh_plugin.h | 42 ++++++++
  13. 5 files changed, 173 insertions(+)
  14. create mode 100644 src/libstrongswan/plugins/gmpdh/Makefile.am
  15. create mode 100644 src/libstrongswan/plugins/gmpdh/gmpdh_plugin.c
  16. create mode 100644 src/libstrongswan/plugins/gmpdh/gmpdh_plugin.h
  17. --- a/configure.ac
  18. +++ b/configure.ac
  19. @@ -146,6 +146,7 @@ ARG_DISBL_SET([fips-prf], [disable
  20. ARG_ENABL_SET([gcm], [enables the GCM AEAD wrapper crypto plugin.])
  21. ARG_ENABL_SET([gcrypt], [enables the libgcrypt plugin.])
  22. ARG_DISBL_SET([gmp], [disable GNU MP (libgmp) based crypto implementation plugin.])
  23. +ARG_DISBL_SET([gmpdh], [disable GNU MP (libgmp) based static-linked crypto DH minimal implementation plugin.])
  24. ARG_DISBL_SET([curve25519], [disable Curve25519 Diffie-Hellman plugin.])
  25. ARG_DISBL_SET([hmac], [disable HMAC crypto implementation plugin.])
  26. ARG_ENABL_SET([md4], [enable MD4 software implementation plugin.])
  27. @@ -1487,6 +1488,7 @@ ADD_PLUGIN([botan], [s ch
  28. ADD_PLUGIN([af-alg], [s charon scepclient pki scripts medsrv attest nm cmd aikgen])
  29. ADD_PLUGIN([fips-prf], [s charon nm cmd])
  30. ADD_PLUGIN([gmp], [s charon scepclient pki scripts manager medsrv attest nm cmd aikgen fuzz])
  31. +ADD_PLUGIN([gmpdh], [s charon scepclient pki scripts manager medsrv attest nm cmd aikgen])
  32. ADD_PLUGIN([curve25519], [s charon pki scripts nm cmd])
  33. ADD_PLUGIN([agent], [s charon nm cmd])
  34. ADD_PLUGIN([keychain], [s charon cmd])
  35. @@ -1628,6 +1630,7 @@ AM_CONDITIONAL(USE_SHA3, test x$sha3 = x
  36. AM_CONDITIONAL(USE_MGF1, test x$mgf1 = xtrue)
  37. AM_CONDITIONAL(USE_FIPS_PRF, test x$fips_prf = xtrue)
  38. AM_CONDITIONAL(USE_GMP, test x$gmp = xtrue)
  39. +AM_CONDITIONAL(USE_GMPDH, test x$gmpdh = xtrue)
  40. AM_CONDITIONAL(USE_CURVE25519, test x$curve25519 = xtrue)
  41. AM_CONDITIONAL(USE_RDRAND, test x$rdrand = xtrue)
  42. AM_CONDITIONAL(USE_AESNI, test x$aesni = xtrue)
  43. @@ -1905,6 +1908,7 @@ AC_CONFIG_FILES([
  44. src/libstrongswan/plugins/mgf1/Makefile
  45. src/libstrongswan/plugins/fips_prf/Makefile
  46. src/libstrongswan/plugins/gmp/Makefile
  47. + src/libstrongswan/plugins/gmpdh/Makefile
  48. src/libstrongswan/plugins/curve25519/Makefile
  49. src/libstrongswan/plugins/rdrand/Makefile
  50. src/libstrongswan/plugins/aesni/Makefile
  51. --- a/src/libstrongswan/Makefile.am
  52. +++ b/src/libstrongswan/Makefile.am
  53. @@ -348,6 +348,13 @@ if MONOLITHIC
  54. endif
  55. endif
  56. +if USE_GMPDH
  57. + SUBDIRS += plugins/gmpdh
  58. +if MONOLITHIC
  59. + libstrongswan_la_LIBADD += plugins/gmpdh/libstrongswan-gmpdh.la
  60. +endif
  61. +endif
  62. +
  63. if USE_CURVE25519
  64. SUBDIRS += plugins/curve25519
  65. if MONOLITHIC
  66. --- /dev/null
  67. +++ b/src/libstrongswan/plugins/gmpdh/Makefile.am
  68. @@ -0,0 +1,19 @@
  69. +AM_CPPFLAGS = \
  70. + -I$(top_srcdir)/src/libstrongswan
  71. +
  72. +AM_CFLAGS = \
  73. + $(PLUGIN_CFLAGS)
  74. +
  75. +if MONOLITHIC
  76. +noinst_LTLIBRARIES = libstrongswan-gmpdh.la
  77. +else
  78. +plugin_LTLIBRARIES = libstrongswan-gmpdh.la
  79. +endif
  80. +
  81. +libstrongswan_gmpdh_la_SOURCES = \
  82. + gmpdh_plugin.h gmpdh_plugin.c \
  83. + ../gmp/gmp_diffie_hellman.c ../gmp/gmp_diffie_hellman.h
  84. +
  85. +
  86. +libstrongswan_gmpdh_la_LDFLAGS = -module -avoid-version -Wl,-Bstatic -Wl,-lgmp -Wl,-Bdynamic -Wl,--as-needed $(FPIC)
  87. +libstrongswan_gmpdh_la_LIBADD =
  88. --- /dev/null
  89. +++ b/src/libstrongswan/plugins/gmpdh/gmpdh_plugin.c
  90. @@ -0,0 +1,101 @@
  91. +/*
  92. + * Copyright (C) 2008-2009 Martin Willi
  93. + * Hochschule fuer Technik Rapperswil
  94. + *
  95. + * This program is free software; you can redistribute it and/or modify it
  96. + * under the terms of the GNU General Public License as published by the
  97. + * Free Software Foundation; either version 2 of the License, or (at your
  98. + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  99. + *
  100. + * This program is distributed in the hope that it will be useful, but
  101. + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  102. + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  103. + * for more details.
  104. + */
  105. +
  106. +#include "gmpdh_plugin.h"
  107. +
  108. +#include <library.h>
  109. +#include "../gmp/gmp_diffie_hellman.h"
  110. +
  111. +typedef struct private_gmpdh_plugin_t private_gmpdh_plugin_t;
  112. +
  113. +/**
  114. + * private data of gmp_plugin
  115. + */
  116. +struct private_gmpdh_plugin_t {
  117. +
  118. + /**
  119. + * public functions
  120. + */
  121. + gmpdh_plugin_t public;
  122. +};
  123. +
  124. +METHOD(plugin_t, get_name, char*,
  125. + private_gmpdh_plugin_t *this)
  126. +{
  127. + return "gmpdh";
  128. +}
  129. +
  130. +METHOD(plugin_t, get_features, int,
  131. + private_gmpdh_plugin_t *this, plugin_feature_t *features[])
  132. +{
  133. + static plugin_feature_t f[] = {
  134. + /* DH groups */
  135. + PLUGIN_REGISTER(DH, gmp_diffie_hellman_create),
  136. + PLUGIN_PROVIDE(DH, MODP_2048_BIT),
  137. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  138. + PLUGIN_PROVIDE(DH, MODP_2048_224),
  139. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  140. + PLUGIN_PROVIDE(DH, MODP_2048_256),
  141. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  142. + PLUGIN_PROVIDE(DH, MODP_1536_BIT),
  143. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  144. + PLUGIN_PROVIDE(DH, MODP_3072_BIT),
  145. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  146. + PLUGIN_PROVIDE(DH, MODP_4096_BIT),
  147. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  148. + PLUGIN_PROVIDE(DH, MODP_6144_BIT),
  149. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  150. + PLUGIN_PROVIDE(DH, MODP_8192_BIT),
  151. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  152. + PLUGIN_PROVIDE(DH, MODP_1024_BIT),
  153. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  154. + PLUGIN_PROVIDE(DH, MODP_1024_160),
  155. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  156. + PLUGIN_PROVIDE(DH, MODP_768_BIT),
  157. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  158. + PLUGIN_REGISTER(DH, gmp_diffie_hellman_create_custom),
  159. + PLUGIN_PROVIDE(DH, MODP_CUSTOM),
  160. + PLUGIN_DEPENDS(RNG, RNG_STRONG),
  161. + };
  162. + *features = f;
  163. + return countof(f);
  164. +}
  165. +
  166. +METHOD(plugin_t, destroy, void,
  167. + private_gmpdh_plugin_t *this)
  168. +{
  169. + free(this);
  170. +}
  171. +
  172. +/*
  173. + * see header file
  174. + */
  175. +plugin_t *gmpdh_plugin_create()
  176. +{
  177. + private_gmpdh_plugin_t *this;
  178. +
  179. + INIT(this,
  180. + .public = {
  181. + .plugin = {
  182. + .get_name = _get_name,
  183. + .get_features = _get_features,
  184. + .destroy = _destroy,
  185. + },
  186. + },
  187. + );
  188. +
  189. + return &this->public.plugin;
  190. +}
  191. +
  192. --- /dev/null
  193. +++ b/src/libstrongswan/plugins/gmpdh/gmpdh_plugin.h
  194. @@ -0,0 +1,42 @@
  195. +/*
  196. + * Copyright (C) 2008 Martin Willi
  197. + * Hochschule fuer Technik Rapperswil
  198. + *
  199. + * This program is free software; you can redistribute it and/or modify it
  200. + * under the terms of the GNU General Public License as published by the
  201. + * Free Software Foundation; either version 2 of the License, or (at your
  202. + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  203. + *
  204. + * This program is distributed in the hope that it will be useful, but
  205. + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  206. + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  207. + * for more details.
  208. + */
  209. +
  210. +/**
  211. + * @defgroup gmpdh_p gmpdh
  212. + * @ingroup plugins
  213. + *
  214. + * @defgroup gmpdh_plugin gmpdh_plugin
  215. + * @{ @ingroup gmpdh_p
  216. + */
  217. +
  218. +#ifndef GMPDH_PLUGIN_H_
  219. +#define GMPDH_PLUGIN_H_
  220. +
  221. +#include <plugins/plugin.h>
  222. +
  223. +typedef struct gmpdh_plugin_t gmpdh_plugin_t;
  224. +
  225. +/**
  226. + * Plugin implementing asymmetric crypto algorithms using the GNU MP library.
  227. + */
  228. +struct gmpdh_plugin_t {
  229. +
  230. + /**
  231. + * implements plugin interface
  232. + */
  233. + plugin_t plugin;
  234. +};
  235. +
  236. +#endif /** GMPDH_PLUGIN_H_ @}*/