ec.c File Reference

ECC (Elliptic Curve Cryptography) More...

#include "core/crypto.h"
#include "ecc/ec.h"
#include "ecc/curve25519.h"
#include "ecc/curve448.h"
#include "ecc/ed25519.h"
#include "ecc/ed448.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

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 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...
 
uint_t ecTwinMultF (uint_t t)
 An auxiliary function for the twin 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] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01}
 

Detailed Description

ECC (Elliptic Curve Cryptography)

License

Copyright (C) 2010-2018 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
1.9.0

Definition in file ec.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 30 of file ec.c.

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 582 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 1148 of file ec.c.

◆ ecAffinify()

error_t ecAffinify ( const EcDomainParameters params,
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

Definition at line 362 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 180 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 450 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 281 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 164 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 73 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 742 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 793 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 208 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 150 of file ec.c.

◆ ecInitDomainParameters()

void ecInitDomainParameters ( EcDomainParameters params)

Initialize EC domain parameters.

Parameters
[in]paramsPointer to the EC domain parameters to be initialized

Definition at line 53 of file ec.c.

◆ ecIsPointAffine()

bool_t ecIsPointAffine ( const EcDomainParameters params,
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

Definition at line 408 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 91 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 1206 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

Definition at line 829 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 338 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 1238 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 1177 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 978 of file ec.c.

◆ ecTwinMultF()

uint_t ecTwinMultF ( uint_t  t)

An auxiliary function for the twin multiplication.

Parameters
[in]tAn integer T such as 0 <= T <= 31
Returns
Output value

Definition at line 936 of file ec.c.

Variable Documentation

◆ EC_PUBLIC_KEY_OID

const uint8_t EC_PUBLIC_KEY_OID[7] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01}

Definition at line 45 of file ec.c.