ec_curves.c File Reference

Elliptic curves. More...

#include "core/crypto.h"
#include "ecc/ec_curves.h"
#include "encoding/oid.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 
#define CLEAR_WORD32(a, i, n)   osMemset((a)->data + i, 0, n * MPI_INT_SIZE);
 
#define COPY_WORD32(a, i, b, j, n)   osMemcpy((a)->data + i, (b)->data + j, n * MPI_INT_SIZE);
 

Functions

error_t secp128r1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp128r1 curve) More...
 
error_t secp128r2Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp128r2 curve) More...
 
error_t secp160k1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp160k1 curve) More...
 
error_t secp160r1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp160r1 curve) More...
 
error_t secp160r2Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp160r2 curve) More...
 
error_t secp192k1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp192k1 curve) More...
 
error_t secp192r1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp192r1 curve) More...
 
error_t secp224k1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp224k1 curve) More...
 
error_t secp224r1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp224r1 curve) More...
 
error_t secp256k1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp256k1 curve) More...
 
error_t secp256r1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp256r1 curve) More...
 
error_t secp384r1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp384r1 curve) More...
 
error_t secp521r1Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (secp521r1 curve) More...
 
error_t sm2Mod (Mpi *a, const Mpi *p)
 Fast modular reduction (SM2 curve) More...
 
const EcCurveInfoecGetCurveInfo (const uint8_t *oid, size_t length)
 Get the elliptic curve that matches the specified OID. More...
 

Variables

const uint8_t SECP112R1_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x06}
 
const uint8_t SECP112R2_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x07}
 
const uint8_t SECP128R1_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x1C}
 
const uint8_t SECP128R2_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x1D}
 
const uint8_t SECP160K1_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x09}
 
const uint8_t SECP160R1_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x08}
 
const uint8_t SECP160R2_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x1E}
 
const uint8_t SECP192K1_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x1F}
 
const uint8_t SECP192R1_OID [8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x01}
 
const uint8_t SECP224K1_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x20}
 
const uint8_t SECP224R1_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x21}
 
const uint8_t SECP256K1_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x0A}
 
const uint8_t SECP256R1_OID [8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07}
 
const uint8_t SECP384R1_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x22}
 
const uint8_t SECP521R1_OID [5] = {0x2B, 0x81, 0x04, 0x00, 0x23}
 
const uint8_t BRAINPOOLP160R1_OID [9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x01}
 
const uint8_t BRAINPOOLP192R1_OID [9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x03}
 
const uint8_t BRAINPOOLP224R1_OID [9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x05}
 
const uint8_t BRAINPOOLP256R1_OID [9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x07}
 
const uint8_t BRAINPOOLP320R1_OID [9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x09}
 
const uint8_t BRAINPOOLP384R1_OID [9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B}
 
const uint8_t BRAINPOOLP512R1_OID [9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D}
 
const uint8_t SM2_OID [8] = {0x2A, 0x81, 0x1C, 0xCF, 0x55, 0x01, 0x82, 0x2D}
 
const uint8_t X25519_OID [3] = {0x2B, 0x65, 0x6E}
 
const uint8_t X448_OID [3] = {0x2B, 0x65, 0x6F}
 
const uint8_t ED25519_OID [3] = {0x2B, 0x65, 0x70}
 
const uint8_t ED448_OID [3] = {0x2B, 0x65, 0x71}
 
const EcCurveInfo secp112r1Curve
 secp112r1 elliptic curve More...
 
const EcCurveInfo secp112r2Curve
 secp112r2 elliptic curve More...
 
const EcCurveInfo secp128r1Curve
 secp128r1 elliptic curve More...
 
const EcCurveInfo secp128r2Curve
 secp128r2 elliptic curve More...
 
const EcCurveInfo secp160k1Curve
 secp160k1 elliptic curve More...
 
const EcCurveInfo secp160r1Curve
 secp160r1 elliptic curve More...
 
const EcCurveInfo secp160r2Curve
 secp160r2 elliptic curve More...
 
const EcCurveInfo secp192k1Curve
 secp192k1 elliptic curve More...
 
const EcCurveInfo secp192r1Curve
 secp192r1 elliptic curve More...
 
const EcCurveInfo secp224k1Curve
 secp224k1 elliptic curve More...
 
const EcCurveInfo secp224r1Curve
 secp224r1 elliptic curve More...
 
const EcCurveInfo secp256k1Curve
 secp256k1 elliptic curve More...
 
const EcCurveInfo secp256r1Curve
 secp256r1 elliptic curve More...
 
const EcCurveInfo secp384r1Curve
 secp384r1 elliptic curve More...
 
const EcCurveInfo secp521r1Curve
 secp521r1 elliptic curve More...
 
const EcCurveInfo brainpoolP160r1Curve
 brainpoolP160r1 elliptic curve More...
 
const EcCurveInfo brainpoolP192r1Curve
 brainpoolP192r1 elliptic curve More...
 
const EcCurveInfo brainpoolP224r1Curve
 brainpoolP224r1 elliptic curve More...
 
const EcCurveInfo brainpoolP256r1Curve
 brainpoolP256r1 elliptic curve More...
 
const EcCurveInfo brainpoolP320r1Curve
 brainpoolP320r1 elliptic curve More...
 
const EcCurveInfo brainpoolP384r1Curve
 brainpoolP384r1 elliptic curve More...
 
const EcCurveInfo brainpoolP512r1Curve
 brainpoolP512r1 elliptic curve More...
 
const EcCurveInfo sm2Curve
 SM2 elliptic curve. More...
 
const EcCurveInfo x25519Curve
 Curve25519 elliptic curve. More...
 
const EcCurveInfo x448Curve
 Curve448 elliptic curve. More...
 
const EcCurveInfo ed25519Curve
 Ed25519 elliptic curve. More...
 
const EcCurveInfo ed448Curve
 Ed448 elliptic curve. More...
 

Detailed Description

Elliptic curves.

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_curves.c.

Macro Definition Documentation

◆ CLEAR_WORD32

#define CLEAR_WORD32 (   a,
  i,
  n 
)    osMemset((a)->data + i, 0, n * MPI_INT_SIZE);

Definition at line 44 of file ec_curves.c.

◆ COPY_WORD32

#define COPY_WORD32 (   a,
  i,
  b,
  j,
  n 
)    osMemcpy((a)->data + i, (b)->data + j, n * MPI_INT_SIZE);

Definition at line 45 of file ec_curves.c.

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file ec_curves.c.

Function Documentation

◆ ecGetCurveInfo()

const EcCurveInfo* ecGetCurveInfo ( const uint8_t *  oid,
size_t  length 
)

Get the elliptic curve that matches the specified OID.

Parameters
[in]oidObject identifier
[in]lengthOID length
Returns
Elliptic curve domain parameters

Definition at line 2374 of file ec_curves.c.

◆ secp128r1Mod()

error_t secp128r1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp128r1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1402 of file ec_curves.c.

◆ secp128r2Mod()

error_t secp128r2Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp128r2 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1450 of file ec_curves.c.

◆ secp160k1Mod()

error_t secp160k1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp160k1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1498 of file ec_curves.c.

◆ secp160r1Mod()

error_t secp160r1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp160r1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1549 of file ec_curves.c.

◆ secp160r2Mod()

error_t secp160r2Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp160r2 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1597 of file ec_curves.c.

◆ secp192k1Mod()

error_t secp192k1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp192k1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1648 of file ec_curves.c.

◆ secp192r1Mod()

error_t secp192r1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp192r1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1699 of file ec_curves.c.

◆ secp224k1Mod()

error_t secp224k1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp224k1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1766 of file ec_curves.c.

◆ secp224r1Mod()

error_t secp224r1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp224r1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1817 of file ec_curves.c.

◆ secp256k1Mod()

error_t secp256k1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp256k1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1892 of file ec_curves.c.

◆ secp256r1Mod()

error_t secp256r1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp256r1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 1943 of file ec_curves.c.

◆ secp384r1Mod()

error_t secp384r1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp384r1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 2059 of file ec_curves.c.

◆ secp521r1Mod()

error_t secp521r1Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (secp521r1 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 2174 of file ec_curves.c.

◆ sm2Mod()

error_t sm2Mod ( Mpi a,
const Mpi p 
)

Fast modular reduction (SM2 curve)

Parameters
[in,out]aThis function accept an integer less than p^2 as input and return (a mod p) as output
[in]pPrime modulus

Definition at line 2220 of file ec_curves.c.

Variable Documentation

◆ BRAINPOOLP160R1_OID

const uint8_t BRAINPOOLP160R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x01}

Definition at line 78 of file ec_curves.c.

◆ brainpoolP160r1Curve

const EcCurveInfo brainpoolP160r1Curve

brainpoolP160r1 elliptic curve

Definition at line 799 of file ec_curves.c.

◆ BRAINPOOLP192R1_OID

const uint8_t BRAINPOOLP192R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x03}

Definition at line 80 of file ec_curves.c.

◆ brainpoolP192r1Curve

const EcCurveInfo brainpoolP192r1Curve

brainpoolP192r1 elliptic curve

Definition at line 845 of file ec_curves.c.

◆ BRAINPOOLP224R1_OID

const uint8_t BRAINPOOLP224R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x05}

Definition at line 82 of file ec_curves.c.

◆ brainpoolP224r1Curve

const EcCurveInfo brainpoolP224r1Curve

brainpoolP224r1 elliptic curve

Definition at line 891 of file ec_curves.c.

◆ BRAINPOOLP256R1_OID

const uint8_t BRAINPOOLP256R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x07}

Definition at line 84 of file ec_curves.c.

◆ brainpoolP256r1Curve

const EcCurveInfo brainpoolP256r1Curve

brainpoolP256r1 elliptic curve

Definition at line 937 of file ec_curves.c.

◆ BRAINPOOLP320R1_OID

const uint8_t BRAINPOOLP320R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x09}

Definition at line 86 of file ec_curves.c.

◆ brainpoolP320r1Curve

const EcCurveInfo brainpoolP320r1Curve

brainpoolP320r1 elliptic curve

Definition at line 983 of file ec_curves.c.

◆ BRAINPOOLP384R1_OID

const uint8_t BRAINPOOLP384R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B}

Definition at line 88 of file ec_curves.c.

◆ brainpoolP384r1Curve

const EcCurveInfo brainpoolP384r1Curve

brainpoolP384r1 elliptic curve

Definition at line 1035 of file ec_curves.c.

◆ BRAINPOOLP512R1_OID

const uint8_t BRAINPOOLP512R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D}

Definition at line 90 of file ec_curves.c.

◆ brainpoolP512r1Curve

const EcCurveInfo brainpoolP512r1Curve

brainpoolP512r1 elliptic curve

Definition at line 1087 of file ec_curves.c.

◆ ED25519_OID

const uint8_t ED25519_OID[3] = {0x2B, 0x65, 0x70}

Definition at line 98 of file ec_curves.c.

◆ ed25519Curve

const EcCurveInfo ed25519Curve

Ed25519 elliptic curve.

Definition at line 1295 of file ec_curves.c.

◆ ED448_OID

const uint8_t ED448_OID[3] = {0x2B, 0x65, 0x71}

Definition at line 100 of file ec_curves.c.

◆ ed448Curve

const EcCurveInfo ed448Curve

Ed448 elliptic curve.

Definition at line 1341 of file ec_curves.c.

◆ SECP112R1_OID

const uint8_t SECP112R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x06}

Definition at line 48 of file ec_curves.c.

◆ secp112r1Curve

const EcCurveInfo secp112r1Curve

secp112r1 elliptic curve

Definition at line 109 of file ec_curves.c.

◆ SECP112R2_OID

const uint8_t SECP112R2_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x07}

Definition at line 50 of file ec_curves.c.

◆ secp112r2Curve

const EcCurveInfo secp112r2Curve

secp112r2 elliptic curve

Definition at line 149 of file ec_curves.c.

◆ SECP128R1_OID

const uint8_t SECP128R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x1C}

Definition at line 52 of file ec_curves.c.

◆ secp128r1Curve

const EcCurveInfo secp128r1Curve

secp128r1 elliptic curve

Definition at line 189 of file ec_curves.c.

◆ SECP128R2_OID

const uint8_t SECP128R2_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x1D}

Definition at line 54 of file ec_curves.c.

◆ secp128r2Curve

const EcCurveInfo secp128r2Curve

secp128r2 elliptic curve

Definition at line 229 of file ec_curves.c.

◆ SECP160K1_OID

const uint8_t SECP160K1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x09}

Definition at line 56 of file ec_curves.c.

◆ secp160k1Curve

const EcCurveInfo secp160k1Curve

secp160k1 elliptic curve

Definition at line 269 of file ec_curves.c.

◆ SECP160R1_OID

const uint8_t SECP160R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x08}

Definition at line 58 of file ec_curves.c.

◆ secp160r1Curve

const EcCurveInfo secp160r1Curve

secp160r1 elliptic curve

Definition at line 315 of file ec_curves.c.

◆ SECP160R2_OID

const uint8_t SECP160R2_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x1E}

Definition at line 60 of file ec_curves.c.

◆ secp160r2Curve

const EcCurveInfo secp160r2Curve

secp160r2 elliptic curve

Definition at line 361 of file ec_curves.c.

◆ SECP192K1_OID

const uint8_t SECP192K1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x1F}

Definition at line 62 of file ec_curves.c.

◆ secp192k1Curve

const EcCurveInfo secp192k1Curve

secp192k1 elliptic curve

Definition at line 407 of file ec_curves.c.

◆ SECP192R1_OID

const uint8_t SECP192R1_OID[8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x01}

Definition at line 64 of file ec_curves.c.

◆ secp192r1Curve

const EcCurveInfo secp192r1Curve

secp192r1 elliptic curve

Definition at line 453 of file ec_curves.c.

◆ SECP224K1_OID

const uint8_t SECP224K1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x20}

Definition at line 66 of file ec_curves.c.

◆ secp224k1Curve

const EcCurveInfo secp224k1Curve

secp224k1 elliptic curve

Definition at line 499 of file ec_curves.c.

◆ SECP224R1_OID

const uint8_t SECP224R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x21}

Definition at line 68 of file ec_curves.c.

◆ secp224r1Curve

const EcCurveInfo secp224r1Curve

secp224r1 elliptic curve

Definition at line 545 of file ec_curves.c.

◆ SECP256K1_OID

const uint8_t SECP256K1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x0A}

Definition at line 70 of file ec_curves.c.

◆ secp256k1Curve

const EcCurveInfo secp256k1Curve

secp256k1 elliptic curve

Definition at line 591 of file ec_curves.c.

◆ SECP256R1_OID

const uint8_t SECP256R1_OID[8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07}

Definition at line 72 of file ec_curves.c.

◆ secp256r1Curve

const EcCurveInfo secp256r1Curve

secp256r1 elliptic curve

Definition at line 637 of file ec_curves.c.

◆ SECP384R1_OID

const uint8_t SECP384R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x22}

Definition at line 74 of file ec_curves.c.

◆ secp384r1Curve

const EcCurveInfo secp384r1Curve

secp384r1 elliptic curve

Definition at line 683 of file ec_curves.c.

◆ SECP521R1_OID

const uint8_t SECP521R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x23}

Definition at line 76 of file ec_curves.c.

◆ secp521r1Curve

const EcCurveInfo secp521r1Curve

secp521r1 elliptic curve

Definition at line 735 of file ec_curves.c.

◆ SM2_OID

const uint8_t SM2_OID[8] = {0x2A, 0x81, 0x1C, 0xCF, 0x55, 0x01, 0x82, 0x2D}

Definition at line 92 of file ec_curves.c.

◆ sm2Curve

const EcCurveInfo sm2Curve

SM2 elliptic curve.

Definition at line 1145 of file ec_curves.c.

◆ X25519_OID

const uint8_t X25519_OID[3] = {0x2B, 0x65, 0x6E}

Definition at line 94 of file ec_curves.c.

◆ x25519Curve

const EcCurveInfo x25519Curve

Curve25519 elliptic curve.

Definition at line 1191 of file ec_curves.c.

◆ X448_OID

const uint8_t X448_OID[3] = {0x2B, 0x65, 0x6F}

Definition at line 96 of file ec_curves.c.

◆ x448Curve

const EcCurveInfo x448Curve

Curve448 elliptic curve.

Definition at line 1237 of file ec_curves.c.