工具/软件:
您好;
我们尝试探索 CC2745中的 HSM 模块、问题是 SDK 中引入的示例仅提供如何操作结果(例如、对于 AESCBC、在调试后、我们仅选择1或2、我们无法输入明文。
这里的问题是、是否有一个 关于如何使用 HSM、 其主应用程序加密、密钥存储...或有关如何利用 HSM 的更多信息的结构化示例。
谢谢您;
此致
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具/软件:
您好;
我们尝试探索 CC2745中的 HSM 模块、问题是 SDK 中引入的示例仅提供如何操作结果(例如、对于 AESCBC、在调试后、我们仅选择1或2、我们无法输入明文。
这里的问题是、是否有一个 关于如何使用 HSM、 其主应用程序加密、密钥存储...或有关如何利用 HSM 的更多信息的结构化示例。
谢谢您;
此致
您好:
对于 TI 驱动程序、HSM 的使用基于加密密钥的编码。 请参阅以下代码:
#include <ti/drivers/AESCCM.h>
#include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
#define USE_HSM
AESCCM_Params params;
AESCCM_Handle handle;
CryptoKey cryptoKey;
int_fast16_t encryptionResult;
uint8_t nonce[] = "Thisisanonce";
uint8_t aad[] = "This string will be authenticated but not encrypted.";
uint8_t plaintext[] = "This string will be encrypted and authenticated.";
uint8_t mac[16];
uint8_t ciphertext[sizeof(plaintext)];
uint8_t keyingMaterial[32] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
AESCCM_Params_init(¶ms)
params.returnBehavior = AESCCM_RETURN_BEHAVIOR_POLLING;
handle = AESCCM_open(0, ¶ms);
if (handle == NULL) {
/* If the handle is returned as NULL, this indicates that the HSM
* firmware has not been flashed.
*/
// handle error
}
#ifdef USE_HSM
/* This is the API uses the HSM. */
CryptoKeyPlaintextHSM_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
#else
/* This uses the LAES engine. */
CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
#endif
AESCCM_OneStepOperation operation;
AESCCM_OneStepOperation_init(&operation);
operation.key = &cryptoKey;
operation.aad = aad;
operation.aadLength = sizeof(aad);
operation.input = plaintext;
operation.output = ciphertext;
operation.inputLength = sizeof(plaintext);
operation.nonce = nonce;
operation.nonceLength = sizeof(nonce);
operation.mac = mac;
operation.macLength = sizeof(mac);
encryptionResult = AESCCM_oneStepEncrypt(handle, &operation);
if (encryptionResult != AESCCM_STATUS_SUCCESS) {
// handle error
}
AESCCM_close(handle); #ifdef USE_HSM
/* This is the API uses the HSM. */
CryptoKeyPlaintextHSM_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
#else
/* This uses the LAES engine. */
CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
#endif
如果 使用 CryptoKeyPlainetxHSM_initKey 初始化密钥、则 HSM 用于涉及该密钥的操作。
相反、如果使用 CryptoKeyPlainetxt_initKey 初始化密钥、则使用 LAES 引擎。
其它加密驱动程序的说明位于驱动程序文档中。 例如、对于 AES-CBC、您可以在此处找到它: AESCBC.h 文件参考。 你会看到一个带有标题的代码片段(我会直接链接到它,但没有办法做到这一点):
对于密钥库、您将需要使用 PSA API (1简介—PSA Certified Crypto API 1.3)。
HSM、密钥库和 PSA 文档即将发布、将使此信息正规化。
此致、
Nima Behmanesh