gd32w5xx_crypto_pkc.c File Reference

GD32W5 public-key hardware accelerator (PKCAU) More...

#include "gd32w51x.h"
#include "core/crypto.h"
#include "hardware/gd32w5xx/gd32w5xx_crypto.h"
#include "hardware/gd32w5xx/gd32w5xx_crypto_pkc.h"
#include "pkc/rsa.h"
#include "ecc/ec.h"
#include "ecc/ecdsa.h"
#include "ecc/curve25519.h"
#include "ecc/curve448.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t pkcauInit (void)
 PKCAU module initialization. More...
 
void pkcauImportArray (const uint8_t *src, size_t srcLen, uint_t destLen, uint_t offset)
 Import byte array. More...
 
void pkcauImportMpi (const Mpi *a, uint_t length, uint_t offset)
 Import multiple-precision integer. More...
 
error_t pkcauExportMpi (Mpi *r, uint_t length, uint_t offset)
 Export multiple-precision integer. More...
 
error_t pkcauModExp (Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
 Modular exponentiation. More...
 
error_t pkcauRsaCrtExp (const RsaPrivateKey *key, const Mpi *c, Mpi *m)
 Modular exponentiation with CRT. More...
 
error_t rsaep (const RsaPublicKey *key, const Mpi *m, Mpi *c)
 RSA encryption primitive. More...
 
error_t rsadp (const RsaPrivateKey *key, const Mpi *c, Mpi *m)
 RSA decryption primitive. More...
 
error_t ecMult (const EcDomainParameters *params, EcPoint *r, const Mpi *d, const EcPoint *s)
 Scalar multiplication. More...
 
error_t ecdsaGenerateSignature (const PrngAlgo *prngAlgo, void *prngContext, const EcDomainParameters *params, const EcPrivateKey *privateKey, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
 ECDSA signature generation. More...
 
error_t ecdsaVerifySignature (const EcDomainParameters *params, const EcPublicKey *publicKey, const uint8_t *digest, size_t digestLen, const EcdsaSignature *signature)
 ECDSA signature verification. More...
 
void curve25519Mul (uint32_t *r, const uint32_t *a, const uint32_t *b)
 Modular multiplication. More...
 
void curve448Mul (uint32_t *r, const uint32_t *a, const uint32_t *b)
 Modular multiplication. More...
 

Detailed Description

GD32W5 public-key hardware accelerator (PKCAU)

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.4

Definition in file gd32w5xx_crypto_pkc.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file gd32w5xx_crypto_pkc.c.

Function Documentation

◆ curve25519Mul()

void curve25519Mul ( uint32_t *  r,
const uint32_t *  a,
const uint32_t *  b 
)

Modular multiplication.

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 847 of file gd32w5xx_crypto_pkc.c.

◆ curve448Mul()

void curve448Mul ( uint32_t *  r,
const uint32_t *  a,
const uint32_t *  b 
)

Modular multiplication.

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 969 of file gd32w5xx_crypto_pkc.c.

◆ ecdsaGenerateSignature()

error_t ecdsaGenerateSignature ( const PrngAlgo prngAlgo,
void *  prngContext,
const EcDomainParameters params,
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]paramsEC domain parameters
[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 608 of file gd32w5xx_crypto_pkc.c.

◆ ecdsaVerifySignature()

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

ECDSA signature verification.

Parameters
[in]paramsEC domain 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 733 of file gd32w5xx_crypto_pkc.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 512 of file gd32w5xx_crypto_pkc.c.

◆ pkcauExportMpi()

error_t pkcauExportMpi ( Mpi r,
uint_t  length,
uint_t  offset 
)

Export multiple-precision integer.

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

Definition at line 182 of file gd32w5xx_crypto_pkc.c.

◆ pkcauImportArray()

void pkcauImportArray ( 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]offsetPKCAU ram offset

Definition at line 85 of file gd32w5xx_crypto_pkc.c.

◆ pkcauImportMpi()

void pkcauImportMpi ( const Mpi a,
uint_t  length,
uint_t  offset 
)

Import multiple-precision integer.

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

Definition at line 146 of file gd32w5xx_crypto_pkc.c.

◆ pkcauInit()

error_t pkcauInit ( void  )

PKCAU module initialization.

Returns
Error code

Definition at line 55 of file gd32w5xx_crypto_pkc.c.

◆ pkcauModExp()

error_t pkcauModExp ( 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 232 of file gd32w5xx_crypto_pkc.c.

◆ pkcauRsaCrtExp()

error_t pkcauRsaCrtExp ( 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 312 of file gd32w5xx_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 471 of file gd32w5xx_crypto_pkc.c.

◆ rsaep()

error_t rsaep ( const RsaPublicKey key,
const Mpi m,
Mpi c 
)

RSA encryption primitive.

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

Definition at line 441 of file gd32w5xx_crypto_pkc.c.