xof: Defined Extended Output Functions
[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) extern crypter_test_vector_t x;
23 #define TEST_VECTOR_AEAD(x) extern aead_test_vector_t x;
24 #define TEST_VECTOR_SIGNER(x) extern signer_test_vector_t x;
25 #define TEST_VECTOR_HASHER(x) extern hasher_test_vector_t x;
26 #define TEST_VECTOR_PRF(x) extern prf_test_vector_t x;
27 #define TEST_VECTOR_XOF(x) extern xof_test_vector_t x;
28 #define TEST_VECTOR_RNG(x) extern rng_test_vector_t x;
29 #define TEST_VECTOR_DH(x) extern dh_test_vector_t x;
30
31 #include "test_vectors.h"
32
33 #undef TEST_VECTOR_CRYPTER
34 #undef TEST_VECTOR_AEAD
35 #undef TEST_VECTOR_SIGNER
36 #undef TEST_VECTOR_HASHER
37 #undef TEST_VECTOR_PRF
38 #undef TEST_VECTOR_XOF
39 #undef TEST_VECTOR_RNG
40 #undef TEST_VECTOR_DH
41
42 #define TEST_VECTOR_CRYPTER(x)
43 #define TEST_VECTOR_AEAD(x)
44 #define TEST_VECTOR_SIGNER(x)
45 #define TEST_VECTOR_HASHER(x)
46 #define TEST_VECTOR_PRF(x)
47 #define TEST_VECTOR_XOF(x)
48 #define TEST_VECTOR_RNG(x)
49 #define TEST_VECTOR_DH(x)
50
51 /* create test vector arrays */
52 #undef TEST_VECTOR_CRYPTER
53 #define TEST_VECTOR_CRYPTER(x) &x,
54 static crypter_test_vector_t *crypter[] = {
55 #include "test_vectors.h"
56 };
57 #undef TEST_VECTOR_CRYPTER
58 #define TEST_VECTOR_CRYPTER(x)
59
60 #undef TEST_VECTOR_AEAD
61 #define TEST_VECTOR_AEAD(x) &x,
62 static aead_test_vector_t *aead[] = {
63 #include "test_vectors.h"
64 };
65 #undef TEST_VECTOR_AEAD
66 #define TEST_VECTOR_AEAD(x)
67
68 #undef TEST_VECTOR_SIGNER
69 #define TEST_VECTOR_SIGNER(x) &x,
70 static signer_test_vector_t *signer[] = {
71 #include "test_vectors.h"
72 };
73 #undef TEST_VECTOR_SIGNER
74 #define TEST_VECTOR_SIGNER(x)
75
76 #undef TEST_VECTOR_HASHER
77 #define TEST_VECTOR_HASHER(x) &x,
78 static hasher_test_vector_t *hasher[] = {
79 #include "test_vectors.h"
80 };
81 #undef TEST_VECTOR_HASHER
82 #define TEST_VECTOR_HASHER(x)
83
84 #undef TEST_VECTOR_PRF
85 #define TEST_VECTOR_PRF(x) &x,
86 static prf_test_vector_t *prf[] = {
87 #include "test_vectors.h"
88 };
89 #undef TEST_VECTOR_PRF
90 #define TEST_VECTOR_PRF(x)
91
92 #undef TEST_VECTOR_XOF
93 #define TEST_VECTOR_XOF(x) &x,
94 static xof_test_vector_t *xof[] = {
95 #include "test_vectors.h"
96 };
97 #undef TEST_VECTOR_XOF
98 #define TEST_VECTOR_XOF(x)
99
100 #undef TEST_VECTOR_RNG
101 #define TEST_VECTOR_RNG(x) &x,
102 static rng_test_vector_t *rng[] = {
103 #include "test_vectors.h"
104 };
105 #undef TEST_VECTOR_RNG
106 #define TEST_VECTOR_RNG(x)
107
108 #undef TEST_VECTOR_DH
109 #define TEST_VECTOR_DH(x) &x,
110 static dh_test_vector_t *dh[] = {
111 #include "test_vectors.h"
112 };
113 #undef TEST_VECTOR_DH
114 #define TEST_VECTOR_DH(x)
115
116 typedef struct private_test_vectors_plugin_t private_test_vectors_plugin_t;
117
118 /**
119 * private data of test_vectors_plugin
120 */
121 struct private_test_vectors_plugin_t {
122
123 /**
124 * public functions
125 */
126 test_vectors_plugin_t public;
127 };
128
129 METHOD(plugin_t, get_name, char*,
130 private_test_vectors_plugin_t *this)
131 {
132 return "test-vectors";
133 }
134
135 METHOD(plugin_t, get_features, int,
136 private_test_vectors_plugin_t *this, plugin_feature_t *features[])
137 {
138 static plugin_feature_t f[] = {
139 PLUGIN_NOOP,
140 PLUGIN_PROVIDE(CUSTOM, "test-vectors"),
141 };
142 *features = f;
143 return countof(f);
144 }
145
146 METHOD(plugin_t, destroy, void,
147 private_test_vectors_plugin_t *this)
148 {
149 free(this);
150 }
151
152 /*
153 * see header file
154 */
155 plugin_t *test_vectors_plugin_create()
156 {
157 private_test_vectors_plugin_t *this;
158 int i;
159
160 INIT(this,
161 .public = {
162 .plugin = {
163 .get_name = _get_name,
164 .get_features = _get_features,
165 .destroy = _destroy,
166 },
167 },
168 );
169
170 for (i = 0; i < countof(crypter); i++)
171 {
172 lib->crypto->add_test_vector(lib->crypto,
173 ENCRYPTION_ALGORITHM, crypter[i]);
174 }
175 for (i = 0; i < countof(aead); i++)
176 {
177 lib->crypto->add_test_vector(lib->crypto,
178 AEAD_ALGORITHM, aead[i]);
179 }
180 for (i = 0; i < countof(signer); i++)
181 {
182 lib->crypto->add_test_vector(lib->crypto,
183 INTEGRITY_ALGORITHM, signer[i]);
184 }
185 for (i = 0; i < countof(hasher); i++)
186 {
187 lib->crypto->add_test_vector(lib->crypto,
188 HASH_ALGORITHM, hasher[i]);
189 }
190 for (i = 0; i < countof(prf); i++)
191 {
192 lib->crypto->add_test_vector(lib->crypto,
193 PSEUDO_RANDOM_FUNCTION, prf[i]);
194 }
195 for (i = 0; i < countof(xof); i++)
196 {
197 lib->crypto->add_test_vector(lib->crypto,
198 EXTENDED_OUTPUT_FUNCTION, xof[i]);
199 }
200 for (i = 0; i < countof(rng); i++)
201 {
202 lib->crypto->add_test_vector(lib->crypto,
203 RANDOM_NUMBER_GENERATOR, rng[i]);
204 }
205 for (i = 0; i < countof(dh); i++)
206 {
207 lib->crypto->add_test_vector(lib->crypto,
208 DIFFIE_HELLMAN_GROUP, dh[i]);
209 }
210
211 return &this->public.plugin;
212 }