STM32 F2/F4 CubeMX and Std Peripheral Library hardware crypto support for RNG, AES, SHA1, DES3 and MD5. Adds new WOLFSSL_STM32_CUBEMX and WOLFSSL_STM32F4 defines. Tested on STM32F437II.

This commit is contained in:
David Garske
2016-10-17 19:17:58 -07:00
parent f3816a4dc5
commit 4a7651a09a
9 changed files with 549 additions and 199 deletions

View File

@ -201,15 +201,46 @@ void wc_AesAsyncFree(Aes* aes)
#endif
/* Define AES implementation includes and functions */
#if defined(STM32F2_CRYPTO)
/* STM32F2 hardware AES support for CBC, CTR modes through the STM32F2
* Standard Peripheral Library. Documentation located in STM32F2xx
* Standard Peripheral Library document (See note in README). */
#include "stm32f2xx.h"
#include "stm32f2xx_cryp.h"
#if defined(STM32F2_CRYPTO) || defined(STM32F4_CRYPTO)
/* STM32F2/F4 hardware AES support for CBC, CTR modes */
#if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT) ||\
defined(HAVE_AESGCM)
static int wc_AesEncrypt(Aes* aes, const byte* inBlock, byte* outBlock)
{
int ret = 0;
#ifdef WOLFSSL_STM32_CUBEMX
CRYP_HandleTypeDef hcryp;
/* load key into correct registers */
switch(aes->rounds) {
case 10: /* 128-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_128B;
break;
case 12: /* 192-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_192B;
break;
case 14: /* 256-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_256B;
break;
default:
break;
}
XMEMSET(&hcryp, 0, sizeof(CRYP_HandleTypeDef));
hcryp.Instance = CRYP;
hcryp.Init.DataType = CRYP_DATATYPE_8B;
hcryp.Init.pKey = (uint8_t*)aes->key;
HAL_CRYP_Init(&hcryp);
if (HAL_CRYP_AESECB_Encrypt(&hcryp, (uint8_t*)inBlock, AES_BLOCK_SIZE,
outBlock, STM32_HAL_TIMEOUT) != HAL_OK) {
ret = WC_TIMEOUT_E;
}
HAL_CRYP_DeInit(&hcryp);
#else
word32 *enc_key;
CRYP_InitTypeDef AES_CRYP_InitStructure;
CRYP_KeyInitTypeDef AES_CRYP_KeyInitStructure;
@ -288,9 +319,54 @@ void wc_AesAsyncFree(Aes* aes)
/* disable crypto processor */
CRYP_Cmd(DISABLE);
return 0;
#endif /* WOLFSSL_STM32_CUBEMX */
return ret;
}
#endif /* AES_CBC or AES_DIRECT or AESGCM */
#ifdef HAVE_AES_DECRYPT
#if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
static int wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
{
int ret = 0;
#ifdef WOLFSSL_STM32_CUBEMX
CRYP_HandleTypeDef hcryp;
/* load key into correct registers */
switch(aes->rounds) {
case 10: /* 128-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_128B;
break;
case 12: /* 192-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_192B;
break;
case 14: /* 256-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_256B;
break;
default:
break;
}
XMEMSET(&hcryp, 0, sizeof(CRYP_HandleTypeDef));
hcryp.Instance = CRYP;
hcryp.Init.DataType = CRYP_DATATYPE_8B;
hcryp.Init.pKey = (uint8_t*)aes->key;
HAL_CRYP_Init(&hcryp);
if (HAL_CRYP_AESECB_Decrypt(&hcryp, (uint8_t*)inBlock, AES_BLOCK_SIZE,
outBlock, STM32_HAL_TIMEOUT) != HAL_OK) {
ret = WC_TIMEOUT_E;
}
HAL_CRYP_DeInit(&hcryp);
#else
#error AES Decrypt not implemented for STM32 StdPeri lib
#endif /* WOLFSSL_STM32_CUBEMX */
return ret;
}
#endif /* AES_CBC or AES_DIRECT */
#endif /* HAVE_AES_DECRYPT */
#elif defined(HAVE_COLDFIRE_SEC)
/* Freescale Coldfire SEC support for CBC mode.
@ -1525,9 +1601,10 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
/* wc_AesSetKey */
#ifdef STM32F2_CRYPTO
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
int dir)
#if defined(STM32F2_CRYPTO) || defined(STM32F4_CRYPTO)
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
const byte* iv, int dir)
{
word32 *rk = aes->key;
@ -1538,7 +1615,9 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
aes->rounds = keylen/4 + 6;
XMEMCPY(rk, userKey, keylen);
#ifndef WOLFSSL_STM32_CUBEMX
ByteReverseWords(rk, rk, keylen);
#endif
return wc_AesSetIV(aes, iv);
}
@ -1549,6 +1628,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
return wc_AesSetKey(aes, userKey, keylen, iv, dir);
}
#endif
#elif defined(HAVE_COLDFIRE_SEC)
#if defined (HAVE_THREADX)
#include "memory_pools.h"
@ -1905,7 +1985,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
}
#endif /* WOLFSSL_AES_DIRECT || WOLFSSL_AES_COUNTER */
#endif /* STM32F2_CRYPTO, wc_AesSetKey block */
#endif /* wc_AesSetKey block */
/* wc_AesSetIV is shared between software and hardware */
@ -1939,10 +2019,7 @@ int wc_InitAes_h(Aes* aes, void* h)
/* AES-DIRECT */
#if defined(WOLFSSL_AES_DIRECT)
#if defined(STM32F2_CRYPTO) && defined(HAVE_AES_DECRYPT)
#error "STM32F2 crypto doesn't yet support AES direct decrypt"
#elif defined(HAVE_COLDFIRE_SEC)
#if defined(HAVE_COLDFIRE_SEC)
#error "Coldfire SEC doesn't yet support AES direct"
#elif defined(WOLFSSL_PIC32MZ_CRYPT)
@ -1994,7 +2071,105 @@ int wc_InitAes_h(Aes* aes, void* h)
/* AES-CBC */
#ifdef HAVE_AES_CBC
#ifdef STM32F2_CRYPTO
#if defined(STM32F2_CRYPTO) || defined(STM32F4_CRYPTO)
#ifdef WOLFSSL_STM32_CUBEMX
int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
{
int ret = 0;
CRYP_HandleTypeDef hcryp;
/* load key into correct registers */
switch(aes->rounds) {
case 10: /* 128-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_128B;
break;
case 12: /* 192-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_192B;
break;
case 14: /* 256-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_256B;
break;
default:
break;
}
XMEMSET(&hcryp, 0, sizeof(CRYP_HandleTypeDef));
hcryp.Instance = CRYP;
hcryp.Init.DataType = CRYP_DATATYPE_8B;
hcryp.Init.pKey = (uint8_t*)aes->key;
hcryp.Init.pInitVect = (uint8_t*)aes->reg;
HAL_CRYP_Init(&hcryp);
while (sz > 0) {
if (HAL_CRYP_AESCBC_Encrypt(&hcryp, (uint8_t*)in, AES_BLOCK_SIZE,
out, STM32_HAL_TIMEOUT) != HAL_OK) {
ret = WC_TIMEOUT_E;
break;
}
/* store iv for next call */
XMEMCPY(aes->reg, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
sz -= AES_BLOCK_SIZE;
in += AES_BLOCK_SIZE;
out += AES_BLOCK_SIZE;
}
HAL_CRYP_DeInit(&hcryp);
return ret;
}
#ifdef HAVE_AES_DECRYPT
int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
{
int ret = 0;
CRYP_HandleTypeDef hcryp;
/* load key into correct registers */
switch(aes->rounds) {
case 10: /* 128-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_128B;
break;
case 12: /* 192-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_192B;
break;
case 14: /* 256-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_256B;
break;
default:
break;
}
XMEMSET(&hcryp, 0, sizeof(CRYP_HandleTypeDef));
hcryp.Instance = CRYP;
hcryp.Init.DataType = CRYP_DATATYPE_8B;
hcryp.Init.pKey = (uint8_t*)aes->key;
hcryp.Init.pInitVect = (uint8_t*)aes->reg;
HAL_CRYP_Init(&hcryp);
while (sz > 0) {
if (HAL_CRYP_AESCBC_Decrypt(&hcryp, (uint8_t*)in, AES_BLOCK_SIZE,
out, STM32_HAL_TIMEOUT) != HAL_OK) {
ret = WC_TIMEOUT_E;
}
/* store iv for next call */
XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE);
sz -= AES_BLOCK_SIZE;
in += AES_BLOCK_SIZE;
out += AES_BLOCK_SIZE;
}
HAL_CRYP_DeInit(&hcryp);
return ret;
}
#endif /* HAVE_AES_DECRYPT */
#else
int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
{
word32 *enc_key, *iv;
@ -2222,6 +2397,8 @@ int wc_InitAes_h(Aes* aes, void* h)
return 0;
}
#endif /* HAVE_AES_DECRYPT */
#endif /* WOLFSSL_STM32_CUBEMX */
#elif defined(HAVE_COLDFIRE_SEC)
static int wc_AesCbcCrypt(Aes* aes, byte* po, const byte* pi, word32 sz,
word32 descHeader)
@ -2663,13 +2840,47 @@ int wc_InitAes_h(Aes* aes, void* h)
}
#endif
#endif /* STM32F2_CRYPTO, AES-CBC block */
#endif /* AES-CBC block */
#endif /* HAVE_AES_CBC */
/* AES-CTR */
#ifdef WOLFSSL_AES_COUNTER
#ifdef STM32F2_CRYPTO
#if defined(STM32F2_CRYPTO) || defined(STM32F4_CRYPTO)
#ifdef WOLFSSL_STM32_CUBEMX
void wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
{
CRYP_HandleTypeDef hcryp;
/* load key into correct registers */
switch(aes->rounds) {
case 10: /* 128-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_128B;
break;
case 12: /* 192-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_192B;
break;
case 14: /* 256-bit key */
hcryp.Init.KeySize = CRYP_KEYSIZE_256B;
break;
default:
break;
}
XMEMSET(&hcryp, 0, sizeof(CRYP_HandleTypeDef));
hcryp.Instance = CRYP;
hcryp.Init.DataType = CRYP_DATATYPE_8B;
hcryp.Init.pKey = aes->key;
hcryp.Init.pInitVect = aes->reg;
HAL_CRYP_Init(&hcryp);
HAL_CRYP_AESCTR_Encrypt(&hcryp, in, AES_BLOCK_SIZE, out,
STM32_HAL_TIMEOUT);
HAL_CRYP_DeInit(&hcryp);
}
#else
void wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
{
word32 *enc_key, *iv;
@ -2772,6 +2983,7 @@ int wc_InitAes_h(Aes* aes, void* h)
/* disable crypto processor */
CRYP_Cmd(DISABLE);
}
#endif /* WOLFSSL_STM32_CUBEMX */
#elif defined(WOLFSSL_PIC32MZ_CRYPT)
void wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
@ -2911,7 +3123,7 @@ int wc_InitAes_h(Aes* aes, void* h)
}
}
#endif /* STM32F2_CRYPTO, AES-CTR block */
#endif /* AES-CTR block */
#endif /* WOLFSSL_AES_COUNTER */

View File

@ -126,14 +126,12 @@ void wc_Des3AsyncFree(Des3* des3)
#endif
#ifdef STM32F2_CRYPTO
#if defined(STM32F2_CRYPTO) || defined(STM32F4_CRYPTO)
/*
* STM32F2 hardware DES/3DES support through the STM32F2 standard
* peripheral library. Documentation located in STM32F2xx Standard
* Peripheral Library document (See note in README).
* STM32F2/F4 hardware DES/3DES support through the standard
* peripheral library. (See note in README).
*/
#include "stm32f2xx.h"
#include "stm32f2xx_cryp.h"
int wc_Des_SetKey(Des* des, const byte* key, const byte* iv, int dir)
{
@ -142,7 +140,9 @@ void wc_Des3AsyncFree(Des3* des3)
(void)dir;
XMEMCPY(dkey, key, 8);
#ifndef WOLFSSL_STM32_CUBEMX
ByteReverseWords(dkey, dkey, 8);
#endif
wc_Des_SetIV(des, iv);
@ -161,9 +161,11 @@ void wc_Des3AsyncFree(Des3* des3)
XMEMCPY(dkey2, key + 8, 8); /* set key 2 */
XMEMCPY(dkey3, key + 16, 8); /* set key 3 */
#ifndef WOLFSSL_STM32_CUBEMX
ByteReverseWords(dkey1, dkey1, 8);
ByteReverseWords(dkey2, dkey2, 8);
ByteReverseWords(dkey3, dkey3, 8);
#endif
return wc_Des3_SetIV(des, iv);
}
@ -171,6 +173,54 @@ void wc_Des3AsyncFree(Des3* des3)
static void DesCrypt(Des* des, byte* out, const byte* in, word32 sz,
int dir, int mode)
{
#ifdef WOLFSSL_STM32_CUBEMX
CRYP_HandleTypeDef hcryp;
XMEMSET(&hcryp, 0, sizeof(CRYP_HandleTypeDef));
hcryp.Instance = CRYP;
hcryp.Init.KeySize = CRYP_KEYSIZE_128B;
hcryp.Init.DataType = CRYP_DATATYPE_8B;
hcryp.Init.pKey = (uint8_t*)des->key;
hcryp.Init.pInitVect = (uint8_t*)des->reg;
HAL_CRYP_Init(&hcryp);
while (sz > 0)
{
/* if input and output same will overwrite input iv */
XMEMCPY(des->tmp, in + sz - DES_BLOCK_SIZE, DES_BLOCK_SIZE);
if (mode == DES_CBC) {
if (dir == DES_ENCRYPTION) {
HAL_CRYP_DESCBC_Encrypt(&hcryp, (uint8_t*)in,
DES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT);
}
else {
HAL_CRYP_DESCBC_Decrypt(&hcryp, (uint8_t*)in,
DES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT);
}
}
else {
if (dir == DES_ENCRYPTION) {
HAL_CRYP_DESECB_Encrypt(&hcryp, (uint8_t*)in,
DES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT);
}
else {
HAL_CRYP_DESECB_Decrypt(&hcryp, (uint8_t*)in,
DES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT);
}
}
/* store iv for next call */
XMEMCPY(des->reg, des->tmp, DES_BLOCK_SIZE);
sz -= DES_BLOCK_SIZE;
in += DES_BLOCK_SIZE;
out += DES_BLOCK_SIZE;
}
HAL_CRYP_DeInit(&hcryp);
#else
word32 *dkey, *iv;
CRYP_InitTypeDef DES_CRYP_InitStructure;
CRYP_KeyInitTypeDef DES_CRYP_KeyInitStructure;
@ -244,6 +294,7 @@ void wc_Des3AsyncFree(Des3* des3)
/* disable crypto processor */
CRYP_Cmd(DISABLE);
#endif /* WOLFSSL_STM32_CUBEMX */
}
int wc_Des_CbcEncrypt(Des* des, byte* out, const byte* in, word32 sz)
@ -267,6 +318,39 @@ void wc_Des3AsyncFree(Des3* des3)
static void Des3Crypt(Des3* des, byte* out, const byte* in, word32 sz,
int dir)
{
#ifdef WOLFSSL_STM32_CUBEMX
CRYP_HandleTypeDef hcryp;
XMEMSET(&hcryp, 0, sizeof(CRYP_HandleTypeDef));
hcryp.Instance = CRYP;
hcryp.Init.KeySize = CRYP_KEYSIZE_128B;
hcryp.Init.DataType = CRYP_DATATYPE_8B;
hcryp.Init.pKey = (uint8_t*)des->key;
hcryp.Init.pInitVect = (uint8_t*)des->reg;
HAL_CRYP_Init(&hcryp);
while (sz > 0)
{
if (dir == DES_ENCRYPTION) {
HAL_CRYP_TDESCBC_Encrypt(&hcryp, (byte*)in,
DES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT);
}
else {
HAL_CRYP_TDESCBC_Decrypt(&hcryp, (byte*)in,
DES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT);
}
/* store iv for next call */
XMEMCPY(des->reg, out + sz - DES_BLOCK_SIZE, DES_BLOCK_SIZE);
sz -= DES_BLOCK_SIZE;
in += DES_BLOCK_SIZE;
out += DES_BLOCK_SIZE;
}
HAL_CRYP_DeInit(&hcryp);
#else
word32 *dkey1, *dkey2, *dkey3, *iv;
CRYP_InitTypeDef DES3_CRYP_InitStructure;
CRYP_KeyInitTypeDef DES3_CRYP_KeyInitStructure;
@ -338,7 +422,7 @@ void wc_Des3AsyncFree(Des3* des3)
/* disable crypto processor */
CRYP_Cmd(DISABLE);
#endif /* WOLFSSL_STM32_CUBEMX */
}
int wc_Des3_CbcEncrypt(Des3* des, byte* out, const byte* in, word32 sz)
@ -979,7 +1063,6 @@ int wc_Des3_SetIV(Des3* des, const byte* iv);
ByteReverseWords((word32*)iv, (word32 *)&(in_p[sz-DES_IVLEN]),
DES_IVLEN);
}
}
ByteReverseWords((word32*)out, (word32 *)KVA0_TO_KVA1(out), sz);
@ -1013,7 +1096,7 @@ int wc_Des3_SetIV(Des3* des, const byte* iv);
return 0;
}
#else /* CTaoCrypt software implementation */
#else /* Begin wolfCrypt software implementation */
/* permuted choice table (key) */
static const byte pc1[] = {
@ -1542,7 +1625,8 @@ int wc_Des_EcbEncrypt(Des* des, byte* out, const byte* in, word32 sz)
#endif /* WOLFSSL_DES_ECB */
#endif /* STM32F2_CRYPTO */
#endif /* End wolfCrypt software implementation */
void wc_Des_SetIV(Des* des, const byte* iv)
{

View File

@ -57,18 +57,15 @@
#endif
#ifdef STM32F2_HASH
#if defined(STM32F2_HASH) || defined(STM32F4_HASH)
/*
* STM32F2 hardware MD5 support through the STM32F2 standard peripheral
* library. Documentation located in STM32F2xx Standard Peripheral Library
* document (See note in README).
* STM32F2/F4 hardware MD5 support through the standard peripheral
* library. (See note in README).
*/
#include "stm32f2xx.h"
#include "stm32f2xx_hash.h"
void wc_InitMd5(Md5* md5)
{
/* STM32F2 struct notes:
/* STM32 struct notes:
* md5->buffer = first 4 bytes used to hold partial block if needed
* md5->buffLen = num bytes currently stored in md5->buffer
* md5->loLen = num bytes that have been written to STM32 FIFO
@ -171,7 +168,7 @@
wc_InitMd5(md5); /* reset state */
}
#else /* CTaoCrypt software implementation */
#else /* Begin wolfCrypt software implementation */
#ifndef WOLFSSL_HAVE_MIN
#define WOLFSSL_HAVE_MIN
@ -300,7 +297,7 @@ static void Transform(Md5* md5)
md5->digest[3] += d;
}
#endif /* FREESCALE_MMCAU */
#endif /* End Software implementation */
static INLINE void AddLength(Md5* md5, word32 len)
@ -379,7 +376,7 @@ void wc_Md5Final(Md5* md5, byte* hash)
wc_InitMd5(md5); /* reset state */
}
#endif /* STM32F2_HASH */
#endif /* End wolfCrypt software implementation */
int wc_Md5Hash(const byte* data, word32 len, byte* hash)

View File

@ -1436,18 +1436,37 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
return 0;
}
#elif defined(STM32F2_RNG)
#undef RNG
#include "stm32f2xx_rng.h"
#include "stm32f2xx_rcc.h"
#elif defined(STM32F2_RNG) || defined(STM32F4_RNG)
/*
* wc_Generate a RNG seed using the hardware random number generator
* on the STM32F2. Documentation located in STM32F2xx Standard Peripheral
* Library document (See note in README).
*/
* on the STM32F2/F4. */
#ifdef WOLFSSL_STM32_CUBEMX
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
RNG_HandleTypeDef hrng;
int i;
(void)os;
/* enable RNG clock source */
__HAL_RCC_RNG_CLK_ENABLE();
/* enable RNG peripheral */
hrng.Instance = RNG;
HAL_RNG_Init(&hrng);
for (i = 0; i < (int)sz; i++) {
/* get value */
output[i] = (byte)HAL_RNG_GetRandomNumber(&hrng);
}
return 0;
}
#else
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
int i;
(void)os;
/* enable RNG clock source */
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
@ -1455,7 +1474,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
/* enable RNG peripheral */
RNG_Cmd(ENABLE);
for (i = 0; i < sz; i++) {
for (i = 0; i < (int)sz; i++) {
/* wait until RNG number is ready */
while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET) { }
@ -1465,6 +1484,8 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
return 0;
}
#endif /* WOLFSSL_STM32_CUBEMX */
#elif defined(WOLFSSL_LPC43xx) || defined(WOLFSSL_STM32F2xx) || defined(MBED) \
|| defined(WOLFSSL_EMBOS)

View File

@ -73,18 +73,16 @@
#define wc_ShaUpdate wc_ShaUpdate_sw
#define wc_ShaFinal wc_ShaFinal_sw
#elif defined(STM32F2_HASH)
#elif defined(STM32F2_HASH) || defined(STM32F4_HASH)
/*
* STM32F2 hardware SHA1 support through the STM32F2 standard peripheral
* library. Documentation located in STM32F2xx Standard Peripheral Library
* document (See note in README).
* STM32F2/F4 hardware SHA1 support through the standard peripheral
* library. (See note in README).
*/
#include "stm32f2xx.h"
#include "stm32f2xx_hash.h"
int wc_InitSha(Sha* sha)
{
/* STM32F2 struct notes:
/* STM32 struct notes:
* sha->buffer = first 4 bytes used to hold partial block if needed
* sha->buffLen = num bytes currently stored in sha->buffer
* sha->loLen = num bytes that have been written to STM32 FIFO

View File

@ -58,7 +58,7 @@ enum {
#define DES3_KEYLEN 24
#ifdef STM32F2_CRYPTO
#if defined(STM32F2_CRYPTO) || defined(STM32F4_CRYPTO)
enum {
DES_CBC = 0,
DES_ECB = 1

View File

@ -40,7 +40,7 @@
/* in bytes */
enum {
#ifdef STM32F2_HASH
#if defined(STM32F2_HASH) || defined(STM32F4_HASH)
MD5_REG_SIZE = 4, /* STM32 register size, bytes */
#endif
MD5 = 0, /* hash type unique */

View File

@ -922,11 +922,49 @@ static char *fgets(char *buff, int sz, FILE *fp)
#define SIZEOF_LONG_LONG 8
#define NO_DEV_RANDOM
#define NO_WOLFSSL_DIR
#undef NO_RABBIT
#define NO_RABBIT
#define STM32F2_RNG
#define STM32F2_CRYPTO
#ifndef __GNUC__
#define KEIL_INTRINSICS
#endif
#define NO_OLD_RNGNAME
#ifdef WOLFSSL_STM32_CUBEMX
#include "stm32f2xx_hal.h"
#ifndef STM32_HAL_TIMEOUT
#define STM32_HAL_TIMEOUT 0xFF
#endif
#else
#include "stm32f2xx.h"
#include "stm32f2xx_cryp.h"
#include "stm32f2xx_hash.h"
#endif /* WOLFSSL_STM32_CUBEMX */
#endif
#ifdef WOLFSSL_STM32F4
#define SIZEOF_LONG_LONG 8
#define NO_DEV_RANDOM
#define NO_WOLFSSL_DIR
#undef NO_RABBIT
#define NO_RABBIT
#define STM32F4_RNG
#define STM32F4_CRYPTO
#define NO_OLD_RNGNAME
#ifndef __GNUC__
#define KEIL_INTRINSICS
#endif
#ifdef WOLFSSL_STM32_CUBEMX
#include "stm32f4xx_hal.h"
#ifndef STM32_HAL_TIMEOUT
#define STM32_HAL_TIMEOUT 0xFF
#endif
#else
#include "stm32f4xx.h"
#include "stm32f4xx_cryp.h"
#include "stm32f4xx_hash.h"
#endif /* WOLFSSL_STM32_CUBEMX */
#endif
#ifdef MICRIUM

View File

@ -43,7 +43,7 @@
#ifndef HAVE_FIPS /* avoid redefining structs */
/* in bytes */
enum {
#ifdef STM32F2_HASH
#if defined(STM32F2_HASH) || defined(STM32F4_HASH)
SHA_REG_SIZE = 4, /* STM32 register size, bytes */
#endif
SHA = 1, /* hash type unique */