iPXE
exchange_test.h
Go to the documentation of this file.
1#ifndef _EXCHANGE_TEST_H
2#define _EXCHANGE_TEST_H
3
4FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5
6#include <stdint.h>
7#include <ipxe/crypto.h>
8#include <ipxe/test.h>
9
10/** A key exchange test */
12 /** Key exchange algorithm */
14 /** Private key */
15 const void *private;
16 /** Length of private key */
18 /** Partner public key */
19 const void *partner;
20 /** Length of partner key */
22 /** Expected public key */
23 const void *public;
24 /** Length of expected public key */
25 size_t public_len;
26 /** Expected shared secret */
27 const void *shared;
28 /** Length of expected shared secret, or 0 to expect failure */
29 size_t shared_len;
30};
31
32/** Define inline private key */
33#define PRIVATE(...) { __VA_ARGS__ }
34
35/** Define inline partner public key */
36#define PARTNER(...) { __VA_ARGS__ }
37
38/** Define inline expected public key */
39#define PUBLIC(...) { __VA_ARGS__ }
40
41/** Define inline expected shared secret */
42#define SHARED(...) { __VA_ARGS__ }
43
44/** Define inline expected failure result */
45#define SHARED_FAIL SHARED()
46
47/**
48 * Define a key exchange test
49 *
50 * @v name Test name
51 * @v EXCHANGE Key exchange algorithm
52 * @v PRIVATE Private key
53 * @v PARTNER Partner public key
54 * @v PUBLIC Expected public key
55 * @v SHARED Expected shared secret
56 * @ret test Key exchange test
57 */
58#define EXCHANGE_TEST( name, EXCHANGE, PRIVATE, PARTNER, PUBLIC, \
59 SHARED ) \
60 static const uint8_t name ## _private[] = PRIVATE; \
61 static const uint8_t name ## _partner[] = PARTNER; \
62 static const uint8_t name ## _public[] = PUBLIC; \
63 static const uint8_t name ## _shared[] = SHARED; \
64 static struct exchange_test name = { \
65 .exchange = EXCHANGE, \
66 .private = name ## _private, \
67 .private_len = sizeof ( name ## _private ), \
68 .partner = name ## _partner, \
69 .partner_len = sizeof ( name ## _partner ), \
70 .public = name ## _public, \
71 .public_len = sizeof ( name ## _public ), \
72 .shared = name ## _shared, \
73 .shared_len = sizeof ( name ## _shared ), \
74 };
75
76/**
77 * Report a key exchange test result
78 *
79 * @v test Key exchange test
80 */
81#define exchange_ok(test) exchange_okx ( test, __FILE__, __LINE__ )
82
83extern void exchange_okx ( struct exchange_test *test, const char *file,
84 unsigned int line );
85
86#endif /* _EXCHANGE_TEST_H */
static int test
Definition epic100.c:73
void exchange_okx(struct exchange_test *test, const char *file, unsigned int line)
Report a key exchange test result.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
Cryptographic API.
A key exchange algorithm.
Definition crypto.h:210
A key exchange test.
size_t public_len
Length of expected public key.
size_t partner_len
Length of partner key.
size_t private_len
Length of private key.
const void * partner
Partner public key.
struct exchange_algorithm * exchange
Key exchange algorithm.
const void * shared
Expected shared secret.
size_t shared_len
Length of expected shared secret, or 0 to expect failure.
Self-test infrastructure.