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