added MD5 test vectors
[strongswan.git] / src / libstrongswan / plugins / test_vectors / test_vectors_plugin.c
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 #include "test_vectors_plugin.h"
17
18 #include <crypto/crypto_factory.h>
19 #include <crypto/crypto_tester.h>
20
21 /* define symbols of all test vectors */
22 #define TEST_VECTOR_CRYPTER(x) crypter_test_vector_t x;
23 #define TEST_VECTOR_SIGNER(x) signer_test_vector_t x;
24 #define TEST_VECTOR_HASHER(x) hasher_test_vector_t x;
25 #define TEST_VECTOR_PRF(x) prf_test_vector_t x;
26 #define TEST_VECTOR_RNG(x) rng_test_vector_t x;
27
28 #include "test_vectors.h"
29
30 #undef TEST_VECTOR_CRYPTER
31 #undef TEST_VECTOR_SIGNER
32 #undef TEST_VECTOR_HASHER
33 #undef TEST_VECTOR_PRF
34 #undef TEST_VECTOR_RNG
35
36 #define TEST_VECTOR_CRYPTER(x)
37 #define TEST_VECTOR_SIGNER(x)
38 #define TEST_VECTOR_HASHER(x)
39 #define TEST_VECTOR_PRF(x)
40 #define TEST_VECTOR_RNG(x)
41
42 /* create test vector arrays */
43 #undef TEST_VECTOR_CRYPTER
44 #define TEST_VECTOR_CRYPTER(x) &x,
45 static crypter_test_vector_t *crypter[] = {
46 #include "test_vectors.h"
47 };
48 #undef TEST_VECTOR_CRYPTER
49 #define TEST_VECTOR_CRYPTER(x)
50
51 #undef TEST_VECTOR_SIGNER
52 #define TEST_VECTOR_SIGNER(x) &x,
53 static signer_test_vector_t *signer[] = {
54 #include "test_vectors.h"
55 };
56 #undef TEST_VECTOR_SIGNER
57 #define TEST_VECTOR_SIGNER(x)
58
59 #undef TEST_VECTOR_HASHER
60 #define TEST_VECTOR_HASHER(x) &x,
61 static hasher_test_vector_t *hasher[] = {
62 #include "test_vectors.h"
63 };
64 #undef TEST_VECTOR_HASHER
65 #define TEST_VECTOR_HASHER(x)
66
67 #undef TEST_VECTOR_PRF
68 #define TEST_VECTOR_PRF(x) &x,
69 static prf_test_vector_t *prf[] = {
70 #include "test_vectors.h"
71 };
72 #undef TEST_VECTOR_PRF
73 #define TEST_VECTOR_PRF(x)
74
75 #undef TEST_VECTOR_RNG
76 #define TEST_VECTOR_RNG(x) &x,
77 static rng_test_vector_t *rng[] = {
78 #include "test_vectors.h"
79 };
80 #undef TEST_VECTOR_RNG
81 #define TEST_VECTOR_RNG(x)
82
83 typedef struct private_test_vectors_plugin_t private_test_vectors_plugin_t;
84
85 /**
86 * private data of test_vectors_plugin
87 */
88 struct private_test_vectors_plugin_t {
89
90 /**
91 * public functions
92 */
93 test_vectors_plugin_t public;
94 };
95
96 /**
97 * Implementation of test_vectors_plugin_t.test_vectorstroy
98 */
99 static void destroy(private_test_vectors_plugin_t *this)
100 {
101 free(this);
102 }
103
104 /*
105 * see header file
106 */
107 plugin_t *plugin_create()
108 {
109 private_test_vectors_plugin_t *this = malloc_thing(private_test_vectors_plugin_t);
110 int i;
111
112 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
113
114 for (i = 0; i < countof(crypter); i++)
115 {
116 lib->crypto->add_test_vector(lib->crypto,
117 ENCRYPTION_ALGORITHM, crypter[i]);
118 }
119 for (i = 0; i < countof(signer); i++)
120 {
121 lib->crypto->add_test_vector(lib->crypto,
122 INTEGRITY_ALGORITHM, signer[i]);
123 }
124 for (i = 0; i < countof(hasher); i++)
125 {
126 lib->crypto->add_test_vector(lib->crypto,
127 HASH_ALGORITHM, hasher[i]);
128 }
129 for (i = 0; i < countof(prf); i++)
130 {
131 lib->crypto->add_test_vector(lib->crypto,
132 PSEUDO_RANDOM_FUNCTION, prf[i]);
133 }
134 for (i = 0; i < countof(rng); i++)
135 {
136 lib->crypto->add_test_vector(lib->crypto,
137 RANDOM_NUMBER_GENERATOR, rng[i]);
138 }
139
140 return &this->public.plugin;
141 }
142