Go to the documentation of this file.
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
35 #include "hw_sce_private.h"
36 #include "hw_sce_rsa_private.h"
37 #include "hw_sce_ecc_private.h"
47 #if (S5D9_CRYPTO_PKC_SUPPORT == ENABLED)
80 if((aLen <= 128 && eLen <= 4 && pLen <= 128) ||
81 (aLen <= 256 && eLen <= 4 && pLen <= 256))
84 n = (pLen <= 128) ? 128 : 256;
99 status = HW_SCE_RSA_1024PublicEncrypt(0, rsaArgs.
m, rsaArgs.
e,
100 rsaArgs.
n, rsaArgs.
c);
104 status = HW_SCE_RSA_2048PublicEncrypt(0, rsaArgs.
m, rsaArgs.
e,
105 rsaArgs.
n, rsaArgs.
c);
109 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
113 if(status == SSP_SUCCESS)
164 if((aLen <= 128 && eLen <= 128 && pLen <= 128) ||
165 (aLen <= 256 && eLen <= 256 && pLen <= 256))
168 n = (pLen <= 128) ? 128 : 256;
183 status = HW_SCE_RSA_1024PrivateKeyDecrypt(0, rsaArgs.
c, rsaArgs.
d,
184 rsaArgs.
n, rsaArgs.
m);
188 status = HW_SCE_RSA_2048PrivateKeyDecrypt(0, rsaArgs.
c, rsaArgs.
d,
189 rsaArgs.
n, rsaArgs.
m);
193 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
197 if(status == SSP_SUCCESS)
240 if(e != 65537 || privateKey == NULL)
250 status = HW_SCE_RSA_1024KeyGenerate(UINT32_MAX, rsaArgs.
d, rsaArgs.
n,
256 status = HW_SCE_RSA_2048KeyGenerate(UINT32_MAX, rsaArgs.
d, rsaArgs.
n,
262 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
266 if(status == SSP_SUCCESS)
280 error =
mpiReadRaw(&privateKey->
d, (uint8_t *) rsaArgs.
d, k);
287 error =
mpiReadRaw(&privateKey->
n, (uint8_t *) rsaArgs.
n, k);
295 (uint8_t *) rsaArgs.
params +
n * 3,
n);
311 (uint8_t *) rsaArgs.
params +
n * 2,
n);
319 (uint8_t *) rsaArgs.
params,
n);
327 (uint8_t *) rsaArgs.
params +
n * 4,
n);
385 if(nLen <= 128 && dLen <= 128)
390 else if(nLen > 0 && pLen > 0 && qLen > 0 && dpLen > 0 && dqLen > 0 &&
448 else if(nLen > 0 && dLen > 0)
489 else if(modLen <= 28)
493 else if(modLen <= 32)
497 else if(modLen <= 48)
525 status = HW_SCE_ECC_192ScalarMultiplication(ecArgs.
params, ecArgs.
d,
530 status = HW_SCE_ECC_224ScalarMultiplication(ecArgs.
params, ecArgs.
d,
535 status = HW_SCE_ECC_256ScalarMultiplication(ecArgs.
params, ecArgs.
d,
540 status = HW_SCE_ECC_384ScalarMultiplication(ecArgs.
params, ecArgs.
d,
545 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
549 if(status == SSP_SUCCESS)
609 else if(modLen <= 28)
613 else if(modLen <= 32)
617 else if(modLen <= 48)
642 status = HW_SCE_ECC_192GenerateKey(ecArgs.
params, ecArgs.
g, ecArgs.
d,
647 status = HW_SCE_ECC_224GenerateKey(ecArgs.
params, ecArgs.
g, ecArgs.
d,
652 status = HW_SCE_ECC_256GenerateKey(ecArgs.
params, ecArgs.
g, ecArgs.
d,
657 status = HW_SCE_ECC_384GenerateKey(ecArgs.
params, ecArgs.
g, ecArgs.
d,
662 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
666 if(status == SSP_SUCCESS)
713 const uint8_t *digest,
size_t digestLen,
EcdsaSignature *signature)
722 if(params == NULL || privateKey == NULL || digest == NULL || signature == NULL)
735 else if(modLen <= 28)
739 else if(modLen <= 32)
743 else if(modLen <= 48)
753 digestLen =
MIN(digestLen, orderLen);
760 osMemcpy((uint8_t *) ecArgs.
digest +
n - digestLen, digest, digestLen);
778 status = HW_SCE_ECC_192GenerateSign(ecArgs.
params, ecArgs.
g, ecArgs.
d,
783 status = HW_SCE_ECC_224GenerateSign(ecArgs.
params, ecArgs.
g, ecArgs.
d,
788 status = HW_SCE_ECC_256GenerateSign(ecArgs.
params, ecArgs.
g, ecArgs.
d,
793 status = HW_SCE_ECC_384GenerateSign(ecArgs.
params, ecArgs.
g, ecArgs.
d,
798 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
802 if(status == SSP_SUCCESS)
839 const EcPublicKey *publicKey,
const uint8_t *digest,
size_t digestLen,
848 if(params == NULL || publicKey == NULL || digest == NULL || signature == NULL)
877 else if(modLen <= 28)
881 else if(modLen <= 32)
885 else if(modLen <= 48)
895 digestLen =
MIN(digestLen, orderLen);
902 osMemcpy((uint8_t *) ecArgs.
digest +
n - digestLen, digest, digestLen);
925 status = HW_SCE_ECC_192VerifySign(ecArgs.
params, ecArgs.
g, ecArgs.
q,
930 status = HW_SCE_ECC_224VerifySign(ecArgs.
params, ecArgs.
g, ecArgs.
q,
935 status = HW_SCE_ECC_256VerifySign(ecArgs.
params, ecArgs.
g, ecArgs.
q,
940 status = HW_SCE_ECC_384VerifySign(ecArgs.
params, ecArgs.
g, ecArgs.
q,
945 status = SSP_ERR_CRYPTO_NOT_IMPLEMENTED;
error_t ecMult(const EcDomainParameters *params, EcPoint *r, const Mpi *d, const EcPoint *s)
Scalar multiplication.
Arbitrary precision integer.
error_t ecdsaVerifySignature(const EcDomainParameters *params, const EcPublicKey *publicKey, const uint8_t *digest, size_t digestLen, const EcdsaSignature *signature)
ECDSA signature verification.
ECDSA (Elliptic Curve Digital Signature Algorithm)
error_t rsaGeneratePrivateKey(const PrngAlgo *prngAlgo, void *prngContext, size_t k, uint_t e, RsaPrivateKey *privateKey)
RSA private key generation.
#define mpiWriteRaw(a, data, length)
error_t mpiSetValue(Mpi *r, int_t a)
Set the value of a multiple precision integer.
error_t mpiExpModFast(Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
Modular exponentiation (fast calculation)
void mpiInit(Mpi *r)
Initialize a multiple precision integer.
#define mpiReadRaw(r, data, length)
error_t mpiMod(Mpi *r, const Mpi *a, const Mpi *p)
Modulo operation.
error_t mpiMul(Mpi *r, const Mpi *a, const Mpi *b)
Multiple precision multiplication.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
error_t mpiSub(Mpi *r, const Mpi *a, const Mpi *b)
Multiple precision subtraction.
error_t mpiAdd(Mpi *r, const Mpi *a, const Mpi *b)
Multiple precision addition.
@ ERROR_FAILURE
Generic error code.
Synergy S5D9 public-key hardware accelerator.
General definitions for cryptographic algorithms.
RSA public-key cryptography standard.
Mpi dq
Second factor's CRT exponent.
error_t rsadp(const RsaPrivateKey *key, const Mpi *c, Mpi *m)
RSA decryption primitive.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
error_t ecGenerateKeyPair(const PrngAlgo *prngAlgo, void *prngContext, const EcDomainParameters *params, EcPrivateKey *privateKey, EcPublicKey *publicKey)
EC key pair generation.
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.
int_t mpiComp(const Mpi *a, const Mpi *b)
Compare two multiple precision integers.
Mpi dp
First factor's CRT exponent.
#define osMemset(p, value, length)
error_t mpiMulMod(Mpi *r, const Mpi *a, const Mpi *b, const Mpi *p)
Modular multiplication.
ECC (Elliptic Curve Cryptography)
@ ERROR_INVALID_SIGNATURE
int_t mpiCompInt(const Mpi *a, int_t b)
Compare a multiple precision integer with an integer.
error_t mpiExpModRegular(Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
Modular exponentiation (regular calculation)
Mpi q
Order of the point G.
error_t mpiExpMod(Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
Modular exponentiation.
Synergy S5D9 hardware cryptographic accelerator (SCE7)
uint_t mpiGetByteLength(const Mpi *a)
Get the actual length in bytes.
void mpiFree(Mpi *r)
Release a multiple precision integer.