]>
Commit | Line | Data |
---|---|---|
81811a9d MW |
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 */ | |
7d1ffe01 MW |
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; | |
81811a9d MW |
29 | |
30 | #include "test_vectors.h" | |
31 | ||
32 | #undef TEST_VECTOR_CRYPTER | |
8ca9e255 | 33 | #undef TEST_VECTOR_AEAD |
81811a9d MW |
34 | #undef TEST_VECTOR_SIGNER |
35 | #undef TEST_VECTOR_HASHER | |
36 | #undef TEST_VECTOR_PRF | |
37 | #undef TEST_VECTOR_RNG | |
79955b2b | 38 | #undef TEST_VECTOR_DH |
81811a9d MW |
39 | |
40 | #define TEST_VECTOR_CRYPTER(x) | |
8ca9e255 | 41 | #define TEST_VECTOR_AEAD(x) |
81811a9d MW |
42 | #define TEST_VECTOR_SIGNER(x) |
43 | #define TEST_VECTOR_HASHER(x) | |
44 | #define TEST_VECTOR_PRF(x) | |
45 | #define TEST_VECTOR_RNG(x) | |
79955b2b | 46 | #define TEST_VECTOR_DH(x) |
81811a9d MW |
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 | ||
8ca9e255 MW |
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 | ||
81811a9d MW |
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 | ||
79955b2b MW |
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 | ||
81811a9d MW |
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 | ||
787b5884 MW |
118 | METHOD(plugin_t, get_name, char*, |
119 | private_test_vectors_plugin_t *this) | |
120 | { | |
121 | return "test-vectors"; | |
122 | } | |
123 | ||
da049149 TB |
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 | ||
621f9324 AS |
135 | METHOD(plugin_t, destroy, void, |
136 | private_test_vectors_plugin_t *this) | |
81811a9d MW |
137 | { |
138 | free(this); | |
139 | } | |
140 | ||
141 | /* | |
142 | * see header file | |
143 | */ | |
9ce567f8 | 144 | plugin_t *test_vectors_plugin_create() |
81811a9d | 145 | { |
621f9324 | 146 | private_test_vectors_plugin_t *this; |
81811a9d | 147 | int i; |
7daf5226 | 148 | |
621f9324 AS |
149 | INIT(this, |
150 | .public = { | |
151 | .plugin = { | |
787b5884 | 152 | .get_name = _get_name, |
da049149 | 153 | .get_features = _get_features, |
621f9324 AS |
154 | .destroy = _destroy, |
155 | }, | |
156 | }, | |
157 | ); | |
7daf5226 | 158 | |
81811a9d MW |
159 | for (i = 0; i < countof(crypter); i++) |
160 | { | |
161 | lib->crypto->add_test_vector(lib->crypto, | |
162 | ENCRYPTION_ALGORITHM, crypter[i]); | |
163 | } | |
8ca9e255 MW |
164 | for (i = 0; i < countof(aead); i++) |
165 | { | |
166 | lib->crypto->add_test_vector(lib->crypto, | |
167 | AEAD_ALGORITHM, aead[i]); | |
168 | } | |
81811a9d MW |
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 | } | |
79955b2b MW |
189 | for (i = 0; i < countof(dh); i++) |
190 | { | |
191 | lib->crypto->add_test_vector(lib->crypto, | |
192 | DIFFIE_HELLMAN_GROUP, dh[i]); | |
193 | } | |
7daf5226 | 194 | |
81811a9d MW |
195 | return &this->public.plugin; |
196 | } |