Go to the documentation of this file.
38 #ifndef SECP112R1_SUPPORT
39 #define SECP112R1_SUPPORT DISABLED
40 #elif (SECP112R1_SUPPORT != ENABLED && SECP112R1_SUPPORT != DISABLED)
41 #error SECP112R1_SUPPORT parameter is not valid
45 #ifndef SECP112R2_SUPPORT
46 #define SECP112R2_SUPPORT DISABLED
47 #elif (SECP112R2_SUPPORT != ENABLED && SECP112R2_SUPPORT != DISABLED)
48 #error SECP112R2_SUPPORT parameter is not valid
52 #ifndef SECP128R1_SUPPORT
53 #define SECP128R1_SUPPORT DISABLED
54 #elif (SECP128R1_SUPPORT != ENABLED && SECP128R1_SUPPORT != DISABLED)
55 #error SECP128R1_SUPPORT parameter is not valid
59 #ifndef SECP128R2_SUPPORT
60 #define SECP128R2_SUPPORT DISABLED
61 #elif (SECP128R2_SUPPORT != ENABLED && SECP128R2_SUPPORT != DISABLED)
62 #error SECP128R2_SUPPORT parameter is not valid
66 #ifndef SECP160K1_SUPPORT
67 #define SECP160K1_SUPPORT DISABLED
68 #elif (SECP160K1_SUPPORT != ENABLED && SECP160K1_SUPPORT != DISABLED)
69 #error SECP160K1_SUPPORT parameter is not valid
73 #ifndef SECP160R1_SUPPORT
74 #define SECP160R1_SUPPORT DISABLED
75 #elif (SECP160R1_SUPPORT != ENABLED && SECP160R1_SUPPORT != DISABLED)
76 #error SECP160R1_SUPPORT parameter is not valid
80 #ifndef SECP160R2_SUPPORT
81 #define SECP160R2_SUPPORT DISABLED
82 #elif (SECP160R2_SUPPORT != ENABLED && SECP160R2_SUPPORT != DISABLED)
83 #error SECP160R2_SUPPORT parameter is not valid
87 #ifndef SECP192K1_SUPPORT
88 #define SECP192K1_SUPPORT DISABLED
89 #elif (SECP192K1_SUPPORT != ENABLED && SECP192K1_SUPPORT != DISABLED)
90 #error SECP192K1_SUPPORT parameter is not valid
94 #ifndef SECP192R1_SUPPORT
95 #define SECP192R1_SUPPORT DISABLED
96 #elif (SECP192R1_SUPPORT != ENABLED && SECP192R1_SUPPORT != DISABLED)
97 #error SECP192R1_SUPPORT parameter is not valid
101 #ifndef SECP224K1_SUPPORT
102 #define SECP224K1_SUPPORT DISABLED
103 #elif (SECP224K1_SUPPORT != ENABLED && SECP224K1_SUPPORT != DISABLED)
104 #error SECP224K1_SUPPORT parameter is not valid
108 #ifndef SECP224R1_SUPPORT
109 #define SECP224R1_SUPPORT ENABLED
110 #elif (SECP224R1_SUPPORT != ENABLED && SECP224R1_SUPPORT != DISABLED)
111 #error SECP224R1_SUPPORT parameter is not valid
115 #ifndef SECP256K1_SUPPORT
116 #define SECP256K1_SUPPORT DISABLED
117 #elif (SECP256K1_SUPPORT != ENABLED && SECP256K1_SUPPORT != DISABLED)
118 #error SECP256K1_SUPPORT parameter is not valid
122 #ifndef SECP256R1_SUPPORT
123 #define SECP256R1_SUPPORT ENABLED
124 #elif (SECP256R1_SUPPORT != ENABLED && SECP256R1_SUPPORT != DISABLED)
125 #error SECP256R1_SUPPORT parameter is not valid
129 #ifndef SECP384R1_SUPPORT
130 #define SECP384R1_SUPPORT ENABLED
131 #elif (SECP384R1_SUPPORT != ENABLED && SECP384R1_SUPPORT != DISABLED)
132 #error SECP384R1_SUPPORT parameter is not valid
136 #ifndef SECP521R1_SUPPORT
137 #define SECP521R1_SUPPORT ENABLED
138 #elif (SECP521R1_SUPPORT != ENABLED && SECP521R1_SUPPORT != DISABLED)
139 #error SECP521R1_SUPPORT parameter is not valid
143 #ifndef BRAINPOOLP160R1_SUPPORT
144 #define BRAINPOOLP160R1_SUPPORT DISABLED
145 #elif (BRAINPOOLP160R1_SUPPORT != ENABLED && BRAINPOOLP160R1_SUPPORT != DISABLED)
146 #error BRAINPOOLP160R1_SUPPORT parameter is not valid
150 #ifndef BRAINPOOLP160T1_SUPPORT
151 #define BRAINPOOLP160T1_SUPPORT DISABLED
152 #elif (BRAINPOOLP160T1_SUPPORT != ENABLED && BRAINPOOLP160T1_SUPPORT != DISABLED)
153 #error BRAINPOOLP160T1_SUPPORT parameter is not valid
157 #ifndef BRAINPOOLP192R1_SUPPORT
158 #define BRAINPOOLP192R1_SUPPORT DISABLED
159 #elif (BRAINPOOLP192R1_SUPPORT != ENABLED && BRAINPOOLP192R1_SUPPORT != DISABLED)
160 #error BRAINPOOLP192R1_SUPPORT parameter is not valid
164 #ifndef BRAINPOOLP192T1_SUPPORT
165 #define BRAINPOOLP192T1_SUPPORT DISABLED
166 #elif (BRAINPOOLP192T1_SUPPORT != ENABLED && BRAINPOOLP192T1_SUPPORT != DISABLED)
167 #error BRAINPOOLP192T1_SUPPORT parameter is not valid
171 #ifndef BRAINPOOLP224R1_SUPPORT
172 #define BRAINPOOLP224R1_SUPPORT DISABLED
173 #elif (BRAINPOOLP224R1_SUPPORT != ENABLED && BRAINPOOLP224R1_SUPPORT != DISABLED)
174 #error BRAINPOOLP224R1_SUPPORT parameter is not valid
178 #ifndef BRAINPOOLP224T1_SUPPORT
179 #define BRAINPOOLP224T1_SUPPORT DISABLED
180 #elif (BRAINPOOLP224T1_SUPPORT != ENABLED && BRAINPOOLP224T1_SUPPORT != DISABLED)
181 #error BRAINPOOLP224T1_SUPPORT parameter is not valid
185 #ifndef BRAINPOOLP256R1_SUPPORT
186 #define BRAINPOOLP256R1_SUPPORT DISABLED
187 #elif (BRAINPOOLP256R1_SUPPORT != ENABLED && BRAINPOOLP256R1_SUPPORT != DISABLED)
188 #error BRAINPOOLP256R1_SUPPORT parameter is not valid
192 #ifndef BRAINPOOLP256T1_SUPPORT
193 #define BRAINPOOLP256T1_SUPPORT DISABLED
194 #elif (BRAINPOOLP256T1_SUPPORT != ENABLED && BRAINPOOLP256T1_SUPPORT != DISABLED)
195 #error BRAINPOOLP256T1_SUPPORT parameter is not valid
199 #ifndef BRAINPOOLP320R1_SUPPORT
200 #define BRAINPOOLP320R1_SUPPORT DISABLED
201 #elif (BRAINPOOLP320R1_SUPPORT != ENABLED && BRAINPOOLP320R1_SUPPORT != DISABLED)
202 #error BRAINPOOLP320R1_SUPPORT parameter is not valid
206 #ifndef BRAINPOOLP320T1_SUPPORT
207 #define BRAINPOOLP320T1_SUPPORT DISABLED
208 #elif (BRAINPOOLP320T1_SUPPORT != ENABLED && BRAINPOOLP320T1_SUPPORT != DISABLED)
209 #error BRAINPOOLP320T1_SUPPORT parameter is not valid
213 #ifndef BRAINPOOLP384R1_SUPPORT
214 #define BRAINPOOLP384R1_SUPPORT DISABLED
215 #elif (BRAINPOOLP384R1_SUPPORT != ENABLED && BRAINPOOLP384R1_SUPPORT != DISABLED)
216 #error BRAINPOOLP384R1_SUPPORT parameter is not valid
220 #ifndef BRAINPOOLP384T1_SUPPORT
221 #define BRAINPOOLP384T1_SUPPORT DISABLED
222 #elif (BRAINPOOLP384T1_SUPPORT != ENABLED && BRAINPOOLP384T1_SUPPORT != DISABLED)
223 #error BRAINPOOLP384T1_SUPPORT parameter is not valid
227 #ifndef BRAINPOOLP512R1_SUPPORT
228 #define BRAINPOOLP512R1_SUPPORT DISABLED
229 #elif (BRAINPOOLP512R1_SUPPORT != ENABLED && BRAINPOOLP512R1_SUPPORT != DISABLED)
230 #error BRAINPOOLP512R1_SUPPORT parameter is not valid
234 #ifndef BRAINPOOLP512T1_SUPPORT
235 #define BRAINPOOLP512T1_SUPPORT DISABLED
236 #elif (BRAINPOOLP512T1_SUPPORT != ENABLED && BRAINPOOLP512T1_SUPPORT != DISABLED)
237 #error BRAINPOOLP512T1_SUPPORT parameter is not valid
241 #ifndef FRP256V1_SUPPORT
242 #define FRP256V1_SUPPORT DISABLED
243 #elif (FRP256V1_SUPPORT != ENABLED && FRP256V1_SUPPORT != DISABLED)
244 #error FRP256V1_SUPPORT parameter is not valid
249 #define SM2_SUPPORT DISABLED
250 #elif (SM2_SUPPORT != ENABLED && SM2_SUPPORT != DISABLED)
251 #error SM2_SUPPORT parameter is not valid
255 #ifndef X25519_SUPPORT
256 #define X25519_SUPPORT DISABLED
257 #elif (X25519_SUPPORT != ENABLED && X25519_SUPPORT != DISABLED)
258 #error X25519_SUPPORT parameter is not valid
263 #define X448_SUPPORT DISABLED
264 #elif (X448_SUPPORT != ENABLED && X448_SUPPORT != DISABLED)
265 #error X448_SUPPORT parameter is not valid
269 #ifndef ED25519_SUPPORT
270 #define ED25519_SUPPORT DISABLED
271 #elif (ED25519_SUPPORT != ENABLED && ED25519_SUPPORT != DISABLED)
272 #error ED25519_SUPPORT parameter is not valid
276 #ifndef ED448_SUPPORT
277 #define ED448_SUPPORT DISABLED
278 #elif (ED448_SUPPORT != ENABLED && ED448_SUPPORT != DISABLED)
279 #error ED448_SUPPORT parameter is not valid
283 #if (SECP521R1_SUPPORT == ENABLED)
284 #define EC_MAX_MODULUS_SIZE 17
285 #elif (BRAINPOOLP512R1_SUPPORT == ENABLED || BRAINPOOLP512T1_SUPPORT == ENABLED)
286 #define EC_MAX_MODULUS_SIZE 16
287 #elif (X448_SUPPORT == ENABLED)
288 #define EC_MAX_MODULUS_SIZE 14
289 #elif (SECP384R1_SUPPORT == ENABLED || BRAINPOOLP384R1_SUPPORT == ENABLED || \
290 BRAINPOOLP384T1_SUPPORT == ENABLED)
291 #define EC_MAX_MODULUS_SIZE 12
292 #elif (BRAINPOOLP320R1_SUPPORT == ENABLED)
293 #define EC_MAX_MODULUS_SIZE 10
294 #elif (SECP256K1_SUPPORT == ENABLED || SECP256R1_SUPPORT == ENABLED || \
295 BRAINPOOLP256R1_SUPPORT == ENABLED || BRAINPOOLP256T1_SUPPORT == ENABLED || \
296 FRP256V1_SUPPORT == ENABLED || SM2_SUPPORT == ENABLED || \
297 X25519_SUPPORT == ENABLED)
298 #define EC_MAX_MODULUS_SIZE 8
299 #elif (SECP224K1_SUPPORT == ENABLED || SECP224R1_SUPPORT == ENABLED || \
300 BRAINPOOLP224R1_SUPPORT == ENABLED || BRAINPOOLP224T1_SUPPORT == ENABLED)
301 #define EC_MAX_MODULUS_SIZE 7
302 #elif (SECP192K1_SUPPORT == ENABLED || SECP192R1_SUPPORT == ENABLED || \
303 BRAINPOOLP192R1_SUPPORT == ENABLED || BRAINPOOLP192T1_SUPPORT == ENABLED)
304 #define EC_MAX_MODULUS_SIZE 6
305 #elif (SECP160K1_SUPPORT == ENABLED || SECP160R1_SUPPORT == ENABLED || \
306 SECP160R2_SUPPORT == ENABLED || BRAINPOOLP160R1_SUPPORT == ENABLED || \
307 BRAINPOOLP160T1_SUPPORT == ENABLED)
308 #define EC_MAX_MODULUS_SIZE 5
310 #define EC_MAX_MODULUS_SIZE 4
314 #if (SECP521R1_SUPPORT == ENABLED)
315 #define EC_MAX_ORDER_SIZE 17
316 #elif (BRAINPOOLP512R1_SUPPORT == ENABLED || BRAINPOOLP512T1_SUPPORT == ENABLED)
317 #define EC_MAX_ORDER_SIZE 16
318 #elif (X448_SUPPORT == ENABLED)
319 #define EC_MAX_ORDER_SIZE 14
320 #elif (SECP384R1_SUPPORT == ENABLED || BRAINPOOLP384R1_SUPPORT == ENABLED || \
321 BRAINPOOLP384T1_SUPPORT == ENABLED)
322 #define EC_MAX_ORDER_SIZE 12
323 #elif (BRAINPOOLP320R1_SUPPORT == ENABLED || BRAINPOOLP320T1_SUPPORT == ENABLED)
324 #define EC_MAX_ORDER_SIZE 10
325 #elif (SECP224K1_SUPPORT == ENABLED || SECP256K1_SUPPORT == ENABLED || \
326 SECP256R1_SUPPORT == ENABLED || BRAINPOOLP256R1_SUPPORT == ENABLED || \
327 BRAINPOOLP256T1_SUPPORT == ENABLED || FRP256V1_SUPPORT == ENABLED || \
328 SM2_SUPPORT == ENABLED || X25519_SUPPORT == ENABLED)
329 #define EC_MAX_ORDER_SIZE 8
330 #elif (SECP224R1_SUPPORT == ENABLED || BRAINPOOLP224R1_SUPPORT == ENABLED || \
331 BRAINPOOLP224T1_SUPPORT == ENABLED)
332 #define EC_MAX_ORDER_SIZE 7
333 #elif (SECP160K1_SUPPORT == ENABLED || SECP160R1_SUPPORT == ENABLED || \
334 SECP160R2_SUPPORT == ENABLED || SECP192K1_SUPPORT == ENABLED || \
335 SECP192R1_SUPPORT == ENABLED || BRAINPOOLP192R1_SUPPORT == ENABLED || \
336 BRAINPOOLP192T1_SUPPORT == ENABLED)
337 #define EC_MAX_ORDER_SIZE 6
338 #elif (BRAINPOOLP160R1_SUPPORT == ENABLED || BRAINPOOLP160T1_SUPPORT == ENABLED)
339 #define EC_MAX_ORDER_SIZE 5
341 #define EC_MAX_ORDER_SIZE 4
346 #define EcCurve struct _EcCurve
error_t ecGeneratePublicKey(const EcPrivateKey *privateKey, EcPublicKey *publicKey)
Derive the public key from an EC private key.
Elliptic curve parameters.
const char_t * name
Curve name.
@ EC_CURVE_TYPE_WEIERSTRASS_A3
@ EC_CURVE_TYPE_MONTGOMERY
@ EC_PUBLIC_KEY_FORMAT_RAW_Y
@ EC_POINT_FORMAT_UNCOMPRESSED
void ecFullSub(EcState *state, EcPoint3 *r, const EcPoint3 *s, const EcPoint3 *t)
Point subtraction.
error_t ecGenerateKeyPair(const PrngAlgo *prngAlgo, void *prngContext, const EcCurve *curve, EcPrivateKey *privateKey, EcPublicKey *publicKey)
EC key pair generation.
EcInvModAlgo fieldInv
Field modular inversion.
const EcCurve * curve
Elliptic curve parameters.
int_t slot
Private key slot.
Working state (fast scalar multiplication)
#define EC_MAX_ORDER_SIZE
const uint32_t b[EC_MAX_MODULUS_SIZE]
Curve parameter b.
@ EC_PUBLIC_KEY_FORMAT_X963
@ EC_POINT_FORMAT_COMPRESSED_ODD
Working state (regular scalar multiplication)
error_t ecImportPrivateKey(EcPrivateKey *key, const EcCurve *curve, const uint8_t *data, size_t length)
Import an EC private key.
Working state (twin multiplication)
error_t ecImportPublicKey(EcPublicKey *key, const EcCurve *curve, const uint8_t *data, size_t length, EcPublicKeyFormat format)
Import an EC public key.
error_t ecMulFast(const EcCurve *curve, EcPoint3 *r, const uint32_t *d, const EcPoint3 *s)
Scalar multiplication (fast calculation)
const uint32_t pmu[EC_MAX_MODULUS_SIZE+1]
Pre-computed value mu.
void ecAdd(EcState *state, EcPoint3 *r, const EcPoint3 *s, const EcPoint3 *t)
Point addition (helper routine)
void ecInitPrivateKey(EcPrivateKey *key)
Initialize an EC private key.
void ecFullAdd(EcState *state, EcPoint3 *r, const EcPoint3 *s, const EcPoint3 *t)
Point addition.
void ecFreePublicKey(EcPublicKey *key)
Release an EC public key.
bool_t ecIsPointAffine(const EcCurve *curve, const EcPoint *s)
Check whether the affine point S is on the curve.
error_t ecGeneratePrivateKey(const PrngAlgo *prngAlgo, void *prngContext, const EcCurve *curve, EcPrivateKey *privateKey)
EC private key generation.
EcPublicKeyFormat
EC public key format.
General definitions for cryptographic algorithms.
const uint32_t p[EC_MAX_MODULUS_SIZE+1]
Prime modulus p.
@ EC_PUBLIC_KEY_FORMAT_RAW
const uint8_t * oid
Object identifier.
EcInvModAlgo scalarInv
Scalar modular inversion.
EC point (affine coordinates)
void ecProjectify(const EcCurve *curve, EcPoint3 *r, const EcPoint *s)
Compute projective representation.
uint_t orderSize
Order size, in bits.
@ EC_POINT_FORMAT_COMPRESSED_EVEN
EcCurveType type
Curve type.
error_t ecImportPoint(const EcCurve *curve, EcPoint *r, const uint8_t *data, size_t length)
Convert an octet string to an EC point.
error_t ecAffinify(const EcCurve *curve, EcPoint3 *r, const EcPoint3 *s)
Recover affine representation.
Working state (point addition/subtraction/doubling)
const uint32_t q[EC_MAX_ORDER_SIZE+1]
Order of the base point G.
EC point (projective coordinates)
void(* EcModAlgo)(const EcCurve *curve, uint32_t *r, const uint32_t *a)
Modular reduction.
const uint8_t EC_PUBLIC_KEY_OID[7]
EcCurveType
Elliptic curve type.
const uint32_t a[EC_MAX_MODULUS_SIZE]
Curve parameter a.
@ EC_PUBLIC_KEY_FORMAT_RAW_X
void(* EcInvModAlgo)(const EcCurve *curve, uint32_t *r, const uint32_t *a)
Modular inverse.
error_t ecExportPrivateKey(const EcPrivateKey *key, uint8_t *data, size_t *length)
Export an EC private key.
void ecInitPublicKey(EcPublicKey *key)
Initialize an EC public key.
@ EC_CURVE_TYPE_WEIERSTRASS
void ecDouble(EcState *state, EcPoint3 *r, const EcPoint3 *s)
Point doubling.
error_t ecExportPublicKey(const EcPublicKey *key, uint8_t *data, size_t *length, EcPublicKeyFormat format)
Export an EC public key.
const uint32_t qmu[EC_MAX_ORDER_SIZE+1]
Pre-computed value mu.
uint_t fieldSize
Field size, in bits.
error_t ecExportPoint(const EcCurve *curve, const EcPoint *a, uint8_t *data, size_t *length)
Convert an EC point to an octet string.
EcModAlgo scalarMod
Scalar modular reduction.
const EcCurve * curve
Elliptic curve parameters.
@ EC_CURVE_TYPE_WEIERSTRASS_A0
error_t ecTwinMul(const EcCurve *curve, EcPoint3 *r, const uint32_t *d0, const EcPoint3 *s, const uint32_t *d1, const EcPoint3 *t)
Twin multiplication.
void ecFreePrivateKey(EcPrivateKey *key)
Release an EC private key.
#define EC_MAX_MODULUS_SIZE
error_t ecMulRegular(const EcCurve *curve, EcPoint3 *r, const uint32_t *d, const EcPoint3 *s)
Scalar multiplication (regular calculation)
EcModAlgo fieldMod
Field modular reduction.
EcPointFormat
EC point format.