esp32_c6_crypto_pkc.c File Reference

ESP32-C6 public-key hardware accelerator. More...

#include "esp_crypto_lock.h"
#include "soc/pcr_reg.h"
#include "soc/hwcrypto_reg.h"
#include "esp_private/periph_ctrl.h"
#include "hardware/esp32_c6/esp32_c6_crypto.h"
#include "hardware/esp32_c6/esp32_c6_crypto_pkc.h"
#include "pkc/rsa.h"
#include "ecc/ec.h"
#include "ecc/ec_misc.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 
#define SECP224R1_PRIME_M   0xFFFFFFFF
 
#define SECP256K1_PRIME_M   0xD2253531
 
#define SECP256R1_PRIME_M   0x00000001
 
#define SECP384R1_PRIME_M   0x00000001
 
#define SECP521R1_PRIME_M   0x00000001
 
#define BRAINPOOLP256R1_PRIME_M   0xCEFD89B9
 
#define BRAINPOOLP384R1_PRIME_M   0xEA9EC825
 
#define BRAINPOOLP512R1_PRIME_M   0x7D89EFC5
 
#define FRP256V1_PRIME_M   0x164E1155
 
#define SM2_PRIME_M   0x00000001
 
#define CURVE25519_PRIME_M   0x286BCA1B
 
#define CURVE448_PRIME_M   0x00000001
 
#define SECP224R1_ORDER_M   0x6A1FC2EB
 
#define SECP256K1_ORDER_M   0x5588B13F
 
#define SECP256R1_ORDER_M   0xEE00BC4F
 
#define SECP384R1_ORDER_M   0xE88FDC45
 
#define SECP521R1_ORDER_M   0x79A995C7
 
#define BRAINPOOLP256R1_ORDER_M   0xCBB40EE9
 
#define BRAINPOOLP384R1_ORDER_M   0x5CB5BB93
 
#define BRAINPOOLP512R1_ORDER_M   0x0F1B7027
 
#define FRP256V1_ORDER_M   0x4FFF51DF
 
#define SM2_ORDER_M   0x72350975
 

Functions

void esp32c6RsaInit (void)
 RSA module initialization. More...
 
error_t mpiMul (Mpi *r, const Mpi *a, const Mpi *b)
 Multiple precision multiplication. More...
 
error_t mpiExpMod (Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
 Modular exponentiation. More...
 
void ecScalarMul (uint32_t *rl, uint32_t *rh, const uint32_t *a, const uint32_t *b, uint_t n)
 Multiplication of two integers. More...
 
void ecScalarSqr (uint32_t *r, const uint32_t *a, uint_t n)
 Squaring operation. More...
 
void ecFieldMulMod (const EcCurve *curve, uint32_t *r, const uint32_t *a, const uint32_t *b)
 Modular multiplication. More...
 
void ecFieldSqrMod (const EcCurve *curve, uint32_t *r, const uint32_t *a)
 Modular squaring. More...
 
void ecScalarMulMod (const EcCurve *curve, uint32_t *r, const uint32_t *a, const uint32_t *b)
 Modular multiplication. More...
 
void ecScalarSqrMod (const EcCurve *curve, uint32_t *r, const uint32_t *a)
 Modular squaring. More...
 

Variables

const uint32_t SECP224R1_PRIME_R2 [7]
 
const uint32_t SECP224R1_ORDER_R2 [7]
 
const uint32_t SECP256K1_PRIME_R2 [8]
 
const uint32_t SECP256K1_ORDER_R2 [8]
 
const uint32_t SECP256R1_PRIME_R2 [8]
 
const uint32_t SECP256R1_ORDER_R2 [8]
 
const uint32_t SECP384R1_PRIME_R2 [12]
 
const uint32_t SECP384R1_ORDER_R2 [12]
 
const uint32_t SECP521R1_PRIME_R2 [17]
 
const uint32_t SECP521R1_ORDER_R2 [17]
 
const uint32_t BRAINPOOLP256R1_PRIME_R2 [8]
 
const uint32_t BRAINPOOLP256R1_ORDER_R2 [8]
 
const uint32_t BRAINPOOLP384R1_PRIME_R2 [12]
 
const uint32_t BRAINPOOLP384R1_ORDER_R2 [12]
 
const uint32_t BRAINPOOLP512R1_PRIME_R2 [16]
 
const uint32_t BRAINPOOLP512R1_ORDER_R2 [16]
 
const uint32_t FRP256V1_PRIME_R2 [8]
 
const uint32_t FRP256V1_ORDER_R2 [8]
 
const uint32_t SM2_PRIME_R2 [8]
 
const uint32_t SM2_ORDER_R2 [8]
 

Detailed Description

ESP32-C6 public-key hardware accelerator.

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

Macro Definition Documentation

◆ BRAINPOOLP256R1_ORDER_M

#define BRAINPOOLP256R1_ORDER_M   0xCBB40EE9

Definition at line 69 of file esp32_c6_crypto_pkc.c.

◆ BRAINPOOLP256R1_PRIME_M

#define BRAINPOOLP256R1_PRIME_M   0xCEFD89B9

Definition at line 55 of file esp32_c6_crypto_pkc.c.

◆ BRAINPOOLP384R1_ORDER_M

#define BRAINPOOLP384R1_ORDER_M   0x5CB5BB93

Definition at line 70 of file esp32_c6_crypto_pkc.c.

◆ BRAINPOOLP384R1_PRIME_M

#define BRAINPOOLP384R1_PRIME_M   0xEA9EC825

Definition at line 56 of file esp32_c6_crypto_pkc.c.

◆ BRAINPOOLP512R1_ORDER_M

#define BRAINPOOLP512R1_ORDER_M   0x0F1B7027

Definition at line 71 of file esp32_c6_crypto_pkc.c.

◆ BRAINPOOLP512R1_PRIME_M

#define BRAINPOOLP512R1_PRIME_M   0x7D89EFC5

Definition at line 57 of file esp32_c6_crypto_pkc.c.

◆ CURVE25519_PRIME_M

#define CURVE25519_PRIME_M   0x286BCA1B

Definition at line 60 of file esp32_c6_crypto_pkc.c.

◆ CURVE448_PRIME_M

#define CURVE448_PRIME_M   0x00000001

Definition at line 61 of file esp32_c6_crypto_pkc.c.

◆ FRP256V1_ORDER_M

#define FRP256V1_ORDER_M   0x4FFF51DF

Definition at line 72 of file esp32_c6_crypto_pkc.c.

◆ FRP256V1_PRIME_M

#define FRP256V1_PRIME_M   0x164E1155

Definition at line 58 of file esp32_c6_crypto_pkc.c.

◆ SECP224R1_ORDER_M

#define SECP224R1_ORDER_M   0x6A1FC2EB

Definition at line 64 of file esp32_c6_crypto_pkc.c.

◆ SECP224R1_PRIME_M

#define SECP224R1_PRIME_M   0xFFFFFFFF

Definition at line 50 of file esp32_c6_crypto_pkc.c.

◆ SECP256K1_ORDER_M

#define SECP256K1_ORDER_M   0x5588B13F

Definition at line 65 of file esp32_c6_crypto_pkc.c.

◆ SECP256K1_PRIME_M

#define SECP256K1_PRIME_M   0xD2253531

Definition at line 51 of file esp32_c6_crypto_pkc.c.

◆ SECP256R1_ORDER_M

#define SECP256R1_ORDER_M   0xEE00BC4F

Definition at line 66 of file esp32_c6_crypto_pkc.c.

◆ SECP256R1_PRIME_M

#define SECP256R1_PRIME_M   0x00000001

Definition at line 52 of file esp32_c6_crypto_pkc.c.

◆ SECP384R1_ORDER_M

#define SECP384R1_ORDER_M   0xE88FDC45

Definition at line 67 of file esp32_c6_crypto_pkc.c.

◆ SECP384R1_PRIME_M

#define SECP384R1_PRIME_M   0x00000001

Definition at line 53 of file esp32_c6_crypto_pkc.c.

◆ SECP521R1_ORDER_M

#define SECP521R1_ORDER_M   0x79A995C7

Definition at line 68 of file esp32_c6_crypto_pkc.c.

◆ SECP521R1_PRIME_M

#define SECP521R1_PRIME_M   0x00000001

Definition at line 54 of file esp32_c6_crypto_pkc.c.

◆ SM2_ORDER_M

#define SM2_ORDER_M   0x72350975

Definition at line 73 of file esp32_c6_crypto_pkc.c.

◆ SM2_PRIME_M

#define SM2_PRIME_M   0x00000001

Definition at line 59 of file esp32_c6_crypto_pkc.c.

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file esp32_c6_crypto_pkc.c.

Function Documentation

◆ ecFieldMulMod()

void ecFieldMulMod ( const EcCurve curve,
uint32_t *  r,
const uint32_t *  a,
const uint32_t *  b 
)

Modular multiplication.

Parameters
[in]curveElliptic curve 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

Definition at line 634 of file esp32_c6_crypto_pkc.c.

◆ ecFieldSqrMod()

void ecFieldSqrMod ( const EcCurve curve,
uint32_t *  r,
const uint32_t *  a 
)

Modular squaring.

Parameters
[in]curveElliptic curve parameters
[out]rResulting integer R = A^2 mod p
[in]aAn integer such as 0 <= A < p

Definition at line 777 of file esp32_c6_crypto_pkc.c.

◆ ecScalarMul()

void ecScalarMul ( uint32_t *  rl,
uint32_t *  rh,
const uint32_t *  a,
const uint32_t *  b,
uint_t  n 
)

Multiplication of two integers.

Parameters
[out]rlLow part of the result R = (A * B) mod (2^32)^n
[out]rhHigh part of the result R = (A * B) / (2^32)^n
[in]aAn integer such as 0 <= A < (2^32)^n
[in]bAn integer such as 0 <= B < (2^32)^n
[in]nSize of the operands, in words

Definition at line 543 of file esp32_c6_crypto_pkc.c.

◆ ecScalarMulMod()

void ecScalarMulMod ( const EcCurve curve,
uint32_t *  r,
const uint32_t *  a,
const uint32_t *  b 
)

Modular multiplication.

Parameters
[in]curveElliptic curve parameters
[out]rResulting integer R = (A * B) mod q
[in]aAn integer such as 0 <= A < q
[in]bAn integer such as 0 <= B < q

Definition at line 792 of file esp32_c6_crypto_pkc.c.

◆ ecScalarSqr()

void ecScalarSqr ( uint32_t *  r,
const uint32_t *  a,
uint_t  n 
)

Squaring operation.

Parameters
[out]rResult R = A ^ 2
[in]aAn integer such as 0 <= A < (2^32)^n
[in]nSize of the integer A, in words

Definition at line 619 of file esp32_c6_crypto_pkc.c.

◆ ecScalarSqrMod()

void ecScalarSqrMod ( const EcCurve curve,
uint32_t *  r,
const uint32_t *  a 
)

Modular squaring.

Parameters
[in]curveElliptic curve parameters
[out]rResulting integer R = A^2 mod q
[in]aAn integer such as 0 <= A < q

Definition at line 935 of file esp32_c6_crypto_pkc.c.

◆ esp32c6RsaInit()

void esp32c6RsaInit ( void  )

RSA module initialization.

Definition at line 210 of file esp32_c6_crypto_pkc.c.

◆ mpiExpMod()

error_t mpiExpMod ( Mpi r,
const Mpi a,
const Mpi e,
const Mpi p 
)

Modular exponentiation.

Parameters
[out]rResulting integer R = A ^ E mod P
[in]aPointer to a multiple precision integer
[in]eExponent
[in]pModulus
Returns
Error code

Definition at line 357 of file esp32_c6_crypto_pkc.c.

◆ mpiMul()

error_t mpiMul ( Mpi r,
const Mpi a,
const Mpi b 
)

Multiple precision multiplication.

Parameters
[out]rResulting integer R = A * B
[in]aFirst operand A
[in]bSecond operand B
Returns
Error code

Definition at line 237 of file esp32_c6_crypto_pkc.c.

Variable Documentation

◆ BRAINPOOLP256R1_ORDER_R2

const uint32_t BRAINPOOLP256R1_ORDER_R2[8]
Initial value:
=
{
0x3312FCA6, 0xE1D8D8DE, 0x1134E4A0, 0xF35D176A, 0x6C815CB0, 0x9B7F25E7, 0xC3236762, 0x0B25F1B9
}

Definition at line 148 of file esp32_c6_crypto_pkc.c.

◆ BRAINPOOLP256R1_PRIME_R2

const uint32_t BRAINPOOLP256R1_PRIME_R2[8]
Initial value:
=
{
0xA6465B6C, 0x8CFEDF7B, 0x614D4F4D, 0x5CCE4C26, 0x6B1AC807, 0xA1ECDACD, 0xE5957FA8, 0x4717AA21
}

Definition at line 142 of file esp32_c6_crypto_pkc.c.

◆ BRAINPOOLP384R1_ORDER_R2

const uint32_t BRAINPOOLP384R1_ORDER_R2[12]
Initial value:
=
{
0xDE771C8E, 0xAC4ED3A2, 0x2F2B6B6E, 0x37264E20, 0x9802688A, 0x2A927E3B, 0x52D748FF, 0x574A74CB,
0x65165FDB, 0x8F886DC9, 0x614E97C2, 0x0CE8941A
}

Definition at line 161 of file esp32_c6_crypto_pkc.c.

◆ BRAINPOOLP384R1_PRIME_R2

const uint32_t BRAINPOOLP384R1_PRIME_R2[12]
Initial value:
=
{
0x40B64BDE, 0x087CEFFF, 0x3D7FD965, 0x53528334, 0xC9940899, 0x8E28F99C, 0x9918D5AF, 0x62140191,
0xA57E052C, 0xD5C6EF3B, 0x178DF842, 0x36BF6883
}

Definition at line 154 of file esp32_c6_crypto_pkc.c.

◆ BRAINPOOLP512R1_ORDER_R2

const uint32_t BRAINPOOLP512R1_ORDER_R2[16]
Initial value:
=
{
0xCDA81671, 0xD2A3681E, 0x95283DDD, 0x0886B758, 0x33B7627F, 0x3EC64BD0, 0x2F0207E8, 0xA6F230C7,
0x3B790DE3, 0xD7F9CC26, 0x2F16BBDF, 0x723C37A2, 0x194B2E56, 0x95DF1B4C, 0x718407B0, 0xA794586A
}

Definition at line 175 of file esp32_c6_crypto_pkc.c.

◆ BRAINPOOLP512R1_PRIME_R2

const uint32_t BRAINPOOLP512R1_PRIME_R2[16]
Initial value:
=
{
0x6158F205, 0x49AD144A, 0x27157905, 0x793FB130, 0x905AFFD3, 0x53B7F9BC, 0x83514A25, 0xE0C19A77,
0xD5898057, 0x19486FD8, 0xD42BFF83, 0xA16DAA5F, 0x2056EECC, 0x202E1940, 0xA9FF6450, 0x3C4C9D05
}

Definition at line 168 of file esp32_c6_crypto_pkc.c.

◆ FRP256V1_ORDER_R2

const uint32_t FRP256V1_ORDER_R2[8]
Initial value:
=
{
0xF849D44D, 0x1416B735, 0xBCC2D0E1, 0xB551ADB5, 0xC380D52D, 0xCFB26475, 0x15C243BB, 0x0DF1A20D
}

Definition at line 188 of file esp32_c6_crypto_pkc.c.

◆ FRP256V1_PRIME_R2

const uint32_t FRP256V1_PRIME_R2[8]
Initial value:
=
{
0xC99F1513, 0xB0C24E77, 0x0C960F92, 0x846F8083, 0xCE137EEE, 0x62B7012F, 0x88EB98AC, 0xB02C8F9F
}

Definition at line 182 of file esp32_c6_crypto_pkc.c.

◆ SECP224R1_ORDER_R2

const uint32_t SECP224R1_ORDER_R2[7]
Initial value:
=
{
0x3AD01289, 0x6BDAAE6C, 0x97A54552, 0x6AD09D91, 0xB1E97961, 0x1822BC47, 0xD4BAA4CF
}

Definition at line 82 of file esp32_c6_crypto_pkc.c.

◆ SECP224R1_PRIME_R2

const uint32_t SECP224R1_PRIME_R2[7]
Initial value:
=
{
0x00000001, 0x00000000, 0x00000000, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000
}

Definition at line 76 of file esp32_c6_crypto_pkc.c.

◆ SECP256K1_ORDER_R2

const uint32_t SECP256K1_ORDER_R2[8]
Initial value:
=
{
0x67D7D140, 0x896CF214, 0x0E7CF878, 0x741496C2, 0x5BCD07C6, 0xE697F5E4, 0x81C69BC5, 0x9D671CD5
}

Definition at line 94 of file esp32_c6_crypto_pkc.c.

◆ SECP256K1_PRIME_R2

const uint32_t SECP256K1_PRIME_R2[8]
Initial value:
=
{
0x000E90A1, 0x000007A2, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
}

Definition at line 88 of file esp32_c6_crypto_pkc.c.

◆ SECP256R1_ORDER_R2

const uint32_t SECP256R1_ORDER_R2[8]
Initial value:
=
{
0xBE79EEA2, 0x83244C95, 0x49BD6FA6, 0x4699799C, 0x2B6BEC59, 0x2845B239, 0xF3D95620, 0x66E12D94
}

Definition at line 106 of file esp32_c6_crypto_pkc.c.

◆ SECP256R1_PRIME_R2

const uint32_t SECP256R1_PRIME_R2[8]
Initial value:
=
{
0x00000003, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFB, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFD, 0x00000004
}

Definition at line 100 of file esp32_c6_crypto_pkc.c.

◆ SECP384R1_ORDER_R2

const uint32_t SECP384R1_ORDER_R2[12]
Initial value:
=
{
0x19B409A9, 0x2D319B24, 0xDF1AA419, 0xFF3D81E5, 0xFCB82947, 0xBC3E483A, 0x4AAB1CC5, 0xD40D4917,
0x28266895, 0x3FB05B7A, 0x2B39BF21, 0x0C84EE01
}

Definition at line 119 of file esp32_c6_crypto_pkc.c.

◆ SECP384R1_PRIME_R2

const uint32_t SECP384R1_PRIME_R2[12]
Initial value:
=
{
0x00000001, 0xFFFFFFFE, 0x00000000, 0x00000002, 0x00000000, 0xFFFFFFFE, 0x00000000, 0x00000002,
0x00000001, 0x00000000, 0x00000000, 0x00000000
}

Definition at line 112 of file esp32_c6_crypto_pkc.c.

◆ SECP521R1_ORDER_R2

const uint32_t SECP521R1_ORDER_R2[17]
Initial value:
=
{
0x61C64CA7, 0x1163115A, 0x4374A642, 0x18354A56, 0x0791D9DC, 0x5D4DD6D3, 0xD3402705, 0x4FB35B72,
0xB7756E3A, 0xCFF3D142, 0xA8E567BC, 0x5BCC6D61, 0x492D0D45, 0x2D8E03D1, 0x8C44383D, 0x5B5A3AFE,
0x0000019A
}

Definition at line 134 of file esp32_c6_crypto_pkc.c.

◆ SECP521R1_PRIME_R2

const uint32_t SECP521R1_PRIME_R2[17]
Initial value:
=
{
0x00000000, 0x00004000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000
}

Definition at line 126 of file esp32_c6_crypto_pkc.c.

◆ SM2_ORDER_R2

const uint32_t SM2_ORDER_R2[8]
Initial value:
=
{
0x7C114F20, 0x901192AF, 0xDE6FA2FA, 0x3464504A, 0x3AFFE0D4, 0x620FC84C, 0xA22B3D3B, 0x1EB5E412
}

Definition at line 200 of file esp32_c6_crypto_pkc.c.

◆ SM2_PRIME_R2

const uint32_t SM2_PRIME_R2[8]
Initial value:
=
{
0x00000003, 0x00000002, 0xFFFFFFFF, 0x00000002, 0x00000001, 0x00000001, 0x00000002, 0x00000004
}

Definition at line 194 of file esp32_c6_crypto_pkc.c.