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 absence of expected public key */
42#define PUBLIC_UNSPECIFIED PUBLIC()
43
44/** Define inline expected shared secret */
45#define SHARED(...) { __VA_ARGS__ }
46
47/** Define inline expected failure result */
48#define SHARED_FAIL SHARED()
49
50/**
51 * Define a key exchange test
52 *
53 * @v name Test name
54 * @v EXCHANGE Key exchange algorithm
55 * @v PRIVATE Private key
56 * @v PARTNER Partner public key
57 * @v PUBLIC Expected public key
58 * @v SHARED Expected shared secret
59 * @ret test Key exchange test
60 */
61#define EXCHANGE_TEST( name, EXCHANGE, PRIVATE, PARTNER, PUBLIC, \
62 SHARED ) \
63 static const uint8_t name ## _private[] = PRIVATE; \
64 static const uint8_t name ## _partner[] = PARTNER; \
65 static const uint8_t name ## _public[] = PUBLIC; \
66 static const uint8_t name ## _shared[] = SHARED; \
67 static struct exchange_test name = { \
68 .exchange = EXCHANGE, \
69 .private = name ## _private, \
70 .private_len = sizeof ( name ## _private ), \
71 .partner = name ## _partner, \
72 .partner_len = sizeof ( name ## _partner ), \
73 .public = name ## _public, \
74 .public_len = sizeof ( name ## _public ), \
75 .shared = name ## _shared, \
76 .shared_len = sizeof ( name ## _shared ), \
77 };
78
79/**
80 * Report a key exchange test result
81 *
82 * @v test Key exchange test
83 */
84#define exchange_ok(test) exchange_okx ( test, __FILE__, __LINE__ )
85
86extern void exchange_okx ( struct exchange_test *test, const char *file,
87 unsigned int line );
88
89#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.