2 Replies Latest reply on Nov 20, 2019 11:31 AM by AnCi_2234676

    PSoC 6 RSA encryption

    AnCi_2234676

      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