4a8743289f6d1aa8bba91f2b77fcdeae6c346ed5
[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) 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;
28
29 #include "test_vectors.h"
30
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
37
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)
44
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"
50 };
51 #undef TEST_VECTOR_CRYPTER
52 #define TEST_VECTOR_CRYPTER(x)
53
54 #undef TEST_VECTOR_AEAD
55 #define TEST_VECTOR_AEAD(x) &x,
56 static aead_test_vector_t *aead[] = {
57 #include "test_vectors.h"
58 };
59 #undef TEST_VECTOR_AEAD
60 #define TEST_VECTOR_AEAD(x)
61
62 #undef TEST_VECTOR_SIGNER
63 #define TEST_VECTOR_SIGNER(x) &x,
64 static signer_test_vector_t *signer[] = {
65 #include "test_vectors.h"
66 };
67 #undef TEST_VECTOR_SIGNER
68 #define TEST_VECTOR_SIGNER(x)
69
70 #undef TEST_VECTOR_HASHER
71 #define TEST_VECTOR_HASHER(x) &x,
72 static hasher_test_vector_t *hasher[] = {
73 #include "test_vectors.h"
74 };
75 #undef TEST_VECTOR_HASHER
76 #define TEST_VECTOR_HASHER(x)
77
78 #undef TEST_VECTOR_PRF
79 #define TEST_VECTOR_PRF(x) &x,
80 static prf_test_vector_t *prf[] = {
81 #include "test_vectors.h"
82 };
83 #undef TEST_VECTOR_PRF
84 #define TEST_VECTOR_PRF(x)
85
86 #undef TEST_VECTOR_RNG
87 #define TEST_VECTOR_RNG(x) &x,
88 static rng_test_vector_t *rng[] = {
89 #include "test_vectors.h"
90 };
91 #undef TEST_VECTOR_RNG
92 #define TEST_VECTOR_RNG(x)
93
94 typedef struct private_test_vectors_plugin_t private_test_vectors_plugin_t;
95
96 /**
97 * private data of test_vectors_plugin
98 */
99 struct private_test_vectors_plugin_t {
100
101 /**
102 * public functions
103 */
104 test_vectors_plugin_t public;
105 };
106
107 METHOD(plugin_t, get_name, char*,
108 private_test_vectors_plugin_t *this)
109 {
110 return "test-vectors";
111 }
112
113 METHOD(plugin_t, destroy, void,
114 private_test_vectors_plugin_t *this)
115 {
116 free(this);
117 }
118
119 /*
120 * see header file
121 */
122 plugin_t *test_vectors_plugin_create()
123 {
124 private_test_vectors_plugin_t *this;
125 int i;
126
127 INIT(this,
128 .public = {
129 .plugin = {
130 .get_name = _get_name,
131 .reload = (void*)return_false,
132 .destroy = _destroy,
133 },
134 },
135 );
136
137 for (i = 0; i < countof(crypter); i++)
138 {
139 lib->crypto->add_test_vector(lib->crypto,
140 ENCRYPTION_ALGORITHM, crypter[i]);
141 }
142 for (i = 0; i < countof(aead); i++)
143 {
144 lib->crypto->add_test_vector(lib->crypto,
145 AEAD_ALGORITHM, aead[i]);
146 }
147 for (i = 0; i < countof(signer); i++)
148 {
149 lib->crypto->add_test_vector(lib->crypto,
150 INTEGRITY_ALGORITHM, signer[i]);
151 }
152 for (i = 0; i < countof(hasher); i++)
153 {
154 lib->crypto->add_test_vector(lib->crypto,
155 HASH_ALGORITHM, hasher[i]);
156 }
157 for (i = 0; i < countof(prf); i++)
158 {
159 lib->crypto->add_test_vector(lib->crypto,
160 PSEUDO_RANDOM_FUNCTION, prf[i]);
161 }
162 for (i = 0; i < countof(rng); i++)
163 {
164 lib->crypto->add_test_vector(lib->crypto,
165 RANDOM_NUMBER_GENERATOR, rng[i]);
166 }
167
168 return &this->public.plugin;
169 }
170