diff --git a/include/libopencm3/stm32/common/crypto_common_f24.h b/include/libopencm3/stm32/common/crypto_common_f24.h index 538c012e..0c84bf7a 100644 --- a/include/libopencm3/stm32/common/crypto_common_f24.h +++ b/include/libopencm3/stm32/common/crypto_common_f24.h @@ -1,8 +1,8 @@ -/** @addtogroup crypto_defines +/** @addtogroup crypto_defines + * + * @warning The CRYP subsystem is present only in a limited set of devices, + * see next section for list of supported devices. * - * @warning The CRYP subsystem is present only in a limited set of devices, - * see next section for list of supported devices. - * * @section crypto_api_supported Supported devices * * - STM32F205 @@ -15,16 +15,16 @@ * - STM32F417 (tested) * - STM32F427 * - STM32F437 - * - * @section crypto_api_theory Theory of operation * - * - * - * @section crypto_api_basic Basic handling API - * + * @section crypto_api_theory Theory of operation + * + * + * + * @section crypto_api_basic Basic handling API + * * * @b Example @b 1: Blocking mode - * + * * @code * //[enable-clocks] * crypto_set_key(CRYPTO_KEY_128BIT,key); @@ -33,33 +33,16 @@ * crypto_set_algorithm(ENCRYPT_AES_ECB); * crypto_start(); * foreach(block in blocks) - * crypto_process_block(plaintext,ciphertext,blocksize); + * crypto_process_block(plaintext,ciphertext,blocksize); * crypto_stop(); * @endcode * - * @section crypto_api_interrupt Interrupt supported handling API + * @section crypto_api_interrupt Interrupt supported handling API * * @warning This operation mode is currently not supported. - * + * * @b Example @b 2: Interrupt mode - * - * @code - * //[enable-clocks] - * crypto_set_key(CRYPTO_KEY_128BIT,key); - * crypto_set_iv(iv); // only in CBC or CTR mode - * crypto_set_datatype(CRYPTO_DATA_16BIT); - * crypto_set_algorithm(ENCRYPT_AES_ECB); - * crypto_start(); - * [... API to be described later ...] - * crypto_stop(); - * @endcode * - * @section crypto_api_dma DMA handling API - * - * @warning This operation mode is currently not supported. - * - * @b Example @b 3: DMA mode - * * @code * //[enable-clocks] * crypto_set_key(CRYPTO_KEY_128BIT,key); @@ -67,7 +50,24 @@ * crypto_set_datatype(CRYPTO_DATA_16BIT); * crypto_set_algorithm(ENCRYPT_AES_ECB); * crypto_start(); - * [... API to be described later ...] + * [... API to be described later ...] + * crypto_stop(); + * @endcode + * + * @section crypto_api_dma DMA handling API + * + * @warning This operation mode is currently not supported. + * + * @b Example @b 3: DMA mode + * + * @code + * //[enable-clocks] + * crypto_set_key(CRYPTO_KEY_128BIT,key); + * crypto_set_iv(iv); // only in CBC or CTR mode + * crypto_set_datatype(CRYPTO_DATA_16BIT); + * crypto_set_algorithm(ENCRYPT_AES_ECB); + * crypto_start(); + * [... API to be described later ...] * crypto_stop(); * @endcode */ @@ -107,7 +107,7 @@ specific memorymap.h header before including this header file.*/ /* --- CRYP registers ------------------------------------------------------ */ /** @defgroup crypto_registers_gen Registers (Generic) * - * @brief Register access to the CRYP controller. (All chips) + * @brief Register access to the CRYP controller. (All chips) * * @ingroup crypto_defines */ @@ -237,7 +237,7 @@ specific memorymap.h header before including this header file.*/ /** @defgroup crypto_api_gen API (Generic) * * @brief API for the CRYP controller - * + * * @ingroup crypto_defines */ /**@{*/ @@ -256,7 +256,7 @@ typedef enum { DECRYPT_DES_CBC = CRYP_CR_ALGOMODE_DES_CBC | CRYP_CR_ALGODIR, DECRYPT_AES_ECB = CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR, DECRYPT_AES_CBC = CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR, - DECRYPT_AES_CTR = CRYP_CR_ALGOMODE_AES_CTR, /* XOR is same ENC as DEC */ + DECRYPT_AES_CTR = CRYP_CR_ALGOMODE_AES_CTR,/* XOR is same ENC as DEC */ } crypto_mode_t; typedef enum { CRYPTO_KEY_128BIT = 0, @@ -271,7 +271,7 @@ typedef enum { CRYPTO_DATA_BIT, } crypto_datatype_t; -BEGIN_DECLS +BEGIN_DECLS void crypto_wait_busy(void); void crypto_set_key(crypto_keysize_t keysize, uint64_t key[]); void crypto_set_iv(uint64_t iv[]); @@ -279,13 +279,14 @@ void crypto_set_datatype(crypto_datatype_t datatype); void crypto_set_algorithm(crypto_mode_t mode); void crypto_start(void); void crypto_stop(void); -uint32_t crypto_process_block(uint32_t * inp, uint32_t * outp, uint32_t length); +uint32_t crypto_process_block(uint32_t *inp, uint32_t *outp, uint32_t length); END_DECLS /**@}*/ /**@}*/ #endif /** @cond */ #else -#warning "crypto_common_f24.h should not be included explicitly, only via crypto.h" +#warning "crypto_common_f24.h should not be included explicitly, " + "only via crypto.h" #endif /** @endcond */ diff --git a/include/libopencm3/stm32/f2/crypto.h b/include/libopencm3/stm32/f2/crypto.h index 0850ad28..f549310d 100644 --- a/include/libopencm3/stm32/f2/crypto.h +++ b/include/libopencm3/stm32/f2/crypto.h @@ -1,7 +1,7 @@ /** @defgroup crypto_defines CRYPTO Defines * * @brief Defined Constants and Types for the STM32F2xx CRYP Controller - * + * * @ingroup STM32F2xx_defines * * @version 1.0.0 diff --git a/include/libopencm3/stm32/f4/crypto.h b/include/libopencm3/stm32/f4/crypto.h index 985a05b3..15554d14 100644 --- a/include/libopencm3/stm32/f4/crypto.h +++ b/include/libopencm3/stm32/f4/crypto.h @@ -1,14 +1,14 @@ /** @defgroup crypto_defines CRYPTO Defines * * @brief Defined constants and Types for the STM32F4xx Crypto Coprocessor - * + * * @ingroup STM32F4xx_defines - * + * * @version 1.0.0 - * + * * @date 22 Jun 2013 * - * LGPL License Terms @ref lgpl_license + * LGPL License Terms @ref lgpl_license */ /* @@ -46,10 +46,10 @@ /**@{*/ /* CRYP_CSGCMCCMxR: Crypto context registers CCM mode, i=0-7*/ -#define CRYP_CSGCMCCMR(i) MMIO32(CRYP_BASE + 0x50 + (i) * 4) +#define CRYP_CSGCMCCMR(i) MMIO32(CRYP_BASE + 0x50 + (i) * 4) /* CRYP_CSGCMxR: Crypto context registers all modes, i=0-7*/ -#define CRYP_CSGCMR(i) MMIO32(CRYP_BASE + 0x70 + (i) * 4) +#define CRYP_CSGCMR(i) MMIO32(CRYP_BASE + 0x70 + (i) * 4) /* --- CRYP_CR values ------------------------------------------------------ */ @@ -70,9 +70,9 @@ /** @defgroup crypto_api API (for F42xx or F43xx only) * - * @brief API for the CRYP controller. - * - * @warning Only for F42xx and 43xx + * @brief API for the CRYP controller. + * + * @warning Only for F42xx and 43xx * * @ingroup crypto_defines */ @@ -82,14 +82,14 @@ typedef enum { ENCRYPT_GCM = CRYP_CR_ALGOMODE_TDES_ECB | CRYP_CR_ALGOMODE3, ENCRYPT_CCM = CRYP_CR_ALGOMODE_TDES_CBC | CRYP_CR_ALGOMODE3, DECRYPT_GCM = CRYP_CR_ALGOMODE_TDES_ECB | CRYP_CR_ALGOMODE3 | - CRYP_CR_ALGODIR, + CRYP_CR_ALGODIR, DECRYPT_CCM = CRYP_CR_ALGOMODE_TDES_CBC | CRYP_CR_ALGOMODE3 | - CRYP_CR_ALGODIR, + CRYP_CR_ALGODIR, } crypto_mode_mac_t; -BEGIN_DECLS +BEGIN_DECLS -void crypto_context_swap(uint32_t * buf); +void crypto_context_swap(uint32_t *buf); void crypto_set_mac_algorithm(crypto_mode_mac_t mode); END_DECLS diff --git a/lib/stm32/common/crypto_common_f24.c b/lib/stm32/common/crypto_common_f24.c index 01ec3c40..bfae72a6 100644 --- a/lib/stm32/common/crypto_common_f24.c +++ b/lib/stm32/common/crypto_common_f24.c @@ -9,7 +9,7 @@ * This library supports the cryptographic coprocessor system for the * STM32 series of ARM Cortex Microcontrollers * - * LGPL License Terms @ref lgpl_license + * LGPL License Terms @ref lgpl_license */ /* * This file is part of the libopencm3 project. @@ -41,13 +41,13 @@ */ void crypto_wait_busy(void) { - while (CRYP_SR & CRYP_SR_BUSY) ; + while (CRYP_SR & CRYP_SR_BUSY); } /** * @brief Set key value to the controller * @param[in] keysize crypto_keysize_t Specified size of the key. - * @param[in] key uint64_t[] Key value (array of 4 items) + * @param[in] key uint64_t[] Key value (array of 4 items) */ void crypto_set_key(crypto_keysize_t keysize, uint64_t key[]) { @@ -56,7 +56,7 @@ void crypto_set_key(crypto_keysize_t keysize, uint64_t key[]) crypto_wait_busy(); CRYP_CR = (CRYP_CR & ~CRYP_CR_KEYSIZE) | - (keysize << CRYP_CR_KEYSIZE_SHIFT); + (keysize << CRYP_CR_KEYSIZE_SHIFT); for (i = 0; i < 4; i++) { CRYP_KR(i) = key[i]; @@ -66,9 +66,9 @@ void crypto_set_key(crypto_keysize_t keysize, uint64_t key[]) /** * @brief Set Initialization Vector * - * @param[in] iv uint64_t[] Initialization vector (array of 4 items) - - * @note Cryptographic controller must be in disabled state + * @param[in] iv uint64_t[] Initialization vector (array of 4 items) + + * @note Cryptographic controller must be in disabled state */ void crypto_set_iv(uint64_t iv[]) { @@ -83,18 +83,18 @@ void crypto_set_iv(uint64_t iv[]) /** * @brief Set the order of the data to be crypted - * - * @param[in] datatype crypto_datatype_t Specified datatype of the key. + * + * @param[in] datatype crypto_datatype_t Specified datatype of the key. */ void crypto_set_datatype(crypto_datatype_t datatype) { CRYP_CR = (CRYP_CR & ~CRYP_CR_DATATYPE) | - (datatype << CRYP_CR_DATATYPE_SHIFT); + (datatype << CRYP_CR_DATATYPE_SHIFT); } /** * @brief Set the algoritm for Encryption/decryption - * + * *@param[in] mode crypto_mode_t Mode of execution */ void crypto_set_algorithm(crypto_mode_t mode) @@ -137,19 +137,19 @@ void crypto_stop(void) /** * @brief Start of encryption or decryption on data buffers - * - * This blocking method transfers input buffer of specified length to the - * cryptographic coprocessor, and instructs him to begin of ciphering or + * + * This blocking method transfers input buffer of specified length to the + * cryptographic coprocessor, and instructs him to begin of ciphering or * deciphering. It waits for data to be ready, and then fills the processed - * data to output buffer. - * + * data to output buffer. + * * @param[in] inp uint32_t* Input array to crypt/decrypt. * @param[in] outp uint32_t* Output array with crypted/encrypted data. * @param[in] length uint32_t Length of the arrays - * - * @returns uint32_t Number of written words + * + * @returns uint32_t Number of written words */ -uint32_t crypto_process_block(uint32_t * inp, uint32_t * outp, uint32_t length) +uint32_t crypto_process_block(uint32_t *inp, uint32_t *outp, uint32_t length) { uint32_t rd = 0, wr = 0; diff --git a/lib/stm32/f4/crypto.c b/lib/stm32/f4/crypto.c index 050500ab..6410e8fb 100644 --- a/lib/stm32/f4/crypto.c +++ b/lib/stm32/f4/crypto.c @@ -1,11 +1,11 @@ /** @defgroup crypto_file CRYPTO * * @ingroup STM32F4xx - * + * * @brief libopencm3 STM32F4xx CRYPTO - * + * * @version 1.0.0 - * + * * @date 18 Jun 2013 * */ @@ -43,10 +43,10 @@ void crypto_set_mac_algorithm(crypto_mode_mac_t mode) /** * @brief Swap context - * - *@param[in] buf uint32_t Memory space for swap (16 items length) + * + *@param[in] buf uint32_t Memory space for swap (16 items length) */ -void crypto_context_swap(uint32_t * buf) +void crypto_context_swap(uint32_t *buf) { int i; /* Apply exact order of ? */