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) 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;
29 #include "test_vectors.h"
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
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)
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"
51 #undef TEST_VECTOR_CRYPTER
52 #define TEST_VECTOR_CRYPTER(x)
54 #undef TEST_VECTOR_AEAD
55 #define TEST_VECTOR_AEAD(x) &x,
56 static aead_test_vector_t
*aead
[] = {
57 #include "test_vectors.h"
59 #undef TEST_VECTOR_AEAD
60 #define TEST_VECTOR_AEAD(x)
62 #undef TEST_VECTOR_SIGNER
63 #define TEST_VECTOR_SIGNER(x) &x,
64 static signer_test_vector_t
*signer
[] = {
65 #include "test_vectors.h"
67 #undef TEST_VECTOR_SIGNER
68 #define TEST_VECTOR_SIGNER(x)
70 #undef TEST_VECTOR_HASHER
71 #define TEST_VECTOR_HASHER(x) &x,
72 static hasher_test_vector_t
*hasher
[] = {
73 #include "test_vectors.h"
75 #undef TEST_VECTOR_HASHER
76 #define TEST_VECTOR_HASHER(x)
78 #undef TEST_VECTOR_PRF
79 #define TEST_VECTOR_PRF(x) &x,
80 static prf_test_vector_t
*prf
[] = {
81 #include "test_vectors.h"
83 #undef TEST_VECTOR_PRF
84 #define TEST_VECTOR_PRF(x)
86 #undef TEST_VECTOR_RNG
87 #define TEST_VECTOR_RNG(x) &x,
88 static rng_test_vector_t
*rng
[] = {
89 #include "test_vectors.h"
91 #undef TEST_VECTOR_RNG
92 #define TEST_VECTOR_RNG(x)
94 typedef struct private_test_vectors_plugin_t private_test_vectors_plugin_t
;
97 * private data of test_vectors_plugin
99 struct private_test_vectors_plugin_t
{
104 test_vectors_plugin_t
public;
107 METHOD(plugin_t
, get_name
, char*,
108 private_test_vectors_plugin_t
*this)
110 return "test-vectors";
113 METHOD(plugin_t
, get_features
, int,
114 private_test_vectors_plugin_t
*this, plugin_feature_t
*features
[])
116 static plugin_feature_t f
[] = {
118 PLUGIN_PROVIDE(CUSTOM
, "test-vectors"),
124 METHOD(plugin_t
, destroy
, void,
125 private_test_vectors_plugin_t
*this)
133 plugin_t
*test_vectors_plugin_create()
135 private_test_vectors_plugin_t
*this;
141 .get_name
= _get_name
,
142 .get_features
= _get_features
,
148 for (i
= 0; i
< countof(crypter
); i
++)
150 lib
->crypto
->add_test_vector(lib
->crypto
,
151 ENCRYPTION_ALGORITHM
, crypter
[i
]);
153 for (i
= 0; i
< countof(aead
); i
++)
155 lib
->crypto
->add_test_vector(lib
->crypto
,
156 AEAD_ALGORITHM
, aead
[i
]);
158 for (i
= 0; i
< countof(signer
); i
++)
160 lib
->crypto
->add_test_vector(lib
->crypto
,
161 INTEGRITY_ALGORITHM
, signer
[i
]);
163 for (i
= 0; i
< countof(hasher
); i
++)
165 lib
->crypto
->add_test_vector(lib
->crypto
,
166 HASH_ALGORITHM
, hasher
[i
]);
168 for (i
= 0; i
< countof(prf
); i
++)
170 lib
->crypto
->add_test_vector(lib
->crypto
,
171 PSEUDO_RANDOM_FUNCTION
, prf
[i
]);
173 for (i
= 0; i
< countof(rng
); i
++)
175 lib
->crypto
->add_test_vector(lib
->crypto
,
176 RANDOM_NUMBER_GENERATOR
, rng
[i
]);
179 return &this->public.plugin
;