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