MTB CAT1 Peripheral driver library
All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages

General Description

Typedefs

typedef cy_en_cryptolite_status_t(* cy_cryptolite_ed25519_sha512_init_t) (void *context)
 Pointer to a sha initialization function.
 
typedef cy_en_cryptolite_status_t(* cy_cryptolite_ed25519_sha512_update_t) (void *context, uint8_t const *input, uint32_t inputSize)
 Pointer to a sha update function.
 
typedef cy_en_cryptolite_status_t(* cy_cryptolite_ed25519_sha512_start_t) (void *context)
 Pointer to a sha start function.
 
typedef cy_en_cryptolite_status_t(* cy_cryptolite_ed25519_sha512_finish_t) (void *context, uint8_t *output)
 Pointer to a sha output function.
 
typedef cy_en_cryptolite_status_t(* cy_cryptolite_ed25519_sha512_free_t) (void *context)
 Pointer to a sha deinitialization function.
 

Functions

cy_en_cryptolite_status_t Cy_Cryptolite_ECC_Init (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, cy_stc_cryptolite_ecc_buffer_t *eccBuffer)
 Init ECC Context. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ECC_Free (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext)
 Clean up ECC Context. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ECC_SignHash (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, const uint8_t *hash, uint32_t hashlen, uint8_t *sig, const cy_stc_cryptolite_ecc_key *key, const uint8_t *messageKey)
 Function to generate an ECC signature. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ECC_VerifyHash (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, const uint8_t *sig, uint32_t siglen, const uint8_t *hash, uint32_t hashlen, cy_en_cryptolite_sig_verify_result_t *stat, const cy_stc_cryptolite_ecc_key *key)
 Verify an ECC signature. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ECC_SharedSecret (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, cy_en_cryptolite_ecc_curve_id_t curveID, const uint8_t *privateKey, const cy_stc_cryptolite_ecc_key *key, uint8_t const *sharedSecret)
 Generate a Shared Secret key from one private key and others public key. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_Init (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, cy_stc_cryptolite_ecc_buffer_t *eccBuffer, cy_stc_cryptolite_ed25519_sha512_t *shaFunctions)
 Init ED25519 Context. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_Free (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext)
 Free ED25519 Context. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_Sign (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, const uint8_t *hash, uint32_t hashlen, uint8_t *sig, const cy_stc_cryptolite_ecc_key *key, cy_en_cryptolite_eddsa_sig_type_t sigType, const uint8_t *sigctx, uint32_t sigctx_len)
 Sign a message. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_PointMultiplication (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, const uint8_t *ecpGX, const uint8_t *ecpGY, const uint8_t *ecpD, uint8_t *ecpQX, uint8_t *ecpQY)
 Edwards 25519 elliptic curve point multiplication in GF(p). More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_PointDecode (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, const uint8_t *publicKey, uint8_t *pubKey_x, uint8_t *pubKey_y)
 Decode ED25519 encoded public key in to x and y. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_Verify (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, uint8_t *sig, const uint8_t *hash, uint32_t hashlen, const cy_stc_cryptolite_ecc_key *key, uint32_t *stat, cy_en_cryptolite_eddsa_sig_type_t sigType, const uint8_t *sigctx, uint32_t sigctx_len)
 Verify ED25519 signed message. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_MakePublicKey (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, const uint8_t *privateKey, cy_stc_cryptolite_ecc_key *publicKey)
 Make a new ED25519 public key. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_EC25519_MakePublicKey (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, const uint8_t *privateKey, cy_stc_cryptolite_ecc_key *publicKey)
 Make a new EC25519 public key. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_EC25519_MakePrivateKey (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, uint8_t *privateKey, cy_func_get_random_data_t GetRandomDataFunc, void *randomDataInfo)
 Make a new EC25519 private key. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_EC25519_PointMultiplication (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_ecdsa_t *cfContext, uint8_t *p_r, const uint8_t *p_x, const uint8_t *p_d)
 EC25519 Elliptic curve point multiplication in GF(p). More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_Rsa_Init (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_rsa_t *cfContext, cy_stc_cryptolite_rsa_buffer_t *rsaBuffers)
 Initialize the RSA context. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_Rsa_Proc (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_rsa_t *cfContext, cy_stc_cryptolite_rsa_pub_key_t *key, uint8_t const *message, uint32_t messageSize, uint8_t *processedMessage)
 RSA process algorithm based on the Montgomery algorithm using Barrett reduction. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_Rsa_Coef (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_rsa_t *cfContext, cy_stc_cryptolite_rsa_pub_key_t *key)
 Calculation constant coefficients to speed-up Montgomery algorithm. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_Rsa_Free (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_rsa_t *cfContext)
 Cleanup the RSA context. More...
 
cy_en_cryptolite_status_t Cy_Cryptolite_Rsa_Verify (CRYPTOLITE_Type *base, cy_stc_cryptolite_context_rsa_t *cfContext, cy_en_cryptolite_sig_verify_result_t *verResult, cy_en_cryptolite_sha_mode_t digestType, uint8_t const *digest, uint32_t digestLength, uint8_t const *decryptedSignature, uint32_t decryptedSignatureLength)
 RSA verification with checks for content, paddings and signature format. More...
 

Function Documentation

◆ Cy_Cryptolite_ECC_Init()

cy_en_cryptolite_status_t Cy_Cryptolite_ECC_Init ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
cy_stc_cryptolite_ecc_buffer_t eccBuffer 
)

Init ECC Context.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
eccBufferThe pointer to the cy_stc_cryptolite_ecc_buffer_t.
Returns
status code. See cy_en_cryptolite_status_t.
Function Usage
uint8_t ecc_p256_signature[] = {
0x0f, 0x8c, 0x19, 0xf5, 0xaf, 0xfe, 0xa6, 0xd5, 0x93, 0xa3, 0x3e, 0x17, 0x6a, 0xa5, 0x27, 0x17,
0xbf, 0xf8, 0xd5, 0x87, 0x51, 0x65, 0xfc, 0x63, 0xe8, 0x0a, 0x2d, 0x65, 0x58, 0x0d, 0x29, 0x57,
0x89, 0xdb, 0x5f, 0xfb, 0x53, 0x97, 0xba, 0x4c, 0x67, 0x83, 0x4e, 0x27, 0x31, 0xee, 0x26, 0x8e,
0xa6, 0xf7, 0xe8, 0x38, 0x46, 0xfb, 0xb0, 0x21, 0x45, 0xb3, 0x54, 0x42, 0xdb, 0x18, 0xcf, 0x0b };
uint8_t hash_256[] = {
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad };
uint8_t ecc_p256_public_key[] = {
0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f, 0x4a, 0xd2, 0x0e,
0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0, 0xba, 0x01, 0x20, 0x42, 0x08,
0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b, 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde,
0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98, 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
memset(&key, 0, sizeof(key));
memset(&sig_ctx, 0, sizeof(sig_ctx));
key.type = PK_PUBLIC;
key.curveID = CY_CRYPTOLITE_ECC_ECP_SECP256R1;
key.pubkey.x = (void *)ecc_p256_public_key;
key.pubkey.y = (void *)(ecc_p256_public_key + sizeof(ecc_p256_public_key)/2);
Cy_Cryptolite_InvertEndianness(key.pubkey.x, sizeof(ecc_p256_public_key)/2);
Cy_Cryptolite_InvertEndianness(key.pubkey.y, sizeof(ecc_p256_public_key)/2);
Cy_Cryptolite_InvertEndianness(hash_256, sizeof(hash_256));
Cy_Cryptolite_InvertEndianness(ecc_p256_signature, sizeof(ecc_p256_signature)/2);
Cy_Cryptolite_InvertEndianness(ecc_p256_signature + sizeof(ecc_p256_signature)/2, sizeof(ecc_p256_signature)/2);
status = Cy_Cryptolite_ECC_Init(CRYPTOLITE,&sig_ctx, &ecdsa_buf);
/* ... check for errors... */
status = Cy_Cryptolite_ECC_VerifyHash(CRYPTOLITE, &sig_ctx, ecc_p256_signature, sizeof(ecc_p256_signature), hash_256, sizeof(hash_256), &verResult, &key);
/* ... check for errors... */
status = Cy_Cryptolite_ECC_Free(CRYPTOLITE, &sig_ctx);
/* ... check for errors & verResult to be CY_CRYPTOLITE_SIG_VALID... */

◆ Cy_Cryptolite_ECC_Free()

cy_en_cryptolite_status_t Cy_Cryptolite_ECC_Free ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext 
)

Clean up ECC Context.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
Returns
status code. See cy_en_cryptolite_status_t.
Function Usage
uint8_t ecc_p256_signature[] = {
0x0f, 0x8c, 0x19, 0xf5, 0xaf, 0xfe, 0xa6, 0xd5, 0x93, 0xa3, 0x3e, 0x17, 0x6a, 0xa5, 0x27, 0x17,
0xbf, 0xf8, 0xd5, 0x87, 0x51, 0x65, 0xfc, 0x63, 0xe8, 0x0a, 0x2d, 0x65, 0x58, 0x0d, 0x29, 0x57,
0x89, 0xdb, 0x5f, 0xfb, 0x53, 0x97, 0xba, 0x4c, 0x67, 0x83, 0x4e, 0x27, 0x31, 0xee, 0x26, 0x8e,
0xa6, 0xf7, 0xe8, 0x38, 0x46, 0xfb, 0xb0, 0x21, 0x45, 0xb3, 0x54, 0x42, 0xdb, 0x18, 0xcf, 0x0b };
uint8_t hash_256[] = {
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad };
uint8_t ecc_p256_public_key[] = {
0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f, 0x4a, 0xd2, 0x0e,
0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0, 0xba, 0x01, 0x20, 0x42, 0x08,
0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b, 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde,
0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98, 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
memset(&key, 0, sizeof(key));
memset(&sig_ctx, 0, sizeof(sig_ctx));
key.type = PK_PUBLIC;
key.curveID = CY_CRYPTOLITE_ECC_ECP_SECP256R1;
key.pubkey.x = (void *)ecc_p256_public_key;
key.pubkey.y = (void *)(ecc_p256_public_key + sizeof(ecc_p256_public_key)/2);
Cy_Cryptolite_InvertEndianness(key.pubkey.x, sizeof(ecc_p256_public_key)/2);
Cy_Cryptolite_InvertEndianness(key.pubkey.y, sizeof(ecc_p256_public_key)/2);
Cy_Cryptolite_InvertEndianness(hash_256, sizeof(hash_256));
Cy_Cryptolite_InvertEndianness(ecc_p256_signature, sizeof(ecc_p256_signature)/2);
Cy_Cryptolite_InvertEndianness(ecc_p256_signature + sizeof(ecc_p256_signature)/2, sizeof(ecc_p256_signature)/2);
status = Cy_Cryptolite_ECC_Init(CRYPTOLITE,&sig_ctx, &ecdsa_buf);
/* ... check for errors... */
status = Cy_Cryptolite_ECC_VerifyHash(CRYPTOLITE, &sig_ctx, ecc_p256_signature, sizeof(ecc_p256_signature), hash_256, sizeof(hash_256), &verResult, &key);
/* ... check for errors... */
status = Cy_Cryptolite_ECC_Free(CRYPTOLITE, &sig_ctx);
/* ... check for errors & verResult to be CY_CRYPTOLITE_SIG_VALID... */

◆ Cy_Cryptolite_ECC_SignHash()

cy_en_cryptolite_status_t Cy_Cryptolite_ECC_SignHash ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
const uint8_t *  hash,
uint32_t  hashlen,
uint8_t *  sig,
const cy_stc_cryptolite_ecc_key key,
const uint8_t *  messageKey 
)

Function to generate an ECC signature.

key, hash and messageKey must be in little endian. Cy_Cryptolite_InvertEndianness() function is used for converting the endianness.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
hashThe hash (message digest) to be signed.
hashlenThe length of the hash (octets).
sigThe pointer to the buffer to store the generated signature 'R' followed by 'S'.
keyThe private ECC key to sign the hash. See cy_stc_cryptolite_ecc_key.
messageKeyThe random number for generating the signature.
Returns
status code. See cy_en_cryptolite_status_t.

◆ Cy_Cryptolite_ECC_VerifyHash()

cy_en_cryptolite_status_t Cy_Cryptolite_ECC_VerifyHash ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
const uint8_t *  sig,
uint32_t  siglen,
const uint8_t *  hash,
uint32_t  hashlen,
cy_en_cryptolite_sig_verify_result_t stat,
const cy_stc_cryptolite_ecc_key key 
)

Verify an ECC signature.

sig, hash and key must be in little endian. Cy_Cryptolite_InvertEndianness() function is used for converting the endianness.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the ecdsa context.
sigThe signature to verify, 'R' followed by 'S'.
siglenThe length of signature.
hashThe hash (message digest) that was signed.
hashlenThe length of the hash (octets).
statResult of signature, 0xAAAAAAAA = invalid, 0x55555555 = valid.
keyThe corresponding public ECC key. See cy_stc_cryptolite_ecc_key.
Returns
status code. See cy_en_cryptolite_status_t.
Function Usage
uint8_t ecc_p256_signature[] = {
0x0f, 0x8c, 0x19, 0xf5, 0xaf, 0xfe, 0xa6, 0xd5, 0x93, 0xa3, 0x3e, 0x17, 0x6a, 0xa5, 0x27, 0x17,
0xbf, 0xf8, 0xd5, 0x87, 0x51, 0x65, 0xfc, 0x63, 0xe8, 0x0a, 0x2d, 0x65, 0x58, 0x0d, 0x29, 0x57,
0x89, 0xdb, 0x5f, 0xfb, 0x53, 0x97, 0xba, 0x4c, 0x67, 0x83, 0x4e, 0x27, 0x31, 0xee, 0x26, 0x8e,
0xa6, 0xf7, 0xe8, 0x38, 0x46, 0xfb, 0xb0, 0x21, 0x45, 0xb3, 0x54, 0x42, 0xdb, 0x18, 0xcf, 0x0b };
uint8_t hash_256[] = {
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad };
uint8_t ecc_p256_public_key[] = {
0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f, 0x4a, 0xd2, 0x0e,
0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0, 0xba, 0x01, 0x20, 0x42, 0x08,
0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b, 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde,
0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98, 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
memset(&key, 0, sizeof(key));
memset(&sig_ctx, 0, sizeof(sig_ctx));
key.type = PK_PUBLIC;
key.curveID = CY_CRYPTOLITE_ECC_ECP_SECP256R1;
key.pubkey.x = (void *)ecc_p256_public_key;
key.pubkey.y = (void *)(ecc_p256_public_key + sizeof(ecc_p256_public_key)/2);
Cy_Cryptolite_InvertEndianness(key.pubkey.x, sizeof(ecc_p256_public_key)/2);
Cy_Cryptolite_InvertEndianness(key.pubkey.y, sizeof(ecc_p256_public_key)/2);
Cy_Cryptolite_InvertEndianness(hash_256, sizeof(hash_256));
Cy_Cryptolite_InvertEndianness(ecc_p256_signature, sizeof(ecc_p256_signature)/2);
Cy_Cryptolite_InvertEndianness(ecc_p256_signature + sizeof(ecc_p256_signature)/2, sizeof(ecc_p256_signature)/2);
status = Cy_Cryptolite_ECC_Init(CRYPTOLITE,&sig_ctx, &ecdsa_buf);
/* ... check for errors... */
status = Cy_Cryptolite_ECC_VerifyHash(CRYPTOLITE, &sig_ctx, ecc_p256_signature, sizeof(ecc_p256_signature), hash_256, sizeof(hash_256), &verResult, &key);
/* ... check for errors... */
status = Cy_Cryptolite_ECC_Free(CRYPTOLITE, &sig_ctx);
/* ... check for errors & verResult to be CY_CRYPTOLITE_SIG_VALID... */

◆ Cy_Cryptolite_ECC_SharedSecret()

cy_en_cryptolite_status_t Cy_Cryptolite_ECC_SharedSecret ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
cy_en_cryptolite_ecc_curve_id_t  curveID,
const uint8_t *  privateKey,
const cy_stc_cryptolite_ecc_key key,
uint8_t const *  sharedSecret 
)

Generate a Shared Secret key from one private key and others public key.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
curveIDThe ECC curve id.
privateKeyThe pointer to the ECC private key.
keyThe generated public ECC key. See cy_stc_cryptolite_ecc_key.
sharedSecretThe pointer to store the generated shared Secret.
Returns
status code. See cy_en_cryptolite_status_t.

◆ Cy_Cryptolite_ED25519_Init()

cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_Init ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
cy_stc_cryptolite_ecc_buffer_t eccBuffer,
cy_stc_cryptolite_ed25519_sha512_t shaFunctions 
)

Init ED25519 Context.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
eccBufferThe pointer to the cy_stc_cryptolite_ecc_buffer_t.
shaFunctionsThe pointer to the cy_stc_cryptolite_ed25519_sha512_t.
Returns
status code. See cy_en_cryptolite_status_t.

◆ Cy_Cryptolite_ED25519_Free()

cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_Free ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext 
)

Free ED25519 Context.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
Returns
status code. See cy_en_cryptolite_status_t.

◆ Cy_Cryptolite_ED25519_Sign()

cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_Sign ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
const uint8_t *  hash,
uint32_t  hashlen,
uint8_t *  sig,
const cy_stc_cryptolite_ecc_key key,
cy_en_cryptolite_eddsa_sig_type_t  sigType,
const uint8_t *  sigctx,
uint32_t  sigctx_len 
)

Sign a message.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
hashThe message to sign. Provided as is in data buffer. This is usually the hash of the original data to be signed.
hashlenThe length of the message in bytes.
sig[out] The destination for the signature, 'r' followed by 's'.
keyKey (Little Endian) used for signature generation. See cy_stc_cryptolite_ecc_key.
sigTypesignature Type. CY_CRYPTOLITE_EDDSA_PURE,CY_CRYPTOLITE_EDDSA_CTX or CY_CRYPTOLITE_EDDSA_PREHASH
sigctxsignature context. can be NULL if EDDSA_PURE is used or if no context is provided.
sigctx_lenThe length of the signature context
Returns
status code. See cy_en_cryptolite_status_t.
Function Usage
mbedtls_sha512_context g_512ctx;
/* message and Key are treated big-endian and sig generated as little-endian
sig(R,S) = ed25519_sign(key,msg)
*/
CY_ALIGN(4) cy_stc_cryptolite_ecc_key myKey;
CY_ALIGN(4) uint8_t sign_msg[CY_CRYPTOLITE_ECC_ED25519_BYTE_SIZE*2] = {0};
CY_ALIGN(4) uint8_t msg[] = {0x05,0x04,0x03,0x02,0x01};
/* */
CY_ALIGN(4) uint8_t prvKey[CY_CRYPTOLITE_ECC_ED25519_BYTE_SIZE] =
{
0x9d, 0x61, 0xb1, 0x9d, 0xef, 0xfd, 0x5a, 0x60, 0xba, 0x84,
0x4a, 0xf4, 0x92, 0xec, 0x2c, 0xc4, 0x44, 0x49, 0xc5, 0x69,
0x7b, 0x32, 0x69, 0x19, 0x70, 0x3b, 0xac, 0x03, 0x1c, 0xae,
0x7f, 0x60
};
CY_ALIGN(4) uint8_t pubKey[CY_CRYPTOLITE_ECC_ED25519_BYTE_SIZE*2] = {0};
myKey.curveID = CY_CRYPTOLITE_ECC_ECP_ED25519;
myKey.type = PK_PRIVATE;
myKey.k = prvKey;
myKey.pubkey.x = &pubKey[0];
myKey.pubkey.y = &pubKey[CY_CRYPTOLITE_ECC_ED25519_BYTE_SIZE];
uint8_t *msg_ptr = msg;
uint32_t msg_size = sizeof(msg);
static const uint8_t publicKey[CY_CRYPTOLITE_ECC_ED25519_BYTE_SIZE] =
{
0xD7,0x5A,0x98,0x01,0x82,0xB1,0x0A,0xB7,0xD5,0x4B,0xFE,0xD3,
0xC9, 0x64, 0x07, 0x3A, 0x0E, 0xE1, 0x72, 0xF3, 0xDA, 0xA6,
0x23, 0x25, 0xAF, 0x02, 0x1A, 0x68, 0xF7, 0x07, 0x51, 0x1A
};
/* Initialize user defined sha512 function pointers */
shaFunctions.shactx = &g_512ctx;
shaFunctions.sha_init = hook_sha512_init;
shaFunctions.sha_start = hook_sha512_start;
shaFunctions.sha_update = hook_sha512_update;
shaFunctions.sha_finish = hook_sha512_finish;
shaFunctions.sha_free = hook_sha512_free;
Cy_Cryptolite_ED25519_Init(CRYPTOLITE, &cfContext, &eccBuffer, &shaFunctions);
/* public key decode test*/
crypto_status = Cy_Cryptolite_ED25519_PointDecode(CRYPTOLITE, &cfContext, publicKey, myKey.pubkey.x, myKey.pubkey.y);
/* Generate Pub Key Test*/
/* private key expected in big-endian */
crypto_status = Cy_Cryptolite_ED25519_MakePublicKey(CRYPTOLITE, &cfContext, prvKey, &myKey);
/* ... check for errors... */
/* CY_CRYPTOLITE_EDDSA_PURE*/
/* Public Key should be in little Endian */
crypto_status = Cy_Cryptolite_ED25519_Sign(CRYPTOLITE, &cfContext, msg_ptr, msg_size, sign_msg, &myKey, CY_CRYPTOLITE_EDDSA_PURE, NULL, 0);
/* ... check for errors... */
/* Verify signatures */
uint32_t stat = 0;
/* PURE Verify*/
msg_ptr = msg;
msg_size = sizeof(msg);
crypto_status = Cy_Cryptolite_ED25519_Verify(CRYPTOLITE, &cfContext, sign_msg, msg_ptr, msg_size, &myKey, &stat, CY_CRYPTOLITE_EDDSA_PURE, NULL, 0);
/* ... check for errors... */

◆ Cy_Cryptolite_ED25519_PointMultiplication()

cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_PointMultiplication ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
const uint8_t *  ecpGX,
const uint8_t *  ecpGY,
const uint8_t *  ecpD,
uint8_t *  ecpQX,
uint8_t *  ecpQY 
)

Edwards 25519 elliptic curve point multiplication in GF(p).

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
ecpGXX coordinate of base point.
ecpGYY coordinate of base point.
ecpDmultiplication scalar value.
ecpQXX coordinate of result point.
ecpQYY coordinate of result point.
Returns
status code. See cy_en_cryptolite_status_t.

◆ Cy_Cryptolite_ED25519_PointDecode()

cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_PointDecode ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
const uint8_t *  publicKey,
uint8_t *  pubKey_x,
uint8_t *  pubKey_y 
)

Decode ED25519 encoded public key in to x and y.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
publicKey[in] encoded 32 byte Public key.
pubKey_x[out] Decoded 32 bytes Public key x in little-endian format.
pubKey_y[out] Decoded 32 bytes Public key y in little-endian format.
Returns
status code. See cy_en_cryptolite_status_t.

◆ Cy_Cryptolite_ED25519_Verify()

cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_Verify ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
uint8_t *  sig,
const uint8_t *  hash,
uint32_t  hashlen,
const cy_stc_cryptolite_ecc_key key,
uint32_t *  stat,
cy_en_cryptolite_eddsa_sig_type_t  sigType,
const uint8_t *  sigctx,
uint32_t  sigctx_len 
)

Verify ED25519 signed message.

On successful verification, CY_CRYPTOLITE_SUCCESS is returned and stat is 0xA1A1A1A1.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
sigThe signature to verify, 'R' followed by 'S'.
hashThe hash or message that was signed.
hashlenThe length of the hash or message (octets).
statResult of signature verification, 0xA1A1A1A1==valid, 0x00BADBAD==invalid.
keyThe corresponding uncompressed public key to use (little-endian). See cy_stc_cryptolite_ecc_key.
sigTypesignature Type. CY_CRYPTOLITE_EDDSA_PURE,CY_CRYPTOLITE_EDDSA_CTX or CY_CRYPTOLITE_EDDSA_PREHASH
sigctxsignature context. can be NULL if EDDSA_PURE is used or if no context is provided.
sigctx_lenThe length of the signature context
Returns
status code. See cy_en_cryptolite_status_t.
Function Usage
mbedtls_sha512_context g_512ctx;
/* message and Key are treated big-endian and sig generated as little-endian
sig(R,S) = ed25519_sign(key,msg)
*/
CY_ALIGN(4) cy_stc_cryptolite_ecc_key myKey;
CY_ALIGN(4) uint8_t sign_msg[CY_CRYPTOLITE_ECC_ED25519_BYTE_SIZE*2] = {0};
CY_ALIGN(4) uint8_t msg[] = {0x05,0x04,0x03,0x02,0x01};
/* */
CY_ALIGN(4) uint8_t prvKey[CY_CRYPTOLITE_ECC_ED25519_BYTE_SIZE] =
{
0x9d, 0x61, 0xb1, 0x9d, 0xef, 0xfd, 0x5a, 0x60, 0xba, 0x84,
0x4a, 0xf4, 0x92, 0xec, 0x2c, 0xc4, 0x44, 0x49, 0xc5, 0x69,
0x7b, 0x32, 0x69, 0x19, 0x70, 0x3b, 0xac, 0x03, 0x1c, 0xae,
0x7f, 0x60
};
CY_ALIGN(4) uint8_t pubKey[CY_CRYPTOLITE_ECC_ED25519_BYTE_SIZE*2] = {0};
myKey.curveID = CY_CRYPTOLITE_ECC_ECP_ED25519;
myKey.type = PK_PRIVATE;
myKey.k = prvKey;
myKey.pubkey.x = &pubKey[0];
myKey.pubkey.y = &pubKey[CY_CRYPTOLITE_ECC_ED25519_BYTE_SIZE];
uint8_t *msg_ptr = msg;
uint32_t msg_size = sizeof(msg);
static const uint8_t publicKey[CY_CRYPTOLITE_ECC_ED25519_BYTE_SIZE] =
{
0xD7,0x5A,0x98,0x01,0x82,0xB1,0x0A,0xB7,0xD5,0x4B,0xFE,0xD3,
0xC9, 0x64, 0x07, 0x3A, 0x0E, 0xE1, 0x72, 0xF3, 0xDA, 0xA6,
0x23, 0x25, 0xAF, 0x02, 0x1A, 0x68, 0xF7, 0x07, 0x51, 0x1A
};
/* Initialize user defined sha512 function pointers */
shaFunctions.shactx = &g_512ctx;
shaFunctions.sha_init = hook_sha512_init;
shaFunctions.sha_start = hook_sha512_start;
shaFunctions.sha_update = hook_sha512_update;
shaFunctions.sha_finish = hook_sha512_finish;
shaFunctions.sha_free = hook_sha512_free;
Cy_Cryptolite_ED25519_Init(CRYPTOLITE, &cfContext, &eccBuffer, &shaFunctions);
/* public key decode test*/
crypto_status = Cy_Cryptolite_ED25519_PointDecode(CRYPTOLITE, &cfContext, publicKey, myKey.pubkey.x, myKey.pubkey.y);
/* Generate Pub Key Test*/
/* private key expected in big-endian */
crypto_status = Cy_Cryptolite_ED25519_MakePublicKey(CRYPTOLITE, &cfContext, prvKey, &myKey);
/* ... check for errors... */
/* CY_CRYPTOLITE_EDDSA_PURE*/
/* Public Key should be in little Endian */
crypto_status = Cy_Cryptolite_ED25519_Sign(CRYPTOLITE, &cfContext, msg_ptr, msg_size, sign_msg, &myKey, CY_CRYPTOLITE_EDDSA_PURE, NULL, 0);
/* ... check for errors... */
/* Verify signatures */
uint32_t stat = 0;
/* PURE Verify*/
msg_ptr = msg;
msg_size = sizeof(msg);
crypto_status = Cy_Cryptolite_ED25519_Verify(CRYPTOLITE, &cfContext, sign_msg, msg_ptr, msg_size, &myKey, &stat, CY_CRYPTOLITE_EDDSA_PURE, NULL, 0);
/* ... check for errors... */

◆ Cy_Cryptolite_ED25519_MakePublicKey()

cy_en_cryptolite_status_t Cy_Cryptolite_ED25519_MakePublicKey ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
const uint8_t *  privateKey,
cy_stc_cryptolite_ecc_key publicKey 
)

Make a new ED25519 public key.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
privateKey[in] Private key.
publicKey[out] Newly created Public key. See cy_stc_cryptolite_ecc_key.
Returns
status code. See cy_en_cryptolite_status_t.

◆ Cy_Cryptolite_EC25519_MakePublicKey()

cy_en_cryptolite_status_t Cy_Cryptolite_EC25519_MakePublicKey ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
const uint8_t *  privateKey,
cy_stc_cryptolite_ecc_key publicKey 
)

Make a new EC25519 public key.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
privateKey[in] Private key.
publicKey[out] Newly created Public key. See cy_stc_cryptolite_ecc_key.
Returns
status code. See cy_en_cryptolite_status_t.

◆ Cy_Cryptolite_EC25519_MakePrivateKey()

cy_en_cryptolite_status_t Cy_Cryptolite_EC25519_MakePrivateKey ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
uint8_t *  privateKey,
cy_func_get_random_data_t  GetRandomDataFunc,
void *  randomDataInfo 
)

Make a new EC25519 private key.

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
privateKey[out] Destination of the newly created key.
GetRandomDataFuncSee cy_func_get_random_data_t.
randomDataInfoArgument for GetRandomDataFunc.
Returns
status code. See cy_en_cryptolite_status_t.

◆ Cy_Cryptolite_EC25519_PointMultiplication()

cy_en_cryptolite_status_t Cy_Cryptolite_EC25519_PointMultiplication ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_ecdsa_t cfContext,
uint8_t *  p_r,
const uint8_t *  p_x,
const uint8_t *  p_d 
)

EC25519 Elliptic curve point multiplication in GF(p).

Parameters
baseThe pointer to a Cryptolite instance.
cfContextThe pointer to the cy_stc_cryptolite_context_ecdsa_t.
p_rPointer to result point.
p_xPointer to X coordinate of base point.
p_dPointer to Scalar multiplication value.
Returns
status code. See cy_en_cryptolite_status_t.

◆ Cy_Cryptolite_Rsa_Init()

cy_en_cryptolite_status_t Cy_Cryptolite_Rsa_Init ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_rsa_t cfContext,
cy_stc_cryptolite_rsa_buffer_t rsaBuffers 
)

Initialize the RSA context.

Parameters
baseThe pointer to the CRYPTOLITE instance.
cfContextThe pointer to the CRYPTOLITE context.
rsaBuffersThe pointer to the RSA buffers.
Returns
cy_en_cryptolite_status_t
Function Usage
CY_ALIGN(4) uint8_t encryptedSignature_2048[] =
{
0x86, 0x1c, 0xf4, 0x97, 0xcc, 0xb0, 0xf9, 0x8e, 0xb1, 0x93, 0x20, 0x30, 0x5b, 0xe4, 0xe2, 0xf4,
0x30, 0x66, 0xa3, 0x6d, 0xe8, 0x74, 0x4f, 0xa9, 0xe9, 0xd1, 0x16, 0xc5, 0x17, 0xc0, 0x97, 0x1d,
0x60, 0x39, 0xb0, 0xda, 0xf4, 0x65, 0xad, 0x7e, 0x59, 0x6c, 0xce, 0x12, 0x29, 0x8b, 0x23, 0xdd,
0x4b, 0xb6, 0xd3, 0xb6, 0x7e, 0x2b, 0x5d, 0xae, 0x55, 0x5e, 0x43, 0xf3, 0x61, 0x8a, 0x8c, 0xbd,
0x47, 0x59, 0x05, 0x21, 0x4b, 0x54, 0x7b, 0x49, 0xd2, 0xbd, 0x33, 0xdb, 0x82, 0x5d, 0xfc, 0xb4,
0xf8, 0xcf, 0x37, 0x2d, 0x2f,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,0x27,0x3f,0x80,0xb3,0x98,0x9d,0x39,0xaa,0x10,0xdc,0x8b,0x6c,0x16,
0xca,0x97,0xef,0x55,0xd6,0x5f,0x18,0x89,0x61,0x0e,0x24,0xb9,0x11,0x4d,0x6e,0xc7
};
CY_ALIGN(4) uint8_t plainTxt[] = "abc";
CY_ALIGN(4) uint8_t publicExponent[] =
{
/* This is a part of public key. (So called e)
* Refer public_key.txt
*/
/* Big endian format */
0x01, 0x00, 0x01
};
CY_ALIGN(4) uint8_t barretCoef[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be modulo length + 1 BITS */
CY_ALIGN(4) uint8_t inverseModulo[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be same as modulo length */
CY_ALIGN(4) uint8_t rBar[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be same as modulo length */
CY_ALIGN(4)uint8_t decryptedSignature[2048/8]={0};
CY_ALIGN(4) uint8_t calculatedHash[32]={0};
memset((void*)&decryptedSignature, 0u, sizeof(decryptedSignature));
memset((void*)&calculatedHash, 0u, sizeof(calculatedHash));
memset((void*)&rsa_buffer, 0u, sizeof(rsa_buffer));
memset((void*)&rsa_ctx, 0u, sizeof(rsa_ctx));
memset((void*)&sha_ctx, 0u, sizeof(sha_ctx));
Cy_Cryptolite_InvertEndianness(modulus_2048, 2048u/8 );
Cy_Cryptolite_InvertEndianness(encryptedSignature_2048, sizeof(encryptedSignature_2048) );
Cy_Cryptolite_InvertEndianness(publicExponent, sizeof(publicExponent));
{
.moduloPtr = modulus_2048,
.moduloLength = 2048u,
.pubExpPtr = publicExponent,
.pubExpLength = sizeof(publicExponent)* 8, /* 17 bits */
.barretCoefPtr = barretCoef,
.inverseModuloPtr = inverseModulo,
.rBarPtr = rBar,
.preCalculatedCoeff = false
};
status = Cy_Cryptolite_Rsa_Init(CRYPTOLITE, &rsa_ctx, &rsa_buffer);
/* ... check for errors... */
/* At first decrypt the received signature. */
status = Cy_Cryptolite_Rsa_Proc(CRYPTOLITE, &rsa_ctx, &pubKeyPtr, encryptedSignature_2048, 2048u, decryptedSignature);
/* ... check for errors... */
/* Calculate the hash from the plain text */
status = Cy_Cryptolite_Sha256_Run(CRYPTOLITE, plainTxt, sizeof(plainTxt)-1, calculatedHash, &sha_ctx);
/* ... check for errors... */
Cy_Cryptolite_InvertEndianness(decryptedSignature, sizeof(encryptedSignature_2048));
/* Finally verify decrypted signature with calculated digest */
status = Cy_Cryptolite_Rsa_Verify(CRYPTOLITE, &rsa_ctx, &verResult, CY_CRYPTOLITE_MODE_SHA256, calculatedHash, sizeof(calculatedHash), decryptedSignature, sizeof(encryptedSignature_2048));
/* ... check for errors... */
Cy_Cryptolite_Rsa_Free(CRYPTOLITE, &rsa_ctx);
/* ... check verResult is CY_CRYPTOLITE_SIG_VALID... */

◆ Cy_Cryptolite_Rsa_Proc()

cy_en_cryptolite_status_t Cy_Cryptolite_Rsa_Proc ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_rsa_t cfContext,
cy_stc_cryptolite_rsa_pub_key_t key,
uint8_t const *  message,
uint32_t  messageSize,
uint8_t *  processedMessage 
)

RSA process algorithm based on the Montgomery algorithm using Barrett reduction.

https://en.wikipedia.org/wiki/RSA_%28cryptosystem%29

Key, message, processedMessage buffers must be 4 byte aligned and end with 4 byte boundary.

Parameters
baseThe pointer to the CRYPTOLITE instance.
cfContextThe pointer to the CRYPTOLITE context.
keyThe pointer to the cy_stc_cryptolite_rsa_pub_key_t structure that stores public key.
messageThe pointer to the message to be processed.
messageSizeThe length of the message to be processed.
processedMessageThe pointer to processed message.
Returns
cy_en_cryptolite_status_t
Function Usage
CY_ALIGN(4) uint8_t encryptedSignature_2048[] =
{
0x86, 0x1c, 0xf4, 0x97, 0xcc, 0xb0, 0xf9, 0x8e, 0xb1, 0x93, 0x20, 0x30, 0x5b, 0xe4, 0xe2, 0xf4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0xf9, 0xc8, 0xa0, 0xcc, 0x83, 0x70, 0x46, 0x31, 0x3a,
0x98, 0x29, 0xae, 0x60, 0x38, 0x6f, 0xe2, 0x7e, 0xac, 0x5b, 0x8e, 0x15, 0xa0, 0x21, 0x00, 0x78,
0x72, 0x4c, 0x87, 0x70, 0x60, 0x6a, 0x23, 0x9a, 0x49, 0x7f, 0x93, 0xfd, 0x26, 0x3f, 0xb9, 0x3d,
0x3e, 0xa8, 0xfe, 0x0a, 0x0c, 0xc6, 0x67, 0x37, 0x19, 0x03, 0xdf, 0xe5, 0x4f, 0x6d, 0x03, 0x4d,
};
CY_ALIGN(4) uint8_t modulus_2048[] =
{
/* Big endian format */
0xbf,0xbe,0x6e,0xc4,0x9e,0x76,0x9d,0x45,0xf9,0x17,0x32,0x9d,0x4a,0xa0,0xe4,0xf0,
0xf9,0x9f,0x02,0x6b,0xb2,0xcb,0x8a,0xe0,0x51,0xd4,0xea,0x7c,0x7c,0xdf,0xa2,0xa9,
0xa5,0x5a,0x64,0x42,0x76,0xcd,0x38,0x90,0x3d,0x42,0x91,0x3d,0x1b,0xc6,0x6c,0x80,
0xc6,0xd7,0x16,0xcb,0x93,0xfe,0x59,0x1f,0xa7,0x97,0x1f,0x57,0xd5,0x6b,0x33,0x53,
0xc8,0x54,0x7f,0xa6,0x4e,0xf8,0x26,0x7e,0x6e,0xd5,0x1f,0x78,0x31,0x32,0xdf,0xca,
0x82,0x39,0xb1,0x42,0x57,0xa8,0xa8,0x9f,0x93,0x4e,0x39,0x7b,0xa7,0xf0,0x39,0x61,
0x42,0x31,0x38,0xa2,0xff,0x05,0xf5,0x0d,0x06,0x0d,0x26,0x66,0xe5,0x71,0x6f,0x0d,
0x52,0x24,0x6f,0x4d,0x83,0x8e,0x97,0xda,0x88,0x91,0x41,0xe4,0x16,0x31,0x70,0x69,
0xea,0x3a,0x61,0x4f,0xb3,0x58,0x4c,0xc7,0xdd,0xf0,0x6a,0xd0,0x7b,0xa5,0x2c,0x47,
0x03,0x06,0x7a,0x31,0x8f,0xab,0xc7,0xca,0x73,0xc4,0xa9,0xe8,0x17,0xd3,0xff,0x2e,
0x2b,0x0d,0x60,0x48,0x5d,0x69,0x8a,0xa0,0xb4,0x8e,0x37,0xe9,0xf5,0x2d,0xb7,0x5f,
0xfd,0x27,0x2b,0x65,0x05,0xfc,0xab,0x43,0x43,0xdc,0x84,0x40,0x7f,0x1b,0x67,0x7d,
0x7e,0xc1,0xa7,0xf5,0x37,0xfa,0xb9,0xcd,0x56,0x7f,0xde,0xb3,0xb8,0x76,0x90,0xf4,
0x00,0x3b,0xcc,0x9b,0xb6,0xf8,0xec,0xbc,0x41,0x92,0x71,0xe3,0xe2,0xf3,0x0d,0xf9,
0xd7,0x7a,0x2a,0x27,0x3f,0x80,0xb3,0x98,0x9d,0x39,0xaa,0x10,0xdc,0x8b,0x6c,0x16,
0xca,0x97,0xef,0x55,0xd6,0x5f,0x18,0x89,0x61,0x0e,0x24,0xb9,0x11,0x4d,0x6e,0xc7
};
CY_ALIGN(4) uint8_t plainTxt[] = "abc";
CY_ALIGN(4) uint8_t publicExponent[] =
{
/* This is a part of public key. (So called e)
* Refer public_key.txt
*/
/* Big endian format */
0x01, 0x00, 0x01
};
CY_ALIGN(4) uint8_t barretCoef[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be modulo length + 1 BITS */
CY_ALIGN(4) uint8_t inverseModulo[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be same as modulo length */
CY_ALIGN(4) uint8_t rBar[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be same as modulo length */
CY_ALIGN(4)uint8_t decryptedSignature[2048/8]={0};
CY_ALIGN(4) uint8_t calculatedHash[32]={0};
memset((void*)&decryptedSignature, 0u, sizeof(decryptedSignature));
memset((void*)&calculatedHash, 0u, sizeof(calculatedHash));
memset((void*)&rsa_buffer, 0u, sizeof(rsa_buffer));
memset((void*)&rsa_ctx, 0u, sizeof(rsa_ctx));
memset((void*)&sha_ctx, 0u, sizeof(sha_ctx));
Cy_Cryptolite_InvertEndianness(modulus_2048, 2048u/8 );
Cy_Cryptolite_InvertEndianness(encryptedSignature_2048, sizeof(encryptedSignature_2048) );
Cy_Cryptolite_InvertEndianness(publicExponent, sizeof(publicExponent));
{
.moduloPtr = modulus_2048,
.moduloLength = 2048u,
.pubExpPtr = publicExponent,
.pubExpLength = sizeof(publicExponent)* 8, /* 17 bits */
.barretCoefPtr = barretCoef,
.inverseModuloPtr = inverseModulo,
.rBarPtr = rBar,
.preCalculatedCoeff = false
};
status = Cy_Cryptolite_Rsa_Init(CRYPTOLITE, &rsa_ctx, &rsa_buffer);
/* ... check for errors... */
/* At first decrypt the received signature. */
status = Cy_Cryptolite_Rsa_Proc(CRYPTOLITE, &rsa_ctx, &pubKeyPtr, encryptedSignature_2048, 2048u, decryptedSignature);
/* ... check for errors... */
/* Calculate the hash from the plain text */
status = Cy_Cryptolite_Sha256_Run(CRYPTOLITE, plainTxt, sizeof(plainTxt)-1, calculatedHash, &sha_ctx);
/* ... check for errors... */
Cy_Cryptolite_InvertEndianness(decryptedSignature, sizeof(encryptedSignature_2048));
/* Finally verify decrypted signature with calculated digest */
status = Cy_Cryptolite_Rsa_Verify(CRYPTOLITE, &rsa_ctx, &verResult, CY_CRYPTOLITE_MODE_SHA256, calculatedHash, sizeof(calculatedHash), decryptedSignature, sizeof(encryptedSignature_2048));
/* ... check for errors... */
Cy_Cryptolite_Rsa_Free(CRYPTOLITE, &rsa_ctx);
/* ... check verResult is CY_CRYPTOLITE_SIG_VALID... */

◆ Cy_Cryptolite_Rsa_Coef()

cy_en_cryptolite_status_t Cy_Cryptolite_Rsa_Coef ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_rsa_t cfContext,
cy_stc_cryptolite_rsa_pub_key_t key 
)

Calculation constant coefficients to speed-up Montgomery algorithm.

These coefficients are: coefficient for Barrett reduction, binary inverse of the modulo, result of (2^moduloLength mod modulo)

Parameters
baseThe pointer to the CRYPTOLITE instance.
cfContextThe pointer to the CRYPTOLITE context.
keyThe pointer to the cy_stc_cryptolite_rsa_pub_key_t structure that stores a public key.
Returns
cy_en_cryptolite_status_t

◆ Cy_Cryptolite_Rsa_Free()

cy_en_cryptolite_status_t Cy_Cryptolite_Rsa_Free ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_rsa_t cfContext 
)

Cleanup the RSA context.

Parameters
baseThe pointer to the CRYPTOLITE instance.
cfContextThe pointer to the CRYPTOLITE context.
Returns
cy_en_cryptolite_status_t
Function Usage
CY_ALIGN(4) uint8_t encryptedSignature_2048[] =
{
0x86, 0x1c, 0xf4, 0x97, 0xcc, 0xb0, 0xf9, 0x8e, 0xb1, 0x93, 0x20, 0x30, 0x5b, 0xe4, 0xe2, 0xf4,
0x30, 0x66, 0xa3, 0x6d, 0xe8, 0x74, 0x4f, 0xa9, 0xe9, 0xd1, 0x16, 0xc5, 0x17, 0xc0, 0x97, 0x1d,
0x60, 0x39, 0xb0, 0xda, 0xf4, 0x65, 0xad, 0x7e, 0x59, 0x6c, 0xce, 0x12, 0x29, 0x8b, 0x23, 0xdd,
0x4b, 0xb6, 0xd3, 0xb6, 0x7e, 0x2b, 0x5d, 0xae, 0x55, 0x5e, 0x43, 0xf3, 0x61, 0x8a, 0x8c, 0xbd,
0x47, 0x59, 0x05, 0x21, 0x4b, 0x54, 0x7b, 0x49, 0xd2, 0xbd, 0x33, 0xdb, 0x82, 0x5d, 0xfc, 0xb4,
0xf8, 0xcf, 0x37, 0x2d, 0x2f, 0x04, 0x76, 0x66, 0x0d, 0x16, 0xea, 0x28, 0xb3, 0xde, 0x40, 0x86,
0x8d, 0x83, 0x2d, 0xca, 0x6d, 0x5d, 0xac, 0xf5, 0x0e, 0x4f, 0xb3, 0xb3, 0x04, 0xb6, 0x91, 0x87,
0xab, 0xac, 0x1f, 0x2f, 0xdc, 0x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1b,0xc6,0x6c,0x80,
0xc6,0xd7,0x16,0xcb,0x93,0xfe,0x59,0x1f,0xa7,0x97,0x1f,0x57,0xd5,0x6b,0x33,0x53,
0xc8,0x54,0x7f,0xa6,0x4e,0xf8,0x26,0x7e,0x6e,0xd5,0x1f,0x78,0x31,0x32,0xdf,0xca,
0x82,0x39,0xb1,0x42,0x57,0xa8,0xa8,0x9f,0x93,0x4e,0x39,0x7b,0xa7,0xf0,0x39,0x61,
0x42,0x31,0x38,0xa2,0xff,0x05,0xf5,0x0d,0x06,0x0d,0x26,0x66,0xe5,0x71,0x6f,0x0d,
0x52,0x24,0x6f,0x4d,0x83,0x8e,0x97,0xda,0x88,0x91,0x41,0xe4,0x16,0x31,0x70,0x69,
0xea,0x3a,0x61,0x4f,0xb3,0x58,0x4c,0xc7,0xdd,0xf0,0x6a,0xd0,0x7b,0xa5,0x2c,0x47,
0x03,0x06,0x7a,0x31,0x8f,0xab,0xc7,0xca,0x73,0xc4,0xa9,0xe8,0x17,0xd3,0xff,0x2e,
0x2b,0x0d,0x60,0x48,0x5d,0x69,0x8a,0xa0,0xb4,0x8e,0x37,0xe9,0xf5,0x2d,0xb7,0x5f,
0xfd,0x27,0x2b,0x65,0x05,0xfc,0xab,0x43,0x43,0xdc,0x84,0x40,0x7f,0x1b,0x67,0x7d,
0x7e,0xc1,0xa7,0xf5,0x37,0xfa,0xb9,0xcd,0x56,0x7f,0xde,0xb3,0xb8,0x76,0x90,0xf4,
0x00,0x3b,0xcc,0x9b,0xb6,0xf8,0xec,0xbc,0x41,0x92,0x71,0xe3,0xe2,0xf3,0x0d,0xf9,
0xd7,0x7a,0x2a,0x27,0x3f,0x80,0xb3,0x98,0x9d,0x39,0xaa,0x10,0xdc,0x8b,0x6c,0x16,
0xca,0x97,0xef,0x55,0xd6,0x5f,0x18,0x89,0x61,0x0e,0x24,0xb9,0x11,0x4d,0x6e,0xc7
};
CY_ALIGN(4) uint8_t plainTxt[] = "abc";
CY_ALIGN(4) uint8_t publicExponent[] =
{
/* This is a part of public key. (So called e)
* Refer public_key.txt
*/
/* Big endian format */
0x01, 0x00, 0x01
};
CY_ALIGN(4) uint8_t barretCoef[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be modulo length + 1 BITS */
CY_ALIGN(4) uint8_t inverseModulo[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be same as modulo length */
CY_ALIGN(4) uint8_t rBar[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be same as modulo length */
CY_ALIGN(4)uint8_t decryptedSignature[2048/8]={0};
CY_ALIGN(4) uint8_t calculatedHash[32]={0};
memset((void*)&decryptedSignature, 0u, sizeof(decryptedSignature));
memset((void*)&calculatedHash, 0u, sizeof(calculatedHash));
memset((void*)&rsa_buffer, 0u, sizeof(rsa_buffer));
memset((void*)&rsa_ctx, 0u, sizeof(rsa_ctx));
memset((void*)&sha_ctx, 0u, sizeof(sha_ctx));
Cy_Cryptolite_InvertEndianness(modulus_2048, 2048u/8 );
Cy_Cryptolite_InvertEndianness(encryptedSignature_2048, sizeof(encryptedSignature_2048) );
Cy_Cryptolite_InvertEndianness(publicExponent, sizeof(publicExponent));
{
.moduloPtr = modulus_2048,
.moduloLength = 2048u,
.pubExpPtr = publicExponent,
.pubExpLength = sizeof(publicExponent)* 8, /* 17 bits */
.barretCoefPtr = barretCoef,
.inverseModuloPtr = inverseModulo,
.rBarPtr = rBar,
.preCalculatedCoeff = false
};
status = Cy_Cryptolite_Rsa_Init(CRYPTOLITE, &rsa_ctx, &rsa_buffer);
/* ... check for errors... */
/* At first decrypt the received signature. */
status = Cy_Cryptolite_Rsa_Proc(CRYPTOLITE, &rsa_ctx, &pubKeyPtr, encryptedSignature_2048, 2048u, decryptedSignature);
/* ... check for errors... */
/* Calculate the hash from the plain text */
status = Cy_Cryptolite_Sha256_Run(CRYPTOLITE, plainTxt, sizeof(plainTxt)-1, calculatedHash, &sha_ctx);
/* ... check for errors... */
Cy_Cryptolite_InvertEndianness(decryptedSignature, sizeof(encryptedSignature_2048));
/* Finally verify decrypted signature with calculated digest */
status = Cy_Cryptolite_Rsa_Verify(CRYPTOLITE, &rsa_ctx, &verResult, CY_CRYPTOLITE_MODE_SHA256, calculatedHash, sizeof(calculatedHash), decryptedSignature, sizeof(encryptedSignature_2048));
/* ... check for errors... */
Cy_Cryptolite_Rsa_Free(CRYPTOLITE, &rsa_ctx);
/* ... check verResult is CY_CRYPTOLITE_SIG_VALID... */

◆ Cy_Cryptolite_Rsa_Verify()

cy_en_cryptolite_status_t Cy_Cryptolite_Rsa_Verify ( CRYPTOLITE_Type *  base,
cy_stc_cryptolite_context_rsa_t cfContext,
cy_en_cryptolite_sig_verify_result_t verResult,
cy_en_cryptolite_sha_mode_t  digestType,
uint8_t const *  digest,
uint32_t  digestLength,
uint8_t const *  decryptedSignature,
uint32_t  decryptedSignatureLength 
)

RSA verification with checks for content, paddings and signature format.

SHA digest of the message and decrypted message should be calculated before. Supports only PKCS1-v1_5 format, inside of this format supported padding using only SHA, cases with MD2 and MD5 are not supported. PKCS1-v1_5 described here, page 31: http://www.emc.com/collateral/white-papers/h11300-pkcs-1v2-2-rsa-cryptography-standard-wp.pdf

The digest and decryptedSignature buffers must be 4 byte aligned

Returns the verification result cy_en_cryptolite_sig_verify_result_t.

Parameters
baseThe pointer to the CRYPTOLITE instance.
cfContextThe pointer to the CRYPTOLITE context.
verResultThe pointer to the verification result cy_en_cryptolite_sig_verify_result_t.
digestTypeSHA mode used for hash calculation cy_en_cryptolite_sha_mode_t.
digestThe pointer to the hash of the message or the message whose signature is to be verified.
digestLengthThe length of the message whose signature is to be verified and is applicable for CY_CRYPTOLITE_MODE_SHA_NONE mode.
decryptedSignatureThe pointer to the decrypted signature to be verified.
decryptedSignatureLengthThe length of the decrypted signature to be verified (in bytes)
Returns
cy_en_cryptolite_status_t
Function Usage
CY_ALIGN(4)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0xc7, 0xd8, 0x4a, 0xa9, 0x6e, 0x3f, 0xc6, 0xdf, 0x7c, 0x12, 0xce, 0xb3,
0x8e, 0x5d, 0x30, 0x2b, 0xb8, 0x66, 0xf4, 0xf9, 0xc8, 0xa0, 0xcc, 0x83, 0x70, 0x46, 0x31, 0x3a,
0x98, 0x29, 0xae, 0x60, 0x38, 0x6f, 0xe2, 0x7e, 0xac, 0x5b, 0x8e, 0x15, 0xa0, 0x21, 0x00, 0x78,
0x72, 0x4c, 0x87, 0x70, 0x60, 0x6a, 0x23, 0x9a, 0x49, 0x7f, 0x93, 0xfd, 0x26, 0x3f, 0xb9, 0x3d,
0x3e, 0xa8, 0xfe, 0x0a, 0x0c, 0xc6, 0x67, 0x37, 0x19, 0x03, 0xdf, 0xe5, 0x4f, 0x6d, 0x03, 0x4d,
};
CY_ALIGN(4) uint8_t modulus_2048[] =
{
/* Big endian format */
0xbf,0xbe,0x6e,0xc4,0x9e,0x76,0x9d,0x45,0xf9,0x17,0x32,0x9d,0x4a,0xa0,0xe4,0xf0,
0xf9,0x9f,0x02,0x6b,0xb2,0xcb,0x8a,0xe0,0x51,0xd4,0xea,0x7c,0x7c,0xdf,0xa2,0xa9,
0xa5,0x5a,0x64,0x42,0x76,0xcd,0x38,0x90,0x3d,0x42,0x91,0x3d,0x1b,0xc6,0x6c,0x80,
0xc6,0xd7,0x16,0xcb,0x93,0xfe,0x59,0x1f,0xa7,0x97,0x1f,0x57,0xd5,0x6b,0x33,0x53,
0xc8,0x54,0x7f,0xa6,0x4e,0xf8,0x26,0x7e,0x6e,0xd5,0x1f,0x78,0x31,0x32,0xdf,0xca,
0x82,0x39,0xb1,0x42,0x57,0xa8,0xa8,0x9f,0x93,0x4e,0x39,0x7b,0xa7,0xf0,0x39,0x61,
0x42,0x31,0x38,0xa2,0xff,0x05,0xf5,0x0d,0x06,0x0d,0x26,0x66,0xe5,0x71,0x6f,0x0d,
0x52,0x24,0x6f,0x4d,0x83,0x8e,0x97,0xda,0x88,0x91,0x41,0xe4,0x16,0x31,0x70,0x69,
0xea,0x3a,0x61,0x4f,0xb3,0x58,0x4c,0xc7,0xdd,0xf0,0x6a,0xd0,0x7b,0xa5,0x2c,0x47,
0x03,0x06,0x7a,0x31,0x8f,0xab,0xc7,0xca,0x73,0xc4,0xa9,0xe8,0x17,0xd3,0xff,0x2e,
0x2b,0x0d,0x60,0x48,0x5d,0x69,0x8a,0xa0,0xb4,0x8e,0x37,0xe9,0xf5,0x2d,0xb7,0x5f,
0xfd,0x27,0x2b,0x65,0x05,0xfc,0xab,0x43,0x43,0xdc,0x84,0x40,0x7f,0x1b,0x67,0x7d,
0x7e,0xc1,0xa7,0xf5,0x37,0xfa,0xb9,0xcd,0x56,0x7f,0xde,0xb3,0xb8,0x76,0x90,0xf4,
0x00,0x3b,0xcc,0x9b,0xb6,0xf8,0xec,0xbc,0x41,0x92,0x71,0xe3,0xe2,0xf3,0x0d,0xf9,
0xd7,0x7a,0x2a,0x27,0x3f,0x80,0xb3,0x98,0x9d,0x39,0xaa,0x10,0xdc,0x8b,0x6c,0x16,
0xca,0x97,0xef,0x55,0xd6,0x5f,0x18,0x89,0x61,0x0e,0x24,0xb9,0x11,0x4d,0x6e,0xc7
};
CY_ALIGN(4) uint8_t plainTxt[] = "abc";
CY_ALIGN(4) uint8_t publicExponent[] =
{
/* This is a part of public key. (So called e)
* Refer public_key.txt
*/
/* Big endian format */
0x01, 0x00, 0x01
};
CY_ALIGN(4) uint8_t barretCoef[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be modulo length + 1 BITS */
CY_ALIGN(4) uint8_t inverseModulo[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be same as modulo length */
CY_ALIGN(4) uint8_t rBar[4*VU_BITS_TO_WORDS(CY_CRYPTOLITE_RSA_BITSIZE+1)]={0}; /* Must be same as modulo length */
CY_ALIGN(4)uint8_t decryptedSignature[2048/8]={0};
CY_ALIGN(4) uint8_t calculatedHash[32]={0};
memset((void*)&decryptedSignature, 0u, sizeof(decryptedSignature));
memset((void*)&calculatedHash, 0u, sizeof(calculatedHash));
memset((void*)&rsa_buffer, 0u, sizeof(rsa_buffer));
memset((void*)&rsa_ctx, 0u, sizeof(rsa_ctx));
memset((void*)&sha_ctx, 0u, sizeof(sha_ctx));
Cy_Cryptolite_InvertEndianness(modulus_2048, 2048u/8 );
Cy_Cryptolite_InvertEndianness(encryptedSignature_2048, sizeof(encryptedSignature_2048) );
Cy_Cryptolite_InvertEndianness(publicExponent, sizeof(publicExponent));
{
.moduloPtr = modulus_2048,
.moduloLength = 2048u,
.pubExpPtr = publicExponent,
.pubExpLength = sizeof(publicExponent)* 8, /* 17 bits */
.barretCoefPtr = barretCoef,
.inverseModuloPtr = inverseModulo,
.rBarPtr = rBar,
.preCalculatedCoeff = false
};
status = Cy_Cryptolite_Rsa_Init(CRYPTOLITE, &rsa_ctx, &rsa_buffer);
/* ... check for errors... */
/* At first decrypt the received signature. */
status = Cy_Cryptolite_Rsa_Proc(CRYPTOLITE, &rsa_ctx, &pubKeyPtr, encryptedSignature_2048, 2048u, decryptedSignature);
/* ... check for errors... */
/* Calculate the hash from the plain text */
status = Cy_Cryptolite_Sha256_Run(CRYPTOLITE, plainTxt, sizeof(plainTxt)-1, calculatedHash, &sha_ctx);
/* ... check for errors... */
Cy_Cryptolite_InvertEndianness(decryptedSignature, sizeof(encryptedSignature_2048));
/* Finally verify decrypted signature with calculated digest */
status = Cy_Cryptolite_Rsa_Verify(CRYPTOLITE, &rsa_ctx, &verResult, CY_CRYPTOLITE_MODE_SHA256, calculatedHash, sizeof(calculatedHash), decryptedSignature, sizeof(encryptedSignature_2048));
/* ... check for errors... */
Cy_Cryptolite_Rsa_Free(CRYPTOLITE, &rsa_ctx);
/* ... check verResult is CY_CRYPTOLITE_SIG_VALID... */