From b487618ca56c2badd6b529a74d9e48969dec48ac Mon Sep 17 00:00:00 2001 From: areviu Date: Sat, 11 Nov 2017 20:07:22 +0000 Subject: added crypto aes and des polling mode git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10983 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c | 1089 +++++++++++++++++++++++++++ os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.h | 299 ++++++++ os/hal/ports/SAMA/SAMA5D2x/platform.mk | 4 +- os/hal/ports/SAMA/SAMA5D2x/sama_pmc.h | 60 ++ 4 files changed, 1451 insertions(+), 1 deletion(-) create mode 100644 os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c create mode 100644 os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.h (limited to 'os/hal/ports/SAMA/SAMA5D2x') diff --git a/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c b/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c new file mode 100644 index 000000000..7665f9204 --- /dev/null +++ b/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c @@ -0,0 +1,1089 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @file hal_crypto_lld.c + * @brief PLATFORM cryptographic subsystem low level driver source. + * + * @addtogroup CRYPTO + * @{ + */ +#include +#include "hal.h" + +#if (HAL_USE_CRY == TRUE) || defined(__DOXYGEN__) + +#include "sama_crypto_lld.h" +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + + +/** @brief CRY1 driver identifier.*/ +#if PLATFORM_CRY_USE_CRY1 || defined(__DOXYGEN__) +CRYDriver CRYD1; +#endif + +/*===========================================================================*/ +/* Driver local variables and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief Low level crypto driver initialization. + * + * @notapi + */ +void cry_lld_init(void) { +#if PLATFORM_CRY_USE_CRY1 == TRUE + cryObjectInit(&CRYD1); + samaCryptoDriverInit(&CRYD1); +#endif +} + +/** + * @brief Configures and activates the crypto peripheral. + * + * @param[in] cryp pointer to the @p CRYDriver object + * + * @notapi + */ +void cry_lld_start(CRYDriver *cryp) { + + if (cryp->state == CRY_STOP) { +#if PLATFORM_CRY_USE_CRY1 + if (&CRYD1 == cryp) { + samaCryptoDriverStart(&CRYD1); + } +#endif /* PLATFORM_CRY_USE_CRY1 */ + } +} + +/** + * @brief Deactivates the crypto peripheral. + * + * @param[in] cryp pointer to the @p CRYDriver object + * + * @notapi + */ +void cry_lld_stop(CRYDriver *cryp) { + + if (cryp->state == CRY_READY) { +#if PLATFORM_CRY_USE_CRY1 + if (&CRYD1 == cryp) { + samaCryptoDriverStop(&CRYD1); + } +#endif /* PLATFORM_CRY_USE_CRY1 */ + + } +} + +/** + * @brief Initializes the transient key for a specific algorithm. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] keyp pointer to the key data + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the specified algorithm is unknown or + * unsupported. + * @retval CRY_ERR_INV_KEY_SIZE if the specified key size is invalid. + * + * @notapi + */ +cryerror_t cry_lld_loadkey(CRYDriver *cryp, cryalgorithm_t algorithm, + size_t size, const uint8_t *keyp) { + + (void)(cryp); + (void)(algorithm); + return samaCryptoDriverWriteTransientKey(keyp, size); + +} + +/** + * @brief Encryption of a single block using AES. + * @note The implementation of this function must guarantee that it can + * be called from any context. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, crykey_t key_id, + const uint8_t *in, uint8_t *out) { + + cryerror_t ret = CRY_NOERROR; + aesparams params; + + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + + if (!(cryp->enabledPer & AES_PER)) { + cryp->enabledPer |= AES_PER; + pmcEnableAES(); + } + + params.encrypt = 1; + params.block_size = 16; + params.mode = 0; + params.iv = NULL; + + + ret = sama_aes_lld_process_polling(cryp, ¶ms, in, out, 16); + + + return ret; +} + +/** + * @brief Decryption of a single block using AES. + * @note The implementation of this function must guarantee that it can + * be called from any context. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] in buffer containing the input cyphertext + * @param[out] out buffer for the output plaintext + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, crykey_t key_id, + const uint8_t *in, uint8_t *out) { + + cryerror_t ret = CRY_NOERROR; + aesparams params; + + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + + if (!(cryp->enabledPer & AES_PER)) { + cryp->enabledPer |= AES_PER; + pmcEnableAES(); + } + + params.encrypt = 0; + params.block_size = 16; + params.mode = 0; + params.iv = NULL; + + + ret = sama_aes_lld_process_polling(cryp, ¶ms, in, out, 16); + + + return ret; +} + +/** + * @brief Encryption operation using AES-ECB. + * @note The function operates on data buffers whose lenght is a multiple + * of an AES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out) { + + cryerror_t ret = CRY_NOERROR; + aesparams params; + + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + + if (!(cryp->enabledPer & AES_PER)) { + cryp->enabledPer |= AES_PER; + pmcEnableAES(); + } + + params.encrypt = 1; + params.block_size = 16; + params.mode = AES_MR_OPMOD_ECB; + params.iv = NULL; + + + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_aes_lld_process_polling(cryp, ¶ms, in, out, size); + else + ret = sama_aes_lld_process_dma(cryp, ¶ms, in, out, size); + + + return ret; +} + +/** + * @brief Decryption operation using AES-ECB. + * @note The function operates on data buffers whose lenght is a multiple + * of an AES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out) { + + cryerror_t ret = CRY_NOERROR; + aesparams params; + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + + if (!(cryp->enabledPer & AES_PER)) { + cryp->enabledPer |= AES_PER; + pmcEnableAES(); + } + + params.encrypt = 0; + params.block_size = 16; + params.mode = AES_MR_OPMOD_ECB; + + + + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_aes_lld_process_polling(cryp, ¶ms, in, out, size); + else + ret = sama_aes_lld_process_dma(cryp, ¶ms, in, out, size); + + + + return ret; +} + +/** + * @brief Encryption operation using AES-CBC. + * @note The function operates on data buffers whose lenght is a multiple + * of an AES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv) { + + cryerror_t ret = CRY_NOERROR; + aesparams params; + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + + if (!(cryp->enabledPer & AES_PER)) { + cryp->enabledPer |= AES_PER; + pmcEnableAES() + ; + } + params.encrypt = 1; + params.block_size = 16; + params.mode = AES_MR_OPMOD_CBC; + params.iv = iv; + + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_aes_lld_process_polling(cryp, ¶ms, in, out, size); + else + ret = sama_aes_lld_process_dma(cryp, ¶ms, in, out, size); + + + + return ret; +} + +/** + * @brief Decryption operation using AES-CBC. + * @note The function operates on data buffers whose lenght is a multiple + * of an AES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv) { + + cryerror_t ret = CRY_NOERROR; + aesparams params; + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + + if (!(cryp->enabledPer & AES_PER)) { + cryp->enabledPer |= AES_PER; + pmcEnableAES() + ; + } + + params.encrypt = 0; + params.block_size = 16; + params.mode = AES_MR_OPMOD_CBC; + params.iv = iv; + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_aes_lld_process_polling(cryp, ¶ms, in, out, size); + else + ret = sama_aes_lld_process_dma(cryp, ¶ms, in, out, size); + + + + return ret; +} + +/** + * @brief Encryption operation using AES-CFB. + * @note The function operates on data buffers whose lenght is a multiple + * of an AES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv) { + + cryerror_t ret = CRY_NOERROR; + aesparams params; + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + + if (!(cryp->enabledPer & AES_PER)) { + cryp->enabledPer |= AES_PER; + pmcEnableAES() + ; + } + params.encrypt = 1; + params.block_size = 16; + switch (cryp->config->cfbs) { + case AES_CFBS_128: + params.block_size = 16; + break; + case AES_CFBS_64: + params.block_size = 8; + break; + case AES_CFBS_32: + params.block_size = 4; + break; + case AES_CFBS_16: + params.block_size = 2; + break; + case AES_CFBS_8: + params.block_size = 1; + break; + } + params.mode = AES_MR_OPMOD_CFB; + params.iv = iv; + + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_aes_lld_process_polling(cryp, ¶ms, in, out, size); + else + ret = sama_aes_lld_process_dma(cryp, ¶ms, in, out, size); + + + return ret; +} + +/** + * @brief Decryption operation using AES-CFB. + * @note The function operates on data buffers whose lenght is a multiple + * of an AES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv) { + + cryerror_t ret = CRY_NOERROR; + aesparams params; + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + + if (!(cryp->enabledPer & AES_PER)) { + cryp->enabledPer |= AES_PER; + pmcEnableAES() + ; + } + + params.encrypt = 0; + params.block_size = 16; + switch (cryp->config->cfbs) { + case AES_CFBS_128: + params.block_size = 16; + break; + case AES_CFBS_64: + params.block_size = 8; + break; + case AES_CFBS_32: + params.block_size = 4; + break; + case AES_CFBS_16: + params.block_size = 2; + break; + case AES_CFBS_8: + params.block_size = 1; + break; + } + params.mode = AES_MR_OPMOD_CFB; + params.iv = iv; + + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_aes_lld_process_polling(cryp, ¶ms, in, out, size); + else + ret = sama_aes_lld_process_dma(cryp, ¶ms, in, out, size); + + + + return ret; +} + +/** + * @brief Encryption operation using AES-CTR. + * @note The function operates on data buffers whose lenght is a multiple + * of an AES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of 16 + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + counter, it contains + * a 96 bits IV and a 32 bits counter + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv) { + + cryerror_t ret = CRY_NOERROR; + aesparams params; + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + + if (!(cryp->enabledPer & AES_PER)) { + cryp->enabledPer |= AES_PER; + pmcEnableAES() + ; + } + + params.encrypt = 1; + params.block_size = 16; + params.mode = AES_MR_OPMOD_CTR; + params.iv = iv; + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_aes_lld_process_polling(cryp, ¶ms, in, out, size); + else + ret = sama_aes_lld_process_dma(cryp, ¶ms, in, out, size); + + + + return ret; +} + +/** + * @brief Decryption operation using AES-CTR. + * @note The function operates on data buffers whose lenght is a multiple + * of an AES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of 16 + * @param[in] in buffer containing the input cyphertext + * @param[out] out buffer for the output plaintext + * @param[in] iv 128 bits initial vector + counter, it contains + * a 96 bits IV and a 32 bits counter + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv) { + + cryerror_t ret = CRY_NOERROR; + aesparams params; + if (key_id != 0) + return CRY_ERR_INV_KEY_ID; + + if (!(cryp->enabledPer & AES_PER)) { + cryp->enabledPer |= AES_PER; + pmcEnableAES() + ; + } + + params.encrypt = 0; + params.block_size = 16; + params.mode = AES_MR_OPMOD_CTR; + params.iv = iv; + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_aes_lld_process_polling(cryp, ¶ms, in, out, size); + else + ret = sama_aes_lld_process_dma(cryp, ¶ms, in, out, size); + + return ret; +} + +/** + * @brief Encryption operation using AES-GCM. + * @note The function operates on data buffers whose lenght is a multiple + * of an AES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the text buffers, this number must be a + * multiple of 16 + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + counter, it contains + * a 96 bits IV and a 32 bits counter + * @param[in] aadsize size of the authentication data, this number must be a + * multiple of 16 + * @param[in] aad buffer containing the authentication data + * @param[in] authtag 128 bits buffer for the generated authentication tag + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv, + size_t aadsize, + const uint8_t *aad, + uint8_t *authtag) { + + (void)cryp; + (void)key_id; + (void)size; + (void)in; + (void)out; + (void)iv; + (void)aadsize; + (void)aad; + (void)authtag; + + return CRY_ERR_INV_ALGO; +} + +/** + * @brief Decryption operation using AES-GCM. + * @note The function operates on data buffers whose lenght is a multiple + * of an AES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the text buffers, this number must be a + * multiple of 16 + * @param[in] in buffer for the output cyphertext + * @param[out] out buffer containing the input plaintext + * @param[in] iv 128 bits initial vector + counter, it contains + * a 96 bits IV and a 32 bits counter + * @param[in] aadsize size of the authentication data, this number must be a + * multiple of 16 + * @param[in] aad buffer containing the authentication data + * @param[in] authtag 128 bits buffer for the generated authentication tag + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv, + size_t aadsize, + const uint8_t *aad, + uint8_t *authtag) { + + (void)cryp; + (void)key_id; + (void)size; + (void)in; + (void)out; + (void)iv; + (void)aadsize; + (void)aad; + (void)authtag; + + return CRY_ERR_INV_ALGO; +} + + +/** + * @brief Encryption of a single block using (T)DES. + * @note The implementation of this function must guarantee that it can + * be called from any context. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, crykey_t key_id, + const uint8_t *in, uint8_t *out) { + + cryerror_t ret = CRY_NOERROR; + + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + + if ( ( cryp->config->tdes_algo == TDES_ALGO_SINGLE && cryp->key0_size != 8 ) || + ( cryp->config->tdes_algo == TDES_ALGO_TRIPLE && cryp->key0_size != 24 ) ) + return CRY_ERR_INV_KEY_SIZE; + + tdes_config_t params = { cryp->config->tdes_algo, + 0 + }; + + if (!(cryp->enabledPer & TDES_PER)) { + cryp->enabledPer |= TDES_PER; + pmcEnableDES(); + } + + ret = sama_tdes_lld_polling(cryp,¶ms, true, in, + 8, out,NULL); + + return ret; +} + +/** + * @brief Decryption of a single block using (T)DES. + * @note The implementation of this function must guarantee that it can + * be called from any context. + * + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] in buffer containing the input cyphertext + * @param[out] out buffer for the output plaintext + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, crykey_t key_id, + const uint8_t *in, uint8_t *out) { + + cryerror_t ret = CRY_NOERROR; + tdes_config_t params = { cryp->config->tdes_algo, + 0 + }; + if(key_id != 0 ) + return CRY_ERR_INV_KEY_ID; + if (!(cryp->enabledPer & TDES_PER)) { + cryp->enabledPer |= TDES_PER; + pmcEnableDES(); + } + + ret = sama_tdes_lld_polling(cryp,¶ms, false, in, + 8, out,NULL); + + + return ret; +} + +/** + * @brief Encryption operation using (T)DES-ECB. + * @note The function operates on data buffers whose length is a multiple + * of an DES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of 8 + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out) { + + cryerror_t ret = CRY_NOERROR; + tdes_config_t params = { cryp->config->tdes_algo, TDES_MODE_ECB }; + if (key_id != 0) + return CRY_ERR_INV_KEY_ID; + + if (cryp->key0_size != 16 && cryp->key0_size != 24) { + return CRY_ERR_INV_KEY_SIZE; + } + + if (!(cryp->enabledPer & TDES_PER)) { + cryp->enabledPer |= TDES_PER; + pmcEnableDES() + ; + } + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_tdes_lld_polling(cryp, ¶ms, true, in, size, out, NULL); + else + ret = sama_tdes_lld_dma(cryp, ¶ms, true, in, size, out, NULL); + + return ret; +} + +/** + * @brief Decryption operation using (T)DES-ECB. + * @note The function operates on data buffers whose length is a multiple + * of an DES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of 8 + * @param[in] in buffer containing the input cyphertext + * @param[out] out buffer for the output plaintext + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out) { + + cryerror_t ret = CRY_NOERROR; + tdes_config_t params = { cryp->config->tdes_algo, TDES_MODE_ECB }; + if (key_id != 0) + return CRY_ERR_INV_KEY_ID; + + if (cryp->key0_size != 16 && cryp->key0_size != 24) { + return CRY_ERR_INV_KEY_SIZE; + } + if (!(cryp->enabledPer & TDES_PER)) { + cryp->enabledPer |= TDES_PER; + pmcEnableDES() + ; + } + + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_tdes_lld_polling(cryp, ¶ms, false, in, size, out, NULL); + else + ret = sama_tdes_lld_dma(cryp, ¶ms, false, in, size, out, NULL); + + return ret; +} + +/** + * @brief Encryption operation using (T)DES-CBC. + * @note The function operates on data buffers whose length is a multiple + * of an DES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of 8 + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 64 bits input vector + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv) { + + + cryerror_t ret = CRY_NOERROR; + tdes_config_t params = { cryp->config->tdes_algo, TDES_MODE_CBC }; + if (key_id != 0) + return CRY_ERR_INV_KEY_ID; + + if (cryp->key0_size != 16 && cryp->key0_size != 24) { + return CRY_ERR_INV_KEY_SIZE; + } + + if (!(cryp->enabledPer & TDES_PER)) { + cryp->enabledPer |= TDES_PER; + pmcEnableDES() + ; + } + + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_tdes_lld_polling(cryp, ¶ms, true, in, size, out, iv); + else + ret = sama_tdes_lld_dma(cryp, ¶ms, true, in, size, out, iv); + return ret; +} + +/** + * @brief Decryption operation using (T)DES-CBC. + * @note The function operates on data buffers whose length is a multiple + * of an DES block, this means that padding must be done by the + * caller. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is the + * transient key, other values are keys stored in an + * unspecified way + * @param[in] size size of the plaintext buffer, this number must be a + * multiple of 8 + * @param[in] in buffer containing the input cyphertext + * @param[out] out buffer for the output plaintext + * @param[in] iv 64 bits input vector + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. + * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid + * or refers to an empty key slot. + * + * @notapi + */ +cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, crykey_t key_id, + size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv) { + + cryerror_t ret = CRY_NOERROR; + tdes_config_t params = { cryp->config->tdes_algo, TDES_MODE_CBC }; + if (key_id != 0) + return CRY_ERR_INV_KEY_ID; + + if (cryp->key0_size != 16 && cryp->key0_size != 24) { + return CRY_ERR_INV_KEY_SIZE; + } + + if (!(cryp->enabledPer & TDES_PER)) { + cryp->enabledPer |= TDES_PER; + pmcEnableDES() + ; + } + + if (cryp->config->transfer_mode == TRANSFER_POLLING) + ret = sama_tdes_lld_polling(cryp, ¶ms, false, in, size, out, iv); + else + ret = sama_tdes_lld_dma(cryp, ¶ms, false, in, size, out, iv); + + return ret; +} + + + +#endif /* HAL_USE_CRY == TRUE */ + +/** @} */ diff --git a/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.h b/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.h new file mode 100644 index 000000000..135ac600c --- /dev/null +++ b/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.h @@ -0,0 +1,299 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file hal_cry_lld.h + * @brief PLATFORM cryptographic subsystem low level driver header. + * + * @addtogroup CRYPTO + * @{ + */ + +#ifndef HAL_CRYPTO_LLD_H +#define HAL_CRYPTO_LLD_H + +#if (HAL_USE_CRY == TRUE) || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/** + * @name Driver capability switches + * @{ + */ +#define CRY_LLD_SUPPORTS_AES TRUE +#define CRY_LLD_SUPPORTS_AES_ECB TRUE +#define CRY_LLD_SUPPORTS_AES_CBC TRUE +#define CRY_LLD_SUPPORTS_AES_CFB TRUE +#define CRY_LLD_SUPPORTS_AES_CTR TRUE +#define CRY_LLD_SUPPORTS_AES_GCM TRUE +#define CRY_LLD_SUPPORTS_DES TRUE +#define CRY_LLD_SUPPORTS_DES_ECB TRUE +#define CRY_LLD_SUPPORTS_DES_CBC TRUE +/** @{ */ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/** + * @name PLATFORM configuration options + * @{ + */ +/** + * @brief CRY1 driver enable switch. + * @details If set to @p TRUE the support for CRY1 is included. + * @note The default is @p FALSE. + */ +#if !defined(PLATFORM_CRY_USE_CRY1) || defined(__DOXYGEN__) +#define PLATFORM_CRY_USE_CRY1 FALSE +#endif +/** @} */ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +typedef struct +{ + uint32_t encrypt; + uint32_t block_size; + uint32_t mode; + const uint8_t *iv; +}aesparams; + +typedef enum { + TRANSFER_DMA = 0, + TRANSFER_POLLING, +}crytransfermode_t; + +typedef enum { + AES_CFBS_128 = 0, + AES_CFBS_64, + AES_CFBS_32, + AES_CFBS_16, + AES_CFBS_8 +}aesciphersize_t; + + +/** + * @brief CRY key identifier type. + */ +typedef uint32_t crykey_t; + +/** + * @brief Type of a structure representing an CRY driver. + */ +typedef struct CRYDriver CRYDriver; + +/** + * @brief Driver configuration structure. + * @note It could be empty on some architectures. + */ + + +typedef enum { + TDES_ALGO_SINGLE = 0, + TDES_ALGO_TRIPLE, + TDES_ALGO_XTEA +}tdes_algo_t; + +typedef struct { + + crytransfermode_t transfer_mode; + uint32_t cfbs; + tdes_algo_t tdes_algo; + +} CRYConfig; + +#define CRY_DRIVER_EXT_FIELDS thread_reference_t thread; \ + sama_dma_channel_t *dmarx; \ + sama_dma_channel_t *dmatx; \ + uint32_t rxdmamode; \ + uint32_t txdmamode; \ + uint8_t dmawith; \ + uint8_t dmachunksize; \ + uint8_t enabledPer; +/** + * @brief Structure representing an CRY driver. + */ +struct CRYDriver { + /** + * @brief Driver state. + */ + crystate_t state; + /** + * @brief Current configuration data. + */ + const CRYConfig *config; + /** + * @brief Algorithm type of transient key. + */ + cryalgorithm_t key0_type; + /** + * @brief Size of transient key. + */ + size_t key0_size; +#if (HAL_CRY_USE_FALLBACK == TRUE) || defined(__DOXYGEN__) + /** + * @brief Key buffer for the fall-back implementation. + */ + uint8_t key0_buffer[HAL_CRY_MAX_KEY_SIZE]; +#endif +#if defined(CRY_DRIVER_EXT_FIELDS) + CRY_DRIVER_EXT_FIELDS +#endif + /* End of the mandatory fields.*/ +}; + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#if (PLATFORM_CRY_USE_CRY1 == TRUE) && !defined(__DOXYGEN__) +extern CRYDriver CRYD1; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + void cry_lld_init(void); + void cry_lld_start(CRYDriver *cryp); + void cry_lld_stop(CRYDriver *cryp); + cryerror_t cry_lld_loadkey(CRYDriver *cryp, + cryalgorithm_t algorithm, + size_t size, + const uint8_t *keyp); + cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, + crykey_t key_id, + const uint8_t *in, + uint8_t *out); + cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, + crykey_t key_id, + const uint8_t *in, + uint8_t *out); + cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out); + cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out); + cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv, + size_t aadsize, + const uint8_t *aad, + uint8_t *authtag); + cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv, + size_t aadsize, + const uint8_t *aad, + uint8_t *authtag); + cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, + crykey_t key_id, + const uint8_t *in, + uint8_t *out); + cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, + crykey_t key_id, + const uint8_t *in, + uint8_t *out); + cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out); + cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out); + cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); +#ifdef __cplusplus +} +#endif + +#endif /* HAL_USE_CRY == TRUE */ + +#endif /* HAL_CRYPTO_LLD_H */ + +/** @} */ diff --git a/os/hal/ports/SAMA/SAMA5D2x/platform.mk b/os/hal/ports/SAMA/SAMA5D2x/platform.mk index 59fda14fc..6f826f1cf 100644 --- a/os/hal/ports/SAMA/SAMA5D2x/platform.mk +++ b/os/hal/ports/SAMA/SAMA5D2x/platform.mk @@ -5,7 +5,8 @@ PLATFORMSRC := $(CHIBIOS)/os/hal/ports/SAMA/SAMA5D2x/hal_lld.c \ $(CHIBIOS)/os/hal/ports/SAMA/SAMA5D2x/aic.c \ $(CHIBIOS)/os/hal/ports/SAMA/SAMA5D2x/sama_matrix.c \ $(CHIBIOS)/os/hal/ports/SAMA/SAMA5D2x/sama_cache.c \ - $(CHIBIOS)/os/hal/ports/SAMA/SAMA5D2x/hal_tc_lld.c + $(CHIBIOS)/os/hal/ports/SAMA/SAMA5D2x/hal_tc_lld.c \ + $(CHIBIOS)/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c # Required include directories. PLATFORMINC := $(CHIBIOS)/os/hal/ports/SAMA/SAMA5D2x @@ -29,3 +30,4 @@ include $(CHIBIOS)/os/hal/ports/SAMA/LLD/PIOv1/driver.mk include $(CHIBIOS)/os/hal/ports/SAMA/LLD/SPIv1/driver.mk include $(CHIBIOS)/os/hal/ports/SAMA/LLD/RTCv1/driver.mk include $(CHIBIOS)/os/hal/ports/SAMA/LLD/USARTv1/driver.mk +include $(CHIBIOS)/os/hal/ports/SAMA/LLD/Cryptov1/driver.mk diff --git a/os/hal/ports/SAMA/SAMA5D2x/sama_pmc.h b/os/hal/ports/SAMA/SAMA5D2x/sama_pmc.h index 8c010a6d8..39354054e 100644 --- a/os/hal/ports/SAMA/SAMA5D2x/sama_pmc.h +++ b/os/hal/ports/SAMA/SAMA5D2x/sama_pmc.h @@ -408,8 +408,68 @@ */ #define pmcDisableTC1() pmcDisablePidHigh(ID_TC1_MSK) + +/** + * @brief Enables the AES peripheral clock. + * + * @api + */ +#define pmcEnableAES() pmcEnablePidLow(ID_AES_MSK) + +/** + * @brief Disables the AES peripheral clock. + * + * @api + */ +#define pmcDisableAES() pmcDisablePidLow(ID_AES_MSK) + +/** + * @brief Enables the TRNG peripheral clock. + * + * @api + */ +#define pmcEnableTRNG() pmcEnablePidHigh(ID_TRNG_MSK) +/** + * @brief Disables the TRNG peripheral clock. + * + * @api + */ +#define pmcDisableTRNG() pmcDisablePidHigh(ID_TRNG_MSK) + +/** + * @brief Enables the DES peripheral clock. + * + * @api + */ +#define pmcEnableDES() pmcEnablePidLow(ID_TDES_MSK) +/** + * @brief Disables the DES peripheral clock. + * + * @api + */ +#define pmcDisableDES() pmcDisablePidLow(ID_TDES_MSK) + +/** + * @brief Enables the SHA peripheral clock. + * + * @api + */ +#define pmcEnableSHA() pmcEnablePidLow(ID_SHA_MSK) +/** + * @brief Disables the SHA peripheral clock. + * + * @api + */ +#define pmcDisableSHA() pmcDisablePidLow(ID_SHA_MSK) + + /** @} */ + + + + + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ -- cgit v1.2.3