加密 - 平台
此模块包含 Crypto 的平台抽象。
摘要
枚举 |
|
---|---|
anonymous enum{
|
枚举 定义密钥用法标志。 |
otCryptoKeyAlgorithm{
|
枚举 定义关键算法。 |
otCryptoKeyStorage{
|
枚举 定义密钥存储类型。 |
otCryptoKeyType{
|
枚举 定义密钥类型。 |
类型定义符 |
|
---|---|
otCryptoContext
|
typedefstruct otCryptoContext
|
otCryptoKey
|
typedefstruct otCryptoKey
|
otCryptoKeyRef
|
typedefuint32_t
此数据类型表示键引用。 |
otPlatCryptoEcdsaKeyPair
|
typedefstruct otPlatCryptoEcdsaKeyPair
|
otPlatCryptoEcdsaPublicKey
|
typedefstruct otPlatCryptoEcdsaPublicKey
|
otPlatCryptoEcdsaSignature
|
typedefstruct otPlatCryptoEcdsaSignature
|
otPlatCryptoSha256Hash
|
typedefstruct otPlatCryptoSha256Hash
表示 SHA-256 哈希值。 |
函数 |
|
---|---|
otPlatCryptoAesEncrypt(otCryptoContext *aContext, const uint8_t *aInput, uint8_t *aOutput)
|
加密给定数据。
|
otPlatCryptoAesFree(otCryptoContext *aContext)
|
释放 AES 上下文。
|
otPlatCryptoAesInit(otCryptoContext *aContext)
|
初始化 AES 操作。
|
otPlatCryptoAesSetKey(otCryptoContext *aContext, const otCryptoKey *aKey)
|
为 AES 操作设置密钥。
|
otPlatCryptoDestroyKey(otCryptoKeyRef aKeyRef)
|
销毁存储在 PSA ITS 中的密钥。
|
otPlatCryptoEcdsaExportPublicKey(otCryptoKeyRef aKeyRef, otPlatCryptoEcdsaPublicKey *aPublicKey)
|
从传递的密钥引用中获取关联的公钥。
|
otPlatCryptoEcdsaGenerateAndImportKey(otCryptoKeyRef aKeyRef)
|
在传递引用时生成并导入新的 ECDSA 密钥对。
|
otPlatCryptoEcdsaGenerateKey(otPlatCryptoEcdsaKeyPair *aKeyPair)
|
生成并使用新的 ECDSA 密钥对填充输出缓冲区。
|
otPlatCryptoEcdsaGetPublicKey(const otPlatCryptoEcdsaKeyPair *aKeyPair, otPlatCryptoEcdsaPublicKey *aPublicKey)
|
从输入上下文获取关联的公钥。
|
otPlatCryptoEcdsaSign(const otPlatCryptoEcdsaKeyPair *aKeyPair, const otPlatCryptoSha256Hash *aHash, otPlatCryptoEcdsaSignature *aSignature)
|
使用输入上下文中的私钥计算经过哈希处理的消息的 ECDSA 签名。
|
otPlatCryptoEcdsaSignUsingKeyRef(otCryptoKeyRef aKeyRef, const otPlatCryptoSha256Hash *aHash, otPlatCryptoEcdsaSignature *aSignature)
|
使用传递的密钥引用计算经过哈希处理的消息的 ECDSA 签名。
|
otPlatCryptoEcdsaVerify(const otPlatCryptoEcdsaPublicKey *aPublicKey, const otPlatCryptoSha256Hash *aHash, const otPlatCryptoEcdsaSignature *aSignature)
|
使用输入上下文中的密钥来验证经过哈希处理的消息的 ECDSA 签名。
|
otPlatCryptoEcdsaVerifyUsingKeyRef(otCryptoKeyRef aKeyRef, const otPlatCryptoSha256Hash *aHash, const otPlatCryptoEcdsaSignature *aSignature)
|
使用 keyref 验证经过哈希处理的消息的 ECDSA 签名。
|
otPlatCryptoExportKey(otCryptoKeyRef aKeyRef, uint8_t *aBuffer, size_t aBufferLen, size_t *aKeyLen)
|
导出存储在 PSA ITS 中的密钥。
|
otPlatCryptoHasKey(otCryptoKeyRef aKeyRef)
|
bool
检查通过的密钥引用是否在 PSA ITS 中具有关联的密钥。
|
otPlatCryptoHkdfDeinit(otCryptoContext *aContext)
|
取消初始化 HKDF 上下文。
|
otPlatCryptoHkdfExpand(otCryptoContext *aContext, const uint8_t *aInfo, uint16_t aInfoLength, uint8_t *aOutputKey, uint16_t aOutputKeyLength)
|
执行 HKDF 展开步骤。
|
otPlatCryptoHkdfExtract(otCryptoContext *aContext, const uint8_t *aSalt, uint16_t aSaltLength, const otCryptoKey *aInputKey)
|
执行 HKDF 提取步骤。
|
otPlatCryptoHkdfInit(otCryptoContext *aContext)
|
初始化 HKDF 上下文。
|
otPlatCryptoHmacSha256Deinit(otCryptoContext *aContext)
|
取消初始化 HMAC 操作。
|
otPlatCryptoHmacSha256Finish(otCryptoContext *aContext, uint8_t *aBuf, size_t aBufLength)
|
完成 HMAC 操作。
|
otPlatCryptoHmacSha256Init(otCryptoContext *aContext)
|
初始化 HMAC 操作。
|
otPlatCryptoHmacSha256Start(otCryptoContext *aContext, const otCryptoKey *aKey)
|
启动 HMAC 操作。
|
otPlatCryptoHmacSha256Update(otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength)
|
使用新的输入更新 HMAC 操作。
|
otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef, otCryptoKeyType aKeyType, otCryptoKeyAlgorithm aKeyAlgorithm, int aKeyUsage, otCryptoKeyStorage aKeyPersistence, const uint8_t *aKey, size_t aKeyLen)
|
将密钥导入 PSA ITS。
|
otPlatCryptoInit(void)
|
void
初始化 Crypto 模块。
|
otPlatCryptoPbkdf2GenerateKey(const uint8_t *aPassword, uint16_t aPasswordLen, const uint8_t *aSalt, uint16_t aSaltLen, uint32_t aIterationCounter, uint16_t aKeyLen, uint8_t *aKey)
|
使用 CMAC (AES-CMAC-PRF-128) 执行 PKCS#5 PBKDF2。
|
otPlatCryptoRandomDeinit(void)
|
void
解初始化加密安全的伪随机数生成器 (CSPRNG)。
|
otPlatCryptoRandomGet(uint8_t *aBuffer, uint16_t aSize)
|
使用能够确保加密安全的随机字节填充给定缓冲区。
|
otPlatCryptoRandomInit(void)
|
void
初始化加密安全的伪随机数生成器 (CSPRNG)。
|
otPlatCryptoSha256Deinit(otCryptoContext *aContext)
|
取消初始化 SHA-256 操作。
|
otPlatCryptoSha256Finish(otCryptoContext *aContext, uint8_t *aHash, uint16_t aHashSize)
|
完成 SHA-256 操作。
|
otPlatCryptoSha256Init(otCryptoContext *aContext)
|
初始化 SHA-256 操作。
|
otPlatCryptoSha256Start(otCryptoContext *aContext)
|
启动 SHA-256 操作。
|
otPlatCryptoSha256Update(otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength)
|
使用新输入更新 SHA-256 操作。
|
结构体 |
|
---|---|
otCryptoContext |
存储平台 API 的上下文对象。 |
otCryptoKey |
表示加密操作所需的密钥材料。 |
otPlatCryptoEcdsaKeyPair |
表示 ECDSA 密钥对(公钥和私钥)。 |
otPlatCryptoEcdsaPublicKey |
表示 ECDSA 公钥。 |
otPlatCryptoEcdsaSignature |
表示 ECDSA 签名。 |
otPlatCryptoSha256Hash |
表示 SHA-256 哈希值。 |
枚举
匿名枚举
anonymous enum
定义密钥用法标志。
属性 | |
---|---|
OT_CRYPTO_KEY_USAGE_DECRYPT
|
密钥用法:AES ECB。 |
OT_CRYPTO_KEY_USAGE_ENCRYPT
|
密钥用途:加密(由供应商定义)。 |
OT_CRYPTO_KEY_USAGE_EXPORT
|
密钥用途:密钥可以导出。 |
OT_CRYPTO_KEY_USAGE_NONE
|
密钥用途:密钥用途为空。 |
OT_CRYPTO_KEY_USAGE_SIGN_HASH
|
密钥用途:签名哈希。 |
OT_CRYPTO_KEY_USAGE_VERIFY_HASH
|
密钥用途:验证哈希。 |
otCryptoKeyAlgorithm
otCryptoKeyAlgorithm
定义关键算法。
属性 | |
---|---|
OT_CRYPTO_KEY_ALG_AES_ECB
|
密钥算法:AES ECB。 |
OT_CRYPTO_KEY_ALG_ECDSA
|
密钥算法:ECDSA。 |
OT_CRYPTO_KEY_ALG_HMAC_SHA_256
|
密钥算法:HMAC SHA-256。 |
OT_CRYPTO_KEY_ALG_VENDOR
|
密钥算法:由供应商定义。 |
otCryptoKeyStorage
otCryptoKeyStorage
定义密钥存储类型。
属性 | |
---|---|
OT_CRYPTO_KEY_STORAGE_PERSISTENT
|
密钥持久性:密钥是永久性的。 |
OT_CRYPTO_KEY_STORAGE_VOLATILE
|
键持久性:键具有易失性。 |
otCryptoKeyType
otCryptoKeyType
定义密钥类型。
属性 | |
---|---|
OT_CRYPTO_KEY_TYPE_AES
|
密钥类型:AES。 |
OT_CRYPTO_KEY_TYPE_ECDSA
|
密钥类型:ECDSA。 |
OT_CRYPTO_KEY_TYPE_HMAC
|
密钥类型:HMAC。 |
OT_CRYPTO_KEY_TYPE_RAW
|
密钥类型:原始数据。 |
类型定义符
otCryptoContext
struct otCryptoContext otCryptoContext
otCryptoKey
struct otCryptoKey otCryptoKey
otCryptoKeyRef
uint32_t otCryptoKeyRef
此数据类型表示键引用。
otPlatCryptoEcdsaKeyPair
struct otPlatCryptoEcdsaKeyPair otPlatCryptoEcdsaKeyPair
otPlatCryptoEcdsaPublicKey
struct otPlatCryptoEcdsaPublicKey otPlatCryptoEcdsaPublicKey
otPlatCryptoEcdsaSignature
struct otPlatCryptoEcdsaSignature otPlatCryptoEcdsaSignature
变量
OT_TOOL_PACKED_END
OT_TOOL_PACKED_BEGIN struct otPlatCryptoSha256Hash OT_TOOL_PACKED_END
函数
otPlatCryptoAesEncrypt
otError otPlatCryptoAesEncrypt(
otCryptoContext *aContext,
const uint8_t *aInput,
uint8_t *aOutput
)
加密给定数据。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoAesFree
otError otPlatCryptoAesFree(
otCryptoContext *aContext
)
释放 AES 上下文。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoAesInit
otError otPlatCryptoAesInit(
otCryptoContext *aContext
)
初始化 AES 操作。
具体说明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otPlatCryptoAesSetKey
otError otPlatCryptoAesSetKey(
otCryptoContext *aContext,
const otCryptoKey *aKey
)
为 AES 操作设置密钥。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoDestroyKey
otError otPlatCryptoDestroyKey(
otCryptoKeyRef aKeyRef
)
销毁存储在 PSA ITS 中的密钥。
具体说明 | |||||
---|---|---|---|---|---|
参数 |
|
||||
返回值 |
|
otPlatCryptoEcdsaExportPublicKey
otError otPlatCryptoEcdsaExportPublicKey(
otCryptoKeyRef aKeyRef,
otPlatCryptoEcdsaPublicKey *aPublicKey
)
从传递的密钥引用中获取关联的公钥。
公钥的存储方式因所使用的加密后端库 (OPENTHREAD_CONFIG_CRYPTO_LIB) 而异。
此 API 必须确保以未压缩曲线点的字节序列表示形式返回公钥(RFC 6605 - 第 4 节)
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoEcdsaGenerateAndImportKey
otError otPlatCryptoEcdsaGenerateAndImportKey(
otCryptoKeyRef aKeyRef
)
在传递引用时生成并导入新的 ECDSA 密钥对。
具体说明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otPlatCryptoEcdsaGenerateKey
otError otPlatCryptoEcdsaGenerateKey(
otPlatCryptoEcdsaKeyPair *aKeyPair
)
生成并使用新的 ECDSA 密钥对填充输出缓冲区。
具体说明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otPlatCryptoEcdsaGetPublicKey
otError otPlatCryptoEcdsaGetPublicKey(
const otPlatCryptoEcdsaKeyPair *aKeyPair,
otPlatCryptoEcdsaPublicKey *aPublicKey
)
从输入上下文获取关联的公钥。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoEcdsaSign
otError otPlatCryptoEcdsaSign(
const otPlatCryptoEcdsaKeyPair *aKeyPair,
const otPlatCryptoSha256Hash *aHash,
otPlatCryptoEcdsaSignature *aSignature
)
使用输入上下文中的私钥计算经过哈希处理的消息的 ECDSA 签名。
使用 RFC 6979 中的确定性数字签名生成过程。
具体说明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otPlatCryptoEcdsaSignUsingKeyRef
otError otPlatCryptoEcdsaSignUsingKeyRef(
otCryptoKeyRef aKeyRef,
const otPlatCryptoSha256Hash *aHash,
otPlatCryptoEcdsaSignature *aSignature
)
使用传递的密钥引用计算经过哈希处理的消息的 ECDSA 签名。
使用 RFC 6979 中的确定性数字签名生成过程。
具体说明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otPlatCryptoEcdsaVerify
otError otPlatCryptoEcdsaVerify(
const otPlatCryptoEcdsaPublicKey *aPublicKey,
const otPlatCryptoSha256Hash *aHash,
const otPlatCryptoEcdsaSignature *aSignature
)
使用输入上下文中的密钥来验证经过哈希处理的消息的 ECDSA 签名。
具体说明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otPlatCryptoEcdsaVerifyUsingKeyRef
otError otPlatCryptoEcdsaVerifyUsingKeyRef(
otCryptoKeyRef aKeyRef,
const otPlatCryptoSha256Hash *aHash,
const otPlatCryptoEcdsaSignature *aSignature
)
使用 keyref 验证经过哈希处理的消息的 ECDSA 签名。
具体说明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otPlatCryptoExportKey
otError otPlatCryptoExportKey(
otCryptoKeyRef aKeyRef,
uint8_t *aBuffer,
size_t aBufferLen,
size_t *aKeyLen
)
导出存储在 PSA ITS 中的密钥。
具体说明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otPlatCryptoHasKey
bool otPlatCryptoHasKey(
otCryptoKeyRef aKeyRef
)
检查通过的密钥引用是否在 PSA ITS 中具有关联的密钥。
具体说明 | |||||
---|---|---|---|---|---|
参数 |
|
||||
返回值 |
|
otPlatCryptoHkdfDeinit
otError otPlatCryptoHkdfDeinit(
otCryptoContext *aContext
)
取消初始化 HKDF 上下文。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoHkdfExpand
otError otPlatCryptoHkdfExpand(
otCryptoContext *aContext,
const uint8_t *aInfo,
uint16_t aInfoLength,
uint8_t *aOutputKey,
uint16_t aOutputKeyLength
)
执行 HKDF 展开步骤。
具体说明 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||||
返回值 |
|
otPlatCryptoHkdfExtract
otError otPlatCryptoHkdfExtract(
otCryptoContext *aContext,
const uint8_t *aSalt,
uint16_t aSaltLength,
const otCryptoKey *aInputKey
)
执行 HKDF 提取步骤。
具体说明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otPlatCryptoHkdfInit
otError otPlatCryptoHkdfInit(
otCryptoContext *aContext
)
初始化 HKDF 上下文。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoHmacSha256Deinit
otError otPlatCryptoHmacSha256Deinit(
otCryptoContext *aContext
)
取消初始化 HMAC 操作。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoHmacSha256Finish
otError otPlatCryptoHmacSha256Finish(
otCryptoContext *aContext,
uint8_t *aBuf,
size_t aBufLength
)
完成 HMAC 操作。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoHmacSha256Init
otError otPlatCryptoHmacSha256Init(
otCryptoContext *aContext
)
初始化 HMAC 操作。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoHmacSha256Start
otError otPlatCryptoHmacSha256Start(
otCryptoContext *aContext,
const otCryptoKey *aKey
)
启动 HMAC 操作。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoHmacSha256Update
otError otPlatCryptoHmacSha256Update(
otCryptoContext *aContext,
const void *aBuf,
uint16_t aBufLength
)
使用新的输入更新 HMAC 操作。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoImportKey
otError otPlatCryptoImportKey(
otCryptoKeyRef *aKeyRef,
otCryptoKeyType aKeyType,
otCryptoKeyAlgorithm aKeyAlgorithm,
int aKeyUsage,
otCryptoKeyStorage aKeyPersistence,
const uint8_t *aKey,
size_t aKeyLen
)
将密钥导入 PSA ITS。
如果针对 aKeyPersistence 传递 OT_CRYPTO_KEY_STORAGE_VOLATILE,然后输出aKeyRef
,则初始值无关紧要,并且平台 API 必须对其进行更新以返回新的密钥引用。
具体说明 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||||||||
返回值 |
|
只有在启用 OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
后,OT 核心才会使用此 API。
otPlatCryptoInit
void otPlatCryptoInit(
void
)
初始化 Crypto 模块。
otPlatCryptoPbkdf2GenerateKey
otError otPlatCryptoPbkdf2GenerateKey(
const uint8_t *aPassword,
uint16_t aPasswordLen,
const uint8_t *aSalt,
uint16_t aSaltLen,
uint32_t aIterationCounter,
uint16_t aKeyLen,
uint8_t *aKey
)
使用 CMAC (AES-CMAC-PRF-128) 执行 PKCS#5 PBKDF2。
具体说明 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||||||||
返回值 |
|
otPlatCryptoRandomDeinit
void otPlatCryptoRandomDeinit(
void
)
解初始化加密安全的伪随机数生成器 (CSPRNG)。
otPlatCryptoRandomGet
otError otPlatCryptoRandomGet(
uint8_t *aBuffer,
uint16_t aSize
)
使用能够确保加密安全的随机字节填充给定缓冲区。
具体说明 | |||||
---|---|---|---|---|---|
参数 |
|
||||
返回值 |
|
otPlatCryptoRandomInit
void otPlatCryptoRandomInit(
void
)
初始化加密安全的伪随机数生成器 (CSPRNG)。
otPlatCryptoSha256Deinit
otError otPlatCryptoSha256Deinit(
otCryptoContext *aContext
)
取消初始化 SHA-256 操作。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoSha256Finish
otError otPlatCryptoSha256Finish(
otCryptoContext *aContext,
uint8_t *aHash,
uint16_t aHashSize
)
完成 SHA-256 操作。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoSha256Init
otError otPlatCryptoSha256Init(
otCryptoContext *aContext
)
初始化 SHA-256 操作。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoSha256Start
otError otPlatCryptoSha256Start(
otCryptoContext *aContext
)
启动 SHA-256 操作。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otPlatCryptoSha256Update
otError otPlatCryptoSha256Update(
otCryptoContext *aContext,
const void *aBuf,
uint16_t aBufLength
)
使用新输入更新 SHA-256 操作。
具体说明 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
宏
OT_CRYPTO_ECDSA_MAX_DER_SIZE
OT_CRYPTO_ECDSA_MAX_DER_SIZE 125
表示 DER 格式的 EDCSA 密钥对的缓冲区大小上限(以字节为单位)。
OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE
OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE 64
表示 EDCSA 公钥的缓冲区空间(以字节为单位)。
OT_CRYPTO_ECDSA_SIGNATURE_SIZE
OT_CRYPTO_ECDSA_SIGNATURE_SIZE 64
表示 EDCSA 签名的缓冲区空间(以字节为单位)。
OT_CRYPTO_PBDKF2_MAX_SALT_SIZE
OT_CRYPTO_PBDKF2_MAX_SALT_SIZE 30
PBKDF2 SALT 长度上限:盐前缀 (6) + 扩展 panid (8) + 网络名称 (16)
OT_CRYPTO_SHA256_HASH_SIZE
OT_CRYPTO_SHA256_HASH_SIZE 32
SHA256 哈希的长度(以字节为单位)。
资源
OpenThread API 参考文档源自 GitHub 上提供的源代码。如需了解详情,或者为我们的文档做贡献,请参阅资源。