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 rng_test_vector_t rng_test_vector_t
;
34 typedef struct dh_test_vector_t dh_test_vector_t
;
36 struct crypter_test_vector_t
{
37 /** encryption algorithm this vector tests */
38 encryption_algorithm_t alg
;
39 /** key length to use, in bytes */
41 /** encryption key of test vector */
43 /** initialization vector, using crypters blocksize bytes */
45 /** length of plain and cipher text */
53 struct aead_test_vector_t
{
54 /** encryption algorithm this vector tests */
55 encryption_algorithm_t alg
;
56 /** key length to use, in bytes */
58 /** salt length to use, in bytes */
60 /** encryption key of test vector */
62 /** initialization vector, using crypters blocksize bytes */
64 /** length of associated data */
66 /** associated data */
68 /** length of plain text */
76 struct signer_test_vector_t
{
77 /** signer algorithm this test vector tests */
78 integrity_algorithm_t alg
;
79 /** key to use, with a length the algorithm expects */
81 /** size of the input data */
85 /** expected output, with ouput size of the tested algorithm */
89 struct hasher_test_vector_t
{
90 /** hash algorithm this test vector tests */
92 /** length of the input data */
96 /** expected hash, with hash size of the tested algorithm */
100 struct prf_test_vector_t
{
101 /** prf algorithm this test vector tests */
102 pseudo_random_function_t alg
;
103 /** is this PRF stateful? */
105 /** key length to use, in bytes */
109 /** size of the seed data */
113 /** expected output, with block size of the tested algorithm */
118 * Test vector for a RNG.
120 * Contains a callback function to analyze the output of a RNG,
122 struct rng_test_vector_t
{
123 /** quality of random data this test vector tests */
124 rng_quality_t quality
;
125 /** callback function to test RNG output, returns TRUE if data ok */
126 bool (*test
)(void *user
, chunk_t data
);
127 /** number of bytes the function requests */
129 /** user data passed back to the test() function on invocation */
133 struct dh_test_vector_t
{
134 /** diffie hellman group to test */
135 diffie_hellman_group_t group
;
136 /** private value of alice */
138 /** private value of bob */
140 /** length of private values */
142 /** expected public value of alice */
144 /** expected public value of bob */
146 /** size of public values */
148 /** expected shared secret */
150 /** size of shared secret */
155 * Cryptographic primitive testing framework.
157 struct crypto_tester_t
{
160 * Test a crypter algorithm, optionally using a specified key size.
162 * @param alg algorithm to test
163 * @param key_size key size to test, 0 for default
164 * @param create constructor function for the crypter
165 * @param speed speed test result, NULL to omit
166 * @return TRUE if test passed
168 bool (*test_crypter
)(crypto_tester_t
*this, encryption_algorithm_t alg
,
169 size_t key_size
, crypter_constructor_t create
,
170 u_int
*speed
, const char *plugin_name
);
173 * Test an aead algorithm, optionally using a specified key size.
175 * @param alg algorithm to test
176 * @param key_size key size to test, 0 for default
177 * @param salt_size salt length to test, 0 for default
178 * @param create constructor function for the aead transform
179 * @param speed speed test result, NULL to omit
180 * @return TRUE if test passed
182 bool (*test_aead
)(crypto_tester_t
*this, encryption_algorithm_t alg
,
183 size_t key_size
, size_t salt_size
,
184 aead_constructor_t create
,
185 u_int
*speed
, const char *plugin_name
);
187 * Test a signer algorithm.
189 * @param alg algorithm to test
190 * @param create constructor function for the signer
191 * @param speed speed test result, NULL to omit
192 * @return TRUE if test passed
194 bool (*test_signer
)(crypto_tester_t
*this, integrity_algorithm_t alg
,
195 signer_constructor_t create
,
196 u_int
*speed
, const char *plugin_name
);
198 * Test a hasher algorithm.
200 * @param alg algorithm to test
201 * @param create constructor function for the hasher
202 * @param speed speed test result, NULL to omit
203 * @return TRUE if test passed
205 bool (*test_hasher
)(crypto_tester_t
*this, hash_algorithm_t alg
,
206 hasher_constructor_t create
,
207 u_int
*speed
, const char *plugin_name
);
209 * Test a PRF algorithm.
211 * @param alg algorithm to test
212 * @param create constructor function for the PRF
213 * @param speed speed test result, NULL to omit
214 * @return TRUE if test passed
216 bool (*test_prf
)(crypto_tester_t
*this, pseudo_random_function_t alg
,
217 prf_constructor_t create
,
218 u_int
*speed
, const char *plugin_name
);
220 * Test a RNG implementation.
222 * @param alg algorithm to test
223 * @param create constructor function for the RNG
224 * @param speed speed test result, NULL to omit
225 * @return TRUE if test passed
227 bool (*test_rng
)(crypto_tester_t
*this, rng_quality_t quality
,
228 rng_constructor_t create
,
229 u_int
*speed
, const char *plugin_name
);
231 * Test a Diffie-Hellman implementation.
233 * @param group group to test
234 * @param create constructor function for the DH backend
235 * @param speed speeed test result, NULL to omit
236 * @return TRUE if test passed
238 bool (*test_dh
)(crypto_tester_t
*this, diffie_hellman_group_t group
,
239 dh_constructor_t create
,
240 u_int
*speed
, const char *plugin_name
);
243 * Add a test vector to test a crypter.
245 * @param vector pointer to test vector
247 void (*add_crypter_vector
)(crypto_tester_t
*this,
248 crypter_test_vector_t
*vector
);
250 * Add a test vector to test an aead transform.
252 * @param vector pointer to test vector
254 void (*add_aead_vector
)(crypto_tester_t
*this,
255 aead_test_vector_t
*vector
);
257 * Add a test vector to test a signer.
259 * @param vector pointer to test vector
261 void (*add_signer_vector
)(crypto_tester_t
*this,
262 signer_test_vector_t
*vector
);
264 * Add a test vector to test a hasher.
266 * @param vector pointer to test vector
268 void (*add_hasher_vector
)(crypto_tester_t
*this,
269 hasher_test_vector_t
*vector
);
271 * Add a test vector to test a PRF.
273 * @param vector pointer to test vector
275 void (*add_prf_vector
)(crypto_tester_t
*this, prf_test_vector_t
*vector
);
278 * Add a test vector to test a RNG.
280 * @param vector pointer to test vector
282 void (*add_rng_vector
)(crypto_tester_t
*this, rng_test_vector_t
*vector
);
285 * Add a test vector to test a Diffie-Hellman backend.
287 * @param vector pointer to test vector
289 void (*add_dh_vector
)(crypto_tester_t
*this, dh_test_vector_t
*vector
);
292 * Destroy a crypto_tester_t.
294 void (*destroy
)(crypto_tester_t
*this);
298 * Create a crypto_tester instance.
300 crypto_tester_t
*crypto_tester_create();
302 #endif /** CRYPTO_TESTER_H_ @}*/