creating default IKE proposals dynamically using algorithm enumeration API
[strongswan.git] / src / libstrongswan / plugins / openssl / openssl_plugin.c
1 /*
2 * Copyright (C) 2008 Tobias Brunner
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 <openssl/evp.h>
19 #include <openssl/engine.h>
20
21 #include "openssl_plugin.h"
22
23 #include <library.h>
24 #include "openssl_crypter.h"
25 #include "openssl_hasher.h"
26 #include "openssl_diffie_hellman.h"
27 #include "openssl_ec_diffie_hellman.h"
28 #include "openssl_rsa_private_key.h"
29 #include "openssl_rsa_public_key.h"
30 #include "openssl_ec_private_key.h"
31 #include "openssl_ec_public_key.h"
32
33 typedef struct private_openssl_plugin_t private_openssl_plugin_t;
34
35 /**
36 * private data of openssl_plugin
37 */
38 struct private_openssl_plugin_t {
39
40 /**
41 * public functions
42 */
43 openssl_plugin_t public;
44 };
45
46 /**
47 * Implementation of openssl_plugin_t.destroy
48 */
49 static void destroy(private_openssl_plugin_t *this)
50 {
51 lib->crypto->remove_crypter(lib->crypto,
52 (crypter_constructor_t)openssl_crypter_create);
53 lib->crypto->remove_hasher(lib->crypto,
54 (hasher_constructor_t)openssl_hasher_create);
55 lib->crypto->remove_dh(lib->crypto,
56 (dh_constructor_t)openssl_diffie_hellman_create);
57 lib->crypto->remove_dh(lib->crypto,
58 (dh_constructor_t)openssl_ec_diffie_hellman_create);
59 lib->creds->remove_builder(lib->creds,
60 (builder_constructor_t)openssl_rsa_private_key_builder);
61 lib->creds->remove_builder(lib->creds,
62 (builder_constructor_t)openssl_rsa_public_key_builder);
63 lib->creds->remove_builder(lib->creds,
64 (builder_constructor_t)openssl_ec_private_key_builder);
65 lib->creds->remove_builder(lib->creds,
66 (builder_constructor_t)openssl_ec_public_key_builder);
67
68 ENGINE_cleanup();
69 EVP_cleanup();
70
71 free(this);
72 }
73
74 /*
75 * see header file
76 */
77 plugin_t *plugin_create()
78 {
79 private_openssl_plugin_t *this = malloc_thing(private_openssl_plugin_t);
80
81 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
82
83 OpenSSL_add_all_algorithms();
84
85 /* activate support for hardware accelerators */
86 ENGINE_load_builtin_engines();
87 ENGINE_register_all_complete();
88
89 /* crypter */
90 lib->crypto->add_crypter(lib->crypto, ENCR_AES_CBC,
91 (crypter_constructor_t)openssl_crypter_create);
92 lib->crypto->add_crypter(lib->crypto, ENCR_3DES,
93 (crypter_constructor_t)openssl_crypter_create);
94 lib->crypto->add_crypter(lib->crypto, ENCR_RC5,
95 (crypter_constructor_t)openssl_crypter_create);
96 lib->crypto->add_crypter(lib->crypto, ENCR_IDEA,
97 (crypter_constructor_t)openssl_crypter_create);
98 lib->crypto->add_crypter(lib->crypto, ENCR_CAST,
99 (crypter_constructor_t)openssl_crypter_create);
100 lib->crypto->add_crypter(lib->crypto, ENCR_BLOWFISH,
101 (crypter_constructor_t)openssl_crypter_create);
102 lib->crypto->add_crypter(lib->crypto, ENCR_DES,
103 (crypter_constructor_t)openssl_crypter_create);
104 lib->crypto->add_crypter(lib->crypto, ENCR_NULL,
105 (crypter_constructor_t)openssl_crypter_create);
106
107 /* hasher */
108 lib->crypto->add_hasher(lib->crypto, HASH_SHA1,
109 (hasher_constructor_t)openssl_hasher_create);
110 lib->crypto->add_hasher(lib->crypto, HASH_MD2,
111 (hasher_constructor_t)openssl_hasher_create);
112 lib->crypto->add_hasher(lib->crypto, HASH_MD5,
113 (hasher_constructor_t)openssl_hasher_create);
114 lib->crypto->add_hasher(lib->crypto, HASH_SHA256,
115 (hasher_constructor_t)openssl_hasher_create);
116 lib->crypto->add_hasher(lib->crypto, HASH_SHA384,
117 (hasher_constructor_t)openssl_hasher_create);
118 lib->crypto->add_hasher(lib->crypto, HASH_SHA512,
119 (hasher_constructor_t)openssl_hasher_create);
120
121 /* ec diffie hellman */
122 lib->crypto->add_dh(lib->crypto, ECP_192_BIT,
123 (dh_constructor_t)openssl_ec_diffie_hellman_create);
124 lib->crypto->add_dh(lib->crypto, ECP_224_BIT,
125 (dh_constructor_t)openssl_ec_diffie_hellman_create);
126 lib->crypto->add_dh(lib->crypto, ECP_256_BIT,
127 (dh_constructor_t)openssl_ec_diffie_hellman_create);
128 lib->crypto->add_dh(lib->crypto, ECP_384_BIT,
129 (dh_constructor_t)openssl_ec_diffie_hellman_create);
130 lib->crypto->add_dh(lib->crypto, ECP_521_BIT,
131 (dh_constructor_t)openssl_ec_diffie_hellman_create);
132
133 /* diffie hellman */
134 lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
135 (dh_constructor_t)openssl_diffie_hellman_create);
136 lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
137 (dh_constructor_t)openssl_diffie_hellman_create);
138 lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
139 (dh_constructor_t)openssl_diffie_hellman_create);
140 lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
141 (dh_constructor_t)openssl_diffie_hellman_create);
142 lib->crypto->add_dh(lib->crypto, MODP_6144_BIT,
143 (dh_constructor_t)openssl_diffie_hellman_create);
144 lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
145 (dh_constructor_t)openssl_diffie_hellman_create);
146 lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
147 (dh_constructor_t)openssl_diffie_hellman_create);
148 lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
149 (dh_constructor_t)openssl_diffie_hellman_create);
150
151 /* rsa */
152 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
153 (builder_constructor_t)openssl_rsa_private_key_builder);
154 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
155 (builder_constructor_t)openssl_rsa_public_key_builder);
156
157 /* ec */
158 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_ECDSA,
159 (builder_constructor_t)openssl_ec_private_key_builder);
160 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_ECDSA,
161 (builder_constructor_t)openssl_ec_public_key_builder);
162
163 return &this->public.plugin;
164 }