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 signer_test_vector_t signer_test_vector_t
;
30 typedef struct hasher_test_vector_t hasher_test_vector_t
;
31 typedef struct prf_test_vector_t prf_test_vector_t
;
32 typedef struct rng_test_vector_t rng_test_vector_t
;
34 struct crypter_test_vector_t
{
35 /** encryption algorithm this vector tests */
36 encryption_algorithm_t alg
;
37 /** key length to use, in bytes */
39 /** encryption key of test vector */
41 /** initialization vector, using crypters blocksize bytes */
43 /** length of plain and cipher text */
51 struct signer_test_vector_t
{
52 /** signer algorithm this test vector tests */
53 pseudo_random_function_t alg
;
54 /** key to use, with a length the algorithm expects */
56 /** size of the input data */
60 /** expected output, with ouput size of the tested algorithm */
64 struct hasher_test_vector_t
{
65 /** hash algorithm this test vector tests */
67 /** length of the input data */
71 /** expected hash, with hash size of the tested algorithm */
75 struct prf_test_vector_t
{
76 /** prf algorithm this test vector tests */
77 pseudo_random_function_t alg
;
78 /** is this PRF stateful? */
80 /** key length to use, in bytes */
84 /** size of the seed data */
88 /** expected output, with block size of the tested algorithm */
93 * Test vector for a RNG.
95 * Contains a callback function to analyze the output of a RNG,
97 struct rng_test_vector_t
{
98 /** quality of random data this test vector tests */
99 rng_quality_t quality
;
100 /** callback function to test RNG output, returns TRUE if data ok */
101 bool (*test
)(void *user
, chunk_t data
);
102 /** number of bytes the function requests */
104 /** user data passed back to the test() function on invocation */
109 * Cryptographic primitive testing framework.
111 struct crypto_tester_t
{
114 * Test a crypter algorithm, optionally using a specified key size.
116 * @param alg algorithm to test
117 * @param key_size key size to test, 0 for all
118 * @param create constructor function for the crypter
119 * @return TRUE if test passed
121 bool (*test_crypter
)(crypto_tester_t
*this, encryption_algorithm_t alg
,
122 size_t key_size
, crypter_constructor_t create
);
124 * Test a signer algorithm.
126 * @param alg algorithm to test
127 * @param create constructor function for the signer
128 * @return TRUE if test passed
130 bool (*test_signer
)(crypto_tester_t
*this, integrity_algorithm_t alg
,
131 signer_constructor_t create
);
133 * Test a hasher algorithm.
135 * @param alg algorithm to test
136 * @param create constructor function for the hasher
137 * @return TRUE if test passed
139 bool (*test_hasher
)(crypto_tester_t
*this, hash_algorithm_t alg
,
140 hasher_constructor_t create
);
142 * Test a PRF algorithm.
144 * @param alg algorithm to test
145 * @param create constructor function for the PRF
146 * @return TRUE if test passed
148 bool (*test_prf
)(crypto_tester_t
*this, pseudo_random_function_t alg
,
149 prf_constructor_t create
);
151 * Test a RNG implementation.
153 * @param alg algorithm to test
154 * @param create constructor function for the RNG
155 * @return TRUE if test passed
157 bool (*test_rng
)(crypto_tester_t
*this, rng_quality_t quality
,
158 rng_constructor_t create
);
160 * Add a test vector to test a crypter.
162 * @param vector pointer to test vector
164 void (*add_crypter_vector
)(crypto_tester_t
*this,
165 crypter_test_vector_t
*vector
);
167 * Add a test vector to test a signer.
169 * @param vector pointer to test vector
171 void (*add_signer_vector
)(crypto_tester_t
*this,
172 signer_test_vector_t
*vector
);
174 * Add a test vector to test a hasher.
176 * @param vector pointer to test vector
178 void (*add_hasher_vector
)(crypto_tester_t
*this,
179 hasher_test_vector_t
*vector
);
181 * Add a test vector to test a PRF.
183 * @param vector pointer to test vector
185 void (*add_prf_vector
)(crypto_tester_t
*this, prf_test_vector_t
*vector
);
188 * Add a test vector to test a RNG.
190 * @param vector pointer to test vector
192 void (*add_rng_vector
)(crypto_tester_t
*this, rng_test_vector_t
*vector
);
195 * Destroy a crypto_tester_t.
197 void (*destroy
)(crypto_tester_t
*this);
201 * Create a crypto_tester instance.
203 crypto_tester_t
*crypto_tester_create();
205 #endif /* CRYPTO_TESTER_ @}*/