此工程提供了两个文件,rsa_private.txt和rsa_public.txt。这些文件包含一个示例私钥和公钥,它们仅作为占位符提供,以帮助您使生成系统正常工作。在投入生产之前,应该将它们替换为您自己的文件。
本节介绍如何生成一组公钥和私钥,将它们格式化为“C”格式,以及使用新密钥更新源文件。
此外,本应用程序说明还描述了带有示例驱动程序库(SDL)的示例代码。本应用程序说明中的代码片段是SDL的一部分。请参阅SDL的参考资料。请参阅sdl_additional_code_examples中16_AN228680_Scure_configuration文件夹的secure configuration.pptx以进行安全配置设置。
此示例代码应用于GHS MULTI环境的CYT2B7系列MCU。
Additional tools required
1. OpenSSL v1.0.2 or later |
2. Python 3 (Required for one of the provided scripts that is used to format the public key.) |
3. SDL 7.5 or later |
有几种方法可以生成RSA私钥和公钥。在以下方法中,您需要在计算机上安装OpenSSL/Python。OpenSSL的这些源代码或二进制文件可以从互联网上的几个源代码下载。
Scripts
该项目提供了两个脚本,用于将OpenSSL的输出转换为与C和Secure Image用于存储公钥的结构兼容的格式。这些脚本在以下路径中可用:
<user>\tviibe1m\04_Util\Scripts\Key_2K, Key_3K or Key_4K
<user>: Sample project stored folder
批处理脚本rsa_keygen.bat调用OpenSSL函数。因此,必须在您的计算机上安装OpenSSL。批处理文件创建一个名为“keys_generated”的目录。将创建两个文件,其中包含使用OpenSSL生成的私钥和公钥。“rsa_private.txt”作为私钥,“rsa_public.txt”作为公钥。
接下来,批处理文件将调用Python脚本“rsa\o_c.py”。该脚本将生成的公钥文件中的数据格式化为与c和Cypress公钥格式兼容。输出与公钥和私钥文件一起放置在keys_generated目录中的文件rsa\o_c_generated.txt中。
下面显示了用于生成rsa-2048私钥和公钥的rsa_keygen.bat:
set OUT_DIR="%~dp0\keys_generated"
set PRIV_NAME=rsa_private_generated.txt
set PUB_NAME=rsa_public_generated.txt
set PRIV_RNAME=rsa_private.txt
set PUB_RNAME=rsa_public.txt
set MOD_NAME=rsa_to_c_generated.txt
if not exist %OUT_DIR% mkdir %OUT_DIR%
:: Generate the RSA-2K public and private keys
openssl genrsa -out %OUT_DIR%\%PRIV_NAME% 2048
openssl rsa -in %OUT_DIR%\%PRIV_NAME% -outform PEM -pubout -out %OUT_DIR%\%PUB_NAME%
copy %OUT_DIR%\%PRIV_NAME% %OUT_DIR%\%PRIV_RNAME%
copy %OUT_DIR%\%PUB_NAME% %OUT_DIR%\%PUB_RNAME%
:: Create C-code ready public key
python %~dp0\rsa_to_c.py %OUT_DIR%\%PUB_NAME% > %OUT_DIR%\%MOD_NAME%
如果为RSA-3072生成私钥和公钥,请将上面bat文件中的2048(line 9)中的文本更改为3072。如果是RSA-4096,请将文本更改为4096。
9.3 运行脚本
批处理文件rsa_keygen.bat可以从命令行界面调用,也可以在Windows 7或10环境中双击(a)调用。脚本运行后,验证keys_generated文件夹(b)中是否已生成以下文件。
• rsa_private.txt (Private RSA key) |
• rsa_public.txt (Public RSA key) |
• rsa_to_c_generated.txt (Public key in C format) |
1、首先使用 openssl 生成一个 2048 位的密钥文件rsa_private_generated.txt (私钥),打开rsa_private_generated.txt 文件,私钥文件(RSA-2048)示例内容如下(BEGIN 和END 之间的为密钥):
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA1evv29SIGUMM/2JHIhZPKVflDKB0iIu87V4zZ6WTyIh9BAJZ
qej3LUSD02JwvoejoVJZrkdUAA1jzNw5mGmbelQyMfBwal78GhYXX2BiKJfmlwob
07NSIQYfmAZGfcJzTKj/DAUK9bDNZvNhwUc8+j8zcuICAVXqzy25qwmSAXwqQuaf
wplzD3zrevOs7N9p973116F1o5AH+uacmVGb1FF7xtrPYH7P9QEALLWy4TIm1bPw
aUVKfex+PX2wdtU6YKl73HOUHXV8IAhGP8rX0H5YA6+uWv8M4RhbcjGFx764MRoL
4rsCpwhaFZtYLdfNq6uLxItF8TwUWZIGOuZY1QIDAQABAoIBAQCyaunOq2An0aiR
h+JUJ882aDx9X4ZSLFoSj7LIC21Kn6vFIECwWcFuW+qm7z+haXesIQbzOEJzGLfY
MQVIfSxTx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wP2lzB4ml9UvvRJa
c1lnmciiiHj9lCTEPw3O8OsQA0Q+M3oMoe9P18mJLn6jtH0woOqWgw==
-----END RSA PRIVATE KEY-----
2. 然后从 rsa_private_generated.txt密钥文件中生成公钥 rsa_public_generated.txt(格式为pem base64编码)
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1evv29SIGUMM/2JHIhZP
KVflDKB0iIu87V4zZ6WTyIh9BAJZqej3LUSD02JwvoejoVJZrkdUAA1jzNw5mGmb
elQyMfBwal78GhYXX2BiKJfmlwob07NSIQYfmAZGfcJzTKj/DAUK9bDNZvNhwUc8
+j8zcuICAVXqzy25qwmSAXwqQuafwplzD3zrevOs7N9p973116F1o5AH+uacmVGb
1FF7xtrPYH7P9QEALLWy4TIm1bPwaUVKfex+PX2wdtU6YKl73HOUHXV8IAhGP8rX
0H5YA6+uWv8M4RhbcjGFx764MRoL4rsCpwhaFZtYLdfNq6uLxItF8TwUWZIGOuZY
1QIDAQAB
-----END PUBLIC KEY-----
3、python脚本中会执行如下语句解析获取公钥
try:# build openssl command linecmd_line = ['openssl', 'rsa', '-text', '-pubin', '-in',sys.argv[1],'-noout']output, error = subprocess.Popen(cmd_line, universal_newlines=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
sys.argv[1]为rsa_public_generated.txt输入文件
cmd_line意思是解析公钥内容,不输出公钥文本。
9.4安装公钥
最后,将生成的rsa_to_c_generated.txt文件中的代码复制到main_cm0plus.c源文件中,更新Secure Image中的公钥的,该文件是Secure Image项目的一部分。此文件更新后的示例如下所示。生成的密钥数据中的替换代码如下所示。以下是RSA-2048的示例:
/** Public key in SFlash */
CY_SECTION(".cy_SFlash_public_key") __USED const cy_si_stc_public_key_t cy_publicKey =
{.objSize = sizeof(cy_si_stc_public_key_t),.signatureScheme = 0UL,.publicKeyStruct ={.moduloAddr = CY_SI_PUBLIC_KEY + offsetof(cy_si_stc_public_key_t, moduloData),.moduloSize = CY_SI_PUBLIC_KEY_SIZEOF_BYTE * CY_SI_PUBLIC_KEY_MODULOLENGTH,.expAddr = CY_SI_PUBLIC_KEY + offsetof(cy_si_stc_public_key_t, expData),.expSize = CY_SI_PUBLIC_KEY_SIZEOF_BYTE * CY_SI_PUBLIC_KEY_EXPLENGTH,.barrettAddr = CY_SI_PUBLIC_KEY + offsetof(cy_si_stc_public_key_t, barrettData),.inverseModuloAddr = CY_SI_PUBLIC_KEY + offsetof(cy_si_stc_public_key_t, inverseModuloData),.rBarAddr = CY_SI_PUBLIC_KEY + offsetof(cy_si_stc_public_key_t, rBarData),},.moduloData ={0x39u, 0xAAu, 0x09u, 0x31u, 0x9Cu, 0x10u, 0x98u, 0x1Eu,0x2Bu, 0x32u, 0x5Cu, 0x3Du, 0x72u, 0x5Au, 0xFFu, 0x47u,0x26u, 0x18u, 0x63u, 0x86u, 0x65u, 0x3Fu, 0x3Bu, 0x57u,0x0Fu, 0xA6u, 0xA3u, 0x8Du, 0x21u, 0x37u, 0x60u, 0xC0u,0xF5u, 0xB2u, 0xBDu, 0x4Cu, 0xA8u, 0xE5u, 0xBAu, 0x50u,0x21u, 0xE8u, 0xA4u, 0x80u, 0x85u, 0xB1u, 0x32u, 0x9Bu,0x9Au, 0xBBu, 0xCFu, 0xBCu, 0x1Au, 0xA1u, 0x94u, 0x80u,0x48u, 0x9Au, 0x75u, 0xD0u, 0xAEu, 0x0Au, 0x6Du, 0xDAu,0x05u, 0x60u, 0x49u, 0xC5u, 0x8Eu, 0x80u, 0xA0u, 0xB0u,0xC1u, 0xA3u, 0x8Eu, 0x86u, 0x95u, 0xF6u, 0xF0u, 0xFFu,0x95u, 0xC6u, 0x98u, 0x49u, 0x52u, 0x2Du, 0x0Au, 0x0Bu,0xBCu, 0xBAu, 0x0Fu, 0xBEu, 0xC2u, 0x2Du, 0xE6u, 0x71u,0x45u, 0x7Eu, 0x6Au, 0xC2u, 0x8Fu, 0x30u, 0xF3u, 0x1Bu,0x3Du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x2Du, 0xADu, 0x4Cu,},
};
Cy_FB_Isvalidkey可以检查公钥结构是否有效。See the “Flash Boot” chapter in the architecture TRM [2] for more details。
根据RSA密钥的大小,需要在以下文件中更改公钥格式的模数位长度:
<user>\ tviibe1m\src\cy_si_keystorage.h
<user>: Sample project stored folder
#define CY_SI_PUBLIC_KEY_MODULOLENGTH (256UL) /**< Modulus length of the RSA 2K key */
//#define CY_SI_PUBLIC_KEY_MODULOLENGTH (384UL) /**< Modulus length of the RSA 3K key */
//#define CY_SI_PUBLIC_KEY_MODULOLENGTH (512UL) /**< Modulus length of the RSA 4K key */