- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I need to use Cy_Crypto_Rsa_CalcCoefs to populate the barretCoefPtr, rBarPtr, and inverseModuloPtr fields of my cy_stc_crypto_rsa_pub_key_t structure. However, I would prefer the arrays to be in flash instead of RAM, so I would need to compute those outside of the firmware, and then declare them as const. Is there a code example of how to compute those arrays (basically what the Cy_Crypto_Rsa_CalcCoefs does)?
Thank you,
Fred
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just found out that Cypress provides a tool to generate all those tables into a C file. That's exactly what I needed.
"C:\Program Files (x86)\Cypress\PDL\version\security\secure_image\src\scripts\rsa_to_c.py"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Fred,
You can calculate these coefficients directly by a call to Cy_Crypto_Rsa_CalcCoefs and print it after calculation. You can then store these values in flash by declaring them as const.
Important note: if you use RSA process function once you don’t need to calculate these coefficients before.
Please look into the key data structure for allocation details:
/**
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*
* The driver uses this structure to store and manipulate the RSA public key and
* additional coefficients to accelerate RSA calculation.
*
* RSA key contained from two fields:
* - n - modulus part of the key
* - e - exponent part of the key.
*
* Other fields are accelerating coefficients and can be calculated by
* \ref Cy_Crypto_Rsa_CalcCoefs.
*
* \note The <b>modulus</b> and <b>exponent</b> values in the
* \ref cy_stc_crypto_rsa_pub_key_t must also be in little-endian order.<br>
* Use \ref Cy_Crypto_InvertEndianness function to convert to or from
* little-endian order.
*/
typedef struct
{
/** \cond INTERNAL */
/** The pointer to the modulus part of public key. */
uint8_t *moduloPtr;
/** The modulus length, in bits, maximum supported size is 2048Bit */
uint32_t moduloLength;
/** The pointer to the exponent part of public key */
uint8_t *pubExpPtr;
/** The exponent length, in bits, maximum supported size is 256Bit */
uint32_t pubExpLength;
/** The pointer to the Barrett coefficient. Memory for it should be
allocated by user with size moduloLength + 1. */
uint8_t *barretCoefPtr;
/** The pointer to the binary inverse of the modulo. Memory for it
should be allocated by user with size moduloLength. */
uint8_t *inverseModuloPtr;
/** The pointer to the (2^moduloLength mod modulo). Memory for it should
be allocated by user with size moduloLength */
uint8_t *rBarPtr;
/** \endcond */
} cy_stc_crypto_rsa_pub_key_t;
Regards,
Dheeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the answer, Dheeraj. However, it's exactly because I don't want to do this process that I'm asking how to compute those arrays outside of the firmware.
Is the computation process proprietary?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Dheeraj,
While your linked example is useful for a how-to generate rsa key pairs, it does not talk about barretCoefPtr, rBarPtr, or inverseModuloPtr.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just found out that Cypress provides a tool to generate all those tables into a C file. That's exactly what I needed.
"C:\Program Files (x86)\Cypress\PDL\version\security\secure_image\src\scripts\rsa_to_c.py"