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 /** Plaintext */
19 const struct asn1_cursor plaintext;
20 /** Ciphertext
21 *
22 * Note that the encryption process may include some random
23 * padding, so a given plaintext will encrypt to multiple
24 * different ciphertexts.
25 */
26 const struct asn1_cursor ciphertext;
27};
28
29/** A public-key signature test */
31 /** Public-key algorithm */
33 /** Private key */
34 const struct asn1_cursor private;
35 /** Public key */
36 const struct asn1_cursor public;
37 /** Plaintext */
38 const void *plaintext;
39 /** Plaintext length */
41 /** Signature algorithm */
43 /** Signature */
44 const struct asn1_cursor signature;
45};
46
47/** Define inline private key data */
48#define PRIVATE(...) { __VA_ARGS__ }
49
50/** Define inline public key data */
51#define PUBLIC(...) { __VA_ARGS__ }
52
53/** Define inline plaintext data */
54#define PLAINTEXT(...) { __VA_ARGS__ }
55
56/** Define inline ciphertext data */
57#define CIPHERTEXT(...) { __VA_ARGS__ }
58
59/** Define inline signature data */
60#define SIGNATURE(...) { __VA_ARGS__ }
61
62/**
63 * Define a public-key encryption and decryption test
64 *
65 * @v name Test name
66 * @v PUBKEY Public-key algorithm
67 * @v PRIVATE Private key
68 * @v PUBLIC Public key
69 * @v PLAINTEXT Plaintext
70 * @v CIPHERTEXT Ciphertext
71 * @ret test Encryption and decryption test
72 */
73#define PUBKEY_TEST( name, PUBKEY, PRIVATE, PUBLIC, PLAINTEXT, \
74 CIPHERTEXT ) \
75 static const uint8_t name ## _private[] = PRIVATE; \
76 static const uint8_t name ## _public[] = PUBLIC; \
77 static const uint8_t name ## _plaintext[] = PLAINTEXT; \
78 static const uint8_t name ## _ciphertext[] = CIPHERTEXT; \
79 static struct pubkey_test name = { \
80 .pubkey = PUBKEY, \
81 .private = { \
82 .data = name ## _private, \
83 .len = sizeof ( name ## _private ), \
84 }, \
85 .public = { \
86 .data = name ## _public, \
87 .len = sizeof ( name ## _public ), \
88 }, \
89 .plaintext = { \
90 .data = name ## _plaintext, \
91 .len = sizeof ( name ## _plaintext ), \
92 }, \
93 .ciphertext = { \
94 .data = name ## _ciphertext, \
95 .len = sizeof ( name ## _ciphertext ), \
96 }, \
97 }
98
99/**
100 * Define a public-key signature test
101 *
102 * @v name Test name
103 * @v PUBKEY Public-key algorithm
104 * @v PRIVATE Private key
105 * @v PUBLIC Public key
106 * @v PLAINTEXT Plaintext
107 * @v DIGEST Digest algorithm
108 * @v SIGNATURE Signature
109 * @ret test Signature test
110 */
111#define PUBKEY_SIGN_TEST( name, PUBKEY, PRIVATE, PUBLIC, PLAINTEXT, \
112 DIGEST, SIGNATURE ) \
113 static const uint8_t name ## _private[] = PRIVATE; \
114 static const uint8_t name ## _public[] = PUBLIC; \
115 static const uint8_t name ## _plaintext[] = PLAINTEXT; \
116 static const uint8_t name ## _signature[] = SIGNATURE; \
117 static struct pubkey_sign_test name = { \
118 .pubkey = PUBKEY, \
119 .private = { \
120 .data = name ## _private, \
121 .len = sizeof ( name ## _private ), \
122 }, \
123 .public = { \
124 .data = name ## _public, \
125 .len = sizeof ( name ## _public ), \
126 }, \
127 .plaintext = name ## _plaintext, \
128 .plaintext_len = sizeof ( name ## _plaintext ), \
129 .digest = DIGEST, \
130 .signature = { \
131 .data = name ## _signature, \
132 .len = sizeof ( name ## _signature ), \
133 }, \
134 }
135
136extern void pubkey_okx ( struct pubkey_test *test,
137 const char *file, unsigned int line );
138extern void pubkey_sign_okx ( struct pubkey_sign_test *test,
139 const char *file, unsigned int line );
140
141/**
142 * Report a public key encryption and decryption test result
143 *
144 * @v test Public key encryption and decryption test
145 */
146#define pubkey_ok( test ) \
147 pubkey_okx ( test, __FILE__, __LINE__ )
148
149/**
150 * Report a public key signature test result
151 *
152 * @v test Public key signature test
153 */
154#define pubkey_sign_ok( test ) \
155 pubkey_sign_okx ( test, __FILE__, __LINE__ )
156
157#endif /* _PUBKEY_TEST_H */
static int test
Definition epic100.c:73
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
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:50
void pubkey_sign_okx(struct pubkey_sign_test *test, const char *file, unsigned int line)
Report public key signature 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:122
A public-key signature test.
Definition pubkey_test.h:30
const struct asn1_cursor public
Public key.
Definition pubkey_test.h:36
struct pubkey_algorithm * pubkey
Public-key algorithm.
Definition pubkey_test.h:32
const struct asn1_cursor private
Private key.
Definition pubkey_test.h:34
struct digest_algorithm * digest
Signature algorithm.
Definition pubkey_test.h:42
const void * plaintext
Plaintext.
Definition pubkey_test.h:38
size_t plaintext_len
Plaintext length.
Definition pubkey_test.h:40
const struct asn1_cursor signature
Signature.
Definition pubkey_test.h:44
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 struct asn1_cursor plaintext
Plaintext.
Definition pubkey_test.h:19
const struct asn1_cursor ciphertext
Ciphertext.
Definition pubkey_test.h:26
Self-test infrastructure.