Some changes to the crypto infrastructure.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12252 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
parent
2dbd855684
commit
ab8cbd8f7c
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -92,7 +92,9 @@
|
|||
|
||||
*** Next ***
|
||||
- NEW: TRNG API now takes a new "size" parameter, the API can now generate
|
||||
random numbers of variable size.
|
||||
random numbers of variable size. The crypto driver now does not store
|
||||
a copy of the transient key inside, the low level can do that if
|
||||
required.
|
||||
- NEW: Added analog watchdog functionality to STM32 ADCv2 driver.
|
||||
- NEW: Added a termination check to the shell.
|
||||
- NEW: Updated CMSIS to version 5.4.0.
|
||||
|
|
Loading…
Reference in New Issue