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