pic32cx_bz_crypto_pkc.c File Reference

PIC32CX BZ2 public-key hardware accelerator (PUKCC) More...

#include "pic32c.h"
#include "pukcc/CryptoLib_typedef_pb.h"
#include "pukcc/CryptoLib_Headers_pb.h"
#include "core/crypto.h"
#include "hardware/pic32cx_bz/pic32cx_bz_crypto.h"
#include "hardware/pic32cx_bz/pic32cx_bz_crypto_pkc.h"
#include "pkc/rsa.h"
#include "ecc/ec.h"
#include "ecc/ecdsa.h"
#include "mpi/mpi.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t pukccInit (void)
 Initialize PUKCC module. More...
 
uint8_t * pukccImportArray (uint8_t **dest, const uint8_t *array, size_t arrayLen, size_t totalLen)
 Import byte array. More...
 
uint8_t * pukccImportMpi (uint8_t **dest, const Mpi *src, size_t totalLen)
 Import multiple-precision integer. More...
 
uint8_t * pukccWorkspace (uint8_t **dest, size_t totalLen)
 Initialize workspace area. More...
 
error_t mpiMul (Mpi *r, const Mpi *a, const Mpi *b)
 Multiple precision multiplication. More...
 
error_t mpiMod2 (Mpi *r, const Mpi *a, const Mpi *p)
 Modulo operation. More...
 
error_t mpiInvMod (Mpi *r, const Mpi *a, const Mpi *p)
 Modular inverse. More...
 
error_t mpiExpMod (Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
 Modular exponentiation. More...
 
error_t mpiCheckProbablePrime (const Mpi *a)
 Test whether a number is probable prime. More...
 
error_t rsadp (const RsaPrivateKey *key, const Mpi *c, Mpi *m)
 RSA decryption primitive. More...
 
bool_t ecIsPointAffine (const EcDomainParameters *ecParams, const EcPoint *s)
 Check whether the affine point S is on the curve. More...
 
error_t ecAffinify (const EcDomainParameters *ecParams, EcPoint *r, const EcPoint *s)
 Recover affine representation. More...
 
error_t ecMult (const EcDomainParameters *ecParams, EcPoint *r, const Mpi *d, const EcPoint *s)
 Scalar multiplication. More...
 
error_t ecdsaGenerateSignature (const PrngAlgo *prngAlgo, void *prngContext, const EcDomainParameters *ecParams, const EcPrivateKey *privateKey, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
 ECDSA signature generation. More...
 
error_t ecdsaVerifySignature (const EcDomainParameters *ecParams, const EcPublicKey *publicKey, const uint8_t *digest, size_t digestLen, const EcdsaSignature *signature)
 ECDSA signature verification. More...
 

Variables

PPUKCL_PARAM pvPUKCLParam
 
PUKCL_PARAM PUKCLParam
 

Detailed Description

PIC32CX BZ2 public-key hardware accelerator (PUKCC)

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

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file pic32cx_bz_crypto_pkc.c.

Function Documentation

◆ ecAffinify()

error_t ecAffinify ( const EcDomainParameters ecParams,
EcPoint r,
const EcPoint s 
)

Recover affine representation.

Parameters
[in]ecParamsEC domain parameters
[out]rAffine representation of the point
[in]sProjective representation of the point
Returns
Error code

Definition at line 954 of file pic32cx_bz_crypto_pkc.c.

◆ ecdsaGenerateSignature()

error_t ecdsaGenerateSignature ( const PrngAlgo prngAlgo,
void *  prngContext,
const EcDomainParameters ecParams,
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]ecParamsEC domain parameters
[in]privateKeySigner's ECDSA 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 1192 of file pic32cx_bz_crypto_pkc.c.

◆ ecdsaVerifySignature()

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

ECDSA signature verification.

Parameters
[in]ecParamsEC domain parameters
[in]publicKeySigner's ECDSA 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 1353 of file pic32cx_bz_crypto_pkc.c.

◆ ecIsPointAffine()

bool_t ecIsPointAffine ( const EcDomainParameters ecParams,
const EcPoint s 
)

Check whether the affine point S is on the curve.

Parameters
[in]ecParamsEC domain parameters
[in]sAffine representation of the point
Returns
TRUE if the affine point S is on the curve, else FALSE

Definition at line 855 of file pic32cx_bz_crypto_pkc.c.

◆ ecMult()

error_t ecMult ( const EcDomainParameters ecParams,
EcPoint r,
const Mpi d,
const EcPoint s 
)

Scalar multiplication.

Parameters
[in]ecParamsEC 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 1064 of file pic32cx_bz_crypto_pkc.c.

◆ mpiCheckProbablePrime()

error_t mpiCheckProbablePrime ( const Mpi a)

Test whether a number is probable prime.

Parameters
[in]aPointer to a multiple precision integer
Returns
Error code

Definition at line 581 of file pic32cx_bz_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 431 of file pic32cx_bz_crypto_pkc.c.

◆ mpiInvMod()

error_t mpiInvMod ( Mpi r,
const Mpi a,
const Mpi p 
)

Modular inverse.

Parameters
[out]rResulting integer R = A^-1 mod P
[in]aThe multiple precision integer A
[in]pThe modulus P
Returns
Error code

Definition at line 356 of file pic32cx_bz_crypto_pkc.c.

◆ mpiMod2()

error_t mpiMod2 ( Mpi r,
const Mpi a,
const Mpi p 
)

Modulo operation.

Parameters
[out]rResulting integer R = A mod P
[in]aThe multiple precision integer to be reduced
[in]pThe modulus P
Returns
Error code

Definition at line 281 of file pic32cx_bz_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 193 of file pic32cx_bz_crypto_pkc.c.

◆ pukccImportArray()

uint8_t* pukccImportArray ( uint8_t **  dest,
const uint8_t *  array,
size_t  arrayLen,
size_t  totalLen 
)

Import byte array.

Parameters
[in,out]destPointer to the crypto memory
[in]arrayPointer to the byte array
[in]arrayLenLength of the array to be copied
[in]totalLenDesired length of the area, in bytes
Returns
Pointer to the initialized area

Definition at line 101 of file pic32cx_bz_crypto_pkc.c.

◆ pukccImportMpi()

uint8_t* pukccImportMpi ( uint8_t **  dest,
const Mpi src,
size_t  totalLen 
)

Import multiple-precision integer.

Parameters
[in,out]destPointer to the crypto memory
[in]srcPointer to the multiple-precision integer
[in]totalLenDesired length of the area, in bytes
Returns
Pointer to the initialized area

Definition at line 138 of file pic32cx_bz_crypto_pkc.c.

◆ pukccInit()

error_t pukccInit ( void  )

Initialize PUKCC module.

Definition at line 59 of file pic32cx_bz_crypto_pkc.c.

◆ pukccWorkspace()

uint8_t* pukccWorkspace ( uint8_t **  dest,
size_t  totalLen 
)

Initialize workspace area.

Parameters
[in,out]destPointer to the crypto memory
[in]totalLenDesired length of the area, in bytes
Returns
Pointer to the initialized area

Definition at line 163 of file pic32cx_bz_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 725 of file pic32cx_bz_crypto_pkc.c.

Variable Documentation

◆ PUKCLParam

PUKCL_PARAM PUKCLParam

Definition at line 52 of file pic32cx_bz_crypto_pkc.c.

◆ pvPUKCLParam

PPUKCL_PARAM pvPUKCLParam

Definition at line 51 of file pic32cx_bz_crypto_pkc.c.