]> git.ipfire.org Git - people/ms/strongswan.git/blob - src/libstrongswan/plugins/aesni/aesni_plugin.c
74645987dff9ea1c9d6a1a2bfb7921cc585b828d
[people/ms/strongswan.git] / src / libstrongswan / plugins / aesni / aesni_plugin.c
1 /*
2 * Copyright (C) 2015 Martin Willi
3 * Copyright (C) 2015 revosec AG
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
16 #include "aesni_plugin.h"
17 #include "aesni_cbc.h"
18
19 #include <stdio.h>
20
21 #include <library.h>
22 #include <utils/debug.h>
23 #include <utils/cpu_feature.h>
24
25 typedef struct private_aesni_plugin_t private_aesni_plugin_t;
26 typedef enum cpuid_feature_t cpuid_feature_t;
27
28 /**
29 * private data of aesni_plugin
30 */
31 struct private_aesni_plugin_t {
32
33 /**
34 * public functions
35 */
36 aesni_plugin_t public;
37 };
38
39 METHOD(plugin_t, get_name, char*,
40 private_aesni_plugin_t *this)
41 {
42 return "aesni";
43 }
44
45 METHOD(plugin_t, get_features, int,
46 private_aesni_plugin_t *this, plugin_feature_t *features[])
47 {
48 static plugin_feature_t f[] = {
49 PLUGIN_REGISTER(CRYPTER, aesni_cbc_create),
50 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 16),
51 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 24),
52 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 32),
53 };
54
55 *features = f;
56 if (cpu_feature_available(CPU_FEATURE_AESNI))
57 {
58 return countof(f);
59 }
60 return 0;
61 }
62
63 METHOD(plugin_t, destroy, void,
64 private_aesni_plugin_t *this)
65 {
66 free(this);
67 }
68
69 /*
70 * see header file
71 */
72 plugin_t *aesni_plugin_create()
73 {
74 private_aesni_plugin_t *this;
75
76 INIT(this,
77 .public = {
78 .plugin = {
79 .get_name = _get_name,
80 .get_features = _get_features,
81 .reload = (void*)return_false,
82 .destroy = _destroy,
83 },
84 },
85 );
86
87 return &this->public.plugin;
88 }