adding diffie hellman with OpenSSL
[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
27 typedef struct private_openssl_plugin_t private_openssl_plugin_t;
28
29 /**
30 * private data of openssl_plugin
31 */
32 struct private_openssl_plugin_t {
33
34 /**
35 * public functions
36 */
37 openssl_plugin_t public;
38 };
39
40 /**
41 * Implementation of openssl_plugin_t.destroy
42 */
43 static void destroy(private_openssl_plugin_t *this)
44 {
45 lib->crypto->remove_crypter(lib->crypto,
46 (crypter_constructor_t)openssl_crypter_create);
47 lib->crypto->remove_hasher(lib->crypto,
48 (hasher_constructor_t)openssl_hasher_create);
49 lib->crypto->remove_dh(lib->crypto,
50 (dh_constructor_t)openssl_diffie_hellman_create);
51
52 EVP_cleanup();
53
54 free(this);
55 }
56
57 /*
58 * see header file
59 */
60 plugin_t *plugin_create()
61 {
62 private_openssl_plugin_t *this = malloc_thing(private_openssl_plugin_t);
63
64 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
65
66 OpenSSL_add_all_algorithms();
67
68 /* crypter */
69 lib->crypto->add_crypter(lib->crypto, ENCR_DES,
70 (crypter_constructor_t)openssl_crypter_create);
71 lib->crypto->add_crypter(lib->crypto, ENCR_3DES,
72 (crypter_constructor_t)openssl_crypter_create);
73 lib->crypto->add_crypter(lib->crypto, ENCR_RC5,
74 (crypter_constructor_t)openssl_crypter_create);
75 lib->crypto->add_crypter(lib->crypto, ENCR_IDEA,
76 (crypter_constructor_t)openssl_crypter_create);
77 lib->crypto->add_crypter(lib->crypto, ENCR_CAST,
78 (crypter_constructor_t)openssl_crypter_create);
79 lib->crypto->add_crypter(lib->crypto, ENCR_BLOWFISH,
80 (crypter_constructor_t)openssl_crypter_create);
81 lib->crypto->add_crypter(lib->crypto, ENCR_NULL,
82 (crypter_constructor_t)openssl_crypter_create);
83 lib->crypto->add_crypter(lib->crypto, ENCR_AES_CBC,
84 (crypter_constructor_t)openssl_crypter_create);
85
86 /* hasher */
87 lib->crypto->add_hasher(lib->crypto, HASH_SHA1,
88 (hasher_constructor_t)openssl_hasher_create);
89 lib->crypto->add_hasher(lib->crypto, HASH_MD2,
90 (hasher_constructor_t)openssl_hasher_create);
91 lib->crypto->add_hasher(lib->crypto, HASH_MD5,
92 (hasher_constructor_t)openssl_hasher_create);
93 lib->crypto->add_hasher(lib->crypto, HASH_SHA256,
94 (hasher_constructor_t)openssl_hasher_create);
95 lib->crypto->add_hasher(lib->crypto, HASH_SHA384,
96 (hasher_constructor_t)openssl_hasher_create);
97 lib->crypto->add_hasher(lib->crypto, HASH_SHA512,
98 (hasher_constructor_t)openssl_hasher_create);
99
100 /* diffie hellman */
101 lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
102 (dh_constructor_t)openssl_diffie_hellman_create);
103 lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
104 (dh_constructor_t)openssl_diffie_hellman_create);
105 lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
106 (dh_constructor_t)openssl_diffie_hellman_create);
107 lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
108 (dh_constructor_t)openssl_diffie_hellman_create);
109 lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
110 (dh_constructor_t)openssl_diffie_hellman_create);
111 lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
112 (dh_constructor_t)openssl_diffie_hellman_create);
113 lib->crypto->add_dh(lib->crypto, MODP_6144_BIT,
114 (dh_constructor_t)openssl_diffie_hellman_create);
115 lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
116 (dh_constructor_t)openssl_diffie_hellman_create);
117
118 return &this->public.plugin;
119 }