testutils.h 1.86 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
#ifndef NETTLE_TESTUTILS_H_INCLUDED
#define NETTLE_TESTUTILS_H_INCLUDED

4
5
6
7
#if HAVE_CONFIG_H
# include "config.h"
#endif

8
#include <inttypes.h>
Niels Möller's avatar
Niels Möller committed
9

10
11
#include <string.h>
#include <stdlib.h>
12
13
14
15
16
#include <stdio.h>

#if HAVE_LIBGMP
# include "rsa.h"
#endif
17
18
19

#include "nettle-meta.h"

Niels Möller's avatar
Niels Möller committed
20
/* Decodes a NUL-terminated hex string. */
21
22
23
24

unsigned
decode_hex_length(const char *hex);

Niels Möller's avatar
Niels Möller committed
25
26
27
28
29
30
31
int
decode_hex(uint8_t *dst, const char *hex);

/* Allocates space */
const uint8_t *
decode_hex_dup(const char *hex);

32
33
34
void
print_hex(unsigned length, uint8_t *data);

Niels Möller's avatar
Niels Möller committed
35
36
37
38
39
40
/* The main program */
int
test_main(void);

extern int verbose;

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
void
test_cipher(const struct nettle_cipher *cipher,
	    unsigned key_length,
	    const uint8_t *key,
	    unsigned length,
	    const uint8_t *cleartext,
	    const uint8_t *ciphertext);

void
test_cipher_cbc(const struct nettle_cipher *cipher,
		unsigned key_length,
		const uint8_t *key,
		unsigned length,
		const uint8_t *cleartext,
		const uint8_t *ciphertext,
		const uint8_t *iv);

void
test_hash(const struct nettle_hash *hash,
	  unsigned length,
	  const uint8_t *data,
	  const uint8_t *digest);
Niels Möller's avatar
Niels Möller committed
63

Niels Möller's avatar
Niels Möller committed
64
65
66
67
68
69
void
test_armor(const struct nettle_armor *armor,
           unsigned data_length,
           const uint8_t *data,
           const uint8_t *ascii);

70
71
72
73
74
75
76
77
78
79
80
81
#if HAVE_LIBGMP
void
test_rsa_md5(struct rsa_public_key *pub,
	     struct rsa_private_key *key,
	     mpz_t expected);

void
test_rsa_sha1(struct rsa_public_key *pub,
	      struct rsa_private_key *key,
	      mpz_t expected);
#endif /* HAVE_LIBGMP */

82
83
84
85
#define H2(d, s) decode_hex((d), (s))
#define H(x) decode_hex_dup(x)
#define HL(x) decode_hex_length(x), decode_hex_dup(x)

86
87
#define LDATA(x) strlen(x), x

88
89
90
91
92
#define MEMEQ(length, a, b) (!memcmp((a), (b), (length)))

#define FAIL() abort()
#define SKIP() exit(77)
#define SUCCESS() return EXIT_SUCCESS
Niels Möller's avatar
Niels Möller committed
93

Niels Möller's avatar
Niels Möller committed
94
95
#define ASSERT(x) do { if (!(x)) FAIL(); } while(0)

Niels Möller's avatar
Niels Möller committed
96
#endif /* NETTLE_TESTUTILS_H_INCLUDED */