aesni: Add a GCM AEAD based on the AES-NI key schedule
[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 #include "aesni_gcm.h"
21 #include "aesni_xcbc.h"
22 #include "aesni_cmac.h"
23
24 #include <stdio.h>
25
26 #include <library.h>
27 #include <utils/debug.h>
28 #include <utils/cpu_feature.h>
29
30 typedef struct private_aesni_plugin_t private_aesni_plugin_t;
31 typedef enum cpuid_feature_t cpuid_feature_t;
32
33 /**
34 * private data of aesni_plugin
35 */
36 struct private_aesni_plugin_t {
37
38 /**
39 * public functions
40 */
41 aesni_plugin_t public;
42 };
43
44 METHOD(plugin_t, get_name, char*,
45 private_aesni_plugin_t *this)
46 {
47 return "aesni";
48 }
49
50 METHOD(plugin_t, get_features, int,
51 private_aesni_plugin_t *this, plugin_feature_t *features[])
52 {
53 static plugin_feature_t f[] = {
54 PLUGIN_REGISTER(CRYPTER, aesni_cbc_create),
55 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 16),
56 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 24),
57 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 32),
58 PLUGIN_REGISTER(CRYPTER, aesni_ctr_create),
59 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CTR, 16),
60 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CTR, 24),
61 PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CTR, 32),
62 PLUGIN_REGISTER(AEAD, aesni_ccm_create),
63 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV8, 16),
64 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV12, 16),
65 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV16, 16),
66 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV8, 24),
67 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV12, 24),
68 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV16, 24),
69 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV8, 32),
70 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV12, 32),
71 PLUGIN_PROVIDE(AEAD, ENCR_AES_CCM_ICV16, 32),
72 PLUGIN_REGISTER(AEAD, aesni_gcm_create),
73 PLUGIN_PROVIDE(AEAD, ENCR_AES_GCM_ICV8, 16),
74 PLUGIN_PROVIDE(AEAD, ENCR_AES_GCM_ICV12, 16),
75 PLUGIN_PROVIDE(AEAD, ENCR_AES_GCM_ICV16, 16),
76 PLUGIN_PROVIDE(AEAD, ENCR_AES_GCM_ICV8, 24),
77 PLUGIN_PROVIDE(AEAD, ENCR_AES_GCM_ICV12, 24),
78 PLUGIN_PROVIDE(AEAD, ENCR_AES_GCM_ICV16, 24),
79 PLUGIN_PROVIDE(AEAD, ENCR_AES_GCM_ICV8, 32),
80 PLUGIN_PROVIDE(AEAD, ENCR_AES_GCM_ICV12, 32),
81 PLUGIN_PROVIDE(AEAD, ENCR_AES_GCM_ICV16, 32),
82 PLUGIN_REGISTER(PRF, aesni_xcbc_prf_create),
83 PLUGIN_PROVIDE(PRF, PRF_AES128_XCBC),
84 PLUGIN_REGISTER(SIGNER, aesni_xcbc_signer_create),
85 PLUGIN_PROVIDE(SIGNER, AUTH_AES_XCBC_96),
86 PLUGIN_REGISTER(PRF, aesni_cmac_prf_create),
87 PLUGIN_PROVIDE(PRF, PRF_AES128_CMAC),
88 PLUGIN_REGISTER(SIGNER, aesni_cmac_signer_create),
89 PLUGIN_PROVIDE(SIGNER, AUTH_AES_CMAC_96),
90 };
91
92 *features = f;
93 if (cpu_feature_available(CPU_FEATURE_AESNI | CPU_FEATURE_PCLMULQDQ))
94 {
95 return countof(f);
96 }
97 return 0;
98 }
99
100 METHOD(plugin_t, destroy, void,
101 private_aesni_plugin_t *this)
102 {
103 free(this);
104 }
105
106 /*
107 * see header file
108 */
109 plugin_t *aesni_plugin_create()
110 {
111 private_aesni_plugin_t *this;
112
113 INIT(this,
114 .public = {
115 .plugin = {
116 .get_name = _get_name,
117 .get_features = _get_features,
118 .reload = (void*)return_false,
119 .destroy = _destroy,
120 },
121 },
122 );
123
124 return &this->public.plugin;
125 }