764ecba18bed191b9c452c70942a28e146b52d78
[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 #include "aesni_ctr.h"
19 #include "aesni_ccm.h"
20
21 #include <stdio.h>
22
23 #include <library.h>
24 #include <utils/debug.h>
25 #include <utils/cpu_feature.h>
26
27 typedef struct private_aesni_plugin_t private_aesni_plugin_t;
28 typedef enum cpuid_feature_t cpuid_feature_t;
29
30 /**
31 * private data of aesni_plugin
32 */
33 struct private_aesni_plugin_t {
34
35 /**
36 * public functions
37 */
38 aesni_plugin_t public;
39 };
40
41 METHOD(plugin_t, get_name, char*,
42 private_aesni_plugin_t *this)
43 {
44 return "aesni";
45 }
46
47 METHOD(plugin_t, get_features, int,
48 private_aesni_plugin_t *this, plugin_feature_t *features[])
49 {
50 static plugin_feature_t f[] = {
51 PLUGIN_REGISTER(CRYPTER, aesni_cbc_create),
52 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 16),
53 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 24),
54 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 32),
55 PLUGIN_REGISTER(CRYPTER, aesni_ctr_create),
56 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CTR, 16),
57 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CTR, 24),
58 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CTR, 32),
59 PLUGIN_REGISTER(AEAD, aesni_ccm_create),
60 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV8, 16),
61 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV12, 16),
62 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV16, 16),
63 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV8, 24),
64 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV12, 24),
65 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV16, 24),
66 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV8, 32),
67 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV12, 32),
68 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV16, 32),
69 };
70
71 *features = f;
72 if (cpu_feature_available(CPU_FEATURE_AESNI))
73 {
74 return countof(f);
75 }
76 return 0;
77 }
78
79 METHOD(plugin_t, destroy, void,
80 private_aesni_plugin_t *this)
81 {
82 free(this);
83 }
84
85 /*
86 * see header file
87 */
88 plugin_t *aesni_plugin_create()
89 {
90 private_aesni_plugin_t *this;
91
92 INIT(this,
93 .public = {
94 .plugin = {
95 .get_name = _get_name,
96 .get_features = _get_features,
97 .reload = (void*)return_false,
98 .destroy = _destroy,
99 },
100 },
101 );
102
103 return &this->public.plugin;
104 }