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