1 #ifndef NETTLE_TESTUTILS_H_INCLUDED
2 #define NETTLE_TESTUTILS_H_INCLUDED
8 #include "nettle-types.h"
22 # include "ecc-curve.h"
24 # include "ecc-internal.h"
26 # include "gmp-glue.h"
29 #include "nettle-meta.h"
39 die(const char *format
, ...) PRINTF_STYLE (1, 2) NORETURN
;
51 tstring_alloc (unsigned length
);
57 tstring_data(unsigned length
, const char *data
);
60 tstring_hex(const char *hex
);
63 tstring_print_hex(const struct tstring
*s
);
65 /* Decodes a NUL-terminated hex string. */
68 print_hex(unsigned length
, const uint8_t *data
);
70 /* The main program */
76 /* FIXME: When interface stabilizes, move to nettle-meta.h */
81 /* Size of the context struct */
82 unsigned context_size
;
87 /* Suggested key size; other sizes are sometimes possible. */
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) { \
97 sizeof(struct hmac_##name##_ctx), \
100 hmac_##name##_set_key, \
101 hmac_##name##_update, \
102 hmac_##name##_digest, \
105 /* Test functions deallocate their inputs when finished.*/
107 test_cipher(const struct nettle_cipher
*cipher
,
108 const struct tstring
*key
,
109 const struct tstring
*cleartext
,
110 const struct tstring
*ciphertext
);
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
);
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
);
127 test_cipher_stream(const struct nettle_cipher
*cipher
,
128 const struct tstring
*key
,
129 const struct tstring
*cleartext
,
130 const struct tstring
*ciphertext
);
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
);
142 test_hash(const struct nettle_hash
*hash
,
143 const struct tstring
*msg
,
144 const struct tstring
*digest
);
147 test_hash_large(const struct nettle_hash
*hash
,
148 unsigned count
, unsigned length
,
150 const struct tstring
*digest
);
153 test_armor(const struct nettle_armor
*armor
,
154 unsigned data_length
,
156 const uint8_t *ascii
);
160 xalloc_limbs (mp_size_t n
);
163 test_rsa_set_key_1(struct rsa_public_key
*pub
,
164 struct rsa_private_key
*key
);
167 test_rsa_md5(struct rsa_public_key
*pub
,
168 struct rsa_private_key
*key
,
172 test_rsa_sha1(struct rsa_public_key
*pub
,
173 struct rsa_private_key
*key
,
177 test_rsa_sha256(struct rsa_public_key
*pub
,
178 struct rsa_private_key
*key
,
182 test_rsa_sha512(struct rsa_public_key
*pub
,
183 struct rsa_private_key
*key
,
187 test_rsa_key(struct rsa_public_key
*pub
,
188 struct rsa_private_key
*key
);
191 test_dsa160(const struct dsa_public_key
*pub
,
192 const struct dsa_private_key
*key
,
193 const struct dsa_signature
*expected
);
196 test_dsa256(const struct dsa_public_key
*pub
,
197 const struct dsa_private_key
*key
,
198 const struct dsa_signature
*expected
);
201 test_dsa_key(struct dsa_public_key
*pub
,
202 struct dsa_private_key
*key
,
205 extern const struct ecc_curve
* const ecc_curves
[];
208 test_ecc_mul_a (unsigned curve
, unsigned n
, const mp_limb_t
*p
);
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 { \
232 fprintf(stderr, "Assert failed %d: %s\n", __LINE__, #x); \
241 #endif /* NETTLE_TESTUTILS_H_INCLUDED */