Crypto - Platform
This module includes the platform abstraction for Crypto.
Classes |
|
| struct | otCryptoKey |
|
This structure represents the Key Material required for Crypto operations.
|
|
| struct | otCryptoContext |
|
This structure stores the context object for platform APIs.
|
|
Typedefs |
|
| typedef uint32_t | otCryptoKeyRef |
|
This datatype represents the key reference.
|
|
| typedef struct otCryptoKey | otCryptoKey |
| typedef struct otCryptoContext | otCryptoContext |
Enumerations |
|
| enum |
otCryptoKeyType
{
OT_CRYPTO_KEY_TYPE_RAW , OT_CRYPTO_KEY_TYPE_AES , OT_CRYPTO_KEY_TYPE_HMAC } |
|
This enumeration defines the key types.
|
|
| enum |
otCryptoKeyAlgorithm
{
OT_CRYPTO_KEY_ALG_VENDOR , OT_CRYPTO_KEY_ALG_AES_ECB , OT_CRYPTO_KEY_ALG_HMAC_SHA_256 } |
|
This enumeration defines the key algorithms.
|
|
| enum |
{
OT_CRYPTO_KEY_USAGE_NONE = 0, OT_CRYPTO_KEY_USAGE_EXPORT = 1 << 0, OT_CRYPTO_KEY_USAGE_ENCRYPT = 1 << 1, OT_CRYPTO_KEY_USAGE_DECRYPT = 1 << 2, OT_CRYPTO_KEY_USAGE_SIGN_HASH = 1 << 3 } |
|
This enumeration defines the key usage flags.
|
|
| enum |
otCryptoKeyStorage
{
OT_CRYPTO_KEY_STORAGE_VOLATILE , OT_CRYPTO_KEY_STORAGE_PERSISTENT } |
|
This enumeration defines the key storage types.
|
|
Functions |
|
| void | otPlatCryptoInit (void) |
|
Initialize the Crypto module.
|
|
| otError | otPlatCryptoImportKey ( otCryptoKeyRef *aKeyRef, otCryptoKeyType aKeyType, otCryptoKeyAlgorithm aKeyAlgorithm, int aKeyUsage, otCryptoKeyStorage aKeyPersistence, const uint8_t *aKey, size_t aKeyLen) |
|
Import a key into PSA ITS.
|
|
| otError | otPlatCryptoExportKey ( otCryptoKeyRef aKeyRef, uint8_t *aBuffer, size_t aBufferLen, size_t *aKeyLen) |
|
Export a key stored in PSA ITS.
|
|
| otError | otPlatCryptoDestroyKey ( otCryptoKeyRef aKeyRef) |
|
Destroy a key stored in PSA ITS.
|
|
| bool | otPlatCryptoHasKey ( otCryptoKeyRef aKeyRef) |
|
Check if the key ref passed has an associated key in PSA ITS.
|
|
| otError | otPlatCryptoHmacSha256Init ( otCryptoContext *aContext) |
|
Initialize the HMAC operation.
|
|
| otError | otPlatCryptoHmacSha256Deinit ( otCryptoContext *aContext) |
|
Uninitialize the HMAC operation.
|
|
| otError | otPlatCryptoHmacSha256Start ( otCryptoContext *aContext, const otCryptoKey *aKey) |
|
Start HMAC operation.
|
|
| otError | otPlatCryptoHmacSha256Update ( otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength) |
|
Update the HMAC operation with new input.
|
|
| otError | otPlatCryptoHmacSha256Finish ( otCryptoContext *aContext, uint8_t *aBuf, size_t aBufLength) |
|
Complete the HMAC operation.
|
|
| otError | otPlatCryptoAesInit ( otCryptoContext *aContext) |
|
Initialise the AES operation.
|
|
| otError | otPlatCryptoAesSetKey ( otCryptoContext *aContext, const otCryptoKey *aKey) |
|
Set the key for AES operation.
|
|
| otError | otPlatCryptoAesEncrypt ( otCryptoContext *aContext, const uint8_t *aInput, uint8_t *aOutput) |
|
Encrypt the given data.
|
|
| otError | otPlatCryptoAesFree ( otCryptoContext *aContext) |
|
Free the AES context.
|
|
| otError | otPlatCryptoHkdfInit ( otCryptoContext *aContext) |
|
Initialise the HKDF context.
|
|
| otError | otPlatCryptoHkdfExpand ( otCryptoContext *aContext, const uint8_t *aInfo, uint16_t aInfoLength, uint8_t *aOutputKey, uint16_t aOutputKeyLength) |
|
Perform HKDF Expand step.
|
|
| otError | otPlatCryptoHkdfExtract ( otCryptoContext *aContext, const uint8_t *aSalt, uint16_t aSaltLength, const otCryptoKey *aInputKey) |
|
Perform HKDF Extract step.
|
|
| otError | otPlatCryptoHkdfDeinit ( otCryptoContext *aContext) |
|
Uninitialize the HKDF context.
|
|
| otError | otPlatCryptoSha256Init ( otCryptoContext *aContext) |
|
Initialise the SHA-256 operation.
|
|
| otError | otPlatCryptoSha256Deinit ( otCryptoContext *aContext) |
|
Uninitialize the SHA-256 operation.
|
|
| otError | otPlatCryptoSha256Start ( otCryptoContext *aContext) |
|
Start SHA-256 operation.
|
|
| otError | otPlatCryptoSha256Update ( otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength) |
|
Update SHA-256 operation with new input.
|
|
| otError | otPlatCryptoSha256Finish ( otCryptoContext *aContext, uint8_t *aHash, uint16_t aHashSize) |
|
Finish SHA-256 operation.
|
|
| void | otPlatCryptoRandomInit (void) |
|
Initialize cryptographically-secure pseudorandom number generator (CSPRNG).
|
|
| void | otPlatCryptoRandomDeinit (void) |
|
Deinitialize cryptographically-secure pseudorandom number generator (CSPRNG).
|
|
| otError | otPlatCryptoRandomGet (uint8_t *aBuffer, uint16_t aSize) |
|
Fills a given buffer with cryptographically secure random bytes.
|
|
Detailed Description
This module includes the platform abstraction for Crypto.
Enumeration Type Documentation
◆ anonymous enum
| anonymous enum |
This enumeration defines the key usage flags.
◆ otCryptoKeyAlgorithm
| enum otCryptoKeyAlgorithm |
◆ otCryptoKeyStorage
| enum otCryptoKeyStorage |
◆ otCryptoKeyType
| enum otCryptoKeyType |
Function Documentation
◆ otPlatCryptoAesEncrypt()
| otError otPlatCryptoAesEncrypt | ( | otCryptoContext * |
aContext,
|
| const uint8_t * |
aInput,
|
||
| uint8_t * |
aOutput
|
||
| ) |
Encrypt the given data.
- Parameters
-
[in] aContextContext for AES operation. [in] aInputPointer to the input buffer. [in] aOutputPointer to the output buffer.
- Return values
-
OT_ERROR_NONESuccessfully encrypted aInput.OT_ERROR_FAILEDFailed to encrypt aInput.OT_ERROR_INVALID_ARGSaContextoraKeyoraOutputwere NULL
◆ otPlatCryptoAesFree()
| otError otPlatCryptoAesFree | ( | otCryptoContext * |
aContext
|
) |
Free the AES context.
- Parameters
-
[in] aContextContext for AES operation.
- Return values
-
OT_ERROR_NONESuccessfully freed AES context. OT_ERROR_FAILEDFailed to free AES context. OT_ERROR_INVALID_ARGSaContextwas NULL
◆ otPlatCryptoAesInit()
| otError otPlatCryptoAesInit | ( | otCryptoContext * |
aContext
|
) |
Initialise the AES operation.
- Parameters
-
[in] aContextContext for AES operation.
- Return values
-
OT_ERROR_NONESuccessfully Initialised AES operation. OT_ERROR_FAILEDFailed to Initialise AES operation. OT_ERROR_INVALID_ARGSaContextwas NULLOT_ERROR_NO_BUFSCannot allocate the context.
- Note
- The platform driver shall point the context to the correct object such as psa_key_id or mbedtls_aes_context_t.
◆ otPlatCryptoAesSetKey()
| otError otPlatCryptoAesSetKey | ( | otCryptoContext * |
aContext,
|
| const otCryptoKey * |
aKey
|
||
| ) |
Set the key for AES operation.
- Parameters
-
[in] aContextContext for AES operation. [out] aKeyKey to use for AES operation.
- Return values
-
OT_ERROR_NONESuccessfully set the key for AES operation. OT_ERROR_FAILEDFailed to set the key for AES operation. OT_ERROR_INVALID_ARGSaContextoraKeywas NULL
◆ otPlatCryptoDestroyKey()
| otError otPlatCryptoDestroyKey | ( | otCryptoKeyRef |
aKeyRef
|
) |
Destroy a key stored in PSA ITS.
- Parameters
-
[in] aKeyRefThe key ref to be destroyed
- Return values
-
OT_ERROR_NONESuccessfully destroyed the key. OT_ERROR_FAILEDFailed to destroy the key.
- Note
-
This API is only used by OT core when
OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLEis enabled.
◆ otPlatCryptoExportKey()
| otError otPlatCryptoExportKey | ( | otCryptoKeyRef |
aKeyRef,
|
| uint8_t * |
aBuffer,
|
||
| size_t |
aBufferLen,
|
||
| size_t * |
aKeyLen
|
||
| ) |
Export a key stored in PSA ITS.
- Parameters
-
[in] aKeyRefThe key ref to be used for crypto operations. [out] aBufferPointer to the buffer where key needs to be exported. [in] aBufferLenLength of the buffer passed to store the exported key. [out] aKeyLenPointer to return the length of the exported key.
- Return values
-
OT_ERROR_NONESuccessfully exported aKeyRef.OT_ERROR_FAILEDFailed to export aKeyRef.OT_ERROR_INVALID_ARGSaBufferwas NULL
- Note
-
This API is only used by OT core when
OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLEis enabled.
◆ otPlatCryptoHasKey()
| bool otPlatCryptoHasKey | ( | otCryptoKeyRef |
aKeyRef
|
) |
Check if the key ref passed has an associated key in PSA ITS.
- Parameters
-
[in] aKeyRefThe Key Ref to check.
- Return values
-
TRUEThere is an associated key with aKeyRef.FALSEThere is no associated key with aKeyRef.
- Note
-
This API is only used by OT core when
OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLEis enabled.
◆ otPlatCryptoHkdfDeinit()
| otError otPlatCryptoHkdfDeinit | ( | otCryptoContext * |
aContext
|
) |
Uninitialize the HKDF context.
- Parameters
-
[in] aContextContext for HKDF operation.
- Return values
-
OT_ERROR_NONESuccessfully un-initialised HKDF operation. OT_ERROR_FAILEDFailed to un-initialised HKDF operation. OT_ERROR_INVALID_ARGSaContextwas NULL
◆ otPlatCryptoHkdfExpand()
| otError otPlatCryptoHkdfExpand | ( | otCryptoContext * |
aContext,
|
| const uint8_t * |
aInfo,
|
||
| uint16_t |
aInfoLength,
|
||
| uint8_t * |
aOutputKey,
|
||
| uint16_t |
aOutputKeyLength
|
||
| ) |
Perform HKDF Expand step.
- Parameters
-
[in] aContextOperation context for HKDF operation. [in] aInfoPointer to the Info sequence. [in] aInfoLengthLength of the Info sequence. [out] aOutputKeyPointer to the output Key. [in] aOutputKeyLengthSize of the output key buffer.
- Return values
-
OT_ERROR_NONEHKDF Expand was successful. OT_ERROR_FAILEDHKDF Expand failed. OT_ERROR_INVALID_ARGSaContextwas NULL
◆ otPlatCryptoHkdfExtract()
| otError otPlatCryptoHkdfExtract | ( | otCryptoContext * |
aContext,
|
| const uint8_t * |
aSalt,
|
||
| uint16_t |
aSaltLength,
|
||
| const otCryptoKey * |
aInputKey
|
||
| ) |
Perform HKDF Extract step.
- Parameters
-
[in] aContextOperation context for HKDF operation. [in] aSaltPointer to the Salt for HKDF. [in] aSaltLengthLength of Salt. [in] aInputKeyPointer to the input key.
- Return values
-
OT_ERROR_NONEHKDF Extract was successful. OT_ERROR_FAILEDHKDF Extract failed.
◆ otPlatCryptoHkdfInit()
| otError otPlatCryptoHkdfInit | ( | otCryptoContext * |
aContext
|
) |
Initialise the HKDF context.
- Parameters
-
[in] aContextContext for HKDF operation.
- Return values
-
OT_ERROR_NONESuccessfully Initialised AES operation. OT_ERROR_FAILEDFailed to Initialise AES operation. OT_ERROR_INVALID_ARGSaContextwas NULL
- Note
- The platform driver shall point the context to the correct object such as psa_key_derivation_operation_t or HmacSha256::Hash
◆ otPlatCryptoHmacSha256Deinit()
| otError otPlatCryptoHmacSha256Deinit | ( | otCryptoContext * |
aContext
|
) |
Uninitialize the HMAC operation.
- Parameters
-
[in] aContextContext for HMAC operation.
- Return values
-
OT_ERROR_NONESuccessfully uninitialized HMAC operation. OT_ERROR_FAILEDFailed to uninitialized HMAC operation. OT_ERROR_INVALID_ARGSaContextwas NULL
◆ otPlatCryptoHmacSha256Finish()
| otError otPlatCryptoHmacSha256Finish | ( | otCryptoContext * |
aContext,
|
| uint8_t * |
aBuf,
|
||
| size_t |
aBufLength
|
||
| ) |
Complete the HMAC operation.
- Parameters
-
[in] aContextContext for HMAC operation. [out] aBufA pointer to the output buffer. [in] aBufLengthThe length of aBufin bytes.
- Return values
-
OT_ERROR_NONESuccessfully completed HMAC operation. OT_ERROR_FAILEDFailed to complete HMAC operation. OT_ERROR_INVALID_ARGSaContextoraBufwas NULL
◆ otPlatCryptoHmacSha256Init()
| otError otPlatCryptoHmacSha256Init | ( | otCryptoContext * |
aContext
|
) |
Initialize the HMAC operation.
- Parameters
-
[in] aContextContext for HMAC operation.
- Return values
-
OT_ERROR_NONESuccessfully initialized HMAC operation. OT_ERROR_FAILEDFailed to initialize HMAC operation. OT_ERROR_INVALID_ARGSaContextwas NULL
- Note
- The platform driver shall point the context to the correct object such as psa_mac_operation_t or mbedtls_md_context_t.
◆ otPlatCryptoHmacSha256Start()
| otError otPlatCryptoHmacSha256Start | ( | otCryptoContext * |
aContext,
|
| const otCryptoKey * |
aKey
|
||
| ) |
Start HMAC operation.
- Parameters
-
[in] aContextContext for HMAC operation. [in] aKeyKey material to be used for for HMAC operation.
- Return values
-
OT_ERROR_NONESuccessfully started HMAC operation. OT_ERROR_FAILEDFailed to start HMAC operation. OT_ERROR_INVALID_ARGSaContextoraKeywas NULL
◆ otPlatCryptoHmacSha256Update()
| otError otPlatCryptoHmacSha256Update | ( | otCryptoContext * |
aContext,
|
| const void * |
aBuf,
|
||
| uint16_t |
aBufLength
|
||
| ) |
Update the HMAC operation with new input.
- Parameters
-
[in] aContextContext for HMAC operation. [in] aBufA pointer to the input buffer. [in] aBufLengthThe length of aBufin bytes.
- Return values
-
OT_ERROR_NONESuccessfully updated HMAC with new input operation. OT_ERROR_FAILEDFailed to update HMAC operation. OT_ERROR_INVALID_ARGSaContextoraBufwas NULL
◆ otPlatCryptoImportKey()
| otError otPlatCryptoImportKey | ( | otCryptoKeyRef * |
aKeyRef,
|
| otCryptoKeyType |
aKeyType,
|
||
| otCryptoKeyAlgorithm |
aKeyAlgorithm,
|
||
| int |
aKeyUsage,
|
||
| otCryptoKeyStorage |
aKeyPersistence,
|
||
| const uint8_t * |
aKey,
|
||
| size_t |
aKeyLen
|
||
| ) |
Import a key into PSA ITS.
- Parameters
-
[in,out] aKeyRefPointer to the key ref to be used for crypto operations. [in] aKeyTypeKey Type encoding for the key. [in] aKeyAlgorithmKey algorithm encoding for the key. [in] aKeyUsageKey Usage encoding for the key (combinations of OT_CRYPTO_KEY_USAGE_*).[in] aKeyPersistenceKey Persistence for this key [in] aKeyActual key to be imported. [in] aKeyLenLength of the key to be imported.
- Return values
-
OT_ERROR_NONESuccessfully imported the key. OT_ERROR_FAILEDFailed to import the key. OT_ERROR_INVALID_ARGSaKeywas set to NULL.
- Note
-
If OT_CRYPTO_KEY_STORAGE_PERSISTENT is passed for aKeyPersistence then
aKeyRefis input and platform should use the given aKeyRef and MUST not change it.
If OT_CRYPTO_KEY_STORAGE_VOLATILE is passed for aKeyPersistence then
aKeyRef
is output, the initial value does not matter and platform API MUST update it to return the new key ref.
This API is only used by OT core when
OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
is enabled.
◆ otPlatCryptoRandomGet()
| otError otPlatCryptoRandomGet | ( | uint8_t * |
aBuffer,
|
| uint16_t |
aSize
|
||
| ) |
Fills a given buffer with cryptographically secure random bytes.
- Parameters
-
[out] aBufferA pointer to a buffer to fill with the random bytes. [in] aSizeSize of buffer (number of bytes to fill).
- Return values
-
OT_ERROR_NONESuccessfully filled buffer with random values. OT_ERROR_FAILEDOperation failed.
◆ otPlatCryptoSha256Deinit()
| otError otPlatCryptoSha256Deinit | ( | otCryptoContext * |
aContext
|
) |
Uninitialize the SHA-256 operation.
- Parameters
-
[in] aContextContext for SHA-256 operation.
- Return values
-
OT_ERROR_NONESuccessfully un-initialised SHA-256 operation. OT_ERROR_FAILEDFailed to un-initialised SHA-256 operation. OT_ERROR_INVALID_ARGSaContextwas NULL
◆ otPlatCryptoSha256Finish()
| otError otPlatCryptoSha256Finish | ( | otCryptoContext * |
aContext,
|
| uint8_t * |
aHash,
|
||
| uint16_t |
aHashSize
|
||
| ) |
Finish SHA-256 operation.
- Parameters
-
[in] aContextContext for SHA-256 operation. [in] aHashA pointer to the output buffer, where hash needs to be stored. [in] aHashSizeThe length of aHashin bytes.
- Return values
-
OT_ERROR_NONESuccessfully completed the SHA-256 operation. OT_ERROR_FAILEDFailed to complete SHA-256 operation. OT_ERROR_INVALID_ARGSaContextoraHashwas NULL
◆ otPlatCryptoSha256Init()
| otError otPlatCryptoSha256Init | ( | otCryptoContext * |
aContext
|
) |
Initialise the SHA-256 operation.
- Parameters
-
[in] aContextContext for SHA-256 operation.
- Return values
-
OT_ERROR_NONESuccessfully initialised SHA-256 operation. OT_ERROR_FAILEDFailed to initialise SHA-256 operation. OT_ERROR_INVALID_ARGSaContextwas NULL
- Note
- The platform driver shall point the context to the correct object such as psa_hash_operation_t or mbedtls_sha256_context.
◆ otPlatCryptoSha256Start()
| otError otPlatCryptoSha256Start | ( | otCryptoContext * |
aContext
|
) |
Start SHA-256 operation.
- Parameters
-
[in] aContextContext for SHA-256 operation.
- Return values
-
OT_ERROR_NONESuccessfully started SHA-256 operation. OT_ERROR_FAILEDFailed to start SHA-256 operation. OT_ERROR_INVALID_ARGSaContextwas NULL
◆ otPlatCryptoSha256Update()
| otError otPlatCryptoSha256Update | ( | otCryptoContext * |
aContext,
|
| const void * |
aBuf,
|
||
| uint16_t |
aBufLength
|
||
| ) |
Update SHA-256 operation with new input.
- Parameters
-
[in] aContextContext for SHA-256 operation. [in] aBufA pointer to the input buffer. [in] aBufLengthThe length of aBufin bytes.
- Return values
-
OT_ERROR_NONESuccessfully updated SHA-256 with new input operation. OT_ERROR_FAILEDFailed to update SHA-256 operation. OT_ERROR_INVALID_ARGSaContextoraBufwas NULL