cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 6 MCU

Contributor II

Is it normal? Using openssl, that's not the case, so I don't see how that would be normal for the PSoC 6.

0 Likes
Reply
1 Solution
Contributor II

I found how it happens, but not why.

So basically, I had made an error when initializing my cy_stc_crypto_rsa_pub_key_t structure. Instead of

    rsaPublicKey.moduloPtr        = (uint8_t*) moduloData;

    rsaPublicKey.moduloLength     = CRYPTO_RSA_KEY_BIT_LENGTH;

    rsaPublicKey.pubExpPtr        = (uint8_t*) rsaExponent;

    rsaPublicKey.pubExpLength     = rsaExponentLength;

    rsaPublicKey.barretCoefPtr    = (uint8_t*) barretData;

    rsaPublicKey.inverseModuloPtr = (uint8_t*) inverseModuloData;

    rsaPublicKey.rBarPtr          = (uint8_t*) rBarData;

I had

    rsaPublicKey.moduloPtr        = (uint8_t*) &moduloData;

    rsaPublicKey.moduloLength     = CRYPTO_RSA_KEY_BIT_LENGTH;

    rsaPublicKey.pubExpPtr        = (uint8_t*) &rsaExponent;

    rsaPublicKey.pubExpLength     = rsaExponentLength;

    rsaPublicKey.barretCoefPtr    = (uint8_t*) &barretData;

    rsaPublicKey.inverseModuloPtr = (uint8_t*) &inverseModuloData;

    rsaPublicKey.rBarPtr          = (uint8_t*) &rBarData;

I was providing the address of the key pointer instead of the key itself.

I don't get why it would result in 3 fixed zeros for RSA encryption, but pointer bugs are the weirdest behaviors.

View solution in original post

0 Likes
Reply
2 Replies
Contributor II

It seems that it only happens when I use an input buffer that didn't have an initial value.

i.e, if I use:

CY_ALIGN(4) uint8_t msgToEncrypt[256];

instead of

CY_ALIGN(4) uint8_t msgToEncrypt[] = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";

Then the last 3 bytes of encryptedBuffer are always zero after calling the following routine:

Cy_Crypto_Rsa_Proc(&rsaPublicKey,

                   (const uint32_t*)msgToEncrypt,

                   CY_CRYPTO_RSA2048_MESSAGE_SIZE,

                   (uint32_t*)encryptedBuffer,

                   &cryptoRsaContext);

while(Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING) != CY_CRYPTO_SUCCESS);

It doesn't matter if I initialize msgToEncrypt in a function, it has to have an initial value.

Why does that happen?

0 Likes
Reply
Contributor II

I found how it happens, but not why.

So basically, I had made an error when initializing my cy_stc_crypto_rsa_pub_key_t structure. Instead of

    rsaPublicKey.moduloPtr        = (uint8_t*) moduloData;

    rsaPublicKey.moduloLength     = CRYPTO_RSA_KEY_BIT_LENGTH;

    rsaPublicKey.pubExpPtr        = (uint8_t*) rsaExponent;

    rsaPublicKey.pubExpLength     = rsaExponentLength;

    rsaPublicKey.barretCoefPtr    = (uint8_t*) barretData;

    rsaPublicKey.inverseModuloPtr = (uint8_t*) inverseModuloData;

    rsaPublicKey.rBarPtr          = (uint8_t*) rBarData;

I had

    rsaPublicKey.moduloPtr        = (uint8_t*) &moduloData;

    rsaPublicKey.moduloLength     = CRYPTO_RSA_KEY_BIT_LENGTH;

    rsaPublicKey.pubExpPtr        = (uint8_t*) &rsaExponent;

    rsaPublicKey.pubExpLength     = rsaExponentLength;

    rsaPublicKey.barretCoefPtr    = (uint8_t*) &barretData;

    rsaPublicKey.inverseModuloPtr = (uint8_t*) &inverseModuloData;

    rsaPublicKey.rBarPtr          = (uint8_t*) &rBarData;

I was providing the address of the key pointer instead of the key itself.

I don't get why it would result in 3 fixed zeros for RSA encryption, but pointer bugs are the weirdest behaviors.

View solution in original post

0 Likes
Reply
Top labels