ECC (Elliptic Curve Cryptography) More...

#include "core/crypto.h"

Go to the source code of this file.

Data Structures

struct  EcPoint
 EC point (affine coordinates) More...
 
struct  EcPoint3
 EC point (projective coordinates) More...
 
struct  EcPublicKey
 EC public key. More...
 
struct  EcPrivateKey
 EC private key. More...
 
struct  EcState
 Working state (point addition/subtraction/doubling) More...
 
struct  EcMulFastState
 Working state (fast scalar multiplication) More...
 
struct  EcMulRegularState
 Working state (regular scalar multiplication) More...
 
struct  EcTwinMulState
 Working state (twin multiplication) More...
 
struct  _EcCurve
 Elliptic curve parameters. More...
 

Macros

#define SECP112R1_SUPPORT   DISABLED
 
#define SECP112R2_SUPPORT   DISABLED
 
#define SECP128R1_SUPPORT   DISABLED
 
#define SECP128R2_SUPPORT   DISABLED
 
#define SECP160K1_SUPPORT   DISABLED
 
#define SECP160R1_SUPPORT   DISABLED
 
#define SECP160R2_SUPPORT   DISABLED
 
#define SECP192K1_SUPPORT   DISABLED
 
#define SECP192R1_SUPPORT   DISABLED
 
#define SECP224K1_SUPPORT   DISABLED
 
#define SECP224R1_SUPPORT   ENABLED
 
#define SECP256K1_SUPPORT   DISABLED
 
#define SECP256R1_SUPPORT   ENABLED
 
#define SECP384R1_SUPPORT   ENABLED
 
#define SECP521R1_SUPPORT   ENABLED
 
#define BRAINPOOLP160R1_SUPPORT   DISABLED
 
#define BRAINPOOLP160T1_SUPPORT   DISABLED
 
#define BRAINPOOLP192R1_SUPPORT   DISABLED
 
#define BRAINPOOLP192T1_SUPPORT   DISABLED
 
#define BRAINPOOLP224R1_SUPPORT   DISABLED
 
#define BRAINPOOLP224T1_SUPPORT   DISABLED
 
#define BRAINPOOLP256R1_SUPPORT   DISABLED
 
#define BRAINPOOLP256T1_SUPPORT   DISABLED
 
#define BRAINPOOLP320R1_SUPPORT   DISABLED
 
#define BRAINPOOLP320T1_SUPPORT   DISABLED
 
#define BRAINPOOLP384R1_SUPPORT   DISABLED
 
#define BRAINPOOLP384T1_SUPPORT   DISABLED
 
#define BRAINPOOLP512R1_SUPPORT   DISABLED
 
#define BRAINPOOLP512T1_SUPPORT   DISABLED
 
#define FRP256V1_SUPPORT   DISABLED
 
#define SM2_SUPPORT   DISABLED
 
#define X25519_SUPPORT   DISABLED
 
#define X448_SUPPORT   DISABLED
 
#define ED25519_SUPPORT   DISABLED
 
#define ED448_SUPPORT   DISABLED
 
#define EC_MAX_MODULUS_SIZE   17
 
#define EC_MAX_ORDER_SIZE   17
 
#define EcCurve   struct _EcCurve
 

Typedefs

typedef void(* EcModAlgo) (const EcCurve *curve, uint32_t *r, const uint32_t *a)
 Modular reduction. More...
 
typedef void(* EcInvModAlgo) (const EcCurve *curve, uint32_t *r, const uint32_t *a)
 Modular inverse. More...
 

Enumerations

enum  EcCurveType {
  EC_CURVE_TYPE_WEIERSTRASS = 1, EC_CURVE_TYPE_WEIERSTRASS_A0 = 2, EC_CURVE_TYPE_WEIERSTRASS_A3 = 3, EC_CURVE_TYPE_MONTGOMERY = 4,
  EC_CURVE_TYPE_EDWARDS = 5
}
 Elliptic curve type. More...
 
enum  EcPointFormat { EC_POINT_FORMAT_COMPRESSED_EVEN = 0x02, EC_POINT_FORMAT_COMPRESSED_ODD = 0x03, EC_POINT_FORMAT_UNCOMPRESSED = 0x04 }
 EC point format. More...
 
enum  EcPublicKeyFormat { EC_PUBLIC_KEY_FORMAT_X963 = 0, EC_PUBLIC_KEY_FORMAT_RAW = 1, EC_PUBLIC_KEY_FORMAT_RAW_X = 2, EC_PUBLIC_KEY_FORMAT_RAW_Y = 3 }
 EC public key format. More...
 

Functions

void ecInitPublicKey (EcPublicKey *key)
 Initialize an EC public key. More...
 
void ecFreePublicKey (EcPublicKey *key)
 Release an EC public key. More...
 
void ecInitPrivateKey (EcPrivateKey *key)
 Initialize an EC private key. More...
 
void ecFreePrivateKey (EcPrivateKey *key)
 Release an EC private key. More...
 
error_t ecGenerateKeyPair (const PrngAlgo *prngAlgo, void *prngContext, const EcCurve *curve, EcPrivateKey *privateKey, EcPublicKey *publicKey)
 EC key pair generation. More...
 
error_t ecGeneratePrivateKey (const PrngAlgo *prngAlgo, void *prngContext, const EcCurve *curve, EcPrivateKey *privateKey)
 EC private key generation. More...
 
error_t ecGeneratePublicKey (const EcPrivateKey *privateKey, EcPublicKey *publicKey)
 Derive the public key from an EC private key. More...
 
error_t ecImportPublicKey (EcPublicKey *key, const EcCurve *curve, const uint8_t *data, size_t length, EcPublicKeyFormat format)
 Import an EC public key. More...
 
error_t ecExportPublicKey (const EcPublicKey *key, uint8_t *data, size_t *length, EcPublicKeyFormat format)
 Export an EC public key. More...
 
error_t ecImportPrivateKey (EcPrivateKey *key, const EcCurve *curve, const uint8_t *data, size_t length)
 Import an EC private key. More...
 
error_t ecExportPrivateKey (const EcPrivateKey *key, uint8_t *data, size_t *length)
 Export an EC private key. More...
 
error_t ecImportPoint (const EcCurve *curve, EcPoint *r, const uint8_t *data, size_t length)
 Convert an octet string to an EC point. More...
 
error_t ecExportPoint (const EcCurve *curve, const EcPoint *a, uint8_t *data, size_t *length)
 Convert an EC point to an octet string. More...
 
void ecProjectify (const EcCurve *curve, EcPoint3 *r, const EcPoint *s)
 Compute projective representation. More...
 
error_t ecAffinify (const EcCurve *curve, EcPoint3 *r, const EcPoint3 *s)
 Recover affine representation. More...
 
bool_t ecIsPointAffine (const EcCurve *curve, const EcPoint *s)
 Check whether the affine point S is on the curve. More...
 
void ecDouble (EcState *state, EcPoint3 *r, const EcPoint3 *s)
 Point doubling. More...
 
void ecAdd (EcState *state, EcPoint3 *r, const EcPoint3 *s, const EcPoint3 *t)
 Point addition (helper routine) More...
 
void ecFullAdd (EcState *state, EcPoint3 *r, const EcPoint3 *s, const EcPoint3 *t)
 Point addition. More...
 
void ecFullSub (EcState *state, EcPoint3 *r, const EcPoint3 *s, const EcPoint3 *t)
 Point subtraction. More...
 
error_t ecMulFast (const EcCurve *curve, EcPoint3 *r, const uint32_t *d, const EcPoint3 *s)
 Scalar multiplication (fast calculation) More...
 
error_t ecMulRegular (const EcCurve *curve, EcPoint3 *r, const uint32_t *d, const EcPoint3 *s)
 Scalar multiplication (regular calculation) More...
 
error_t ecTwinMul (const EcCurve *curve, EcPoint3 *r, const uint32_t *d0, const EcPoint3 *s, const uint32_t *d1, const EcPoint3 *t)
 Twin multiplication. More...
 

Variables

const uint8_t EC_PUBLIC_KEY_OID [7]
 

Detailed Description

ECC (Elliptic Curve Cryptography)

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.5.0

Definition in file ec.h.

Macro Definition Documentation

◆ BRAINPOOLP160R1_SUPPORT

#define BRAINPOOLP160R1_SUPPORT   DISABLED

Definition at line 144 of file ec.h.

◆ BRAINPOOLP160T1_SUPPORT

#define BRAINPOOLP160T1_SUPPORT   DISABLED

Definition at line 151 of file ec.h.

◆ BRAINPOOLP192R1_SUPPORT

#define BRAINPOOLP192R1_SUPPORT   DISABLED

Definition at line 158 of file ec.h.

◆ BRAINPOOLP192T1_SUPPORT

#define BRAINPOOLP192T1_SUPPORT   DISABLED

Definition at line 165 of file ec.h.

◆ BRAINPOOLP224R1_SUPPORT

#define BRAINPOOLP224R1_SUPPORT   DISABLED

Definition at line 172 of file ec.h.

◆ BRAINPOOLP224T1_SUPPORT

#define BRAINPOOLP224T1_SUPPORT   DISABLED

Definition at line 179 of file ec.h.

◆ BRAINPOOLP256R1_SUPPORT

#define BRAINPOOLP256R1_SUPPORT   DISABLED

Definition at line 186 of file ec.h.

◆ BRAINPOOLP256T1_SUPPORT

#define BRAINPOOLP256T1_SUPPORT   DISABLED

Definition at line 193 of file ec.h.

◆ BRAINPOOLP320R1_SUPPORT

#define BRAINPOOLP320R1_SUPPORT   DISABLED

Definition at line 200 of file ec.h.

◆ BRAINPOOLP320T1_SUPPORT

#define BRAINPOOLP320T1_SUPPORT   DISABLED

Definition at line 207 of file ec.h.

◆ BRAINPOOLP384R1_SUPPORT

#define BRAINPOOLP384R1_SUPPORT   DISABLED

Definition at line 214 of file ec.h.

◆ BRAINPOOLP384T1_SUPPORT

#define BRAINPOOLP384T1_SUPPORT   DISABLED

Definition at line 221 of file ec.h.

◆ BRAINPOOLP512R1_SUPPORT

#define BRAINPOOLP512R1_SUPPORT   DISABLED

Definition at line 228 of file ec.h.

◆ BRAINPOOLP512T1_SUPPORT

#define BRAINPOOLP512T1_SUPPORT   DISABLED

Definition at line 235 of file ec.h.

◆ EC_MAX_MODULUS_SIZE

#define EC_MAX_MODULUS_SIZE   17

Definition at line 284 of file ec.h.

◆ EC_MAX_ORDER_SIZE

#define EC_MAX_ORDER_SIZE   17

Definition at line 315 of file ec.h.

◆ EcCurve

#define EcCurve   struct _EcCurve

Definition at line 346 of file ec.h.

◆ ED25519_SUPPORT

#define ED25519_SUPPORT   DISABLED

Definition at line 270 of file ec.h.

◆ ED448_SUPPORT

#define ED448_SUPPORT   DISABLED

Definition at line 277 of file ec.h.

◆ FRP256V1_SUPPORT

#define FRP256V1_SUPPORT   DISABLED

Definition at line 242 of file ec.h.

◆ SECP112R1_SUPPORT

#define SECP112R1_SUPPORT   DISABLED

Definition at line 39 of file ec.h.

◆ SECP112R2_SUPPORT

#define SECP112R2_SUPPORT   DISABLED

Definition at line 46 of file ec.h.

◆ SECP128R1_SUPPORT

#define SECP128R1_SUPPORT   DISABLED

Definition at line 53 of file ec.h.

◆ SECP128R2_SUPPORT

#define SECP128R2_SUPPORT   DISABLED

Definition at line 60 of file ec.h.

◆ SECP160K1_SUPPORT

#define SECP160K1_SUPPORT   DISABLED

Definition at line 67 of file ec.h.

◆ SECP160R1_SUPPORT

#define SECP160R1_SUPPORT   DISABLED

Definition at line 74 of file ec.h.

◆ SECP160R2_SUPPORT

#define SECP160R2_SUPPORT   DISABLED

Definition at line 81 of file ec.h.

◆ SECP192K1_SUPPORT

#define SECP192K1_SUPPORT   DISABLED

Definition at line 88 of file ec.h.

◆ SECP192R1_SUPPORT

#define SECP192R1_SUPPORT   DISABLED

Definition at line 95 of file ec.h.

◆ SECP224K1_SUPPORT

#define SECP224K1_SUPPORT   DISABLED

Definition at line 102 of file ec.h.

◆ SECP224R1_SUPPORT

#define SECP224R1_SUPPORT   ENABLED

Definition at line 109 of file ec.h.

◆ SECP256K1_SUPPORT

#define SECP256K1_SUPPORT   DISABLED

Definition at line 116 of file ec.h.

◆ SECP256R1_SUPPORT

#define SECP256R1_SUPPORT   ENABLED

Definition at line 123 of file ec.h.

◆ SECP384R1_SUPPORT

#define SECP384R1_SUPPORT   ENABLED

Definition at line 130 of file ec.h.

◆ SECP521R1_SUPPORT

#define SECP521R1_SUPPORT   ENABLED

Definition at line 137 of file ec.h.

◆ SM2_SUPPORT

#define SM2_SUPPORT   DISABLED

Definition at line 249 of file ec.h.

◆ X25519_SUPPORT

#define X25519_SUPPORT   DISABLED

Definition at line 256 of file ec.h.

◆ X448_SUPPORT

#define X448_SUPPORT   DISABLED

Definition at line 263 of file ec.h.

Typedef Documentation

◆ EcInvModAlgo

typedef void(* EcInvModAlgo) (const EcCurve *curve, uint32_t *r, const uint32_t *a)

Modular inverse.

Definition at line 509 of file ec.h.

◆ EcModAlgo

typedef void(* EcModAlgo) (const EcCurve *curve, uint32_t *r, const uint32_t *a)

Modular reduction.

Definition at line 501 of file ec.h.

Enumeration Type Documentation

◆ EcCurveType

Elliptic curve type.

Enumerator
EC_CURVE_TYPE_WEIERSTRASS 
EC_CURVE_TYPE_WEIERSTRASS_A0 
EC_CURVE_TYPE_WEIERSTRASS_A3 
EC_CURVE_TYPE_MONTGOMERY 
EC_CURVE_TYPE_EDWARDS 

Definition at line 358 of file ec.h.

◆ EcPointFormat

EC point format.

Enumerator
EC_POINT_FORMAT_COMPRESSED_EVEN 
EC_POINT_FORMAT_COMPRESSED_ODD 
EC_POINT_FORMAT_UNCOMPRESSED 

Definition at line 372 of file ec.h.

◆ EcPublicKeyFormat

EC public key format.

Enumerator
EC_PUBLIC_KEY_FORMAT_X963 
EC_PUBLIC_KEY_FORMAT_RAW 
EC_PUBLIC_KEY_FORMAT_RAW_X 
EC_PUBLIC_KEY_FORMAT_RAW_Y 

Definition at line 384 of file ec.h.

Function Documentation

◆ ecAdd()

void ecAdd ( EcState state,
EcPoint3 r,
const EcPoint3 s,
const EcPoint3 t 
)

Point addition (helper routine)

Parameters
[in]statePointer to the working state
[out]rResulting point R = S + T
[in]sFirst operand
[in]tSecond operand

Definition at line 957 of file ec.c.

◆ ecAffinify()

error_t ecAffinify ( const EcCurve curve,
EcPoint3 r,
const EcPoint3 s 
)

Recover affine representation.

Parameters
[in]curveElliptic curve parameters
[out]rAffine representation of the point
[in]sProjective representation of the point
Returns
Error code

Definition at line 749 of file ec.c.

◆ ecDouble()

void ecDouble ( EcState state,
EcPoint3 r,
const EcPoint3 s 
)

Point doubling.

Parameters
[in]statePointer to the working state
[out]rResulting point R = 2S
[in]sPoint S

Definition at line 848 of file ec.c.

◆ ecExportPoint()

error_t ecExportPoint ( const EcCurve curve,
const EcPoint a,
uint8_t *  data,
size_t *  length 
)

Convert an EC point to an octet string.

Parameters
[in]curveElliptic curve parameters
[in]aEC point to be converted
[out]dataPointer to the octet string
[out]lengthLength of the resulting octet string
Returns
Error code

Definition at line 675 of file ec.c.

◆ ecExportPrivateKey()

error_t ecExportPrivateKey ( const EcPrivateKey key,
uint8_t *  data,
size_t *  length 
)

Export an EC private key.

Parameters
[in]keyEC private key
[out]dataPointer to the octet string
[out]lengthLength of the octet string, in bytes
Returns
Error code

Definition at line 554 of file ec.c.

◆ ecExportPublicKey()

error_t ecExportPublicKey ( const EcPublicKey key,
uint8_t *  data,
size_t *  length,
EcPublicKeyFormat  format 
)

Export an EC public key.

Parameters
[in]keyEC public key
[out]dataPointer to the octet string
[out]lengthLength of the octet string, in bytes
[in]formatEC public key format (X9.63 or raw format)
Returns
Error code

Definition at line 378 of file ec.c.

◆ ecFreePrivateKey()

void ecFreePrivateKey ( EcPrivateKey key)

Release an EC private key.

Parameters
[in]keyPointer to the EC public key to free

Definition at line 100 of file ec.c.

◆ ecFreePublicKey()

void ecFreePublicKey ( EcPublicKey key)

Release an EC public key.

Parameters
[in]keyPointer to the EC public key to free

Definition at line 68 of file ec.c.

◆ ecFullAdd()

void ecFullAdd ( EcState state,
EcPoint3 r,
const EcPoint3 s,
const EcPoint3 t 
)

Point addition.

Parameters
[in]statePointer to the working state
[out]rResulting point R = S + T
[in]sFirst operand
[in]tSecond operand

Definition at line 1094 of file ec.c.

◆ ecFullSub()

void ecFullSub ( EcState state,
EcPoint3 r,
const EcPoint3 s,
const EcPoint3 t 
)

Point subtraction.

Parameters
[in]statePointer to the working state
[out]rResulting point R = S - T
[in]sFirst operand
[in]tSecond operand

Definition at line 1151 of file ec.c.

◆ ecGenerateKeyPair()

error_t ecGenerateKeyPair ( const PrngAlgo prngAlgo,
void *  prngContext,
const EcCurve curve,
EcPrivateKey privateKey,
EcPublicKey publicKey 
)

EC key pair generation.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]curveElliptic curve parameters
[out]privateKeyEC private key
[out]publicKeyEC public key (optional parameter)
Returns
Error code

Definition at line 117 of file ec.c.

◆ ecGeneratePrivateKey()

error_t ecGeneratePrivateKey ( const PrngAlgo prngAlgo,
void *  prngContext,
const EcCurve curve,
EcPrivateKey privateKey 
)

EC private key generation.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]curveElliptic curve parameters
[out]privateKeyEC private key
Returns
Error code

Definition at line 158 of file ec.c.

◆ ecGeneratePublicKey()

error_t ecGeneratePublicKey ( const EcPrivateKey privateKey,
EcPublicKey publicKey 
)

Derive the public key from an EC private key.

Parameters
[in]privateKeyEC private key
[out]publicKeyEC public key
Returns
Error code

Definition at line 200 of file ec.c.

◆ ecImportPoint()

error_t ecImportPoint ( const EcCurve curve,
EcPoint r,
const uint8_t *  data,
size_t  length 
)

Convert an octet string to an EC point.

Parameters
[in]curveElliptic curve parameters
[out]rEC point resulting from the conversion
[in]dataPointer to the octet string
[in]lengthLength of the octet string
Returns
Error code

Definition at line 626 of file ec.c.

◆ ecImportPrivateKey()

error_t ecImportPrivateKey ( EcPrivateKey key,
const EcCurve curve,
const uint8_t *  data,
size_t  length 
)

Import an EC private key.

Parameters
[out]keyEC private key
[in]dataPointer to the octet string
[in]lengthLength of the octet string, in bytes
Returns
Error code

Definition at line 490 of file ec.c.

◆ ecImportPublicKey()

error_t ecImportPublicKey ( EcPublicKey key,
const EcCurve curve,
const uint8_t *  data,
size_t  length,
EcPublicKeyFormat  format 
)

Import an EC public key.

Parameters
[out]keyEC public key
[in]curveElliptic curve parameters
[in]dataPointer to the octet string
[in]lengthLength of the octet string, in bytes
[in]formatEC public key format (X9.63 or raw format)
Returns
Error code

Definition at line 263 of file ec.c.

◆ ecInitPrivateKey()

void ecInitPrivateKey ( EcPrivateKey key)

Initialize an EC private key.

Parameters
[in]keyPointer to the EC private key to initialize

Definition at line 80 of file ec.c.

◆ ecInitPublicKey()

void ecInitPublicKey ( EcPublicKey key)

Initialize an EC public key.

Parameters
[in]keyPointer to the EC public key to initialize

Definition at line 52 of file ec.c.

◆ ecIsPointAffine()

bool_t ecIsPointAffine ( const EcCurve curve,
const EcPoint s 
)

Check whether the affine point S is on the curve.

Parameters
[in]curveElliptic curve parameters
[in]sAffine representation of the point
Returns
TRUE if the affine point S is on the curve, else FALSE

Definition at line 798 of file ec.c.

◆ ecMulFast()

error_t ecMulFast ( const EcCurve curve,
EcPoint3 r,
const uint32_t *  d,
const EcPoint3 s 
)

Scalar multiplication (fast calculation)

Parameters
[in]curveElliptic curve parameters
[out]rResulting point R = d.S
[in]dAn integer d such as 0 <= d < q
[in]sEC point
Returns
Error code
Parameters
[in]curveElliptic curve parameters
[out]rResulting point R = d.S
[in]dAn integer d such as 0 <= d < p
[in]sEC point
Returns
Error code

Definition at line 1181 of file ec.c.

◆ ecMulRegular()

error_t ecMulRegular ( const EcCurve curve,
EcPoint3 r,
const uint32_t *  d,
const EcPoint3 s 
)

Scalar multiplication (regular calculation)

Parameters
[in]curveElliptic curve parameters
[out]rResulting point R = d.S
[in]dAn integer d such as 0 <= d < q
[in]sEC point
Returns
Error code

Definition at line 1312 of file ec.c.

◆ ecProjectify()

void ecProjectify ( const EcCurve curve,
EcPoint3 r,
const EcPoint s 
)

Compute projective representation.

Parameters
[in]curveElliptic curve parameters
[out]rProjective representation of the point
[in]sAffine representation of the point

Definition at line 720 of file ec.c.

◆ ecTwinMul()

error_t ecTwinMul ( const EcCurve curve,
EcPoint3 r,
const uint32_t *  d0,
const EcPoint3 s,
const uint32_t *  d1,
const EcPoint3 t 
)

Twin multiplication.

Parameters
[in]curveElliptic curve parameters
[out]rResulting point R = d0.S + d1.T
[in]d0An integer d such as 0 <= d0 < q
[in]sEC point
[in]d1An integer d such as 0 <= d1 < q
[in]tEC point
Returns
Error code
Parameters
[in]curveElliptic curve parameters
[out]rResulting point R = d0.S + d1.T
[in]d0An integer d such as 0 <= d0 < p
[in]sEC point
[in]d1An integer d such as 0 <= d1 < p
[in]tEC point
Returns
Error code

Definition at line 1418 of file ec.c.

Variable Documentation

◆ EC_PUBLIC_KEY_OID

const uint8_t EC_PUBLIC_KEY_OID[7]
extern

Definition at line 44 of file ec.c.