2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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>.
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
16 #include "test_vectors_plugin.h"
18 #include <crypto/crypto_factory.h>
19 #include <crypto/crypto_tester.h>
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;
30 #include "test_vectors.h"
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
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)
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"
54 #undef TEST_VECTOR_CRYPTER
55 #define TEST_VECTOR_CRYPTER(x)
57 #undef TEST_VECTOR_AEAD
58 #define TEST_VECTOR_AEAD(x) &x,
59 static aead_test_vector_t
*aead
[] = {
60 #include "test_vectors.h"
62 #undef TEST_VECTOR_AEAD
63 #define TEST_VECTOR_AEAD(x)
65 #undef TEST_VECTOR_SIGNER
66 #define TEST_VECTOR_SIGNER(x) &x,
67 static signer_test_vector_t
*signer
[] = {
68 #include "test_vectors.h"
70 #undef TEST_VECTOR_SIGNER
71 #define TEST_VECTOR_SIGNER(x)
73 #undef TEST_VECTOR_HASHER
74 #define TEST_VECTOR_HASHER(x) &x,
75 static hasher_test_vector_t
*hasher
[] = {
76 #include "test_vectors.h"
78 #undef TEST_VECTOR_HASHER
79 #define TEST_VECTOR_HASHER(x)
81 #undef TEST_VECTOR_PRF
82 #define TEST_VECTOR_PRF(x) &x,
83 static prf_test_vector_t
*prf
[] = {
84 #include "test_vectors.h"
86 #undef TEST_VECTOR_PRF
87 #define TEST_VECTOR_PRF(x)
89 #undef TEST_VECTOR_RNG
90 #define TEST_VECTOR_RNG(x) &x,
91 static rng_test_vector_t
*rng
[] = {
92 #include "test_vectors.h"
94 #undef TEST_VECTOR_RNG
95 #define TEST_VECTOR_RNG(x)
98 #define TEST_VECTOR_DH(x) &x,
99 static dh_test_vector_t
*dh
[] = {
100 #include "test_vectors.h"
102 #undef TEST_VECTOR_DH
103 #define TEST_VECTOR_DH(x)
105 typedef struct private_test_vectors_plugin_t private_test_vectors_plugin_t
;
108 * private data of test_vectors_plugin
110 struct private_test_vectors_plugin_t
{
115 test_vectors_plugin_t
public;
118 METHOD(plugin_t
, get_name
, char*,
119 private_test_vectors_plugin_t
*this)
121 return "test-vectors";
124 METHOD(plugin_t
, get_features
, int,
125 private_test_vectors_plugin_t
*this, plugin_feature_t
*features
[])
127 static plugin_feature_t f
[] = {
129 PLUGIN_PROVIDE(CUSTOM
, "test-vectors"),
135 METHOD(plugin_t
, destroy
, void,
136 private_test_vectors_plugin_t
*this)
144 plugin_t
*test_vectors_plugin_create()
146 private_test_vectors_plugin_t
*this;
152 .get_name
= _get_name
,
153 .get_features
= _get_features
,
159 for (i
= 0; i
< countof(crypter
); i
++)
161 lib
->crypto
->add_test_vector(lib
->crypto
,
162 ENCRYPTION_ALGORITHM
, crypter
[i
]);
164 for (i
= 0; i
< countof(aead
); i
++)
166 lib
->crypto
->add_test_vector(lib
->crypto
,
167 AEAD_ALGORITHM
, aead
[i
]);
169 for (i
= 0; i
< countof(signer
); i
++)
171 lib
->crypto
->add_test_vector(lib
->crypto
,
172 INTEGRITY_ALGORITHM
, signer
[i
]);
174 for (i
= 0; i
< countof(hasher
); i
++)
176 lib
->crypto
->add_test_vector(lib
->crypto
,
177 HASH_ALGORITHM
, hasher
[i
]);
179 for (i
= 0; i
< countof(prf
); i
++)
181 lib
->crypto
->add_test_vector(lib
->crypto
,
182 PSEUDO_RANDOM_FUNCTION
, prf
[i
]);
184 for (i
= 0; i
< countof(rng
); i
++)
186 lib
->crypto
->add_test_vector(lib
->crypto
,
187 RANDOM_NUMBER_GENERATOR
, rng
[i
]);
189 for (i
= 0; i
< countof(dh
); i
++)
191 lib
->crypto
->add_test_vector(lib
->crypto
,
192 DIFFIE_HELLMAN_GROUP
, dh
[i
]);
195 return &this->public.plugin
;