2 * Copyright (C) 2009 Martin Willi
3 * Copyright (C) 2016-2019 Andreas Steffen
5 * Copyright (C) secunet Security Networks AG
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * @defgroup crypto_tester crypto_tester
23 #ifndef CRYPTO_TESTER_H_
24 #define CRYPTO_TESTER_H_
26 typedef struct crypto_tester_t crypto_tester_t
;
28 #include <crypto/crypto_factory.h>
30 typedef struct crypter_test_vector_t crypter_test_vector_t
;
31 typedef struct aead_test_vector_t aead_test_vector_t
;
32 typedef struct signer_test_vector_t signer_test_vector_t
;
33 typedef struct hasher_test_vector_t hasher_test_vector_t
;
34 typedef struct prf_test_vector_t prf_test_vector_t
;
35 typedef struct xof_test_vector_t xof_test_vector_t
;
36 typedef struct kdf_test_vector_t kdf_test_vector_t
;
37 typedef struct kdf_test_args_t kdf_test_args_t
;
38 typedef struct drbg_test_vector_t drbg_test_vector_t
;
39 typedef struct rng_test_vector_t rng_test_vector_t
;
40 typedef struct ke_test_vector_t ke_test_vector_t
;
42 struct crypter_test_vector_t
{
43 /** encryption algorithm this vector tests */
44 encryption_algorithm_t alg
;
45 /** key length to use, in bytes */
47 /** encryption key of test vector */
49 /** initialization vector, using crypters blocksize bytes */
51 /** length of plain and cipher text */
59 struct aead_test_vector_t
{
60 /** encryption algorithm this vector tests */
61 encryption_algorithm_t alg
;
62 /** key length to use, in bytes */
64 /** salt length to use, in bytes */
66 /** encryption key of test vector */
68 /** initialization vector, using crypters blocksize bytes */
70 /** length of associated data */
72 /** associated data */
74 /** length of plain text */
82 struct signer_test_vector_t
{
83 /** signer algorithm this test vector tests */
84 integrity_algorithm_t alg
;
85 /** key to use, with a length the algorithm expects */
87 /** size of the input data */
91 /** expected output, with output size of the tested algorithm */
95 struct hasher_test_vector_t
{
96 /** hash algorithm this test vector tests */
98 /** length of the input data */
102 /** expected hash, with hash size of the tested algorithm */
106 struct prf_test_vector_t
{
107 /** prf algorithm this test vector tests */
108 pseudo_random_function_t alg
;
109 /** is this PRF stateful? */
111 /** key length to use, in bytes */
115 /** size of the seed data */
119 /** expected output, with block size of the tested algorithm */
123 struct xof_test_vector_t
{
124 /** xof algorithm this test vector tests */
125 ext_out_function_t alg
;
126 /** size of the seed data */
130 /** size of the output */
132 /** expected output of size*/
136 struct kdf_test_vector_t
{
137 /** kdf algorithm this test vector tests */
138 key_derivation_function_t alg
;
139 /** argument passed to constructor, type depends on alg */
141 pseudo_random_function_t prf
;
147 /** expected output */
151 struct kdf_test_args_t
{
152 /** the arguments used to construct the KDF */
156 struct drbg_test_vector_t
{
157 /** drbg type this test vector tests */
159 /** security strength in bits */
161 /** optional personalization string */
162 chunk_t personalization_str
;
163 /** entropy_input | nonce | entropy_input_reseed */
165 /** returned output bits */
170 * Test vector for a RNG.
172 * Contains a callback function to analyze the output of a RNG,
174 struct rng_test_vector_t
{
175 /** quality of random data this test vector tests */
176 rng_quality_t quality
;
177 /** callback function to test RNG output, returns TRUE if data ok */
178 bool (*test
)(void *user
, chunk_t data
);
179 /** number of bytes the function requests */
181 /** user data passed back to the test() function on invocation */
185 struct ke_test_vector_t
{
186 /** key exchange method to test */
187 key_exchange_method_t method
;
188 /** private key of alice */
190 /** private key of bob */
192 /** length of private keys */
194 /** expected public key of alice */
196 /** expected public key of bob */
198 /** size of public keys */
200 /** expected shared secret */
202 /** size of shared secret */
207 * Cryptographic primitive testing framework.
209 struct crypto_tester_t
{
212 * Test a crypter algorithm, optionally using a specified key size.
214 * @param alg algorithm to test
215 * @param key_size key size to test, 0 for default
216 * @param create constructor function for the crypter
217 * @param speed speed test result, NULL to omit
218 * @return TRUE if test passed
220 bool (*test_crypter
)(crypto_tester_t
*this, encryption_algorithm_t alg
,
221 size_t key_size
, crypter_constructor_t create
,
222 u_int
*speed
, const char *plugin_name
);
225 * Test an aead algorithm, optionally using a specified key size.
227 * @param alg algorithm to test
228 * @param key_size key size to test, 0 for default
229 * @param salt_size salt length to test, 0 for default
230 * @param create constructor function for the aead transform
231 * @param speed speed test result, NULL to omit
232 * @return TRUE if test passed
234 bool (*test_aead
)(crypto_tester_t
*this, encryption_algorithm_t alg
,
235 size_t key_size
, size_t salt_size
,
236 aead_constructor_t create
,
237 u_int
*speed
, const char *plugin_name
);
239 * Test a signer algorithm.
241 * @param alg algorithm to test
242 * @param create constructor function for the signer
243 * @param speed speed test result, NULL to omit
244 * @return TRUE if test passed
246 bool (*test_signer
)(crypto_tester_t
*this, integrity_algorithm_t alg
,
247 signer_constructor_t create
,
248 u_int
*speed
, const char *plugin_name
);
250 * Test a hasher algorithm.
252 * @param alg algorithm to test
253 * @param create constructor function for the hasher
254 * @param speed speed test result, NULL to omit
255 * @return TRUE if test passed
257 bool (*test_hasher
)(crypto_tester_t
*this, hash_algorithm_t alg
,
258 hasher_constructor_t create
,
259 u_int
*speed
, const char *plugin_name
);
261 * Test a PRF algorithm.
263 * @param alg algorithm to test
264 * @param create constructor function for the PRF
265 * @param speed speed test result, NULL to omit
266 * @return TRUE if test passed
268 bool (*test_prf
)(crypto_tester_t
*this, pseudo_random_function_t alg
,
269 prf_constructor_t create
,
270 u_int
*speed
, const char *plugin_name
);
272 * Test an XOF algorithm.
274 * @param alg algorithm to test
275 * @param create constructor function for the XOF
276 * @param speed speed test result, NULL to omit
277 * @return TRUE if test passed
279 bool (*test_xof
)(crypto_tester_t
*this, ext_out_function_t alg
,
280 xof_constructor_t create
,
281 u_int
*speed
, const char *plugin_name
);
283 * Test a KDF algorithm.
285 * If constructor arguments are passed, only matching test vectors are
286 * tried. Otherwise, all are tried and implementations are allowed to fail
287 * construction with unsupported arguments.
289 * @param alg algorithm to test
290 * @param create constructor function for the XOF
291 * @param args optional arguments to pass to constructor
292 * @param speed speed test result, NULL to omit
293 * @return TRUE if test passed
295 bool (*test_kdf
)(crypto_tester_t
*this, key_derivation_function_t alg
,
296 kdf_constructor_t create
, kdf_test_args_t
*args
,
297 u_int
*speed
, const char *plugin_name
);
301 * @param type DRBG type to test
302 * @param create constructor function for the DRBG
303 * @param speed speed test result, NULL to omit
304 * @return TRUE if test passed
306 bool (*test_drbg
)(crypto_tester_t
*this, drbg_type_t type
,
307 drbg_constructor_t create
,
308 u_int
*speed
, const char *plugin_name
);
310 * Test a RNG implementation.
312 * @param alg algorithm to test
313 * @param create constructor function for the RNG
314 * @param speed speed test result, NULL to omit
315 * @return TRUE if test passed
317 bool (*test_rng
)(crypto_tester_t
*this, rng_quality_t quality
,
318 rng_constructor_t create
,
319 u_int
*speed
, const char *plugin_name
);
321 * Test a key exchange implementation.
323 * @param ke key exchange method to test
324 * @param create constructor function for the key exchange method
325 * @param speed speed test result, NULL to omit
326 * @return TRUE if test passed
328 bool (*test_ke
)(crypto_tester_t
*this, key_exchange_method_t ke
,
329 ke_constructor_t create
,
330 u_int
*speed
, const char *plugin_name
);
333 * Add a test vector to test a crypter.
335 * @param vector pointer to test vector
337 void (*add_crypter_vector
)(crypto_tester_t
*this,
338 crypter_test_vector_t
*vector
);
340 * Add a test vector to test an aead transform.
342 * @param vector pointer to test vector
344 void (*add_aead_vector
)(crypto_tester_t
*this,
345 aead_test_vector_t
*vector
);
347 * Add a test vector to test a signer.
349 * @param vector pointer to test vector
351 void (*add_signer_vector
)(crypto_tester_t
*this,
352 signer_test_vector_t
*vector
);
354 * Add a test vector to test a hasher.
356 * @param vector pointer to test vector
358 void (*add_hasher_vector
)(crypto_tester_t
*this,
359 hasher_test_vector_t
*vector
);
361 * Add a test vector to test a PRF.
363 * @param vector pointer to test vector
365 void (*add_prf_vector
)(crypto_tester_t
*this, prf_test_vector_t
*vector
);
368 * Add a test vector to test an XOF.
370 * @param vector pointer to test vector
372 void (*add_xof_vector
)(crypto_tester_t
*this, xof_test_vector_t
*vector
);
375 * Add a test vector to test a KDF.
377 * @param vector pointer to test vector
379 void (*add_kdf_vector
)(crypto_tester_t
*this, kdf_test_vector_t
*vector
);
382 * Add a test vector to test a DRBG.
384 * @param vector pointer to test vector
386 void (*add_drbg_vector
)(crypto_tester_t
*this, drbg_test_vector_t
*vector
);
389 * Add a test vector to test a RNG.
391 * @param vector pointer to test vector
393 void (*add_rng_vector
)(crypto_tester_t
*this, rng_test_vector_t
*vector
);
396 * Add a test vector to test a Diffie-Hellman backend.
398 * @param vector pointer to test vector
400 void (*add_ke_vector
)(crypto_tester_t
*this, ke_test_vector_t
*vector
);
403 * Destroy a crypto_tester_t.
405 void (*destroy
)(crypto_tester_t
*this);
409 * Create a crypto_tester instance.
411 crypto_tester_t
*crypto_tester_create();
413 #endif /** CRYPTO_TESTER_H_ @}*/