aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c')
-rw-r--r--os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c1078
1 files changed, 630 insertions, 448 deletions
diff --git a/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c b/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c
index 2e8a67309..5f1c62339 100644
--- a/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c
+++ b/os/hal/ports/SAMA/SAMA5D2x/hal_crypto_lld.c
@@ -12,7 +12,7 @@
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
@@ -73,10 +73,11 @@ void cry_lld_init(void) {
#endif
}
+
/**
* @brief Configures and activates the crypto peripheral.
*
- * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[in] cryp pointer to the @p CRYDriver object
*
* @notapi
*/
@@ -85,9 +86,9 @@ void cry_lld_start(CRYDriver *cryp) {
if (cryp->state == CRY_STOP) {
//clear key
for (size_t i=0;i<KEY0_BUFFER_SIZE_W;i++)
- {
+ {
cryp->key0_buffer[i] = 0;
- }
+ }
#if PLATFORM_CRY_USE_CRY1
if (&CRYD1 == cryp) {
@@ -119,9 +120,11 @@ void cry_lld_stop(CRYDriver *cryp) {
/**
* @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.
+ * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[in] algorithm the algorithm identifier
+ * @param[in] size key size in bytes
+ * @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.
@@ -129,8 +132,11 @@ void cry_lld_stop(CRYDriver *cryp) {
*
* @notapi
*/
-cryerror_t cry_lld_loadkey(CRYDriver *cryp, cryalgorithm_t algorithm,
- size_t size, const uint8_t *keyp) {
+cryerror_t cry_lld_loadkey(CRYDriver *cryp,
+ cryalgorithm_t algorithm,
+ size_t size,
+ const uint8_t *keyp) {
+
uint8_t *p = (uint8_t *)cryp->key0_buffer;
@@ -138,27 +144,27 @@ cryerror_t cry_lld_loadkey(CRYDriver *cryp, cryalgorithm_t algorithm,
(void)algorithm;
- if (size <= HAL_CRY_MAX_KEY_SIZE)
+ if (size <= HAL_CRY_MAX_KEY_SIZE)
+ {
+ osalMutexLock(&cryp->mutex);
+ //clear key
+ for (size_t i=0;i<KEY0_BUFFER_SIZE_W;i++)
{
- osalMutexLock(&cryp->mutex);
- //clear key
- for (size_t i=0;i<KEY0_BUFFER_SIZE_W;i++)
- {
- cryp->key0_buffer[i] = 0;
- }
-
- for (size_t i=0;i<size;i++)
- {
- p[i] = keyp[i];
- }
- osalMutexUnlock(&cryp->mutex);
+ cryp->key0_buffer[i] = 0;
}
- else
+
+ for (size_t i=0;i<size;i++)
{
- return CRY_ERR_INV_KEY_SIZE;
+ p[i] = keyp[i];
}
+ osalMutexUnlock(&cryp->mutex);
+ }
+ else
+ {
+ return CRY_ERR_INV_KEY_SIZE;
+ }
- return CRY_NOERROR;
+ return CRY_NOERROR;
}
@@ -167,13 +173,13 @@ cryerror_t cry_lld_loadkey(CRYDriver *cryp, cryalgorithm_t algorithm,
* @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.
+ * @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.
@@ -183,30 +189,33 @@ cryerror_t cry_lld_loadkey(CRYDriver *cryp, cryalgorithm_t algorithm,
*
* @notapi
*/
-cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, crykey_t key_id,
- const uint8_t *in, uint8_t *out) {
+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;
+ aesparams params;
- if(key_id != 0 )
- return CRY_ERR_INV_KEY_ID;
+ if(key_id != 0 )
+ return CRY_ERR_INV_KEY_ID;
- if (!(cryp->enabledPer & AES_PER)) {
- cryp->enabledPer |= AES_PER;
- pmcEnableAES();
- }
+ if (!(cryp->enabledPer & AES_PER)) {
+ cryp->enabledPer |= AES_PER;
+ pmcEnableAES();
+ }
- params.encrypt = 1;
- params.block_size = 16;
- params.mode = 0;
- params.iv = NULL;
+ params.encrypt = 1;
+ params.block_size = 16;
+ params.mode = 0;
+ params.iv = NULL;
- ret = sama_aes_lld_process_polling(cryp, &params, in, out, 16);
+ ret = sama_aes_lld_process_polling(cryp, &params, in, out, 16);
- return ret;
+ return ret;
}
/**
@@ -214,13 +223,13 @@ cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, crykey_t key_id,
* @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.
+ * @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.
@@ -230,30 +239,33 @@ cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, crykey_t key_id,
*
* @notapi
*/
-cryerror_t cry_lld_decrypt_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 ret = CRY_NOERROR;
- aesparams params;
+ aesparams params;
- if(key_id != 0 )
- return CRY_ERR_INV_KEY_ID;
+ if(key_id != 0 )
+ return CRY_ERR_INV_KEY_ID;
- if (!(cryp->enabledPer & AES_PER)) {
- cryp->enabledPer |= AES_PER;
- pmcEnableAES();
- }
+ if (!(cryp->enabledPer & AES_PER)) {
+ cryp->enabledPer |= AES_PER;
+ pmcEnableAES();
+ }
- params.encrypt = 0;
- params.block_size = 16;
- params.mode = 0;
- params.iv = NULL;
+ params.encrypt = 0;
+ params.block_size = 16;
+ params.mode = 0;
+ params.iv = NULL;
- ret = sama_aes_lld_process_polling(cryp, &params, in, out, 16);
+ ret = sama_aes_lld_process_polling(cryp, &params, in, out, 16);
- return ret;
+ return ret;
}
/**
@@ -262,15 +274,15 @@ cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -280,8 +292,11 @@ cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, crykey_t key_id,
*
* @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 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;
@@ -315,15 +330,15 @@ cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -333,13 +348,16 @@ cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id,
*
* @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 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;
+ return CRY_ERR_INV_KEY_ID;
if (!(cryp->enabledPer & AES_PER)) {
cryp->enabledPer |= AES_PER;
@@ -347,15 +365,15 @@ cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id,
}
params.encrypt = 0;
- params.block_size = 16;
- params.mode = AES_MR_OPMOD_ECB;
+ params.block_size = 16;
+ params.mode = AES_MR_OPMOD_ECB;
- if (cryp->config->transfer_mode == TRANSFER_POLLING)
- ret = sama_aes_lld_process_polling(cryp, &params, in, out, size);
- else
- ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
+ if (cryp->config->transfer_mode == TRANSFER_POLLING)
+ ret = sama_aes_lld_process_polling(cryp, &params, in, out, size);
+ else
+ ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
@@ -368,16 +386,16 @@ cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -387,13 +405,17 @@ cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id,
*
* @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 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;
+ return CRY_ERR_INV_KEY_ID;
if (!(cryp->enabledPer & AES_PER)) {
cryp->enabledPer |= AES_PER;
@@ -405,10 +427,10 @@ cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id,
params.mode = AES_MR_OPMOD_CBC;
params.iv = iv;
- if (cryp->config->transfer_mode == TRANSFER_POLLING)
- ret = sama_aes_lld_process_polling(cryp, &params, in, out, size);
- else
- ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
+ if (cryp->config->transfer_mode == TRANSFER_POLLING)
+ ret = sama_aes_lld_process_polling(cryp, &params, in, out, size);
+ else
+ ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
@@ -421,16 +443,16 @@ cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -440,13 +462,17 @@ cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id,
*
* @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 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;
+ return CRY_ERR_INV_KEY_ID;
if (!(cryp->enabledPer & AES_PER)) {
cryp->enabledPer |= AES_PER;
@@ -455,13 +481,13 @@ cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id,
}
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, &params, in, out, size);
- else
- ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
+ 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, &params, in, out, size);
+ else
+ ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
@@ -474,16 +500,16 @@ cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -493,13 +519,17 @@ cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id,
*
* @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 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;
+ return CRY_ERR_INV_KEY_ID;
if (!(cryp->enabledPer & AES_PER)) {
cryp->enabledPer |= AES_PER;
@@ -507,31 +537,31 @@ cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id,
;
}
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, &params, in, out, size);
- else
- ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
+ 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, &params, in, out, size);
+ else
+ ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
return ret;
@@ -543,16 +573,16 @@ cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -562,13 +592,17 @@ cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id,
*
* @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 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;
+ return CRY_ERR_INV_KEY_ID;
if (!(cryp->enabledPer & AES_PER)) {
cryp->enabledPer |= AES_PER;
@@ -577,31 +611,31 @@ cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id,
}
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, &params, in, out, size);
- else
- ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
+ 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, &params, in, out, size);
+ else
+ ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
@@ -614,17 +648,17 @@ cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -634,13 +668,17 @@ cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id,
*
* @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 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;
+ return CRY_ERR_INV_KEY_ID;
if (!(cryp->enabledPer & AES_PER)) {
cryp->enabledPer |= AES_PER;
@@ -649,13 +687,13 @@ cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, crykey_t key_id,
}
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, &params, in, out, size);
- else
- ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
+ 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, &params, in, out, size);
+ else
+ ret = sama_aes_lld_process_dma(cryp, &params, in, out, size);
@@ -668,17 +706,17 @@ cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -688,8 +726,12 @@ cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, crykey_t key_id,
*
* @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 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;
@@ -720,21 +762,22 @@ cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -754,17 +797,17 @@ cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp,
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;
+ (void)cryp;
+ (void)key_id;
+ (void)size;
+ (void)in;
+ (void)out;
+ (void)iv;
+ (void)aadsize;
+ (void)aad;
+ (void)authtag;
+
+ return CRY_ERR_INV_ALGO;
}
/**
@@ -773,21 +816,22 @@ cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp,
* 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.
+ * @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.
@@ -807,17 +851,17 @@ cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp,
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;
+ (void)cryp;
+ (void)key_id;
+ (void)size;
+ (void)in;
+ (void)out;
+ (void)iv;
+ (void)aadsize;
+ (void)aad;
+ (void)authtag;
+
+ return CRY_ERR_INV_ALGO;
}
@@ -826,13 +870,13 @@ cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp,
* @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.
+ * @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.
@@ -842,20 +886,28 @@ cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp,
*
* @notapi
*/
-cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, crykey_t key_id,
- const uint8_t *in, uint8_t *out) {
+cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp,
+ crykey_t key_id,
+ const uint8_t *in,
+ uint8_t *out) {
cryerror_t ret = CRY_NOERROR;
+ tdes_config_t params = { 0, 0 };
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 == 16 || cryp->key0_size == 24)))
+ if (cryp->key0_size == 8)
+ {
+ params.algo = TDES_ALGO_SINGLE;
+ }
+ else if (cryp->key0_size == 16 || cryp->key0_size == 24)
+ {
+ params.algo = TDES_ALGO_TRIPLE;
+ }
+ else
return CRY_ERR_INV_KEY_SIZE;
- tdes_config_t params = { cryp->config->tdes_algo, 0 };
if (!(cryp->enabledPer & TDES_PER)) {
cryp->enabledPer |= TDES_PER;
@@ -873,13 +925,13 @@ cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -889,17 +941,26 @@ cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, crykey_t key_id,
*
* @notapi
*/
-cryerror_t cry_lld_decrypt_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 ret = CRY_NOERROR;
- tdes_config_t params = { cryp->config->tdes_algo, 0 };
+ tdes_config_t params = { 0, 0 };
+
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 == 16 || cryp->key0_size == 24)))
+ if (cryp->key0_size == 8)
+ {
+ params.algo = TDES_ALGO_SINGLE;
+ }
+ else if (cryp->key0_size == 16 || cryp->key0_size == 24)
+ {
+ params.algo = TDES_ALGO_TRIPLE;
+ }
+ else
return CRY_ERR_INV_KEY_SIZE;
if (!(cryp->enabledPer & TDES_PER)) {
@@ -918,15 +979,15 @@ cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -936,21 +997,27 @@ cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, crykey_t key_id,
*
* @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 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 };
-
+ tdes_config_t params = { 0, TDES_MODE_ECB };
if (key_id != 0)
return CRY_ERR_INV_KEY_ID;
- if (cryp->config->tdes_algo == TDES_ALGO_SINGLE && cryp->key0_size != 8) {
- return CRY_ERR_INV_KEY_SIZE;
+ if (cryp->key0_size == 8)
+ {
+ params.algo = TDES_ALGO_SINGLE;
}
- if (cryp->config->tdes_algo == TDES_ALGO_TRIPLE && !(cryp->key0_size == 16 || cryp->key0_size == 24) ) {
- return CRY_ERR_INV_KEY_SIZE;
+ else if (cryp->key0_size == 16 || cryp->key0_size == 24)
+ {
+ params.algo = TDES_ALGO_TRIPLE;
}
+ else
+ return CRY_ERR_INV_KEY_SIZE;
if (!(cryp->enabledPer & TDES_PER)) {
cryp->enabledPer |= TDES_PER;
@@ -970,15 +1037,15 @@ cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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 T he operation status.
* @retval CRY_NOERROR if the operation succeeded.
* @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
* device instance.
@@ -988,20 +1055,28 @@ cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, crykey_t key_id,
*
* @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 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 };
+ tdes_config_t params = { 0, TDES_MODE_ECB };
if (key_id != 0)
return CRY_ERR_INV_KEY_ID;
- if (cryp->config->tdes_algo == TDES_ALGO_SINGLE && cryp->key0_size != 8) {
- return CRY_ERR_INV_KEY_SIZE;
+ if (cryp->key0_size == 8)
+ {
+ params.algo = TDES_ALGO_SINGLE;
}
- if (cryp->config->tdes_algo == TDES_ALGO_TRIPLE && !(cryp->key0_size == 16 || cryp->key0_size == 24) ) {
- return CRY_ERR_INV_KEY_SIZE;
+ else if (cryp->key0_size == 16 || cryp->key0_size == 24)
+ {
+ params.algo = TDES_ALGO_TRIPLE;
}
+ else
+ return CRY_ERR_INV_KEY_SIZE;
+
if (!(cryp->enabledPer & TDES_PER)) {
cryp->enabledPer |= TDES_PER;
pmcEnableDES()
@@ -1022,16 +1097,16 @@ cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -1041,22 +1116,30 @@ cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, crykey_t key_id,
*
* @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 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 };
+ tdes_config_t params = { 0, TDES_MODE_CBC };
if (key_id != 0)
return CRY_ERR_INV_KEY_ID;
- if (cryp->config->tdes_algo == TDES_ALGO_SINGLE)
- return CRY_ERR_INV_ALGO;
-
- if (cryp->key0_size != 16 && cryp->key0_size != 24) {
- return CRY_ERR_INV_KEY_SIZE;
- }
+ if (cryp->key0_size == 8)
+ {
+ params.algo = TDES_ALGO_SINGLE;
+ }
+ else if (cryp->key0_size == 16 || cryp->key0_size == 24)
+ {
+ params.algo = TDES_ALGO_TRIPLE;
+ }
+ else
+ return CRY_ERR_INV_KEY_SIZE;
if (!(cryp->enabledPer & TDES_PER)) {
cryp->enabledPer |= TDES_PER;
@@ -1077,16 +1160,16 @@ cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, crykey_t key_id,
* 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.
+ * @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.
@@ -1096,21 +1179,29 @@ cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, crykey_t key_id,
*
* @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 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 };
+ tdes_config_t params = { 0, TDES_MODE_CBC };
if (key_id != 0)
return CRY_ERR_INV_KEY_ID;
- if (cryp->config->tdes_algo == TDES_ALGO_SINGLE)
- return CRY_ERR_INV_ALGO;
-
- if (cryp->key0_size != 16 && cryp->key0_size != 24) {
- return CRY_ERR_INV_KEY_SIZE;
+ if (cryp->key0_size == 8)
+ {
+ params.algo = TDES_ALGO_SINGLE;
+ }
+ else if (cryp->key0_size == 16 || cryp->key0_size == 24)
+ {
+ params.algo = TDES_ALGO_TRIPLE;
}
+ else
+ return CRY_ERR_INV_KEY_SIZE;
if (!(cryp->enabledPer & TDES_PER)) {
cryp->enabledPer |= TDES_PER;
@@ -1129,97 +1220,188 @@ cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, crykey_t key_id,
/**
- * @brief Hash using SHA1.
- * @NOTE Use of this algorithm is not recommended because proven weak.
+ * @brief Hash initialization using SHA1.
+ * @note Use of this algorithm is not recommended because proven weak.
*
- * @param[in] cryp pointer to the @p CRYDriver object
- * @param[in] size size of input buffer
- * @param[in] in buffer containing the input text
- * @param[out] out 160 bits output buffer
- * @return The operation status.
+ * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[out] sha1ctxp pointer to a SHA1 context to be initialized
* @retval CRY_NOERROR if the operation succeeded.
* @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
* device instance.
*
- * @api
+ * @notapi
*/
-cryerror_t cry_lld_SHA1(CRYDriver *cryp, size_t size,
- const uint8_t *in, uint8_t *out) {
+cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp) {
- cryerror_t ret;
+ sha1ctxp->sha.algo = CRY_SHA_1;
- shaparams_t params = {CRY_SHA_1};
+ return sama_sha_lld_init(cryp, &sha1ctxp->sha);
+}
- ret = sama_sha_lld_process(cryp,
- &params,
- in,
- out,
- size
- );
+/**
+ * @brief Hash update using SHA1.
+ * @note Use of this algorithm is not recommended because proven weak.
+ *
+ * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[in] sha1ctxp pointer to a SHA1 context
+ * @param[in] size size of input buffer
+ * @param[in] in buffer containing the input text
+ * @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.
+ *
+ * @notapi
+ */
+cryerror_t cry_lld_SHA1_update(CRYDriver *cryp, SHA1Context *sha1ctxp,
+ size_t size, const uint8_t *in) {
- return ret;
+ sha1ctxp->sha.in = in;
+ sha1ctxp->sha.indata_len = size;
+
+ return sama_sha_lld_update(cryp, &sha1ctxp->sha);
}
/**
- * @brief Hash using SHA256.
+ * @brief Hash finalization using SHA1.
+ * @note Use of this algorithm is not recommended because proven weak.
*
- * @param[in] cryp pointer to the @p CRYDriver object
- * @param[in] size size of input buffer
- * @param[in] in buffer containing the input text
- * @param[out] out 256 bits output buffer
- * @return The operation status.
+ * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[in] sha1ctxp pointer to a SHA1 context
+ * @param[out] out 160 bits output buffer
+ * @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.
*
- * @api
+ * @notapi
+ */
+cryerror_t cry_lld_SHA1_final(CRYDriver *cryp,
+ SHA1Context *sha1ctxp,
+ uint8_t *out)
+{
+ sha1ctxp->sha.out = out;
+ return sama_sha_lld_final(cryp, &sha1ctxp->sha);
+}
+
+/**
+ * @brief Hash initialization using SHA256.
+ *
+ * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[out] sha256ctxp pointer to a SHA256 context to be initialized
+ * @retval CRY_NOERROR if the operation succeeded.
+ * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
+ * device instance.
+ *
+ * @notapi
+ */
+cryerror_t cry_lld_SHA256_init(CRYDriver *cryp, SHA256Context *sha256ctxp) {
+
+ sha256ctxp->sha.algo = CRY_SHA_256;
+
+ return sama_sha_lld_init(cryp, &sha256ctxp->sha);
+}
+
+/**
+ * @brief Hash update using SHA256.
+ *
+ * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[in] sha256ctxp pointer to a SHA256 context
+ * @param[in] size size of input buffer
+ * @param[in] in buffer containing the input text
+ * @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.
+ *
+ * @notapi
*/
-cryerror_t cry_lld_SHA256(CRYDriver *cryp, size_t size,
- const uint8_t *in, uint8_t *out) {
+cryerror_t cry_lld_SHA256_update(CRYDriver *cryp, SHA256Context *sha256ctxp,
+ size_t size, const uint8_t *in) {
- cryerror_t ret;
+ sha256ctxp->sha.in = in;
+ sha256ctxp->sha.indata_len = size;
- shaparams_t params = {CRY_SHA_256};
+ return sama_sha_lld_update(cryp, &sha256ctxp->sha);
+}
- ret = sama_sha_lld_process(cryp,
- &params,
- in,
- out,
- size
- );
+/**
+ * @brief Hash finalization using SHA256.
+ *
+ * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[in] sha256ctxp pointer to a SHA256 context
+ * @param[out] out 256 bits output buffer
+ * @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.
+ *
+ * @notapi
+ */
+cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp,
+ uint8_t *out) {
- return ret;
+ sha256ctxp->sha.out = out;
+ return sama_sha_lld_final(cryp, &sha256ctxp->sha);
}
/**
- * @brief Hash using SHA512.
+ * @brief Hash initialization using SHA512.
*
- * @param[in] cryp pointer to the @p CRYDriver object
- * @param[in] size size of input buffer
- * @param[in] in buffer containing the input text
- * @param[out] out 512 bits output buffer
- * @return The operation status.
+ * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[out] sha512ctxp pointer to a SHA512 context to be initialized
* @retval CRY_NOERROR if the operation succeeded.
* @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
* device instance.
*
- * @api
+ * @notapi
+ */
+cryerror_t cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp) {
+ sha512ctxp->sha.algo = CRY_SHA_512;
+ return sama_sha_lld_init(cryp, &sha512ctxp->sha);
+}
+
+/**
+ * @brief Hash update using SHA512.
+ *
+ * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[in] sha512ctxp pointer to a SHA512 context
+ * @param[in] size size of input buffer
+ * @param[in] in buffer containing the input text
+ * @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.
+ *
+ * @notapi
*/
-cryerror_t cry_lld_SHA512(CRYDriver *cryp, size_t size,
- const uint8_t *in, uint8_t *out) {
+cryerror_t cry_lld_SHA512_update(CRYDriver *cryp, SHA512Context *sha512ctxp,
+ size_t size, const uint8_t *in) {
- cryerror_t ret;
+ sha512ctxp->sha.in = in;
+ sha512ctxp->sha.indata_len = size;
- shaparams_t params = {CRY_SHA_512};
+ return sama_sha_lld_update(cryp, &sha512ctxp->sha);
+}
- ret = sama_sha_lld_process(cryp,
- &params,
- in,
- out,
- size
- );
+/**
+ * @brief Hash finalization using SHA512.
+ *
+ * @param[in] cryp pointer to the @p CRYDriver object
+ * @param[in] sha512ctxp pointer to a SHA512 context
+ * @param[out] out 512 bits output buffer
+ * @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.
+ *
+ * @notapi
+ */
+cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp,
+ uint8_t *out) {
- return ret;
+ sha512ctxp->sha.out = out;
+ return sama_sha_lld_final(cryp, &sha512ctxp->sha);
}
/**