added wrapper for OpenSSL hashers
[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
26 typedef struct private_openssl_plugin_t private_openssl_plugin_t;
27
28 /**
29 * private data of openssl_plugin
30 */
31 struct private_openssl_plugin_t {
32
33 /**
34 * public functions
35 */
36 openssl_plugin_t public;
37 };
38
39 /**
40 * Implementation of openssl_plugin_t.destroy
41 */
42 static void destroy(private_openssl_plugin_t *this)
43 {
44 lib->crypto->remove_crypter(lib->crypto,
45 (crypter_constructor_t)openssl_crypter_create);
46 lib->crypto->remove_hasher(lib->crypto,
47 (hasher_constructor_t)openssl_hasher_create);
48
49 EVP_cleanup();
50
51 free(this);
52 }
53
54 /*
55 * see header file
56 */
57 plugin_t *plugin_create()
58 {
59 private_openssl_plugin_t *this = malloc_thing(private_openssl_plugin_t);
60
61 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
62
63 OpenSSL_add_all_algorithms();
64
65 /* crypter */
66 lib->crypto->add_crypter(lib->crypto, ENCR_DES,
67 (crypter_constructor_t)openssl_crypter_create);
68 lib->crypto->add_crypter(lib->crypto, ENCR_3DES,
69 (crypter_constructor_t)openssl_crypter_create);
70 lib->crypto->add_crypter(lib->crypto, ENCR_RC5,
71 (crypter_constructor_t)openssl_crypter_create);
72 lib->crypto->add_crypter(lib->crypto, ENCR_IDEA,
73 (crypter_constructor_t)openssl_crypter_create);
74 lib->crypto->add_crypter(lib->crypto, ENCR_CAST,
75 (crypter_constructor_t)openssl_crypter_create);
76 lib->crypto->add_crypter(lib->crypto, ENCR_BLOWFISH,
77 (crypter_constructor_t)openssl_crypter_create);
78 lib->crypto->add_crypter(lib->crypto, ENCR_NULL,
79 (crypter_constructor_t)openssl_crypter_create);
80 lib->crypto->add_crypter(lib->crypto, ENCR_AES_CBC,
81 (crypter_constructor_t)openssl_crypter_create);
82
83 /* hasher */
84 lib->crypto->add_hasher(lib->crypto, HASH_MD2,
85 (hasher_constructor_t)openssl_hasher_create);
86 lib->crypto->add_hasher(lib->crypto, HASH_MD5,
87 (hasher_constructor_t)openssl_hasher_create);
88 lib->crypto->add_hasher(lib->crypto, HASH_SHA1,
89 (hasher_constructor_t)openssl_hasher_create);
90 lib->crypto->add_hasher(lib->crypto, HASH_SHA256,
91 (hasher_constructor_t)openssl_hasher_create);
92 lib->crypto->add_hasher(lib->crypto, HASH_SHA384,
93 (hasher_constructor_t)openssl_hasher_create);
94 lib->crypto->add_hasher(lib->crypto, HASH_SHA512,
95 (hasher_constructor_t)openssl_hasher_create);
96
97 return &this->public.plugin;
98 }