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
17 * @defgroup crypto_tester crypto_tester
21 #ifndef CRYPTO_TESTER_H_
22 #define CRYPTO_TESTER_H_
24 typedef struct crypto_tester_t crypto_tester_t
;
26 #include <crypto/crypto_factory.h>
28 typedef struct crypter_test_vector_t crypter_test_vector_t
;
29 typedef struct aead_test_vector_t aead_test_vector_t
;
30 typedef struct signer_test_vector_t signer_test_vector_t
;
31 typedef struct hasher_test_vector_t hasher_test_vector_t
;
32 typedef struct prf_test_vector_t prf_test_vector_t
;
33 typedef struct xof_test_vector_t xof_test_vector_t
;
34 typedef struct rng_test_vector_t rng_test_vector_t
;
35 typedef struct dh_test_vector_t dh_test_vector_t
;
37 struct crypter_test_vector_t
{
38 /** encryption algorithm this vector tests */
39 encryption_algorithm_t alg
;
40 /** key length to use, in bytes */
42 /** encryption key of test vector */
44 /** initialization vector, using crypters blocksize bytes */
46 /** length of plain and cipher text */
54 struct aead_test_vector_t
{
55 /** encryption algorithm this vector tests */
56 encryption_algorithm_t alg
;
57 /** key length to use, in bytes */
59 /** salt length to use, in bytes */
61 /** encryption key of test vector */
63 /** initialization vector, using crypters blocksize bytes */
65 /** length of associated data */
67 /** associated data */
69 /** length of plain text */
77 struct signer_test_vector_t
{
78 /** signer algorithm this test vector tests */
79 integrity_algorithm_t alg
;
80 /** key to use, with a length the algorithm expects */
82 /** size of the input data */
86 /** expected output, with ouput size of the tested algorithm */
90 struct hasher_test_vector_t
{
91 /** hash algorithm this test vector tests */
93 /** length of the input data */
97 /** expected hash, with hash size of the tested algorithm */
101 struct prf_test_vector_t
{
102 /** prf algorithm this test vector tests */
103 pseudo_random_function_t alg
;
104 /** is this PRF stateful? */
106 /** key length to use, in bytes */
110 /** size of the seed data */
114 /** expected output, with block size of the tested algorithm */
118 struct xof_test_vector_t
{
119 /** xof algorithm this test vector tests */
120 ext_out_function_t alg
;
121 /** size of the seed data */
125 /** size of the output */
127 /** expected output of size*/
132 * Test vector for a RNG.
134 * Contains a callback function to analyze the output of a RNG,
136 struct rng_test_vector_t
{
137 /** quality of random data this test vector tests */
138 rng_quality_t quality
;
139 /** callback function to test RNG output, returns TRUE if data ok */
140 bool (*test
)(void *user
, chunk_t data
);
141 /** number of bytes the function requests */
143 /** user data passed back to the test() function on invocation */
147 struct dh_test_vector_t
{
148 /** diffie hellman group to test */
149 diffie_hellman_group_t group
;
150 /** private value of alice */
152 /** private value of bob */
154 /** length of private values */
156 /** expected public value of alice */
158 /** expected public value of bob */
160 /** size of public values */
162 /** expected shared secret */
164 /** size of shared secret */
169 * Cryptographic primitive testing framework.
171 struct crypto_tester_t
{
174 * Test a crypter algorithm, optionally using a specified key size.
176 * @param alg algorithm to test
177 * @param key_size key size to test, 0 for default
178 * @param create constructor function for the crypter
179 * @param speed speed test result, NULL to omit
180 * @return TRUE if test passed
182 bool (*test_crypter
)(crypto_tester_t
*this, encryption_algorithm_t alg
,
183 size_t key_size
, crypter_constructor_t create
,
184 u_int
*speed
, const char *plugin_name
);
187 * Test an aead algorithm, optionally using a specified key size.
189 * @param alg algorithm to test
190 * @param key_size key size to test, 0 for default
191 * @param salt_size salt length to test, 0 for default
192 * @param create constructor function for the aead transform
193 * @param speed speed test result, NULL to omit
194 * @return TRUE if test passed
196 bool (*test_aead
)(crypto_tester_t
*this, encryption_algorithm_t alg
,
197 size_t key_size
, size_t salt_size
,
198 aead_constructor_t create
,
199 u_int
*speed
, const char *plugin_name
);
201 * Test a signer algorithm.
203 * @param alg algorithm to test
204 * @param create constructor function for the signer
205 * @param speed speed test result, NULL to omit
206 * @return TRUE if test passed
208 bool (*test_signer
)(crypto_tester_t
*this, integrity_algorithm_t alg
,
209 signer_constructor_t create
,
210 u_int
*speed
, const char *plugin_name
);
212 * Test a hasher algorithm.
214 * @param alg algorithm to test
215 * @param create constructor function for the hasher
216 * @param speed speed test result, NULL to omit
217 * @return TRUE if test passed
219 bool (*test_hasher
)(crypto_tester_t
*this, hash_algorithm_t alg
,
220 hasher_constructor_t create
,
221 u_int
*speed
, const char *plugin_name
);
223 * Test a PRF algorithm.
225 * @param alg algorithm to test
226 * @param create constructor function for the PRF
227 * @param speed speed test result, NULL to omit
228 * @return TRUE if test passed
230 bool (*test_prf
)(crypto_tester_t
*this, pseudo_random_function_t alg
,
231 prf_constructor_t create
,
232 u_int
*speed
, const char *plugin_name
);
234 * Test an XOF algorithm.
236 * @param alg algorithm to test
237 * @param create constructor function for the XOF
238 * @param speed speed test result, NULL to omit
239 * @return TRUE if test passed
241 bool (*test_xof
)(crypto_tester_t
*this, ext_out_function_t alg
,
242 xof_constructor_t create
,
243 u_int
*speed
, const char *plugin_name
);
245 * Test a RNG implementation.
247 * @param alg algorithm to test
248 * @param create constructor function for the RNG
249 * @param speed speed test result, NULL to omit
250 * @return TRUE if test passed
252 bool (*test_rng
)(crypto_tester_t
*this, rng_quality_t quality
,
253 rng_constructor_t create
,
254 u_int
*speed
, const char *plugin_name
);
256 * Test a Diffie-Hellman implementation.
258 * @param group group to test
259 * @param create constructor function for the DH backend
260 * @param speed speeed test result, NULL to omit
261 * @return TRUE if test passed
263 bool (*test_dh
)(crypto_tester_t
*this, diffie_hellman_group_t group
,
264 dh_constructor_t create
,
265 u_int
*speed
, const char *plugin_name
);
268 * Add a test vector to test a crypter.
270 * @param vector pointer to test vector
272 void (*add_crypter_vector
)(crypto_tester_t
*this,
273 crypter_test_vector_t
*vector
);
275 * Add a test vector to test an aead transform.
277 * @param vector pointer to test vector
279 void (*add_aead_vector
)(crypto_tester_t
*this,
280 aead_test_vector_t
*vector
);
282 * Add a test vector to test a signer.
284 * @param vector pointer to test vector
286 void (*add_signer_vector
)(crypto_tester_t
*this,
287 signer_test_vector_t
*vector
);
289 * Add a test vector to test a hasher.
291 * @param vector pointer to test vector
293 void (*add_hasher_vector
)(crypto_tester_t
*this,
294 hasher_test_vector_t
*vector
);
296 * Add a test vector to test a PRF.
298 * @param vector pointer to test vector
300 void (*add_prf_vector
)(crypto_tester_t
*this, prf_test_vector_t
*vector
);
303 * Add a test vector to test an XOF.
305 * @param vector pointer to test vector
307 void (*add_xof_vector
)(crypto_tester_t
*this, xof_test_vector_t
*vector
);
310 * Add a test vector to test a RNG.
312 * @param vector pointer to test vector
314 void (*add_rng_vector
)(crypto_tester_t
*this, rng_test_vector_t
*vector
);
317 * Add a test vector to test a Diffie-Hellman backend.
319 * @param vector pointer to test vector
321 void (*add_dh_vector
)(crypto_tester_t
*this, dh_test_vector_t
*vector
);
324 * Destroy a crypto_tester_t.
326 void (*destroy
)(crypto_tester_t
*this);
330 * Create a crypto_tester instance.
332 crypto_tester_t
*crypto_tester_create();
334 #endif /** CRYPTO_TESTER_H_ @}*/