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 test */
12 /** Public-key algorithm */
14 /** Private key */
15 const struct asn1_cursor private;
16 /** Public key */
17 const struct asn1_cursor public;
18};
19
20/** A public-key encryption/decryption test */
22 /** Test key */
23 const struct pubkey_test *key;
24 /** Random data input */
25 const void *random;
26 /** Random data input length */
27 size_t random_len;
28 /** Plaintext */
29 const struct asn1_cursor plaintext;
30 /** Ciphertext */
31 const struct asn1_cursor ciphertext;
32};
33
34/** A public-key signature/verification test */
36 /** Test key */
37 const struct pubkey_test *key;
38 /** Random data input */
39 const void *random;
40 /** Random data input length */
41 size_t random_len;
42 /** Plaintext */
43 const void *plaintext;
44 /** Plaintext length */
46 /** Signature algorithm */
48 /** Signature */
49 const struct asn1_cursor signature;
50};
51
52/** Define inline private key data */
53#define PRIVATE(...) { __VA_ARGS__ }
54
55/** Define inline public key data */
56#define PUBLIC(...) { __VA_ARGS__ }
57
58/** Define inline random data */
59#define RANDOM(...) { __VA_ARGS__ }
60
61/** Define inline plaintext data */
62#define PLAINTEXT(...) { __VA_ARGS__ }
63
64/** Define inline ciphertext data */
65#define CIPHERTEXT(...) { __VA_ARGS__ }
66
67/** Define inline signature data */
68#define SIGNATURE(...) { __VA_ARGS__ }
69
70/**
71 * Define a public-key test
72 *
73 * @v name Test name
74 * @v PUBKEY Public-key algorithm
75 * @v PRIVATE Private key
76 * @v PUBLIC Public key
77 * @v RANDOM Random data
78 * @v PLAINTEXT Plaintext
79 * @v CIPHERTEXT Ciphertext
80 * @ret test Encryption and decryption test
81 */
82#define PUBKEY_TEST( name, PUBKEY, PRIVATE, PUBLIC ) \
83 static const uint8_t name ## _private[] = PRIVATE; \
84 static const uint8_t name ## _public[] = PUBLIC; \
85 static struct pubkey_test name = { \
86 .pubkey = PUBKEY, \
87 .private = { \
88 .data = name ## _private, \
89 .len = sizeof ( name ## _private ), \
90 }, \
91 .public = { \
92 .data = name ## _public, \
93 .len = sizeof ( name ## _public ), \
94 }, \
95 }
96
97/**
98 * Define a public-key encryption/decryption test
99 *
100 * @v name Test name
101 * @v KEY Test key
102 * @v RANDOM Random data
103 * @v PLAINTEXT Plaintext
104 * @v CIPHERTEXT Ciphertext
105 * @ret test Encryption and decryption test
106 */
107#define PUBKEY_ENCRYPTION_TEST( name, KEY, RANDOM, PLAINTEXT, \
108 CIPHERTEXT ) \
109 static const uint8_t name ## _random[] = RANDOM; \
110 static const uint8_t name ## _plaintext[] = PLAINTEXT; \
111 static const uint8_t name ## _ciphertext[] = CIPHERTEXT; \
112 static struct pubkey_encryption_test name = { \
113 .key = KEY, \
114 .random = name ## _random, \
115 .random_len = sizeof ( name ## _random ), \
116 .plaintext = { \
117 .data = name ## _plaintext, \
118 .len = sizeof ( name ## _plaintext ), \
119 }, \
120 .ciphertext = { \
121 .data = name ## _ciphertext, \
122 .len = sizeof ( name ## _ciphertext ), \
123 }, \
124 }
125
126/**
127 * Define a public-key signature/verification test
128 *
129 * @v name Test name
130 * @v KEY Test key
131 * @v RANDOM Random data
132 * @v PLAINTEXT Plaintext
133 * @v DIGEST Digest algorithm
134 * @v SIGNATURE Signature
135 * @ret test Signature test
136 */
137#define PUBKEY_SIGNATURE_TEST( name, KEY, RANDOM, PLAINTEXT, DIGEST, \
138 SIGNATURE ) \
139 static const uint8_t name ## _random[] = RANDOM; \
140 static const uint8_t name ## _plaintext[] = PLAINTEXT; \
141 static const uint8_t name ## _signature[] = SIGNATURE; \
142 static struct pubkey_signature_test name = { \
143 .key = KEY, \
144 .random = name ## _random, \
145 .random_len = sizeof ( name ## _random ), \
146 .plaintext = name ## _plaintext, \
147 .plaintext_len = sizeof ( name ## _plaintext ), \
148 .digest = DIGEST, \
149 .signature = { \
150 .data = name ## _signature, \
151 .len = sizeof ( name ## _signature ), \
152 }, \
153 }
154
155extern int pubkey_test_get_random ( void *data, size_t len );
157 const char *file, unsigned int line );
159 const char *file, unsigned int line );
161 const char *file, unsigned int line );
163 const char *file, unsigned int line );
165 const char *file,
166 unsigned int line );
167extern void pubkey_sign_okx ( struct pubkey_signature_test *test,
168 const char *file, unsigned int line );
169extern void pubkey_verify_okx ( struct pubkey_signature_test *test,
170 const char *file, unsigned int line );
172 const char *file, unsigned int line );
174 const char *file, unsigned int line );
175
176/**
177 * Report a public key encryption test result
178 *
179 * @v test Public key encryption/decryption test
180 */
181#define pubkey_encrypt_ok( test ) \
182 pubkey_encrypt_okx ( test, __FILE__, __LINE__ )
183
184/**
185 * Report a public key decryption test result
186 *
187 * @v test Public key encryption/decryption test
188 */
189#define pubkey_decrypt_ok( test ) \
190 pubkey_decrypt_okx ( test, __FILE__, __LINE__ )
191
192/**
193 * Report a public key encryption failure test result
194 *
195 * @v test Public key encryption/decryption test
196 */
197#define pubkey_encrypt_fail_ok( test ) \
198 pubkey_encrypt_fail_okx ( test, __FILE__, __LINE__ )
199
200/**
201 * Report a public key decryption failure test result
202 *
203 * @v test Public key decryption/decryption test
204 */
205#define pubkey_decrypt_fail_ok( test ) \
206 pubkey_decrypt_fail_okx ( test, __FILE__, __LINE__ )
207
208/**
209 * Report a public key encryption and decryption test result
210 *
211 * @v test Public key encryption/decryption test
212 */
213#define pubkey_encrypt_decrypt_ok( test ) \
214 pubkey_encrypt_decrypt_okx ( test, __FILE__, __LINE__ )
215
216/**
217 * Report a public key signature test result
218 *
219 * @v test Public key signature/verification test
220 */
221#define pubkey_sign_ok( test ) \
222 pubkey_sign_okx ( test, __FILE__, __LINE__ )
223
224/**
225 * Report a public key verification test result
226 *
227 * @v test Public key signature/verification test
228 */
229#define pubkey_verify_ok( test ) \
230 pubkey_verify_okx ( test, __FILE__, __LINE__ )
231
232/**
233 * Report a public key verification failure test result
234 *
235 * @v test Public key signature/verification test
236 */
237#define pubkey_verify_fail_ok( test ) \
238 pubkey_verify_fail_okx ( test, __FILE__, __LINE__ )
239
240/**
241 * Report a public key signature and verification test result
242 *
243 * @v test Public key signature/verification test
244 */
245#define pubkey_sign_verify_ok( test ) \
246 pubkey_sign_verify_okx ( test, __FILE__, __LINE__ )
247
248#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_encrypt_fail_okx(struct pubkey_encryption_test *test, const char *file, unsigned int line)
Report a public key encryption failure test result.
void pubkey_sign_okx(struct pubkey_signature_test *test, const char *file, unsigned int line)
Report a public key signature test result.
void pubkey_encrypt_decrypt_okx(struct pubkey_encryption_test *test, const char *file, unsigned int line)
Report a public key encryption and decryption test result.
void pubkey_decrypt_fail_okx(struct pubkey_encryption_test *test, const char *file, unsigned int line)
Report a public key decryption failure test result.
void pubkey_sign_verify_okx(struct pubkey_signature_test *test, const char *file, unsigned int line)
Report a public key signature and verification test result.
void pubkey_decrypt_okx(struct pubkey_encryption_test *test, const char *file, unsigned int line)
Report a public key decryption test result.
void pubkey_verify_okx(struct pubkey_signature_test *test, const char *file, unsigned int line)
Report a public key verification test result.
void pubkey_encrypt_okx(struct pubkey_encryption_test *test, const char *file, unsigned int line)
Report a public key encryption test result.
Definition pubkey_test.c:78
int pubkey_test_get_random(void *data, size_t len)
Get random data input.
Definition pubkey_test.c:56
void pubkey_verify_fail_okx(struct pubkey_signature_test *test, const char *file, unsigned int line)
Report a public key verification failure test result.
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 encryption/decryption test.
Definition pubkey_test.h:21
const struct asn1_cursor plaintext
Plaintext.
Definition pubkey_test.h:29
const struct asn1_cursor ciphertext
Ciphertext.
Definition pubkey_test.h:31
size_t random_len
Random data input length.
Definition pubkey_test.h:27
const void * random
Random data input.
Definition pubkey_test.h:25
const struct pubkey_test * key
Test key.
Definition pubkey_test.h:23
A public-key signature/verification test.
Definition pubkey_test.h:35
const struct pubkey_test * key
Test key.
Definition pubkey_test.h:37
const void * random
Random data input.
Definition pubkey_test.h:39
size_t random_len
Random data input length.
Definition pubkey_test.h:41
struct digest_algorithm * digest
Signature algorithm.
Definition pubkey_test.h:47
const struct asn1_cursor signature
Signature.
Definition pubkey_test.h:49
const void * plaintext
Plaintext.
Definition pubkey_test.h:43
size_t plaintext_len
Plaintext length.
Definition pubkey_test.h:45
A public-key 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
Self-test infrastructure.