Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / testsuite / testutils.h
blob123bae2b680b9d45eefd6cc196d37abc6cb5b3d6
1 #ifndef NETTLE_TESTUTILS_H_INCLUDED
2 #define NETTLE_TESTUTILS_H_INCLUDED
4 #if HAVE_CONFIG_H
5 # include "config.h"
6 #endif
8 #include "nettle-types.h"
10 #include <stdarg.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
15 #if HAVE_LIBGMP
16 # include "bignum.h"
17 #endif
19 #if WITH_HOGWEED
20 # include "rsa.h"
21 # include "dsa.h"
22 # include "ecc-curve.h"
23 # include "ecc.h"
24 # include "ecc-internal.h"
25 # include "ecdsa.h"
26 # include "gmp-glue.h"
27 #endif
29 #include "nettle-meta.h"
31 /* Forward declare */
32 struct nettle_aead;
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
38 void
39 die(const char *format, ...) PRINTF_STYLE (1, 2) NORETURN;
41 void *
42 xalloc(size_t size);
44 struct tstring {
45 struct tstring *next;
46 unsigned length;
47 uint8_t data[1];
50 struct tstring *
51 tstring_alloc (unsigned length);
53 void
54 tstring_clear(void);
56 struct tstring *
57 tstring_data(unsigned length, const char *data);
59 struct tstring *
60 tstring_hex(const char *hex);
62 void
63 tstring_print_hex(const struct tstring *s);
65 /* Decodes a NUL-terminated hex string. */
67 void
68 print_hex(unsigned length, const uint8_t *data);
70 /* The main program */
71 void
72 test_main(void);
74 extern int verbose;
76 /* FIXME: When interface stabilizes, move to nettle-meta.h */
77 struct nettle_mac
79 const char *name;
81 /* Size of the context struct */
82 unsigned context_size;
84 /* Size of digests */
85 unsigned digest_size;
87 /* Suggested key size; other sizes are sometimes possible. */
88 unsigned key_size;
90 nettle_set_key_func *set_key;
91 nettle_hash_update_func *update;
92 nettle_hash_digest_func *digest;
95 #define _NETTLE_HMAC(name, NAME, keysize) { \
96 #name, \
97 sizeof(struct hmac_##name##_ctx), \
98 NAME##_DIGEST_SIZE, \
99 NAME##_DIGEST_SIZE, \
100 hmac_##name##_set_key, \
101 hmac_##name##_update, \
102 hmac_##name##_digest, \
105 /* Test functions deallocate their inputs when finished.*/
106 void
107 test_cipher(const struct nettle_cipher *cipher,
108 const struct tstring *key,
109 const struct tstring *cleartext,
110 const struct tstring *ciphertext);
112 void
113 test_cipher_cbc(const struct nettle_cipher *cipher,
114 const struct tstring *key,
115 const struct tstring *cleartext,
116 const struct tstring *ciphertext,
117 const struct tstring *iv);
119 void
120 test_cipher_ctr(const struct nettle_cipher *cipher,
121 const struct tstring *key,
122 const struct tstring *cleartext,
123 const struct tstring *ciphertext,
124 const struct tstring *iv);
126 void
127 test_cipher_stream(const struct nettle_cipher *cipher,
128 const struct tstring *key,
129 const struct tstring *cleartext,
130 const struct tstring *ciphertext);
132 void
133 test_aead(const struct nettle_aead *aead,
134 const struct tstring *key,
135 const struct tstring *authtext,
136 const struct tstring *cleartext,
137 const struct tstring *ciphertext,
138 const struct tstring *iv,
139 const struct tstring *digest);
141 void
142 test_hash(const struct nettle_hash *hash,
143 const struct tstring *msg,
144 const struct tstring *digest);
146 void
147 test_hash_large(const struct nettle_hash *hash,
148 unsigned count, unsigned length,
149 uint8_t c,
150 const struct tstring *digest);
152 void
153 test_armor(const struct nettle_armor *armor,
154 unsigned data_length,
155 const uint8_t *data,
156 const uint8_t *ascii);
158 #if WITH_HOGWEED
159 mp_limb_t *
160 xalloc_limbs (mp_size_t n);
162 void
163 test_rsa_set_key_1(struct rsa_public_key *pub,
164 struct rsa_private_key *key);
166 void
167 test_rsa_md5(struct rsa_public_key *pub,
168 struct rsa_private_key *key,
169 mpz_t expected);
171 void
172 test_rsa_sha1(struct rsa_public_key *pub,
173 struct rsa_private_key *key,
174 mpz_t expected);
176 void
177 test_rsa_sha256(struct rsa_public_key *pub,
178 struct rsa_private_key *key,
179 mpz_t expected);
181 void
182 test_rsa_sha512(struct rsa_public_key *pub,
183 struct rsa_private_key *key,
184 mpz_t expected);
186 void
187 test_rsa_key(struct rsa_public_key *pub,
188 struct rsa_private_key *key);
190 void
191 test_dsa160(const struct dsa_public_key *pub,
192 const struct dsa_private_key *key,
193 const struct dsa_signature *expected);
195 void
196 test_dsa256(const struct dsa_public_key *pub,
197 const struct dsa_private_key *key,
198 const struct dsa_signature *expected);
200 void
201 test_dsa_key(struct dsa_public_key *pub,
202 struct dsa_private_key *key,
203 unsigned q_size);
205 extern const struct ecc_curve * const ecc_curves[];
207 void
208 test_ecc_mul_a (unsigned curve, unsigned n, const mp_limb_t *p);
210 void
211 test_ecc_mul_j (unsigned curve, unsigned n, const mp_limb_t *p);
213 #endif /* WITH_HOGWEED */
215 /* LDATA needs to handle NUL characters. */
216 #define LLENGTH(x) (sizeof(x) - 1)
217 #define LDATA(x) LLENGTH(x), x
218 #define LDUP(x) strlen(x), strdup(x)
220 #define SHEX(x) (tstring_hex(x))
221 #define SDATA(x) ((const struct tstring *)tstring_data(LLENGTH(x), x))
222 #define H(x) (SHEX(x)->data)
224 #define MEMEQ(length, a, b) (!memcmp((a), (b), (length)))
226 #define FAIL() abort()
227 #define SKIP() exit(77)
229 #define ASSERT(x) do { \
230 if (!(x)) \
232 fprintf(stderr, "Assert failed %d: %s\n", __LINE__, #x); \
233 FAIL(); \
235 } while(0)
237 #ifdef __cplusplus
239 #endif
241 #endif /* NETTLE_TESTUTILS_H_INCLUDED */