aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-09-08 12:54:58 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-09-08 12:54:58 +0000
commitab8cbd8f7c824a3311c1878157e8b6d7721e470d (patch)
treed82a10430b547335fda2e94799e08207d247c170 /os/hal
parent2dbd855684b925c7a57982d883abcc9e0ecec10c (diff)
downloadChibiOS-ab8cbd8f7c824a3311c1878157e8b6d7721e470d.tar.gz
ChibiOS-ab8cbd8f7c824a3311c1878157e8b6d7721e470d.tar.bz2
ChibiOS-ab8cbd8f7c824a3311c1878157e8b6d7721e470d.zip
Some changes to the crypto infrastructure.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12252 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'os/hal')
-rw-r--r--os/hal/include/hal_crypto.h10
-rw-r--r--os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c59
-rw-r--r--os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h14
-rw-r--r--os/hal/src/hal_crypto.c9
-rw-r--r--os/hal/templates/hal_crypto_lld.h14
5 files changed, 59 insertions, 47 deletions
diff --git a/os/hal/include/hal_crypto.h b/os/hal/include/hal_crypto.h
index 78f164692..4df1a45c3 100644
--- a/os/hal/include/hal_crypto.h
+++ b/os/hal/include/hal_crypto.h
@@ -31,13 +31,6 @@
/* Driver constants. */
/*===========================================================================*/
-/**
- * @brief Maximum size of a key for all supported algorithms.
- * @note It could be redefined by the LLD or the crypto fallback
- * implementations.
- */
-#define HAL_CRY_MAX_KEY_SIZE 32
-
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
@@ -165,9 +158,6 @@ typedef struct {
struct CRYDriver {
crystate_t state;
const CRYConfig *config;
- cryalgorithm_t key0_type;
- size_t key0_size;
- uint8_t key0_buffer[HAL_CRY_MAX_KEY_SIZE];
};
#endif /* HAL_CRY_ENFORCE_FALLBACK == TRUE */
diff --git a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c
index c9ca9858b..5c02434e3 100644
--- a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c
+++ b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c
@@ -62,6 +62,18 @@ CRYDriver CRYD1;
*/
void cry_lld_init(void) {
+#if STM32_CRY_ENABLED1
+ cryObjectInit(&CRYD1);
+#if STM32_CRY_USE_CRYP1
+ CRYD1.cryp = CRYP;
+#endif
+#if STM32_CRY_USE_HASH1
+ CRYD1.hash = HASH;
+#endif
+#if STM32_CRY_USE_RNG1
+ CRYD1.rng = RNG;
+#endif
+#endif
}
/**
@@ -74,8 +86,30 @@ void cry_lld_init(void) {
void cry_lld_start(CRYDriver *cryp) {
if (cryp->state == CRY_STOP) {
-
+#if STM32_CRY_ENABLED1
+ if (&CRYD1 == cryp) {
+#if STM32_CRY_USE_CRYP1
+ rccEnableCRYP(true);
+#endif
+#if STM32_CRY_USE_HASH1
+ rccEnableHASH(true);
+#endif
+#if STM32_CRY_USE_RNG1
+ rccEnableRNG(true);
+#endif
+ }
+#endif
}
+
+#if STM32_CRY_USE_CRYP1
+ /* CRYP setup and enable.*/
+#endif
+#if STM32_CRY_USE_HASH1
+ /* HASH setup and enable.*/
+#endif
+#if STM32_CRY_USE_RNG1
+ /* RNG setup and enable.*/
+#endif
}
/**
@@ -89,6 +123,29 @@ void cry_lld_stop(CRYDriver *cryp) {
if (cryp->state == CRY_READY) {
+#if STM32_CRY_USE_CRYP1
+ /* CRYP disable.*/
+#endif
+#if STM32_CRY_USE_HASH1
+ /* HASH disable.*/
+#endif
+#if STM32_CRY_USE_RNG1
+ /* RNG disable.*/
+#endif
+
+#if STM32_CRY_ENABLED1
+ if (&CRYD1 == cryp) {
+#if STM32_CRY_USE_CRYP1
+ rccDisableCRYP();
+#endif
+#if STM32_CRY_USE_HASH1
+ rccDisableHASH();
+#endif
+#if STM32_CRY_USE_RNG1
+ rccDisableRNG();
+#endif
+ }
+#endif
}
}
diff --git a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h
index b66be5e29..60c50e03c 100644
--- a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h
+++ b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h
@@ -185,20 +185,6 @@ struct CRYDriver {
* @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
diff --git a/os/hal/src/hal_crypto.c b/os/hal/src/hal_crypto.c
index 7d9461d38..a58cc7bec 100644
--- a/os/hal/src/hal_crypto.c
+++ b/os/hal/src/hal_crypto.c
@@ -149,8 +149,7 @@ cryerror_t cryLoadTransientKey(CRYDriver *cryp,
const uint8_t *keyp) {
cryerror_t err;
- osalDbgCheck((cryp != NULL) && (size <= HAL_CRY_MAX_KEY_SIZE) &&
- (keyp != NULL));
+ osalDbgCheck((cryp != NULL) && (keyp != NULL));
#if HAL_CRY_ENFORCE_FALLBACK == FALSE
@@ -166,12 +165,6 @@ cryerror_t cryLoadTransientKey(CRYDriver *cryp,
}
#endif
- if (err == CRY_NOERROR) {
- /* Storing the transient key info.*/
- cryp->key0_type = algorithm;
- cryp->key0_size = size;
- }
-
return err;
}
diff --git a/os/hal/templates/hal_crypto_lld.h b/os/hal/templates/hal_crypto_lld.h
index 23f592ec3..d3b1f5755 100644
--- a/os/hal/templates/hal_crypto_lld.h
+++ b/os/hal/templates/hal_crypto_lld.h
@@ -108,20 +108,6 @@ struct CRYDriver {
* @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