Crypto - 平台
這個模組包含 Crypto 的平台抽象層。
摘要
列舉 |
|
---|---|
anonymous enum{
|
列舉 此列舉定義了主要的使用標記, |
otCryptoKeyAlgorithm{
|
列舉 此列舉會定義主要演算法。 |
otCryptoKeyStorage{
|
列舉 此列舉會定義金鑰儲存空間類型。 |
otCryptoKeyType{
|
列舉 此列舉會定義金鑰類型。 |
Typedefs |
|
---|---|
otCryptoContext
|
typedefstruct otCryptoContext
|
otCryptoKey
|
typedefstruct otCryptoKey
|
otCryptoKeyRef
|
typedefuint32_t
這個資料類型代表鍵參照。 |
otPlatCryptoEcdsaKeyPair
|
typedefstruct otPlatCryptoEcdsaKeyPair
|
otPlatCryptoEcdsaPublicKey
|
typedefstruct otPlatCryptoEcdsaPublicKey
|
otPlatCryptoEcdsaSignature
|
typedefstruct otPlatCryptoEcdsaSignature
|
otPlatCryptoSha256Hash
|
typedefstruct otPlatCryptoSha256Hash
此結構代表一個 SHA-256 雜湊。 |
變數 |
|
---|---|
OT_TOOL_PACKED_END
|
Functions |
|
---|---|
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 中的金鑰。
|
otPlatCryptoEcdsaGenerateKey(otPlatCryptoEcdsaKeyPair *aKeyPair)
|
使用新的 ECDSA 金鑰組產生並填入輸出緩衝區。
|
otPlatCryptoEcdsaGetPublicKey(const otPlatCryptoEcdsaKeyPair *aKeyPair, otPlatCryptoEcdsaPublicKey *aPublicKey)
|
從輸入內容取得相關聯的公開金鑰。
|
otPlatCryptoEcdsaSign(const otPlatCryptoEcdsaKeyPair *aKeyPair, const otPlatCryptoSha256Hash *aHash, otPlatCryptoEcdsaSignature *aSignature)
|
使用輸入內容中的私密金鑰計算雜湊訊息的 ECDSA 簽名。
|
otPlatCryptoEcdsaVerify(const otPlatCryptoEcdsaPublicKey *aPublicKey, const otPlatCryptoSha256Hash *aHash, const otPlatCryptoEcdsaSignature *aSignature)
|
使用輸入內容中的金鑰來驗證經雜湊處理訊息的 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 Extract 步驟。
|
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)
|
void
使用 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 |
這個結構代表 Crypto 作業所需的金鑰內容。 |
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
|
金鑰使用:HMAC SHA-256。 |
加密編譯金鑰加密演算法
otCryptoKeyAlgorithm
此列舉會定義主要演算法。
屬性 | |
---|---|
OT_CRYPTO_KEY_ALG_AES_ECB
|
金鑰演算法:AES ECB。 |
OT_CRYPTO_KEY_ALG_HMAC_SHA_256
|
金鑰演算法:HMAC SHA-256。 |
OT_CRYPTO_KEY_ALG_VENDOR
|
金鑰演算法:廠商定義。 |
otCryptoKey 儲存
otCryptoKeyStorage
此列舉會定義金鑰儲存空間類型。
屬性 | |
---|---|
OT_CRYPTO_KEY_STORAGE_PERSISTENT
|
金鑰持續性:金鑰是永久性的。 |
OT_CRYPTO_KEY_STORAGE_VOLATILE
|
金鑰持續性:金鑰屬於揮發性。 |
otCryptoKeyType
otCryptoKeyType
此列舉會定義金鑰類型。
屬性 | |
---|---|
OT_CRYPTO_KEY_TYPE_AES
|
金鑰類型:AES。 |
OT_CRYPTO_KEY_TYPE_HMAC
|
金鑰類型:HMAC。 |
OT_CRYPTO_KEY_TYPE_RAW
|
索引鍵類型:原始資料。 |
Typedefs
OTCryptoContext
struct otCryptoContext otCryptoContext
NFC
struct otCryptoKey otCryptoKey
OTCryptoKeyRef
uint32_t otCryptoKeyRef
這個資料類型代表鍵參照。
otPlatCryptoEcdsaKeyPair
struct otPlatCryptoEcdsaKeyPair otPlatCryptoEcdsaKeyPair
otPlatCryptoEcdsaPublicKey
struct otPlatCryptoEcdsaPublicKey otPlatCryptoEcdsaPublicKey
otPlatCryptoEcdsa 簽名
struct otPlatCryptoEcdsaSignature otPlatCryptoEcdsaSignature
變數
OT_TOOL_PACKED_END
OT_TOOL_PACKED_BEGIN struct otPlatCryptoSha256Hash OT_TOOL_PACKED_END
Functions
otPlatCryptoAesEncrypt
otError otPlatCryptoAesEncrypt( otCryptoContext *aContext, const uint8_t *aInput, uint8_t *aOutput )
加密指定資料。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoAesFree
otError otPlatCryptoAesFree( otCryptoContext *aContext )
釋出 AES 背景資訊。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
OTPPCryptoAesInit
otError otPlatCryptoAesInit( otCryptoContext *aContext )
初始化 AES 作業。
詳細資料 | |||||||||
---|---|---|---|---|---|---|---|---|---|
參數 |
|
||||||||
回傳值 |
|
otPlatCryptoAesSetKey
otError otPlatCryptoAesSetKey( otCryptoContext *aContext, const otCryptoKey *aKey )
設定 AES 作業的金鑰。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoDestroyKey
otError otPlatCryptoDestroyKey( otCryptoKeyRef aKeyRef )
刪除儲存在 PSA ITS 中的金鑰。
詳細資料 | |||||
---|---|---|---|---|---|
參數 |
|
||||
回傳值 |
|
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 的確定性數位簽章產生程序。
詳細資料 | |||||||||
---|---|---|---|---|---|---|---|---|---|
參數 |
|
||||||||
回傳值 |
|
otPlatCryptoEcdsaVerify
otError otPlatCryptoEcdsaVerify( const otPlatCryptoEcdsaPublicKey *aPublicKey, const otPlatCryptoSha256Hash *aHash, const otPlatCryptoEcdsaSignature *aSignature )
使用輸入內容中的金鑰來驗證經雜湊處理訊息的 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 Extract 步驟。
詳細資料 | |||||||||
---|---|---|---|---|---|---|---|---|---|
參數 |
|
||||||||
回傳值 |
|
OTPPCryptoHkdfInit
otError otPlatCryptoHkdfInit( otCryptoContext *aContext )
初始化 HKDF 結構定義。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoHmacSha256Deinit
otError otPlatCryptoHmacSha256Deinit( otCryptoContext *aContext )
取消初始化 HMAC 作業。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoHmacSha256 完成
otError otPlatCryptoHmacSha256Finish( otCryptoContext *aContext, uint8_t *aBuf, size_t aBufLength )
完成 HMAC 作業。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoHmacSha256Init
otError otPlatCryptoHmacSha256Init( otCryptoContext *aContext )
初始化 HMAC 作業。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoHmacSha256 起點
otError otPlatCryptoHmacSha256Start( otCryptoContext *aContext, const otCryptoKey *aKey )
啟動 HMAC 作業。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoHmacSha256 更新
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_PERSISTENT,則輸入 aKeyRef
,且平台應使用指定的 aKeyRef,且不得變更。針對 aKeyPersistence 傳遞 OT_CRYPTO_KEY_STORAGE_VOLATILE 之後,aKeyRef
會輸出,初始值並無任何影響,平台 API 必須「更新」 以傳回新的金鑰 ref.
詳細資料 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
參數 |
|
||||||||||||||
回傳值 |
|
只有在啟用 OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
時,OT Core 才會使用這個 API。
OTPPCryptoInit
void otPlatCryptoInit( void )
初始化 Crypto 模組。
otPlatCryptoPbkdf2GenerateKey
void 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 )
在指定的緩衝區中填入經過加密保護的隨機位元組。
詳細資料 | |||||
---|---|---|---|---|---|
參數 |
|
||||
回傳值 |
|
OTPPCryptoRandomInit
void otPlatCryptoRandomInit( void )
初始化加密安全的虛擬隨機號碼產生器 (CSPRNG)。
otPlatCryptoSha256Deinit
otError otPlatCryptoSha256Deinit( otCryptoContext *aContext )
取消初始化 SHA-256 作業。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoSha256 完成
otError otPlatCryptoSha256Finish( otCryptoContext *aContext, uint8_t *aHash, uint16_t aHashSize )
完成 SHA-256 作業。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoSha256Init
otError otPlatCryptoSha256Init( otCryptoContext *aContext )
初始化 SHA-256 作業。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoSha256 起點
otError otPlatCryptoSha256Start( otCryptoContext *aContext )
啟動 SHA-256 作業。
詳細資料 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
回傳值 |
|
otPlatCryptoSha256 更新
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 取得。如需詳細資訊或為說明文件貢獻一己之力,請參閱資源。