- /* coefficient a*/
- const uint8_t secp256_a[] =
- {
- 0x00
- };
- /* coefficient b */
- const uint8_t secp256_b[] =
- {
- 0x7
- };
- /* prime modulus p*/
- const uint8_t secp256_p[] =
- {
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,
- 0xff,0xfc,0x2f
- };
- /* order n*/
- const uint8_t secp256_n[] = {
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,
- 0x36,0x41,0x41
-
- };
- /* base point Gx*/
- const uint8_t secp256_Gx[] =
- {
- 0x79,0xbe,0x66,0x7e,0xf9,0xdc,0xbb,0xac,0x55,0xa0,0x62,0x95,0xce,0x87,
- 0x0b,0x07,0x02,0x9b,0xfc,0xdb,0x2d,0xce,0x28,0xd9,0x59,0xf2,0x81,0x5b,0x16,
- 0xf8,0x17,0x98
-
- };
- /* base point Gy*/
- const uint8_t secp256_Gy[] =
- {
- 0x48,0x3a,0xda,0x77,0x26,0xa3,0xc4,0x65,0x5d,0xa4,0xfb,0xfc,
- 0x0e,0x11,0x08,0xa8,0xfd,0x17,0xb4,0x48,0xa6,0x85,0x54,0x19,0x9c,0x47,0xd0,
- 0x8f,0xfb,0x10,0xd4,0xb8
- };
用户可以直接将此参数拷贝 STM32 加密库的例程,例如
STM32CubeExpansion_Crypto_V3.1.0\Fw_Crypto\STM32L4\Projects\STM32L476RG
Nucleo\ECC\KeyGen_Sign_Verif\Src\main.c。该例程演示的功能包括:生成 ECC 公私钥匙密钥对,使用私钥对指定消息签
名,再使用对应公钥对签名做验签。
为了对这个曲线做如上运行,需要在例程代码的循环处增加一个案例,条件 3,如:
- case 3:
- /* Initialize the ECC curve structure, with all the parameters */
- EC_st.pmA = secp256_a;
- EC_st.pmP = secp256_p;
- EC_st.pmN = secp256_n;
- EC_st.pmGx = secp256_Gx;
- EC_st.pmGy = secp256_Gy;
- EC_st.mAsize = sizeof(secp256_a);
- EC_st.mNsize = sizeof(secp256_n);
- EC_st.mPsize = sizeof(secp256_p);
- EC_st.mGxsize = sizeof(secp256_Gx);
- EC_st.mGysize = sizeof(secp256_Gy);
- break;
别忘了将 for 循环的条件修改成
param_ecc_counter < 4
param_ecc_counter < 4
param_ecc_counter < 4case 3: