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