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