3cbd2f19831eea87791495c84f5380cb3d429efe
[strongswan.git] / src / libstrongswan / plugins / gmp / gmp_plugin.c
1 /*
2 * Copyright (C) 2008 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 * $Id$
16 */
17
18 #include "gmp_plugin.h"
19
20 #include <library.h>
21 #include "gmp_diffie_hellman.h"
22 #include "gmp_public_key.h"
23 #include "gmp_rsa_private_key.h"
24 #include "gmp_rsa_public_key.h"
25
26 typedef struct private_gmp_plugin_t private_gmp_plugin_t;
27
28 /**
29 * private data of gmp_plugin
30 */
31 struct private_gmp_plugin_t {
32
33 /**
34 * public functions
35 */
36 gmp_plugin_t public;
37 };
38
39 /**
40 * Implementation of gmp_plugin_t.gmptroy
41 */
42 static void destroy(private_gmp_plugin_t *this)
43 {
44 lib->crypto->remove_dh(lib->crypto,
45 (dh_constructor_t)gmp_diffie_hellman_create);
46 lib->creds->remove_builder(lib->creds,
47 (builder_constructor_t)gmp_rsa_private_key_builder);
48 lib->creds->remove_builder(lib->creds,
49 (builder_constructor_t)gmp_rsa_public_key_builder);
50 lib->creds->remove_builder(lib->creds,
51 (builder_constructor_t)gmp_public_key_builder);
52 free(this);
53 }
54
55 /*
56 * see header file
57 */
58 plugin_t *plugin_create()
59 {
60 private_gmp_plugin_t *this = malloc_thing(private_gmp_plugin_t);
61
62 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
63
64 lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
65 (dh_constructor_t)gmp_diffie_hellman_create);
66 lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
67 (dh_constructor_t)gmp_diffie_hellman_create);
68 lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
69 (dh_constructor_t)gmp_diffie_hellman_create);
70 lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
71 (dh_constructor_t)gmp_diffie_hellman_create);
72 lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
73 (dh_constructor_t)gmp_diffie_hellman_create);
74 lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
75 (dh_constructor_t)gmp_diffie_hellman_create);
76 lib->crypto->add_dh(lib->crypto, MODP_6144_BIT,
77 (dh_constructor_t)gmp_diffie_hellman_create);
78 lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
79 (dh_constructor_t)gmp_diffie_hellman_create);
80
81 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
82 (builder_constructor_t)gmp_rsa_private_key_builder);
83 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
84 (builder_constructor_t)gmp_rsa_public_key_builder);
85 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
86 (builder_constructor_t)gmp_public_key_builder);
87
88 return &this->public.plugin;
89 }
90