stm32u5xx_crypto_pkc.c File Reference

STM32U5 public-key hardware accelerator (PKA) More...

#include "stm32u5xx.h"
#include "stm32u5xx_hal.h"
#include "core/crypto.h"
#include "hardware/stm32u5xx/stm32u5xx_crypto.h"
#include "hardware/stm32u5xx/stm32u5xx_crypto_pkc.h"
#include "pkc/rsa.h"
#include "ecc/ec.h"
#include "ecc/ec_misc.h"
#include "ecc/ecdsa.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t pkaInit (void)
 PKA module initialization. More...
 
void pkaImportArray (const uint8_t *src, size_t srcLen, uint_t destLen, uint_t offset)
 Import byte array. More...
 
void pkaImportScalar (const uint32_t *src, uint_t length, uint_t offset)
 Import scalar. More...
 
void pkaImportMpi (const Mpi *src, uint_t length, uint_t offset)
 Import multiple-precision integer. More...
 
void pkaExportScalar (uint32_t *dest, uint_t length, uint_t offset)
 Export scalar. More...
 
error_t pkaExportMpi (Mpi *dest, uint_t length, uint_t offset)
 Export multiple-precision integer. More...
 
error_t mpiExpMod (Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
 Modular exponentiation. More...
 
error_t pkaRsaCrtExp (const RsaPrivateKey *key, const Mpi *c, Mpi *m)
 Modular exponentiation with CRT. More...
 
error_t rsadp (const RsaPrivateKey *key, const Mpi *c, Mpi *m)
 RSA decryption primitive. 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 ecdsaGenerateSignature (const PrngAlgo *prngAlgo, void *prngContext, const EcPrivateKey *privateKey, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
 ECDSA signature generation. More...
 
error_t ecdsaVerifySignature (const EcPublicKey *publicKey, const uint8_t *digest, size_t digestLen, const EcdsaSignature *signature)
 ECDSA signature verification. More...
 

Detailed Description

STM32U5 public-key hardware accelerator (PKA)

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

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file stm32u5xx_crypto_pkc.c.

Function Documentation

◆ ecdsaGenerateSignature()

error_t ecdsaGenerateSignature ( const PrngAlgo prngAlgo,
void *  prngContext,
const EcPrivateKey privateKey,
const uint8_t *  digest,
size_t  digestLen,
EcdsaSignature signature 
)

ECDSA signature generation.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]privateKeySigner's EC private key
[in]digestDigest of the message to be signed
[in]digestLenLength in octets of the digest
[out]signature(R, S) integer pair
Returns
Error code

Definition at line 634 of file stm32u5xx_crypto_pkc.c.

◆ ecdsaVerifySignature()

error_t ecdsaVerifySignature ( const EcPublicKey publicKey,
const uint8_t *  digest,
size_t  digestLen,
const EcdsaSignature signature 
)

ECDSA signature verification.

Parameters
[in]publicKeySigner's EC public key
[in]digestDigest of the message whose signature is to be verified
[in]digestLenLength in octets of the digest
[in]signature(R, S) integer pair
Returns
Error code

Definition at line 767 of file stm32u5xx_crypto_pkc.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 < p
[in]sEC point
Returns
Error code

Definition at line 502 of file stm32u5xx_crypto_pkc.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 519 of file stm32u5xx_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 291 of file stm32u5xx_crypto_pkc.c.

◆ pkaExportMpi()

error_t pkaExportMpi ( Mpi dest,
uint_t  length,
uint_t  offset 
)

Export multiple-precision integer.

Parameters
[out]destPointer to the multiple-precision integer
[in]lengthLength of the operand, in bits
[in]offsetPKA ram offset
Returns
Error code

Definition at line 239 of file stm32u5xx_crypto_pkc.c.

◆ pkaExportScalar()

void pkaExportScalar ( uint32_t *  dest,
uint_t  length,
uint_t  offset 
)

Export scalar.

Parameters
[out]destPointer to the scalar
[in]lengthLength of the operand, in bits
[in]offsetPKA ram offset

Definition at line 216 of file stm32u5xx_crypto_pkc.c.

◆ pkaImportArray()

void pkaImportArray ( const uint8_t *  src,
size_t  srcLen,
uint_t  destLen,
uint_t  offset 
)

Import byte array.

Parameters
[in]srcPointer to the byte array
[in]srcLenLength of the array to be copied, in bytes
[in]destLenLength of the operand, in bits
[in]offsetPKA ram offset

Definition at line 85 of file stm32u5xx_crypto_pkc.c.

◆ pkaImportMpi()

void pkaImportMpi ( const Mpi src,
uint_t  length,
uint_t  offset 
)

Import multiple-precision integer.

Parameters
[in]srcPointer to the multiple-precision integer
[in]lengthLength of the operand, in bits
[in]offsetPKA ram offset

Definition at line 180 of file stm32u5xx_crypto_pkc.c.

◆ pkaImportScalar()

void pkaImportScalar ( const uint32_t *  src,
uint_t  length,
uint_t  offset 
)

Import scalar.

Parameters
[in]srcPointer to the scalar
[in]lengthLength of the operand, in bits
[in]offsetPKA ram offset

Definition at line 147 of file stm32u5xx_crypto_pkc.c.

◆ pkaInit()

error_t pkaInit ( void  )

PKA module initialization.

Returns
Error code

Definition at line 55 of file stm32u5xx_crypto_pkc.c.

◆ pkaRsaCrtExp()

error_t pkaRsaCrtExp ( const RsaPrivateKey key,
const Mpi c,
Mpi m 
)

Modular exponentiation with CRT.

Parameters
[in]keyRSA public key
[in]mMessage representative
[out]cCiphertext representative
Returns
Error code

Definition at line 376 of file stm32u5xx_crypto_pkc.c.

◆ rsadp()

error_t rsadp ( const RsaPrivateKey key,
const Mpi c,
Mpi m 
)

RSA decryption primitive.

Parameters
[in]keyRSA private key
[in]cCiphertext representative
[out]mMessage representative
Returns
Error code

Definition at line 459 of file stm32u5xx_crypto_pkc.c.