Tool/software:
Hi,
I ran the sample code at the URL below, but the return value of ECDSA_sign is -32.
What could be the cause?
ECDSA_ReturnBehavior is set with ECDSA_RETURN_BEHAVIOR_CALLBACK.
The same phenomenon occurs with ECDSA_RETURN_BEHAVIOR_BLOCKING.
The source code used is also attached.
[Conditions]
SDK:simplelink_lowpower_f3_sdk_8_30_00_11_ea
[URL]
software-dl.ti.com/.../_e_c_d_s_a_8h.html
[Sample]
ECDSA sign with plaintext CryptoKeys for CC27XX and CC35XX devices
Best Regards,
Katsuya
/* * ======== empty.c ======== */ /* For usleep() */ #include <unistd.h> #include <stdint.h> #include <stddef.h> #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h> #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyKeyStore_PSA_init.h> #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyKeyStore_PSA_helpers.h> #include <ti/drivers/ECDSA.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> // #include <ti/drivers/I2C.h> // #include <ti/drivers/SPI.h> // #include <ti/drivers/Watchdog.h> /* Driver configuration */ #include "ti_drivers_config.h" static void ECDSA_Callback( ECDSA_Handle ecdsaHandle, int_fast16_t s2t_ReturnStatus, ECDSA_Operation stt_Operation, ECDSA_OperationType s4t_OperationType); static void startecdsa( void); int_fast16_t operationResult; /* * ======== mainThread ======== */ uint8_t myPrivateKeyingMaterial[32] = {0x96, 0xBF, 0x85, 0x49, 0xC3, 0x79, 0xE4, 0x04, 0xED, 0xA1, 0x08, 0xA5, 0x51, 0xF8, 0x36, 0x23, 0x12, 0xD8, 0xD1, 0xB2, 0xA5, 0xFA, 0x57, 0x06, 0xE2, 0xCC, 0x22, 0x5C, 0xF6, 0xF9, 0x77, 0xC4}; uint8_t messageHash[32] = {0xA4,0x1A,0x41,0xA1,0x2A,0x79,0x95,0x48, 0x21,0x1C,0x41,0x0C,0x65,0xD8,0x13,0x3A, 0xFD,0xE3,0x4D,0x28,0xBD,0xD5,0x42,0xE4, 0xB6,0x80,0xCF,0x28,0x99,0xC8,0xA8,0xC4}; uint8_t r[32]; uint8_t s[32]; static void ECDSA_Callback( ECDSA_Handle ecdsaHandle, int_fast16_t s2t_ReturnStatus, ECDSA_Operation stt_Operation, ECDSA_OperationType s4t_OperationType) { if( ECDSA_STATUS_SUCCESS == s2t_ReturnStatus ) { } } static void startecdsa( void ) { CryptoKey myPrivateKey; ECDSA_Handle ecdsaHandle; ECDSA_OperationSign operationSign; ECDSA_Params ECDSA_params; // Since we are using default ECDSA_Params, we just pass in NULL for that parameter. ECDSA_init(); ECDSA_Params_init( &ECDSA_params ); ECDSA_params.returnBehavior = ECDSA_RETURN_BEHAVIOR_CALLBACK; ECDSA_params.callbackFxn = ECDSA_Callback; ecdsaHandle = ECDSA_open(0, &ECDSA_params); // Since the ECDSA driver for CC27XX and CC35XX relies on one HW engine (the HSM) for all of its operations // If the HSM boot up sequence fails, ECDSA_open() will return NULL. if (!ecdsaHandle) { // Handle error } // Initialize myPrivateKey CryptoKeyPlaintextHSM_initKey(&myPrivateKey, myPrivateKeyingMaterial, sizeof(myPrivateKeyingMaterial)); //CryptoKeyPlaintext_initKey(&myPrivateKey, // myPrivateKeyingMaterial, // sizeof(myPrivateKeyingMaterial)); // Initialize the operation // For CC27XX and CC35XX devices, you must specify the curveType instead of providing a pointer to the curve like // the case with other devices. ECDSA_OperationSign_init(&operationSign); operationSign.curve = &ECCParams_NISTP256; operationSign.myPrivateKey = &myPrivateKey; operationSign.hash = messageHash; operationSign.r = r; operationSign.s = s; // Generate the signature operationResult = ECDSA_sign(ecdsaHandle, &operationSign); // ← Return -32 if (operationResult != ECDSA_STATUS_SUCCESS) { // Handle error } } void *mainThread(void *arg0) { /* 1 second delay */ uint32_t time = 1; startecdsa(); while (1) { sleep(time); //GPIO_toggle(CONFIG_GPIO_LED_0); } }