]> git.ipfire.org Git - people/ms/strongswan.git/blame - src/libstrongswan/crypto/crypto_tester.h
added support for stateful PRFs (such as the FIPS_PRF)
[people/ms/strongswan.git] / src / libstrongswan / crypto / crypto_tester.h
CommitLineData
3e889166
MW
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
24typedef struct crypto_tester_t crypto_tester_t;
25
26#include <crypto/crypto_factory.h>
27
28typedef struct crypter_test_vector_t crypter_test_vector_t;
29typedef struct signer_test_vector_t signer_test_vector_t;
30typedef struct hasher_test_vector_t hasher_test_vector_t;
31typedef struct prf_test_vector_t prf_test_vector_t;
32typedef struct rng_test_vector_t rng_test_vector_t;
33
34struct crypter_test_vector_t {
35 /** encryption algorithm this vector tests */
36 encryption_algorithm_t alg;
37 /** key length to use, in bytes */
38 size_t key_size;
39 /** encryption key of test vector */
40 u_char *key;
41 /** initialization vector, using crypters blocksize bytes */
42 u_char *iv;
43 /** length of plain and cipher text */
44 size_t len;
45 /** plain text */
46 u_char *plain;
47 /** cipher text */
48 u_char *cipher;
49};
50
51struct 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 */
55 u_char *key;
56 /** size of the input data */
57 size_t len;
58 /** input data */
59 u_char *data;
60 /** expected output, with ouput size of the tested algorithm */
61 u_char *mac;
62};
63
64struct hasher_test_vector_t {
65 /** hash algorithm this test vector tests */
66 hash_algorithm_t alg;
67 /** length of the input data */
68 size_t len;
69 /** input data */
70 u_char *data;
71 /** expected hash, with hash size of the tested algorithm */
72 u_char *hash;
73};
74
75struct prf_test_vector_t {
76 /** prf algorithm this test vector tests */
77 pseudo_random_function_t alg;
371a54c7
MW
78 /** is this PRF stateful? */
79 bool stateful;
3e889166
MW
80 /** key length to use, in bytes */
81 size_t key_size;
82 /** key to use */
83 u_char *key;
84 /** size of the seed data */
85 size_t len;
86 /** seed data */
87 u_char *seed;
88 /** expected output, with block size of the tested algorithm */
89 u_char *out;
90};
91
92/**
93 * Test vector for a RNG.
94 *
95 * Contains a callback function to analyze the output of a RNG,
96 */
97struct 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 */
103 size_t len;
104 /** user data passed back to the test() function on invocation */
105 void *user;
106};
107
108/**
109 * Cryptographic primitive testing framework.
110 */
111struct crypto_tester_t {
112
113 /**
114 * Test a crypter algorithm, optionally using a specified key size.
115 *
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
120 */
121 bool (*test_crypter)(crypto_tester_t *this, encryption_algorithm_t alg,
122 size_t key_size, crypter_constructor_t create);
123 /**
124 * Test a signer algorithm.
125 *
126 * @param alg algorithm to test
127 * @param create constructor function for the signer
128 * @return TRUE if test passed
129 */
130 bool (*test_signer)(crypto_tester_t *this, integrity_algorithm_t alg,
131 signer_constructor_t create);
132 /**
133 * Test a hasher algorithm.
134 *
135 * @param alg algorithm to test
136 * @param create constructor function for the hasher
137 * @return TRUE if test passed
138 */
139 bool (*test_hasher)(crypto_tester_t *this, hash_algorithm_t alg,
140 hasher_constructor_t create);
141 /**
142 * Test a PRF algorithm.
143 *
144 * @param alg algorithm to test
145 * @param create constructor function for the PRF
146 * @return TRUE if test passed
147 */
148 bool (*test_prf)(crypto_tester_t *this, pseudo_random_function_t alg,
149 prf_constructor_t create);
150 /**
151 * Test a RNG implementation.
152 *
153 * @param alg algorithm to test
154 * @param create constructor function for the RNG
155 * @return TRUE if test passed
156 */
157 bool (*test_rng)(crypto_tester_t *this, rng_quality_t quality,
158 rng_constructor_t create);
159 /**
160 * Add a test vector to test a crypter.
161 *
162 * @param vector pointer to test vector
163 */
164 void (*add_crypter_vector)(crypto_tester_t *this,
165 crypter_test_vector_t *vector);
166 /**
167 * Add a test vector to test a signer.
168 *
169 * @param vector pointer to test vector
170 */
171 void (*add_signer_vector)(crypto_tester_t *this,
172 signer_test_vector_t *vector);
173 /**
174 * Add a test vector to test a hasher.
175 *
176 * @param vector pointer to test vector
177 */
178 void (*add_hasher_vector)(crypto_tester_t *this,
179 hasher_test_vector_t *vector);
180 /**
181 * Add a test vector to test a PRF.
182 *
183 * @param vector pointer to test vector
184 */
185 void (*add_prf_vector)(crypto_tester_t *this, prf_test_vector_t *vector);
186
187 /**
188 * Add a test vector to test a RNG.
189 *
190 * @param vector pointer to test vector
191 */
192 void (*add_rng_vector)(crypto_tester_t *this, rng_test_vector_t *vector);
193
194 /**
195 * Destroy a crypto_tester_t.
196 */
197 void (*destroy)(crypto_tester_t *this);
198};
199
200/**
201 * Create a crypto_tester instance.
202 */
203crypto_tester_t *crypto_tester_create();
204
205#endif /* CRYPTO_TESTER_ @}*/