ec.h File Reference

ECC (Elliptic Curve Cryptography) More...

#include "core/crypto.h"
#include "ecc/ec_curves.h"

Go to the source code of this file.

Data Structures

struct  EcPoint
 EC point. More...
 
struct  EcDomainParameters
 EC domain parameters. More...
 
struct  EcPublicKey
 EC public key. More...
 
struct  EcPrivateKey
 EC private key. More...
 

Macros

#define EC_CHECK(f)   if((error = f) != NO_ERROR) goto end
 

Enumerations

enum  EcPointFormat { EC_POINT_FORMAT_COMPRESSED_EVEN = 0x02 , EC_POINT_FORMAT_COMPRESSED_ODD = 0x03 , EC_POINT_FORMAT_UNCOMPRESSED = 0x04 }
 EC point format. More...
 

Functions

void ecInitDomainParameters (EcDomainParameters *params)
 Initialize EC domain parameters. More...
 
void ecFreeDomainParameters (EcDomainParameters *params)
 Release EC domain parameters. More...
 
error_t ecLoadDomainParameters (EcDomainParameters *params, const EcCurveInfo *curveInfo)
 Load EC domain parameters. More...
 
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 EdDSA private key. More...
 
error_t ecGenerateKeyPair (const PrngAlgo *prngAlgo, void *prngContext, const EcDomainParameters *params, EcPrivateKey *privateKey, EcPublicKey *publicKey)
 EC key pair generation. More...
 
error_t ecGeneratePrivateKey (const PrngAlgo *prngAlgo, void *prngContext, const EcDomainParameters *params, EcPrivateKey *privateKey)
 EC private key generation. More...
 
error_t ecGeneratePublicKey (const EcDomainParameters *params, const EcPrivateKey *privateKey, EcPublicKey *publicKey)
 Derive the public key from an EC private key. More...
 
void ecInit (EcPoint *r)
 Initialize elliptic curve point. More...
 
void ecFree (EcPoint *r)
 Release an elliptic curve point. More...
 
error_t ecCopy (EcPoint *r, const EcPoint *s)
 Copy EC point. More...
 
error_t ecImport (const EcDomainParameters *params, EcPoint *r, const uint8_t *data, size_t length)
 Convert an octet string to an EC point. More...
 
error_t ecExport (const EcDomainParameters *params, const EcPoint *a, uint8_t *data, size_t *length)
 Convert an EC point to an octet string. More...
 
error_t ecProjectify (const EcDomainParameters *params, EcPoint *r, const EcPoint *s)
 Compute projective representation. More...
 
error_t ecAffinify (const EcDomainParameters *params, EcPoint *r, const EcPoint *s)
 Recover affine representation. More...
 
bool_t ecIsPointAffine (const EcDomainParameters *params, const EcPoint *s)
 Check whether the affine point S is on the curve. More...
 
error_t ecDouble (const EcDomainParameters *params, EcPoint *r, const EcPoint *s)
 Point doubling. More...
 
error_t ecAdd (const EcDomainParameters *params, EcPoint *r, const EcPoint *s, const EcPoint *t)
 Point addition (helper routine) More...
 
error_t ecFullAdd (const EcDomainParameters *params, EcPoint *r, const EcPoint *s, const EcPoint *t)
 Point addition. More...
 
error_t ecFullSub (const EcDomainParameters *params, EcPoint *r, const EcPoint *s, const EcPoint *t)
 Point subtraction. More...
 
error_t ecMult (const EcDomainParameters *params, EcPoint *r, const Mpi *d, const EcPoint *s)
 Scalar multiplication. More...
 
error_t ecTwinMult (const EcDomainParameters *params, EcPoint *r, const Mpi *d0, const EcPoint *s, const Mpi *d1, const EcPoint *t)
 Twin multiplication. More...
 
error_t ecAddMod (const EcDomainParameters *params, Mpi *r, const Mpi *a, const Mpi *b)
 Fast modular addition. More...
 
error_t ecSubMod (const EcDomainParameters *params, Mpi *r, const Mpi *a, const Mpi *b)
 Fast modular subtraction. More...
 
error_t ecMulMod (const EcDomainParameters *params, Mpi *r, const Mpi *a, const Mpi *b)
 Fast modular multiplication. More...
 
error_t ecSqrMod (const EcDomainParameters *params, Mpi *r, const Mpi *a)
 Fast modular squaring. 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-2024 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.4.0

Definition in file ec.h.

Macro Definition Documentation

◆ EC_CHECK

#define EC_CHECK (   f)    if((error = f) != NO_ERROR) goto end

Definition at line 39 of file ec.h.

Enumeration Type Documentation

◆ EcPointFormat

EC point format.

Enumerator
EC_POINT_FORMAT_COMPRESSED_EVEN 
EC_POINT_FORMAT_COMPRESSED_ODD 
EC_POINT_FORMAT_UNCOMPRESSED 

Definition at line 51 of file ec.h.

Function Documentation

◆ ecAdd()

error_t ecAdd ( const EcDomainParameters params,
EcPoint r,
const EcPoint s,
const EcPoint t 
)

Point addition (helper routine)

Parameters
[in]paramsEC domain parameters
[out]rResulting point R = S + T
[in]sFirst operand
[in]tSecond operand
Returns
Error code

Definition at line 739 of file ec.c.

◆ ecAddMod()

error_t ecAddMod ( const EcDomainParameters params,
Mpi r,
const Mpi a,
const Mpi b 
)

Fast modular addition.

Parameters
[in]paramsEC domain parameters
[out]rResulting integer R = (A + B) mod p
[in]aAn integer such as 0 <= A < p
[in]bAn integer such as 0 <= B < p
Returns
Error code

Definition at line 1305 of file ec.c.

◆ ecAffinify()

error_t ecAffinify ( const EcDomainParameters ecParams,
EcPoint r,
const EcPoint s 
)

Recover affine representation.

Parameters
[in]paramsEC domain parameters
[out]rAffine representation of the point
[in]sProjective representation of the point
Returns
Error code
Parameters
[in]ecParamsEC domain parameters
[out]rAffine representation of the point
[in]sProjective representation of the point
Returns
Error code

Definition at line 519 of file ec.c.

◆ ecCopy()

error_t ecCopy ( EcPoint r,
const EcPoint s 
)

Copy EC point.

Parameters
[out]rDestination EC point
[in]sSource EC point
Returns
Error code

Definition at line 337 of file ec.c.

◆ ecDouble()

error_t ecDouble ( const EcDomainParameters params,
EcPoint r,
const EcPoint s 
)

Point doubling.

Parameters
[in]paramsEC domain parameters
[out]rResulting point R = 2S
[in]sPoint S
Returns
Error code

Definition at line 607 of file ec.c.

◆ ecExport()

error_t ecExport ( const EcDomainParameters params,
const EcPoint a,
uint8_t *  data,
size_t *  length 
)

Convert an EC point to an octet string.

Parameters
[in]paramsEC domain 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 438 of file ec.c.

◆ ecFree()

void ecFree ( EcPoint r)

Release an elliptic curve point.

Parameters
[in,out]rPointer to the EC point to initialize to free

Definition at line 321 of file ec.c.

◆ ecFreeDomainParameters()

void ecFreeDomainParameters ( EcDomainParameters params)

Release EC domain parameters.

Parameters
[in]paramsPointer to the EC domain parameters to free

Definition at line 72 of file ec.c.

◆ ecFreePrivateKey()

void ecFreePrivateKey ( EcPrivateKey key)

Release an EdDSA private key.

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

Definition at line 192 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 165 of file ec.c.

◆ ecFullAdd()

error_t ecFullAdd ( const EcDomainParameters params,
EcPoint r,
const EcPoint s,
const EcPoint t 
)

Point addition.

Parameters
[in]paramsEC domain parameters
[out]rResulting point R = S + T
[in]sFirst operand
[in]tSecond operand
Returns
Error code

Definition at line 899 of file ec.c.

◆ ecFullSub()

error_t ecFullSub ( const EcDomainParameters params,
EcPoint r,
const EcPoint s,
const EcPoint t 
)

Point subtraction.

Parameters
[in]paramsEC domain parameters
[out]rResulting point R = S - T
[in]sFirst operand
[in]tSecond operand
Returns
Error code

Definition at line 950 of file ec.c.

◆ ecGenerateKeyPair()

error_t ecGenerateKeyPair ( const PrngAlgo prngAlgo,
void *  prngContext,
const EcDomainParameters params,
EcPrivateKey privateKey,
EcPublicKey publicKey 
)

EC key pair generation.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]paramsEC domain parameters
[out]privateKeyEC private key
[out]publicKeyEC public key
Returns
Error code

Definition at line 209 of file ec.c.

◆ ecGeneratePrivateKey()

error_t ecGeneratePrivateKey ( const PrngAlgo prngAlgo,
void *  prngContext,
const EcDomainParameters params,
EcPrivateKey privateKey 
)

EC private key generation.

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

Definition at line 239 of file ec.c.

◆ ecGeneratePublicKey()

error_t ecGeneratePublicKey ( const EcDomainParameters params,
const EcPrivateKey privateKey,
EcPublicKey publicKey 
)

Derive the public key from an EC private key.

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

Definition at line 275 of file ec.c.

◆ ecImport()

error_t ecImport ( const EcDomainParameters params,
EcPoint r,
const uint8_t *  data,
size_t  length 
)

Convert an octet string to an EC point.

Parameters
[in]paramsEC domain 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 365 of file ec.c.

◆ ecInit()

void ecInit ( EcPoint r)

Initialize elliptic curve point.

Parameters
[in,out]rPointer to the EC point to be initialized

Definition at line 307 of file ec.c.

◆ ecInitDomainParameters()

void ecInitDomainParameters ( EcDomainParameters params)

Initialize EC domain parameters.

Parameters
[in]paramsPointer to the EC domain parameters to initialize

Definition at line 51 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 177 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 153 of file ec.c.

◆ ecIsPointAffine()

bool_t ecIsPointAffine ( const EcDomainParameters ecParams,
const EcPoint s 
)

Check whether the affine point S is on the curve.

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

Definition at line 565 of file ec.c.

◆ ecLoadDomainParameters()

error_t ecLoadDomainParameters ( EcDomainParameters params,
const EcCurveInfo curveInfo 
)

Load EC domain parameters.

Parameters
[out]paramsPointer to the structure to be initialized
[in]curveInfoElliptic curve parameters
Returns
Error code

Definition at line 90 of file ec.c.

◆ ecMulMod()

error_t ecMulMod ( const EcDomainParameters params,
Mpi r,
const Mpi a,
const Mpi b 
)

Fast modular multiplication.

Parameters
[in]paramsEC domain parameters
[out]rResulting integer R = (A * B) mod p
[in]aAn integer such as 0 <= A < p
[in]bAn integer such as 0 <= B < p
Returns
Error code

Definition at line 1363 of file ec.c.

◆ ecMult()

error_t ecMult ( const EcDomainParameters params,
EcPoint r,
const Mpi d,
const EcPoint s 
)

Scalar multiplication.

Parameters
[in]paramsEC domain parameters
[out]rResulting point R = d.S
[in]dAn integer d such as 0 <= d < p
[in]sEC point
Returns
Error code
Parameters
[in]ecParamsEC domain 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 986 of file ec.c.

◆ ecProjectify()

error_t ecProjectify ( const EcDomainParameters params,
EcPoint r,
const EcPoint s 
)

Compute projective representation.

Parameters
[in]paramsEC domain parameters
[out]rProjective representation of the point
[in]sAffine representation of the point
Returns
Error code

Definition at line 495 of file ec.c.

◆ ecSqrMod()

error_t ecSqrMod ( const EcDomainParameters params,
Mpi r,
const Mpi a 
)

Fast modular squaring.

Parameters
[in]paramsEC domain parameters
[out]rResulting integer R = (A ^ 2) mod p
[in]aAn integer such as 0 <= A < p
Returns
Error code

Definition at line 1395 of file ec.c.

◆ ecSubMod()

error_t ecSubMod ( const EcDomainParameters params,
Mpi r,
const Mpi a,
const Mpi b 
)

Fast modular subtraction.

Parameters
[in]paramsEC domain parameters
[out]rResulting integer R = (A - B) mod p
[in]aAn integer such as 0 <= A < p
[in]bAn integer such as 0 <= B < p
Returns
Error code

Definition at line 1334 of file ec.c.

◆ ecTwinMult()

error_t ecTwinMult ( const EcDomainParameters params,
EcPoint r,
const Mpi d0,
const EcPoint s,
const Mpi d1,
const EcPoint t 
)

Twin multiplication.

Parameters
[in]paramsEC domain 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 1135 of file ec.c.

Variable Documentation

◆ EC_PUBLIC_KEY_OID

const uint8_t EC_PUBLIC_KEY_OID[7]
extern

Definition at line 43 of file ec.c.