- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I want to encrypt 16 bytes of data using RSA (key length: 2048 bits ) with PKCS1 v1.5 padding. After padding here is what my function looks like:
int8_t Crypto_RsaEncrypt(const uint8_t paddedMessage[256], uint8_t* out) {
cy_rslt_t result;
int8_t retVal;
cy_en_crypto_status_t cryptoResult;
CRYPTO_Type* cryptoBase = CRYPTO;
cyhal_resource_inst_t resource = {
.type = CYHAL_RSC_CRYPTO,
.block_num = 0,
.channel_num = 0
};
result = cyhal_crypto_reserve(&cryptoBase, &resource, CYHAL_CRYPTO_COMMON);
if (result == CY_RSLT_SUCCESS) {
cryptoResult = Cy_Crypto_Core_Rsa_Proc(cryptoBase, &rsaPublicKey, (uint8_t const *)paddedMessage, 256, out);
if (cryptoResult == CY_CRYPTO_SUCCESS) {
retVal = 0;
} else {
retVal = -1;
}
cyhal_crypto_free(cryptoBase, &resource, CYHAL_CRYPTO_COMMON);
} else {
retVal = -1;
}
return retVal;
}
I get an assert fail at in function Cy_Crypto_Core_Vu_SetMemValue() (cy_crypto_core_vy.c) at line 63:
CY_ASSERT_L1(size <= Cy_Crypto_Core_Vu_RegBitSizeRead(base, dstReg));
Any idea what I am doing wrong?
I am using Modus Toolbox 2.0 with CY8PROTO-063-BLE kit.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The issue was with moduloLength the public key. I entered it in bytes, not in bits. My bad. Now it seems to work, but I can't decrypt the data with openssl. See PSoC 6 RSA Encryption Example?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The error suggests that the size of the moduloLength given for the public key is more than the supported size of 2048 bit. I cannot guarantee this without the project.
Please attach your project so that I can get more information on the issue.
Regards,
Dheeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The issue was with moduloLength the public key. I entered it in bytes, not in bits. My bad. Now it seems to work, but I can't decrypt the data with openssl. See PSoC 6 RSA Encryption Example?