iPXE
pubkey_test.h
Go to the documentation of this file.
1#ifndef _PUBKEY_TEST_H
2#define _PUBKEY_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 public-key encryption and decryption test */
12 /** Public-key algorithm */
14 /** Private key */
15 const struct asn1_cursor private;
16 /** Public key */
17 const struct asn1_cursor public;
18 /** Random data input */
19 const void *random;
20 /** Random data input length */
21 size_t random_len;
22 /** Plaintext */
23 const struct asn1_cursor plaintext;
24 /** Ciphertext */
25 const struct asn1_cursor ciphertext;
26};
27
28/** A public-key signature test */
30 /** Public-key algorithm */
32 /** Private key */
33 const struct asn1_cursor private;
34 /** Public key */
35 const struct asn1_cursor public;
36 /** Random data input */
37 const void *random;
38 /** Random data input length */
39 size_t random_len;
40 /** Plaintext */
41 const void *plaintext;
42 /** Plaintext length */
44 /** Signature algorithm */
46 /** Signature */
47 const struct asn1_cursor signature;
48};
49
50/** Define inline private key data */
51#define PRIVATE(...) { __VA_ARGS__ }
52
53/** Define inline public key data */
54#define PUBLIC(...) { __VA_ARGS__ }
55
56/** Define inline random data */
57#define RANDOM(...) { __VA_ARGS__ }
58
59/** Define inline plaintext data */
60#define PLAINTEXT(...) { __VA_ARGS__ }
61
62/** Define inline ciphertext data */
63#define CIPHERTEXT(...) { __VA_ARGS__ }
64
65/** Define inline signature data */
66#define SIGNATURE(...) { __VA_ARGS__ }
67
68/**
69 * Define a public-key encryption and decryption test
70 *
71 * @v name Test name
72 * @v PUBKEY Public-key algorithm
73 * @v PRIVATE Private key
74 * @v PUBLIC Public key
75 * @v RANDOM Random data
76 * @v PLAINTEXT Plaintext
77 * @v CIPHERTEXT Ciphertext
78 * @ret test Encryption and decryption test
79 */
80#define PUBKEY_TEST( name, PUBKEY, PRIVATE, PUBLIC, RANDOM, PLAINTEXT, \
81 CIPHERTEXT ) \
82 static const uint8_t name ## _private[] = PRIVATE; \
83 static const uint8_t name ## _public[] = PUBLIC; \
84 static const uint8_t name ## _random[] = RANDOM; \
85 static const uint8_t name ## _plaintext[] = PLAINTEXT; \
86 static const uint8_t name ## _ciphertext[] = CIPHERTEXT; \
87 static struct pubkey_test name = { \
88 .pubkey = PUBKEY, \
89 .private = { \
90 .data = name ## _private, \
91 .len = sizeof ( name ## _private ), \
92 }, \
93 .public = { \
94 .data = name ## _public, \
95 .len = sizeof ( name ## _public ), \
96 }, \
97 .random = name ## _random, \
98 .random_len = sizeof ( name ## _random ), \
99 .plaintext = { \
100 .data = name ## _plaintext, \
101 .len = sizeof ( name ## _plaintext ), \
102 }, \
103 .ciphertext = { \
104 .data = name ## _ciphertext, \
105 .len = sizeof ( name ## _ciphertext ), \
106 }, \
107 }
108
109/**
110 * Define a public-key signature test
111 *
112 * @v name Test name
113 * @v PUBKEY Public-key algorithm
114 * @v PRIVATE Private key
115 * @v PUBLIC Public key
116 * @v RANDOM Random data
117 * @v PLAINTEXT Plaintext
118 * @v DIGEST Digest algorithm
119 * @v SIGNATURE Signature
120 * @ret test Signature test
121 */
122#define PUBKEY_SIGN_TEST( name, PUBKEY, PRIVATE, PUBLIC, RANDOM, \
123 PLAINTEXT, DIGEST, SIGNATURE ) \
124 static const uint8_t name ## _private[] = PRIVATE; \
125 static const uint8_t name ## _public[] = PUBLIC; \
126 static const uint8_t name ## _random[] = RANDOM; \
127 static const uint8_t name ## _plaintext[] = PLAINTEXT; \
128 static const uint8_t name ## _signature[] = SIGNATURE; \
129 static struct pubkey_sign_test name = { \
130 .pubkey = PUBKEY, \
131 .private = { \
132 .data = name ## _private, \
133 .len = sizeof ( name ## _private ), \
134 }, \
135 .public = { \
136 .data = name ## _public, \
137 .len = sizeof ( name ## _public ), \
138 }, \
139 .random = name ## _random, \
140 .random_len = sizeof ( name ## _random ), \
141 .plaintext = name ## _plaintext, \
142 .plaintext_len = sizeof ( name ## _plaintext ), \
143 .digest = DIGEST, \
144 .signature = { \
145 .data = name ## _signature, \
146 .len = sizeof ( name ## _signature ), \
147 }, \
148 }
149
150extern int pubkey_test_get_random ( void *data, size_t len );
151extern void pubkey_okx ( struct pubkey_test *test,
152 const char *file, unsigned int line );
153extern void pubkey_sign_okx ( struct pubkey_sign_test *test,
154 const char *file, unsigned int line );
155
156/**
157 * Report a public key encryption and decryption test result
158 *
159 * @v test Public key encryption and decryption test
160 */
161#define pubkey_ok( test ) \
162 pubkey_okx ( test, __FILE__, __LINE__ )
163
164/**
165 * Report a public key signature test result
166 *
167 * @v test Public key signature test
168 */
169#define pubkey_sign_ok( test ) \
170 pubkey_sign_okx ( test, __FILE__, __LINE__ )
171
172#endif /* _PUBKEY_TEST_H */
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
static int test
Definition epic100.c:73
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
Cryptographic API.
void pubkey_okx(struct pubkey_test *test, const char *file, unsigned int line)
Report public key encryption and decryption test result.
Definition pubkey_test.c:78
void pubkey_sign_okx(struct pubkey_sign_test *test, const char *file, unsigned int line)
Report public key signature test result.
int pubkey_test_get_random(void *data, size_t len)
Get random data input.
Definition pubkey_test.c:56
An ASN.1 object cursor.
Definition asn1.h:21
A message digest algorithm.
Definition crypto.h:19
A public key algorithm.
Definition crypto.h:142
A public-key signature test.
Definition pubkey_test.h:29
const struct asn1_cursor public
Public key.
Definition pubkey_test.h:35
struct pubkey_algorithm * pubkey
Public-key algorithm.
Definition pubkey_test.h:31
const struct asn1_cursor private
Private key.
Definition pubkey_test.h:33
struct digest_algorithm * digest
Signature algorithm.
Definition pubkey_test.h:45
const void * plaintext
Plaintext.
Definition pubkey_test.h:41
size_t random_len
Random data input length.
Definition pubkey_test.h:39
const void * random
Random data input.
Definition pubkey_test.h:37
size_t plaintext_len
Plaintext length.
Definition pubkey_test.h:43
const struct asn1_cursor signature
Signature.
Definition pubkey_test.h:47
A public-key encryption and decryption test.
Definition pubkey_test.h:11
const struct asn1_cursor private
Private key.
Definition pubkey_test.h:15
const struct asn1_cursor public
Public key.
Definition pubkey_test.h:17
struct pubkey_algorithm * pubkey
Public-key algorithm.
Definition pubkey_test.h:13
const void * random
Random data input.
Definition pubkey_test.h:19
const struct asn1_cursor plaintext
Plaintext.
Definition pubkey_test.h:23
size_t random_len
Random data input length.
Definition pubkey_test.h:21
const struct asn1_cursor ciphertext
Ciphertext.
Definition pubkey_test.h:25
Self-test infrastructure.