PSoC 6 RSA encryption

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
AnCi_2234676
Level 4
Level 4
10 replies posted 5 replies posted 10 questions asked

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

0 Likes
1 Solution

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?

View solution in original post

0 Likes
2 Replies
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

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

0 Likes

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?

0 Likes