Added support for DH groups 22, 23 and 24, patch contributed by Joy Latten
[strongswan.git] / src / libstrongswan / plugins / gmp / gmp_plugin.c
1 /*
2 * Copyright (C) 2008-2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "gmp_plugin.h"
17
18 #include <library.h>
19 #include "gmp_diffie_hellman.h"
20 #include "gmp_rsa_private_key.h"
21 #include "gmp_rsa_public_key.h"
22
23 typedef struct private_gmp_plugin_t private_gmp_plugin_t;
24
25 /**
26 * private data of gmp_plugin
27 */
28 struct private_gmp_plugin_t {
29
30 /**
31 * public functions
32 */
33 gmp_plugin_t public;
34 };
35
36 /**
37 * Implementation of gmp_plugin_t.gmptroy
38 */
39 static void destroy(private_gmp_plugin_t *this)
40 {
41 lib->crypto->remove_dh(lib->crypto,
42 (dh_constructor_t)gmp_diffie_hellman_create);
43 lib->creds->remove_builder(lib->creds,
44 (builder_function_t)gmp_rsa_private_key_gen);
45 lib->creds->remove_builder(lib->creds,
46 (builder_function_t)gmp_rsa_private_key_load);
47 lib->creds->remove_builder(lib->creds,
48 (builder_function_t)gmp_rsa_public_key_load);
49 free(this);
50 }
51
52 /*
53 * see header file
54 */
55 plugin_t *gmp_plugin_create()
56 {
57 private_gmp_plugin_t *this = malloc_thing(private_gmp_plugin_t);
58
59 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
60
61 lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
62 (dh_constructor_t)gmp_diffie_hellman_create);
63 lib->crypto->add_dh(lib->crypto, MODP_2048_224,
64 (dh_constructor_t)gmp_diffie_hellman_create);
65 lib->crypto->add_dh(lib->crypto, MODP_2048_256,
66 (dh_constructor_t)gmp_diffie_hellman_create);
67 lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
68 (dh_constructor_t)gmp_diffie_hellman_create);
69 lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
70 (dh_constructor_t)gmp_diffie_hellman_create);
71 lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
72 (dh_constructor_t)gmp_diffie_hellman_create);
73 lib->crypto->add_dh(lib->crypto, MODP_6144_BIT,
74 (dh_constructor_t)gmp_diffie_hellman_create);
75 lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
76 (dh_constructor_t)gmp_diffie_hellman_create);
77 lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
78 (dh_constructor_t)gmp_diffie_hellman_create);
79 lib->crypto->add_dh(lib->crypto, MODP_1024_160,
80 (dh_constructor_t)gmp_diffie_hellman_create);
81 lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
82 (dh_constructor_t)gmp_diffie_hellman_create);
83
84 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
85 (builder_function_t)gmp_rsa_private_key_gen);
86 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
87 (builder_function_t)gmp_rsa_private_key_load);
88 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
89 (builder_function_t)gmp_rsa_public_key_load);
90
91 return &this->public.plugin;
92 }
93