![Texas Instruments CC3220 Скачать руководство пользователя страница 225](http://html.mh-extra.com/html/texas-instruments/cc3220/cc3220_programmers-manual_1094609225.webp)
Introduction
225
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
Crypto Utilities
An example of installing a key and then uninstalling it follows:
SlNetUtilCryptoCmdKeyMgnt_t keyAttrib;
SlNetUtilCryptoPubKeyInfo_t *pInfoKey;
_i16 Status;
_u8 buf[256];
_u16 resultLen;
keyAttrib.ObjId = 5;
/* key index is 5 */
keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_INSTALL_SUB_CMD;
pInfoKey->KeyAlgo = SL_NETUTIL_CRYPTO_PUB_KEY_ALGO_EC;
pInfoKey->KeyParams.EcParams.CurveType = SL_NETUTIL_CRYPTO_EC_CURVE_TYPE_NAMED;
pInfoKey-
>KeyParams.EcParams.CurveParams.NamedCurveParams = SL_NETUTIL_CRYPTO_EC_NAMED_CURVE_SECP256R1;
pInfoKey = (SlNetUtilCryptoPubKeyInfo_t *)buf;
name = ((_u8 *)pInfoKey) +
sizeof
(SlNetUtilCryptoPubKeyInfo_t);
pInfoKey->KeyAlgo = SL_NETUTIL_CRYPTO_PUB_KEY_ALGO_EC;
pInfoKey->KeyParams.EcParams.CurveType = SL_NETUTIL_CRYPTO_EC_CURVE_TYPE_NAMED;
pInfoKey-
>KeyParams.EcParams.CurveParams.NamedCurveParams = SL_NETUTIL_CRYPTO_EC_NAMED_CURVE_SECP256R1;
pInfoKey->CertFileNameLen = 0;
/* unused */
name += pInfoKey->CertFileNameLen;
strcpy((
char
*)name, "extkey.der");
/* private key in the file system */
pInfoKey->KeyFileNameLen = strlen("extkey.der")+1;
Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_INSTALL_OP,
(_u8 *)&keyAttrib,
sizeof
(SlNetUtilCryptoCmdKeyMgnt_t),
(_u8 *)pInfo,
sizeof
(SlNetUtilCryptoPubKeyInfo_t) + pInfoKey->KeyFileNameLen,
NULL, &resultLen);
if
(Status < 0)
{
/* error */
}
resultLen = 0;
keyAttrib.ObjId = 5;
keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_UNINSTALL_SUB_CMD;
/* Uninstall the key */
Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_INSTALL_OP, (_u8 *)&keyAttrib,
sizeof
(SlNetUtilCryptoCmdKeyMgnt_t), NULL, 0 , NULL, &resultLen);
if
(Status < 0)
{
/* error */
}
16.1.1.2 Create or Remove Temporary Key
This command is used to create or remove a temporary ECC key-pair with the SECP256R1 curve on a
given index. Create and remove operations are done using the sl_NetUtilsCmd API. The key is generated
internally by the SimpleLink Wi-Fi device. The key is not persistent over the power cycle, and is overridden
if using create temporary key again on that index. The operation fails if the desired index is already
occupied by an installed key-pair (not a temporary one).
An example of creating a temporary key pair follows:
SlNetUtilCryptoCmdKeyMgnt_t keyAttrib;
_i16 Status;
_u16 resultLen;
keyAttrib.ObjId = 1;
/* key index is 1 */
keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_TEMP_KEYS_CREATE;
Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_TEMP_KEYS,
(_u8 *)&keyAttrib,
sizeof
(SlNetUtilCryptoCmdKeyMgnt_t),