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
;
35 struct crypter_test_vector_t
{
36 /** encryption algorithm this vector tests */
37 encryption_algorithm_t alg
;
38 /** key length to use, in bytes */
40 /** encryption key of test vector */
42 /** initialization vector, using crypters blocksize bytes */
44 /** length of plain and cipher text */
52 struct aead_test_vector_t
{
53 /** encryption algorithm this vector tests */
54 encryption_algorithm_t alg
;
55 /** key length to use, in bytes */
57 /** salt length to use, in bytes */
59 /** encryption key of test vector */
61 /** initialization vector, using crypters blocksize bytes */
63 /** length of associated data */
65 /** associated data */
67 /** length of plain text */
75 struct signer_test_vector_t
{
76 /** signer algorithm this test vector tests */
77 integrity_algorithm_t alg
;
78 /** key to use, with a length the algorithm expects */
80 /** size of the input data */
84 /** expected output, with ouput size of the tested algorithm */
88 struct hasher_test_vector_t
{
89 /** hash algorithm this test vector tests */
91 /** length of the input data */
95 /** expected hash, with hash size of the tested algorithm */
99 struct prf_test_vector_t
{
100 /** prf algorithm this test vector tests */
101 pseudo_random_function_t alg
;
102 /** is this PRF stateful? */
104 /** key length to use, in bytes */
108 /** size of the seed data */
112 /** expected output, with block size of the tested algorithm */
117 * Test vector for a RNG.
119 * Contains a callback function to analyze the output of a RNG,
121 struct rng_test_vector_t
{
122 /** quality of random data this test vector tests */
123 rng_quality_t quality
;
124 /** callback function to test RNG output, returns TRUE if data ok */
125 bool (*test
)(void *user
, chunk_t data
);
126 /** number of bytes the function requests */
128 /** user data passed back to the test() function on invocation */
133 * Cryptographic primitive testing framework.
135 struct crypto_tester_t
{
138 * Test a crypter algorithm, optionally using a specified key size.
140 * @param alg algorithm to test
141 * @param key_size key size to test, 0 for default
142 * @param create constructor function for the crypter
143 * @param speed speed test result, NULL to omit
144 * @return TRUE if test passed
146 bool (*test_crypter
)(crypto_tester_t
*this, encryption_algorithm_t alg
,
147 size_t key_size
, crypter_constructor_t create
,
148 u_int
*speed
, const char *plugin_name
);
151 * Test an aead algorithm, optionally using a specified key size.
153 * @param alg algorithm to test
154 * @param key_size key size to test, 0 for default
155 * @param salt_size salt length to test, 0 for default
156 * @param create constructor function for the aead transform
157 * @param speed speed test result, NULL to omit
158 * @return TRUE if test passed
160 bool (*test_aead
)(crypto_tester_t
*this, encryption_algorithm_t alg
,
161 size_t key_size
, size_t salt_size
,
162 aead_constructor_t create
,
163 u_int
*speed
, const char *plugin_name
);
165 * Test a signer algorithm.
167 * @param alg algorithm to test
168 * @param create constructor function for the signer
169 * @param speed speed test result, NULL to omit
170 * @return TRUE if test passed
172 bool (*test_signer
)(crypto_tester_t
*this, integrity_algorithm_t alg
,
173 signer_constructor_t create
,
174 u_int
*speed
, const char *plugin_name
);
176 * Test a hasher algorithm.
178 * @param alg algorithm to test
179 * @param create constructor function for the hasher
180 * @param speed speed test result, NULL to omit
181 * @return TRUE if test passed
183 bool (*test_hasher
)(crypto_tester_t
*this, hash_algorithm_t alg
,
184 hasher_constructor_t create
,
185 u_int
*speed
, const char *plugin_name
);
187 * Test a PRF algorithm.
189 * @param alg algorithm to test
190 * @param create constructor function for the PRF
191 * @param speed speed test result, NULL to omit
192 * @return TRUE if test passed
194 bool (*test_prf
)(crypto_tester_t
*this, pseudo_random_function_t alg
,
195 prf_constructor_t create
,
196 u_int
*speed
, const char *plugin_name
);
198 * Test a RNG implementation.
200 * @param alg algorithm to test
201 * @param create constructor function for the RNG
202 * @param speed speed test result, NULL to omit
203 * @return TRUE if test passed
205 bool (*test_rng
)(crypto_tester_t
*this, rng_quality_t quality
,
206 rng_constructor_t create
,
207 u_int
*speed
, const char *plugin_name
);
209 * Add a test vector to test a crypter.
211 * @param vector pointer to test vector
213 void (*add_crypter_vector
)(crypto_tester_t
*this,
214 crypter_test_vector_t
*vector
);
216 * Add a test vector to test an aead transform.
218 * @param vector pointer to test vector
220 void (*add_aead_vector
)(crypto_tester_t
*this,
221 aead_test_vector_t
*vector
);
223 * Add a test vector to test a signer.
225 * @param vector pointer to test vector
227 void (*add_signer_vector
)(crypto_tester_t
*this,
228 signer_test_vector_t
*vector
);
230 * Add a test vector to test a hasher.
232 * @param vector pointer to test vector
234 void (*add_hasher_vector
)(crypto_tester_t
*this,
235 hasher_test_vector_t
*vector
);
237 * Add a test vector to test a PRF.
239 * @param vector pointer to test vector
241 void (*add_prf_vector
)(crypto_tester_t
*this, prf_test_vector_t
*vector
);
244 * Add a test vector to test a RNG.
246 * @param vector pointer to test vector
248 void (*add_rng_vector
)(crypto_tester_t
*this, rng_test_vector_t
*vector
);
251 * Destroy a crypto_tester_t.
253 void (*destroy
)(crypto_tester_t
*this);
257 * Create a crypto_tester instance.
259 crypto_tester_t
*crypto_tester_create();
261 #endif /** CRYPTO_TESTER_H_ @}*/