- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it normal? Using openssl, that's not the case, so I don't see how that would be normal for the PSoC 6.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.