Crypto - Platform
This module includes the platform abstraction for Crypto.
Summary
Enumerations |
|
---|---|
Anonymous Enum 11{
|
enum Defines the key usage flags. |
otCryptoKeyAlgorithm{
|
enum Defines the key algorithms. |
otCryptoKeyStorage{
|
enum Defines the key storage types. |
otCryptoKeyType{
|
enum Defines the key types. |
Typedefs |
|
---|---|
otCryptoContext
|
typedefstruct otCryptoContext
|
otCryptoKey
|
typedefstruct otCryptoKey
|
otCryptoKeyRef
|
typedefuint32_t
This datatype represents the key reference. |
otPlatCryptoEcdsaKeyPair
|
typedefstruct otPlatCryptoEcdsaKeyPair
|
otPlatCryptoEcdsaPublicKey
|
typedefstruct otPlatCryptoEcdsaPublicKey
|
otPlatCryptoEcdsaSignature
|
typedefstruct otPlatCryptoEcdsaSignature
|
otPlatCryptoSha256Hash
|
typedefstruct otPlatCryptoSha256Hash
Represents a SHA-256 hash. |
Variables |
|
---|---|
OT_TOOL_PACKED_END
|
Functions |
|
---|---|
otPlatCryptoAesEncrypt(otCryptoContext *aContext, const uint8_t *aInput, uint8_t *aOutput)
|
Encrypt the given data.
|
otPlatCryptoAesFree(otCryptoContext *aContext)
|
Free the AES context.
|
otPlatCryptoAesInit(otCryptoContext *aContext)
|
Initialise the AES operation.
|
otPlatCryptoAesSetKey(otCryptoContext *aContext, const otCryptoKey *aKey)
|
Set the key for AES operation.
|
otPlatCryptoDestroyKey(otCryptoKeyRef aKeyRef)
|
Destroy a key stored in PSA ITS.
|
otPlatCryptoEcdsaExportPublicKey(otCryptoKeyRef aKeyRef, otPlatCryptoEcdsaPublicKey *aPublicKey)
|
Get the associated public key from the key reference passed.
|
otPlatCryptoEcdsaGenerateAndImportKey(otCryptoKeyRef aKeyRef)
|
Generate and import a new ECDSA key-pair at reference passed.
|
otPlatCryptoEcdsaGenerateKey(otPlatCryptoEcdsaKeyPair *aKeyPair)
|
Generate and populate the output buffer with a new ECDSA key-pair.
|
otPlatCryptoEcdsaGetPublicKey(const otPlatCryptoEcdsaKeyPair *aKeyPair, otPlatCryptoEcdsaPublicKey *aPublicKey)
|
Get the associated public key from the input context.
|
otPlatCryptoEcdsaSign(const otPlatCryptoEcdsaKeyPair *aKeyPair, const otPlatCryptoSha256Hash *aHash, otPlatCryptoEcdsaSignature *aSignature)
|
Calculate the ECDSA signature for a hashed message using the private key from the input context.
|
otPlatCryptoEcdsaSignUsingKeyRef(otCryptoKeyRef aKeyRef, const otPlatCryptoSha256Hash *aHash, otPlatCryptoEcdsaSignature *aSignature)
|
Calculate the ECDSA signature for a hashed message using the Key reference passed.
|
otPlatCryptoEcdsaVerify(const otPlatCryptoEcdsaPublicKey *aPublicKey, const otPlatCryptoSha256Hash *aHash, const otPlatCryptoEcdsaSignature *aSignature)
|
Use the key from the input context to verify the ECDSA signature of a hashed message.
|
otPlatCryptoEcdsaVerifyUsingKeyRef(otCryptoKeyRef aKeyRef, const otPlatCryptoSha256Hash *aHash, const otPlatCryptoEcdsaSignature *aSignature)
|
Use the keyref to verify the ECDSA signature of a hashed message.
|
otPlatCryptoExportKey(otCryptoKeyRef aKeyRef, uint8_t *aBuffer, size_t aBufferLen, size_t *aKeyLen)
|
Export a key stored in PSA ITS.
|
otPlatCryptoHasKey(otCryptoKeyRef aKeyRef)
|
bool
Check if the key ref passed has an associated key in PSA ITS.
|
otPlatCryptoHkdfDeinit(otCryptoContext *aContext)
|
Uninitialize the HKDF context.
|
otPlatCryptoHkdfExpand(otCryptoContext *aContext, const uint8_t *aInfo, uint16_t aInfoLength, uint8_t *aOutputKey, uint16_t aOutputKeyLength)
|
Perform HKDF Expand step.
|
otPlatCryptoHkdfExtract(otCryptoContext *aContext, const uint8_t *aSalt, uint16_t aSaltLength, const otCryptoKey *aInputKey)
|
Perform HKDF Extract step.
|
otPlatCryptoHkdfInit(otCryptoContext *aContext)
|
Initialise the HKDF context.
|
otPlatCryptoHmacSha256Deinit(otCryptoContext *aContext)
|
Uninitialize the HMAC operation.
|
otPlatCryptoHmacSha256Finish(otCryptoContext *aContext, uint8_t *aBuf, size_t aBufLength)
|
Complete the HMAC operation.
|
otPlatCryptoHmacSha256Init(otCryptoContext *aContext)
|
Initialize the HMAC operation.
|
otPlatCryptoHmacSha256Start(otCryptoContext *aContext, const otCryptoKey *aKey)
|
Start HMAC operation.
|
otPlatCryptoHmacSha256Update(otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength)
|
Update the HMAC operation with new input.
|
otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef, otCryptoKeyType aKeyType, otCryptoKeyAlgorithm aKeyAlgorithm, int aKeyUsage, otCryptoKeyStorage aKeyPersistence, const uint8_t *aKey, size_t aKeyLen)
|
Import a key into PSA ITS.
|
otPlatCryptoInit(void)
|
void
Initialize the Crypto module.
|
otPlatCryptoPbkdf2GenerateKey(const uint8_t *aPassword, uint16_t aPasswordLen, const uint8_t *aSalt, uint16_t aSaltLen, uint32_t aIterationCounter, uint16_t aKeyLen, uint8_t *aKey)
|
Perform PKCS#5 PBKDF2 using CMAC (AES-CMAC-PRF-128).
|
otPlatCryptoRandomDeinit(void)
|
void
Deinitialize cryptographically-secure pseudorandom number generator (CSPRNG).
|
otPlatCryptoRandomGet(uint8_t *aBuffer, uint16_t aSize)
|
Fills a given buffer with cryptographically secure random bytes.
|
otPlatCryptoRandomInit(void)
|
void
Initialize cryptographically-secure pseudorandom number generator (CSPRNG).
|
otPlatCryptoSha256Deinit(otCryptoContext *aContext)
|
Uninitialize the SHA-256 operation.
|
otPlatCryptoSha256Finish(otCryptoContext *aContext, uint8_t *aHash, uint16_t aHashSize)
|
Finish SHA-256 operation.
|
otPlatCryptoSha256Init(otCryptoContext *aContext)
|
Initialise the SHA-256 operation.
|
otPlatCryptoSha256Start(otCryptoContext *aContext)
|
Start SHA-256 operation.
|
otPlatCryptoSha256Update(otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength)
|
Update SHA-256 operation with new input.
|
Macros |
|
---|---|
OT_CRYPTO_ECDSA_MAX_DER_SIZE 125
|
Max buffer size (in bytes) for representing the EDCSA key-pair in DER format.
|
OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE 64
|
Buffer size (in bytes) for representing the EDCSA public key.
|
OT_CRYPTO_ECDSA_SIGNATURE_SIZE 64
|
Buffer size (in bytes) for representing the EDCSA signature.
|
OT_CRYPTO_PBDKF2_MAX_SALT_SIZE 30
|
Max PBKDF2 SALT length: salt prefix (6) + extended panid (8) + network name (16)
|
OT_CRYPTO_SHA256_HASH_SIZE 32
|
Length of SHA256 hash (in bytes).
|
Structs |
|
---|---|
otCryptoContext |
Stores the context object for platform APIs. |
otCryptoKey |
Represents the Key Material required for Crypto operations. |
otPlatCryptoEcdsaKeyPair |
Represents an ECDSA key pair (public and private keys). |
otPlatCryptoEcdsaPublicKey |
Represents a ECDSA public key. |
otPlatCryptoEcdsaSignature |
Represents an ECDSA signature. |
otPlatCryptoSha256Hash |
Represents a SHA-256 hash. |
Enumerations
Anonymous Enum 11
Anonymous Enum 11
Defines the key usage flags.
otCryptoKeyAlgorithm
otCryptoKeyAlgorithm
otCryptoKeyStorage
otCryptoKeyStorage
otCryptoKeyType
otCryptoKeyType
Typedefs
otCryptoContext
struct otCryptoContext otCryptoContext
otCryptoKey
struct otCryptoKey otCryptoKey
otCryptoKeyRef
uint32_t otCryptoKeyRef
This datatype represents the key reference.
otPlatCryptoEcdsaKeyPair
struct otPlatCryptoEcdsaKeyPair otPlatCryptoEcdsaKeyPair
otPlatCryptoEcdsaPublicKey
struct otPlatCryptoEcdsaPublicKey otPlatCryptoEcdsaPublicKey
otPlatCryptoEcdsaSignature
struct otPlatCryptoEcdsaSignature otPlatCryptoEcdsaSignature
otPlatCryptoSha256Hash
struct otPlatCryptoSha256Hash otPlatCryptoSha256Hash
Represents a SHA-256 hash.
Variables
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 )
Encrypt the given data.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoAesFree
otError otPlatCryptoAesFree( otCryptoContext *aContext )
Free the AES context.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoAesInit
otError otPlatCryptoAesInit( otCryptoContext *aContext )
Initialise the AES operation.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otPlatCryptoAesSetKey
otError otPlatCryptoAesSetKey( otCryptoContext *aContext, const otCryptoKey *aKey )
Set the key for AES operation.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoDestroyKey
otError otPlatCryptoDestroyKey( otCryptoKeyRef aKeyRef )
Destroy a key stored in PSA ITS.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
otPlatCryptoEcdsaExportPublicKey
otError otPlatCryptoEcdsaExportPublicKey( otCryptoKeyRef aKeyRef, otPlatCryptoEcdsaPublicKey *aPublicKey )
Get the associated public key from the key reference passed.
The public key is stored differently depending on the crypto backend library being used (OPENTHREAD_CONFIG_CRYPTO_LIB).
This API must make sure to return the public key as a byte sequence representation of an uncompressed curve point (RFC 6605 - sec 4)
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoEcdsaGenerateAndImportKey
otError otPlatCryptoEcdsaGenerateAndImportKey( otCryptoKeyRef aKeyRef )
Generate and import a new ECDSA key-pair at reference passed.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otPlatCryptoEcdsaGenerateKey
otError otPlatCryptoEcdsaGenerateKey( otPlatCryptoEcdsaKeyPair *aKeyPair )
Generate and populate the output buffer with a new ECDSA key-pair.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otPlatCryptoEcdsaGetPublicKey
otError otPlatCryptoEcdsaGetPublicKey( const otPlatCryptoEcdsaKeyPair *aKeyPair, otPlatCryptoEcdsaPublicKey *aPublicKey )
Get the associated public key from the input context.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoEcdsaSign
otError otPlatCryptoEcdsaSign( const otPlatCryptoEcdsaKeyPair *aKeyPair, const otPlatCryptoSha256Hash *aHash, otPlatCryptoEcdsaSignature *aSignature )
Calculate the ECDSA signature for a hashed message using the private key from the input context.
Uses the deterministic digital signature generation procedure from RFC 6979.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otPlatCryptoEcdsaSignUsingKeyRef
otError otPlatCryptoEcdsaSignUsingKeyRef( otCryptoKeyRef aKeyRef, const otPlatCryptoSha256Hash *aHash, otPlatCryptoEcdsaSignature *aSignature )
Calculate the ECDSA signature for a hashed message using the Key reference passed.
Uses the deterministic digital signature generation procedure from RFC 6979.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otPlatCryptoEcdsaVerify
otError otPlatCryptoEcdsaVerify( const otPlatCryptoEcdsaPublicKey *aPublicKey, const otPlatCryptoSha256Hash *aHash, const otPlatCryptoEcdsaSignature *aSignature )
Use the key from the input context to verify the ECDSA signature of a hashed message.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otPlatCryptoEcdsaVerifyUsingKeyRef
otError otPlatCryptoEcdsaVerifyUsingKeyRef( otCryptoKeyRef aKeyRef, const otPlatCryptoSha256Hash *aHash, const otPlatCryptoEcdsaSignature *aSignature )
Use the keyref to verify the ECDSA signature of a hashed message.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otPlatCryptoExportKey
otError otPlatCryptoExportKey( otCryptoKeyRef aKeyRef, uint8_t *aBuffer, size_t aBufferLen, size_t *aKeyLen )
Export a key stored in PSA ITS.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otPlatCryptoHasKey
bool otPlatCryptoHasKey( otCryptoKeyRef aKeyRef )
Check if the key ref passed has an associated key in PSA ITS.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
otPlatCryptoHkdfDeinit
otError otPlatCryptoHkdfDeinit( otCryptoContext *aContext )
Uninitialize the HKDF context.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoHkdfExpand
otError otPlatCryptoHkdfExpand( otCryptoContext *aContext, const uint8_t *aInfo, uint16_t aInfoLength, uint8_t *aOutputKey, uint16_t aOutputKeyLength )
Perform HKDF Expand step.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
otPlatCryptoHkdfExtract
otError otPlatCryptoHkdfExtract( otCryptoContext *aContext, const uint8_t *aSalt, uint16_t aSaltLength, const otCryptoKey *aInputKey )
Perform HKDF Extract step.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otPlatCryptoHkdfInit
otError otPlatCryptoHkdfInit( otCryptoContext *aContext )
Initialise the HKDF context.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoHmacSha256Deinit
otError otPlatCryptoHmacSha256Deinit( otCryptoContext *aContext )
Uninitialize the HMAC operation.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoHmacSha256Finish
otError otPlatCryptoHmacSha256Finish( otCryptoContext *aContext, uint8_t *aBuf, size_t aBufLength )
Complete the HMAC operation.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoHmacSha256Init
otError otPlatCryptoHmacSha256Init( otCryptoContext *aContext )
Initialize the HMAC operation.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoHmacSha256Start
otError otPlatCryptoHmacSha256Start( otCryptoContext *aContext, const otCryptoKey *aKey )
Start HMAC operation.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoHmacSha256Update
otError otPlatCryptoHmacSha256Update( otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength )
Update the HMAC operation with new input.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
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.
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.
Details | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||||||
Return Values |
|
This API is only used by OT core when OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
is enabled.
otPlatCryptoInit
void otPlatCryptoInit( void )
Initialize the Crypto module.
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 )
Perform PKCS#5 PBKDF2 using CMAC (AES-CMAC-PRF-128).
Details | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||||||
Return Values |
|
otPlatCryptoRandomDeinit
void otPlatCryptoRandomDeinit( void )
Deinitialize cryptographically-secure pseudorandom number generator (CSPRNG).
otPlatCryptoRandomGet
otError otPlatCryptoRandomGet( uint8_t *aBuffer, uint16_t aSize )
Fills a given buffer with cryptographically secure random bytes.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
otPlatCryptoRandomInit
void otPlatCryptoRandomInit( void )
Initialize cryptographically-secure pseudorandom number generator (CSPRNG).
otPlatCryptoSha256Deinit
otError otPlatCryptoSha256Deinit( otCryptoContext *aContext )
Uninitialize the SHA-256 operation.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoSha256Finish
otError otPlatCryptoSha256Finish( otCryptoContext *aContext, uint8_t *aHash, uint16_t aHashSize )
Finish SHA-256 operation.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoSha256Init
otError otPlatCryptoSha256Init( otCryptoContext *aContext )
Initialise the SHA-256 operation.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoSha256Start
otError otPlatCryptoSha256Start( otCryptoContext *aContext )
Start SHA-256 operation.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otPlatCryptoSha256Update
otError otPlatCryptoSha256Update( otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength )
Update SHA-256 operation with new input.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
Macros
OT_CRYPTO_ECDSA_MAX_DER_SIZE
OT_CRYPTO_ECDSA_MAX_DER_SIZE 125
Max buffer size (in bytes) for representing the EDCSA key-pair in DER format.
OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE
OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE 64
Buffer size (in bytes) for representing the EDCSA public key.
OT_CRYPTO_ECDSA_SIGNATURE_SIZE
OT_CRYPTO_ECDSA_SIGNATURE_SIZE 64
Buffer size (in bytes) for representing the EDCSA signature.
OT_CRYPTO_PBDKF2_MAX_SALT_SIZE
OT_CRYPTO_PBDKF2_MAX_SALT_SIZE 30
Max PBKDF2 SALT length: salt prefix (6) + extended panid (8) + network name (16)
OT_CRYPTO_SHA256_HASH_SIZE
OT_CRYPTO_SHA256_HASH_SIZE 32
Length of SHA256 hash (in bytes).
Resources
OpenThread API Reference topics originate from the source code, available on GitHub. For more information, or to contribute to our documentation, refer to Resources.