2 * Copyright (C) 2008 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
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>.
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
18 #include <openssl/evp.h>
19 #include <openssl/engine.h>
21 #include "openssl_plugin.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"
33 typedef struct private_openssl_plugin_t private_openssl_plugin_t
;
36 * private data of openssl_plugin
38 struct private_openssl_plugin_t
{
43 openssl_plugin_t
public;
47 * Implementation of openssl_plugin_t.destroy
49 static void destroy(private_openssl_plugin_t
*this)
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
);
77 plugin_t
*plugin_create()
79 private_openssl_plugin_t
*this = malloc_thing(private_openssl_plugin_t
);
81 this->public.plugin
.destroy
= (void(*)(plugin_t
*))destroy
;
83 OpenSSL_add_all_algorithms();
85 /* activate support for hardware accelerators */
86 ENGINE_load_builtin_engines();
87 ENGINE_register_all_complete();
90 lib
->crypto
->add_crypter(lib
->crypto
, ENCR_DES
,
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_NULL
,
103 (crypter_constructor_t
)openssl_crypter_create
);
104 lib
->crypto
->add_crypter(lib
->crypto
, ENCR_AES_CBC
,
105 (crypter_constructor_t
)openssl_crypter_create
);
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
);
122 lib
->crypto
->add_dh(lib
->crypto
, MODP_768_BIT
,
123 (dh_constructor_t
)openssl_diffie_hellman_create
);
124 lib
->crypto
->add_dh(lib
->crypto
, MODP_1024_BIT
,
125 (dh_constructor_t
)openssl_diffie_hellman_create
);
126 lib
->crypto
->add_dh(lib
->crypto
, MODP_1536_BIT
,
127 (dh_constructor_t
)openssl_diffie_hellman_create
);
128 lib
->crypto
->add_dh(lib
->crypto
, MODP_2048_BIT
,
129 (dh_constructor_t
)openssl_diffie_hellman_create
);
130 lib
->crypto
->add_dh(lib
->crypto
, MODP_3072_BIT
,
131 (dh_constructor_t
)openssl_diffie_hellman_create
);
132 lib
->crypto
->add_dh(lib
->crypto
, MODP_4096_BIT
,
133 (dh_constructor_t
)openssl_diffie_hellman_create
);
134 lib
->crypto
->add_dh(lib
->crypto
, MODP_6144_BIT
,
135 (dh_constructor_t
)openssl_diffie_hellman_create
);
136 lib
->crypto
->add_dh(lib
->crypto
, MODP_8192_BIT
,
137 (dh_constructor_t
)openssl_diffie_hellman_create
);
139 /* ec diffie hellman */
140 lib
->crypto
->add_dh(lib
->crypto
, ECP_192_BIT
,
141 (dh_constructor_t
)openssl_ec_diffie_hellman_create
);
142 lib
->crypto
->add_dh(lib
->crypto
, ECP_224_BIT
,
143 (dh_constructor_t
)openssl_ec_diffie_hellman_create
);
144 lib
->crypto
->add_dh(lib
->crypto
, ECP_256_BIT
,
145 (dh_constructor_t
)openssl_ec_diffie_hellman_create
);
146 lib
->crypto
->add_dh(lib
->crypto
, ECP_384_BIT
,
147 (dh_constructor_t
)openssl_ec_diffie_hellman_create
);
148 lib
->crypto
->add_dh(lib
->crypto
, ECP_521_BIT
,
149 (dh_constructor_t
)openssl_ec_diffie_hellman_create
);
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
);
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
);
163 return &this->public.plugin
;