iPXE
elliptic_test.h
Go to the documentation of this file.
1#ifndef _ELLIPTIC_TEST_H
2#define _ELLIPTIC_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/** An elliptic curve point multiplication test */
12 /** Elliptic curve */
14 /** Base point */
15 const void *base;
16 /** Length of base point (or 0 to use generator) */
17 size_t base_len;
18 /** Scalar multiple */
19 const void *scalar;
20 /** Length of scalar multiple */
21 size_t scalar_len;
22 /** Expected result point */
23 const void *expected;
24 /** Length of expected result point (or 0 to expect failure) */
26};
27
28/** An elliptic curve point addition test */
30 /** Elliptic curve */
32 /** Addend point */
33 const void *addend;
34 /** Length of addend point */
35 size_t addend_len;
36 /** Augend point */
37 const void *augend;
38 /** Length of augend point */
39 size_t augend_len;
40 /** Expected result point */
41 const void *expected;
42 /** Length of expected result point (or 0 to expect failure) */
44};
45
46/** Define inline base point */
47#define BASE(...) { __VA_ARGS__ }
48
49/** Define base point to be curve's generator */
50#define BASE_GENERATOR BASE()
51
52/** Define inline scalar multiple */
53#define SCALAR(...) { __VA_ARGS__ }
54
55/** Define inline addend point */
56#define ADDEND(...) { __VA_ARGS__ }
57
58/** Define inline augend point */
59#define AUGEND(...) { __VA_ARGS__ }
60
61/** Define inline expected result point */
62#define EXPECTED(...) { __VA_ARGS__ }
63
64/** Define result as an expected failure */
65#define EXPECTED_FAIL EXPECTED()
66
67/**
68 * Define an elliptic curve point multiplication test
69 *
70 * @v name Test name
71 * @v CURVE Elliptic curve
72 * @v BASE Base point
73 * @v SCALAR Scalar multiple
74 * @v EXPECTED Expected result point
75 * @ret test Elliptic curve point multiplication test
76 */
77#define ELLIPTIC_MULTIPLY_TEST( name, CURVE, BASE, SCALAR, EXPECTED ) \
78 static const uint8_t name ## _base[] = BASE; \
79 static const uint8_t name ## _scalar[] = SCALAR; \
80 static const uint8_t name ## _expected[] = EXPECTED; \
81 static struct elliptic_multiply_test name = { \
82 .curve = CURVE, \
83 .base = name ## _base, \
84 .base_len = sizeof ( name ## _base ), \
85 .scalar = name ## _scalar, \
86 .scalar_len = sizeof ( name ## _scalar ), \
87 .expected = name ## _expected, \
88 .expected_len = sizeof ( name ## _expected ), \
89 };
90
91/**
92 * Define an elliptic curve point addition test
93 *
94 * @v name Test name
95 * @v CURVE Elliptic curve
96 * @v ADDEND Addend point
97 * @v AUGEND Augend point
98 * @v EXPECTED Expected result point
99 * @ret test Elliptic curve point multiplication test
100 */
101#define ELLIPTIC_ADD_TEST( name, CURVE, ADDEND, AUGEND, EXPECTED ) \
102 static const uint8_t name ## _addend[] = ADDEND; \
103 static const uint8_t name ## _augend[] = AUGEND; \
104 static const uint8_t name ## _expected[] = EXPECTED; \
105 static struct elliptic_add_test name = { \
106 .curve = CURVE, \
107 .addend = name ## _addend, \
108 .addend_len = sizeof ( name ## _addend ), \
109 .augend = name ## _augend, \
110 .augend_len = sizeof ( name ## _augend ), \
111 .expected = name ## _expected, \
112 .expected_len = sizeof ( name ## _expected ), \
113 };
114
115extern void elliptic_curve_okx ( struct elliptic_curve *curve,
116 const char *file, unsigned int line );
118 const char *file, unsigned int line );
119extern void elliptic_add_okx ( struct elliptic_add_test *test,
120 const char *file, unsigned int line );
121
122/**
123 * Report an elliptic curve sanity test result
124 *
125 * @v curve Elliptic curve
126 */
127#define elliptic_curve_ok( curve ) \
128 elliptic_curve_okx ( curve, __FILE__, __LINE__ )
129
130/**
131 * Report an elliptic curve point multiplication test result
132 *
133 * @v test Elliptic curve point multiplication test
134 */
135#define elliptic_multiply_ok( test ) \
136 elliptic_multiply_okx ( test, __FILE__, __LINE__ )
137
138/**
139 * Report an elliptic curve point addition test result
140 *
141 * @v test Elliptic curve point addition test
142 */
143#define elliptic_add_ok( test ) \
144 elliptic_add_okx ( test, __FILE__, __LINE__ )
145
146#endif /* _ELLIPTIC_TEST_H */
void elliptic_curve_okx(struct elliptic_curve *curve, const char *file, unsigned int line)
Report elliptic curve sanity test result.
void elliptic_multiply_okx(struct elliptic_multiply_test *test, const char *file, unsigned int line)
Report elliptic curve point multiplication test result.
void elliptic_add_okx(struct elliptic_add_test *test, const char *file, unsigned int line)
Report elliptic curve point addition test result.
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.
An elliptic curve point addition test.
struct elliptic_curve * curve
Elliptic curve.
const void * augend
Augend point.
const void * addend
Addend point.
size_t expected_len
Length of expected result point (or 0 to expect failure)
const void * expected
Expected result point.
size_t addend_len
Length of addend point.
size_t augend_len
Length of augend point.
An elliptic curve.
Definition crypto.h:178
An elliptic curve point multiplication test.
const void * scalar
Scalar multiple.
size_t expected_len
Length of expected result point (or 0 to expect failure)
size_t scalar_len
Length of scalar multiple.
const void * base
Base point.
const void * expected
Expected result point.
struct elliptic_curve * curve
Elliptic curve.
size_t base_len
Length of base point (or 0 to use generator)
Self-test infrastructure.