1 #ifndef NETTLE_TESTUTILS_H_INCLUDED
2 #define NETTLE_TESTUTILS_H_INCLUDED
8 #include "nettle-types.h"
23 #include "nettle-meta.h"
32 /* Decodes a NUL-terminated hex string. */
35 decode_hex_length(const char *hex);
38 decode_hex(uint8_t *dst, const char *hex);
42 decode_hex_dup(const char *hex);
45 print_hex(unsigned length, const uint8_t *data);
47 /* The main program */
53 /* FIXME: When interface stabilizes, move to nettle-meta.h */
58 /* Size of the context struct */
59 unsigned context_size;
64 /* Suggested key size; other sizes are sometimes possible. */
67 nettle_set_key_func *set_key;
68 nettle_hash_update_func *update;
69 nettle_hash_digest_func *digest;
72 #define _NETTLE_HMAC(name, NAME, keysize) { \
74 sizeof(struct hmac_##name##_ctx), \
77 hmac_##name##_set_key, \
78 hmac_##name##_update, \
79 hmac_##name##_digest, \
83 test_cipher(const struct nettle_cipher *cipher,
87 const uint8_t *cleartext,
88 const uint8_t *ciphertext);
91 test_cipher_cbc(const struct nettle_cipher *cipher,
95 const uint8_t *cleartext,
96 const uint8_t *ciphertext,
100 test_cipher_ctr(const struct nettle_cipher *cipher,
104 const uint8_t *cleartext,
105 const uint8_t *ciphertext,
109 test_cipher_stream(const struct nettle_cipher *cipher,
113 const uint8_t *cleartext,
114 const uint8_t *ciphertext);
117 test_hash(const struct nettle_hash *hash,
120 const uint8_t *digest);
123 test_hash_large(const struct nettle_hash *hash,
124 unsigned count, unsigned length,
126 const uint8_t *digest);
129 test_mac(const struct nettle_mac *mac,
130 unsigned key_length, const uint8_t *key,
131 unsigned msg_length, const uint8_t *msg,
132 const uint8_t *digest);
135 test_armor(const struct nettle_armor *armor,
136 unsigned data_length,
138 const uint8_t *ascii);
142 test_rsa_set_key_1(struct rsa_public_key *pub,
143 struct rsa_private_key *key);
146 test_rsa_md5(struct rsa_public_key *pub,
147 struct rsa_private_key *key,
151 test_rsa_sha1(struct rsa_public_key *pub,
152 struct rsa_private_key *key,
156 test_rsa_sha256(struct rsa_public_key *pub,
157 struct rsa_private_key *key,
161 test_rsa_sha512(struct rsa_public_key *pub,
162 struct rsa_private_key *key,
166 test_rsa_key(struct rsa_public_key *pub,
167 struct rsa_private_key *key);
170 test_dsa160(const struct dsa_public_key *pub,
171 const struct dsa_private_key *key,
172 const struct dsa_signature *expected);
175 test_dsa256(const struct dsa_public_key *pub,
176 const struct dsa_private_key *key,
177 const struct dsa_signature *expected);
180 test_dsa_key(struct dsa_public_key *pub,
181 struct dsa_private_key *key,
184 #endif /* WITH_HOGWEED */
190 #define H2(d, s) decode_hex((d), (s))
191 #define H(x) decode_hex_dup(x)
192 #define HL(x) decode_hex_length(x), decode_hex_dup(x)
194 /* LDATA needs to handle NUL characters. */
195 #define LLENGTH(x) (sizeof(x) - 1)
196 #define LDATA(x) (sizeof(x) - 1), x
197 #define LDUP(x) strlen(x), strdup(x)
199 #define MEMEQ(length, a, b) (!memcmp((a), (b), (length)))
200 #define MEMEQH(length, a, b) \
201 ((length) == decode_hex_length((b)) \
202 && !memcmp((a), decode_hex_dup((b)), (length)))
204 #define FAIL() abort()
205 #define SKIP() exit(77)
206 #define SUCCESS() return EXIT_SUCCESS
208 #define ASSERT(x) do { if (!(x)) FAIL(); } while(0)
210 #endif /* NETTLE_TESTUTILS_H_INCLUDED */