test-vectors: Use plugin features
[strongswan.git] / src / libstrongswan / plugins / test_vectors / test_vectors_plugin.c
1 /*
2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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 "test_vectors_plugin.h"
17
18 #include <crypto/crypto_factory.h>
19 #include <crypto/crypto_tester.h>
20
21 /* define symbols of all test vectors */
22 #define TEST_VECTOR_CRYPTER(x) crypter_test_vector_t x;
23 #define TEST_VECTOR_AEAD(x) aead_test_vector_t x;
24 #define TEST_VECTOR_SIGNER(x) signer_test_vector_t x;
25 #define TEST_VECTOR_HASHER(x) hasher_test_vector_t x;
26 #define TEST_VECTOR_PRF(x) prf_test_vector_t x;
27 #define TEST_VECTOR_RNG(x) rng_test_vector_t x;
28
29 #include "test_vectors.h"
30
31 #undef TEST_VECTOR_CRYPTER
32 #undef TEST_VECTOR_AEAD
33 #undef TEST_VECTOR_SIGNER
34 #undef TEST_VECTOR_HASHER
35 #undef TEST_VECTOR_PRF
36 #undef TEST_VECTOR_RNG
37
38 #define TEST_VECTOR_CRYPTER(x)
39 #define TEST_VECTOR_AEAD(x)
40 #define TEST_VECTOR_SIGNER(x)
41 #define TEST_VECTOR_HASHER(x)
42 #define TEST_VECTOR_PRF(x)
43 #define TEST_VECTOR_RNG(x)
44
45 /* create test vector arrays */
46 #undef TEST_VECTOR_CRYPTER
47 #define TEST_VECTOR_CRYPTER(x) &x,
48 static crypter_test_vector_t *crypter[] = {
49 #include "test_vectors.h"
50 };
51 #undef TEST_VECTOR_CRYPTER
52 #define TEST_VECTOR_CRYPTER(x)
53
54 #undef TEST_VECTOR_AEAD
55 #define TEST_VECTOR_AEAD(x) &x,
56 static aead_test_vector_t *aead[] = {
57 #include "test_vectors.h"
58 };
59 #undef TEST_VECTOR_AEAD
60 #define TEST_VECTOR_AEAD(x)
61
62 #undef TEST_VECTOR_SIGNER
63 #define TEST_VECTOR_SIGNER(x) &x,
64 static signer_test_vector_t *signer[] = {
65 #include "test_vectors.h"
66 };
67 #undef TEST_VECTOR_SIGNER
68 #define TEST_VECTOR_SIGNER(x)
69
70 #undef TEST_VECTOR_HASHER
71 #define TEST_VECTOR_HASHER(x) &x,
72 static hasher_test_vector_t *hasher[] = {
73 #include "test_vectors.h"
74 };
75 #undef TEST_VECTOR_HASHER
76 #define TEST_VECTOR_HASHER(x)
77
78 #undef TEST_VECTOR_PRF
79 #define TEST_VECTOR_PRF(x) &x,
80 static prf_test_vector_t *prf[] = {
81 #include "test_vectors.h"
82 };
83 #undef TEST_VECTOR_PRF
84 #define TEST_VECTOR_PRF(x)
85
86 #undef TEST_VECTOR_RNG
87 #define TEST_VECTOR_RNG(x) &x,
88 static rng_test_vector_t *rng[] = {
89 #include "test_vectors.h"
90 };
91 #undef TEST_VECTOR_RNG
92 #define TEST_VECTOR_RNG(x)
93
94 typedef struct private_test_vectors_plugin_t private_test_vectors_plugin_t;
95
96 /**
97 * private data of test_vectors_plugin
98 */
99 struct private_test_vectors_plugin_t {
100
101 /**
102 * public functions
103 */
104 test_vectors_plugin_t public;
105 };
106
107 METHOD(plugin_t, get_name, char*,
108 private_test_vectors_plugin_t *this)
109 {
110 return "test-vectors";
111 }
112
113 METHOD(plugin_t, get_features, int,
114 private_test_vectors_plugin_t *this, plugin_feature_t *features[])
115 {
116 static plugin_feature_t f[] = {
117 PLUGIN_NOOP,
118 PLUGIN_PROVIDE(CUSTOM, "test-vectors"),
119 };
120 *features = f;
121 return countof(f);
122 }
123
124 METHOD(plugin_t, destroy, void,
125 private_test_vectors_plugin_t *this)
126 {
127 free(this);
128 }
129
130 /*
131 * see header file
132 */
133 plugin_t *test_vectors_plugin_create()
134 {
135 private_test_vectors_plugin_t *this;
136 int i;
137
138 INIT(this,
139 .public = {
140 .plugin = {
141 .get_name = _get_name,
142 .get_features = _get_features,
143 .destroy = _destroy,
144 },
145 },
146 );
147
148 for (i = 0; i < countof(crypter); i++)
149 {
150 lib->crypto->add_test_vector(lib->crypto,
151 ENCRYPTION_ALGORITHM, crypter[i]);
152 }
153 for (i = 0; i < countof(aead); i++)
154 {
155 lib->crypto->add_test_vector(lib->crypto,
156 AEAD_ALGORITHM, aead[i]);
157 }
158 for (i = 0; i < countof(signer); i++)
159 {
160 lib->crypto->add_test_vector(lib->crypto,
161 INTEGRITY_ALGORITHM, signer[i]);
162 }
163 for (i = 0; i < countof(hasher); i++)
164 {
165 lib->crypto->add_test_vector(lib->crypto,
166 HASH_ALGORITHM, hasher[i]);
167 }
168 for (i = 0; i < countof(prf); i++)
169 {
170 lib->crypto->add_test_vector(lib->crypto,
171 PSEUDO_RANDOM_FUNCTION, prf[i]);
172 }
173 for (i = 0; i < countof(rng); i++)
174 {
175 lib->crypto->add_test_vector(lib->crypto,
176 RANDOM_NUMBER_GENERATOR, rng[i]);
177 }
178
179 return &this->public.plugin;
180 }
181