aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/SAMA/LLD/CRYPTOv1/sama_tdes_lld.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/ports/SAMA/LLD/CRYPTOv1/sama_tdes_lld.c')
-rw-r--r--os/hal/ports/SAMA/LLD/CRYPTOv1/sama_tdes_lld.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/os/hal/ports/SAMA/LLD/CRYPTOv1/sama_tdes_lld.c b/os/hal/ports/SAMA/LLD/CRYPTOv1/sama_tdes_lld.c
index a2dcd5cd3..76ff34145 100644
--- a/os/hal/ports/SAMA/LLD/CRYPTOv1/sama_tdes_lld.c
+++ b/os/hal/ports/SAMA/LLD/CRYPTOv1/sama_tdes_lld.c
@@ -44,6 +44,9 @@ cryerror_t sama_tdes_lld_polling(CRYDriver *cryp, tdes_config_t *params,
uint32_t i;
uint8_t size = 8;
uint32_t *vectors = (uint32_t *) iv;
+
+ osalMutexLock(&cryp->mutex);
+
//soft reset
TDES->TDES_CR = TDES_CR_SWRST;
//configure
@@ -78,7 +81,7 @@ cryerror_t sama_tdes_lld_polling(CRYDriver *cryp, tdes_config_t *params,
}
TDES->TDES_MR = mode;
- osalMutexLock(&cryp->mutex);
+
//write keys
TDES->TDES_KEY1WR[0] = cryp->key0_buffer[0];
@@ -106,7 +109,7 @@ cryerror_t sama_tdes_lld_polling(CRYDriver *cryp, tdes_config_t *params,
if (params->algo == TDES_ALGO_XTEA) {
TDES->TDES_XTEA_RNDR = TDES_XTEA_RNDR_XTEA_RNDS(32);
}
- osalMutexUnlock(&cryp->mutex);
+
//load 64 bit data size in tdes registers
for (i = 0; i < data_len; i += size) {
if (size == 8)
@@ -129,6 +132,9 @@ cryerror_t sama_tdes_lld_polling(CRYDriver *cryp, tdes_config_t *params,
tdes_get_output((uint32_t *) ((out) + i), NULL);
}
+ osalMutexUnlock(&cryp->mutex);
+
+
return CRY_NOERROR;
}
@@ -139,6 +145,8 @@ cryerror_t sama_tdes_lld_dma(CRYDriver *cryp, tdes_config_t *params,
uint32_t mode = 0;
uint32_t *vectors = (uint32_t *) iv;
+ osalMutexLock(&cryp->mutex);
+
cryp->dmachunksize = DMA_CHUNK_SIZE_1;
cryp->dmawith = DMA_DATA_WIDTH_WORD;
@@ -214,7 +222,7 @@ cryerror_t sama_tdes_lld_dma(CRYDriver *cryp, tdes_config_t *params,
TDES->TDES_MR = mode;
- osalMutexLock(&cryp->mutex);
+
//write keys
TDES->TDES_KEY1WR[0] = cryp->key0_buffer[0];
@@ -240,7 +248,7 @@ cryerror_t sama_tdes_lld_dma(CRYDriver *cryp, tdes_config_t *params,
TDES->TDES_IVR[1] = vectors[1];
}
- osalMutexUnlock(&cryp->mutex);
+
if (params->algo == TDES_ALGO_XTEA) {
TDES->TDES_XTEA_RNDR = TDES_XTEA_RNDR_XTEA_RNDS(32);
@@ -257,6 +265,8 @@ cryerror_t sama_tdes_lld_dma(CRYDriver *cryp, tdes_config_t *params,
osalThreadSuspendS(&cryp->thread);
osalSysUnlock();
+ osalMutexUnlock(&cryp->mutex);
+
return CRY_NOERROR;
}