Other Parts Discussed in Thread: SYSCONFIG, CC2745R10-Q1
Tool/software:
To use the ECDH_generatePublicKey() function, I wrote the following code based on the documentation.
However, this code returns ECDH_STATUS_RESOURCE_UNAVAILABLE (-2) as the return value of the function.
The same result is returned when I change the value to the value of the secret key, which should be able to generate other key pairs. Is there a problem with the usage?
"""
void ecdhGenPubCallback(ECDH_Handle handle, int_fast16_t returnStatus, ECDH_Operation operation, ECDH_OperationType operationType)
{
/* LED OFF */
ECDH_close(handle);
}
void *mainThread(void *arg0)
{
uint8_t myPrivateKeyingMaterial[CURVE_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
uint8_t myPublicKeyingMaterial[2 * CURVE_LENGTH + 1] = {0};
GPIO_init();
/* LED ON */
GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
// Since we are using default ECDH_Params, we just pass in NULL for that parameter.
ECDH_Params_init(&Params);
Params.returnBehavior = ECDH_RETURN_BEHAVIOR_CALLBACK;
Params.callbackFxn = ecdhGenPubCallback;
ecdhHandle = ECDH_open(0, &Params);
if (!ecdhHandle) {
// Handle error
}
// Initialize myPrivateKey and myPublicKey
CryptoKeyPlaintext_initKey(&myPrivateKey, myPrivateKeyingMaterial, sizeof(myPrivateKeyingMaterial));
CryptoKeyPlaintext_initBlankKey(&myPublicKey, myPublicKeyingMaterial, sizeof(myPublicKeyingMaterial));
ECDH_OperationGeneratePublicKey_init(&operationGeneratePublicKey);
operationGeneratePublicKey.curve = &ECCParams_NISTP256;
operationGeneratePublicKey.myPrivateKey = &myPrivateKey;
operationGeneratePublicKey.myPublicKey = &myPublicKey;
// Generate the keying material for myPublicKey and store it in myPublicKeyingMaterial
operationResult = ECDH_generatePublicKey(ecdhHandle, &operationGeneratePublicKey);
while (1)
{
sleep(100);
}
}