]> git.ipfire.org Git - people/ms/strongswan.git/blob - src/libstrongswan/crypto/crypto_tester.h
add3b1cdff59a327af5021f0579c008844a62ece
[people/ms/strongswan.git] / src / libstrongswan / crypto / crypto_tester.h
1 /*
2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 /**
17 * @defgroup crypto_tester crypto_tester
18 * @{ @ingroup crypto
19 */
20
21 #ifndef CRYPTO_TESTER_H_
22 #define CRYPTO_TESTER_H_
23
24 typedef struct crypto_tester_t crypto_tester_t;
25
26 #include <crypto/crypto_factory.h>
27
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
35 struct crypter_test_vector_t {
36 /** encryption algorithm this vector tests */
37 encryption_algorithm_t alg;
38 /** key length to use, in bytes */
39 size_t key_size;
40 /** encryption key of test vector */
41 u_char *key;
42 /** initialization vector, using crypters blocksize bytes */
43 u_char *iv;
44 /** length of plain and cipher text */
45 size_t len;
46 /** plain text */
47 u_char *plain;
48 /** cipher text */
49 u_char *cipher;
50 };
51
52 struct aead_test_vector_t {
53 /** encryption algorithm this vector tests */
54 encryption_algorithm_t alg;
55 /** key length to use, in bytes */
56 size_t key_size;
57 /** salt length to use, in bytes */
58 size_t salt_size;
59 /** encryption key of test vector */
60 u_char *key;
61 /** initialization vector, using crypters blocksize bytes */
62 u_char *iv;
63 /** length of associated data */
64 size_t alen;
65 /** associated data */
66 u_char *adata;
67 /** length of plain text */
68 size_t len;
69 /** plain text */
70 u_char *plain;
71 /** cipher text */
72 u_char *cipher;
73 };
74
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 */
79 u_char *key;
80 /** size of the input data */
81 size_t len;
82 /** input data */
83 u_char *data;
84 /** expected output, with ouput size of the tested algorithm */
85 u_char *mac;
86 };
87
88 struct hasher_test_vector_t {
89 /** hash algorithm this test vector tests */
90 hash_algorithm_t alg;
91 /** length of the input data */
92 size_t len;
93 /** input data */
94 u_char *data;
95 /** expected hash, with hash size of the tested algorithm */
96 u_char *hash;
97 };
98
99 struct prf_test_vector_t {
100 /** prf algorithm this test vector tests */
101 pseudo_random_function_t alg;
102 /** is this PRF stateful? */
103 bool stateful;
104 /** key length to use, in bytes */
105 size_t key_size;
106 /** key to use */
107 u_char *key;
108 /** size of the seed data */
109 size_t len;
110 /** seed data */
111 u_char *seed;
112 /** expected output, with block size of the tested algorithm */
113 u_char *out;
114 };
115
116 /**
117 * Test vector for a RNG.
118 *
119 * Contains a callback function to analyze the output of a RNG,
120 */
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 */
127 size_t len;
128 /** user data passed back to the test() function on invocation */
129 void *user;
130 };
131
132 /**
133 * Cryptographic primitive testing framework.
134 */
135 struct crypto_tester_t {
136
137 /**
138 * Test a crypter algorithm, optionally using a specified key size.
139 *
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
145 */
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);
149
150 /**
151 * Test an aead algorithm, optionally using a specified key size.
152 *
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
159 */
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);
164 /**
165 * Test a signer algorithm.
166 *
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
171 */
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);
175 /**
176 * Test a hasher algorithm.
177 *
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
182 */
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);
186 /**
187 * Test a PRF algorithm.
188 *
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
193 */
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);
197 /**
198 * Test a RNG implementation.
199 *
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
204 */
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);
208 /**
209 * Add a test vector to test a crypter.
210 *
211 * @param vector pointer to test vector
212 */
213 void (*add_crypter_vector)(crypto_tester_t *this,
214 crypter_test_vector_t *vector);
215 /**
216 * Add a test vector to test an aead transform.
217 *
218 * @param vector pointer to test vector
219 */
220 void (*add_aead_vector)(crypto_tester_t *this,
221 aead_test_vector_t *vector);
222 /**
223 * Add a test vector to test a signer.
224 *
225 * @param vector pointer to test vector
226 */
227 void (*add_signer_vector)(crypto_tester_t *this,
228 signer_test_vector_t *vector);
229 /**
230 * Add a test vector to test a hasher.
231 *
232 * @param vector pointer to test vector
233 */
234 void (*add_hasher_vector)(crypto_tester_t *this,
235 hasher_test_vector_t *vector);
236 /**
237 * Add a test vector to test a PRF.
238 *
239 * @param vector pointer to test vector
240 */
241 void (*add_prf_vector)(crypto_tester_t *this, prf_test_vector_t *vector);
242
243 /**
244 * Add a test vector to test a RNG.
245 *
246 * @param vector pointer to test vector
247 */
248 void (*add_rng_vector)(crypto_tester_t *this, rng_test_vector_t *vector);
249
250 /**
251 * Destroy a crypto_tester_t.
252 */
253 void (*destroy)(crypto_tester_t *this);
254 };
255
256 /**
257 * Create a crypto_tester instance.
258 */
259 crypto_tester_t *crypto_tester_create();
260
261 #endif /** CRYPTO_TESTER_H_ @}*/