Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
411 changes: 311 additions & 100 deletions wolfcrypt/src/aes.c

Large diffs are not rendered by default.

251 changes: 169 additions & 82 deletions wolfcrypt/src/des3.c

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions wolfcrypt/src/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,21 @@
#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:
* md5->buffer = first 4 bytes used to hold partial block if needed
/* 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
*/
XMEMSET(md5->buffer, 0, MD5_REG_SIZE);

md5->buffLen = 0;
md5->loLen = 0;

Expand All @@ -83,7 +80,7 @@

/* configure algo used, algo mode, datatype */
HASH->CR &= ~ (HASH_CR_ALGO | HASH_CR_DATATYPE | HASH_CR_MODE);
HASH->CR |= (HASH_AlgoSelection_MD5 | HASH_AlgoMode_HASH
HASH->CR |= (HASH_AlgoSelection_MD5 | HASH_AlgoMode_HASH
| HASH_DataType_8b);

/* reset HASH processor */
Expand Down Expand Up @@ -157,7 +154,7 @@

/* wait until Busy flag == RESET */
while (HASH_GetFlagStatus(HASH_FLAG_BUSY) != RESET) {}

/* read message digest */
md5->digest[0] = HASH->HR[0];
md5->digest[1] = HASH->HR[1];
Expand All @@ -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
Expand Down Expand Up @@ -292,15 +289,15 @@ static void Transform(Md5* md5)
MD5STEP(F4, d, a, b, c, md5->buffer[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, md5->buffer[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, md5->buffer[9] + 0xeb86d391, 21);

/* Add the working vars back into digest state[] */
md5->digest[0] += a;
md5->digest[1] += b;
md5->digest[2] += c;
md5->digest[3] += d;
}

#endif /* FREESCALE_MMCAU */
#endif /* End Software implementation */


static INLINE void AddLength(Md5* md5, word32 len)
Expand Down Expand Up @@ -356,9 +353,9 @@ void wc_Md5Final(Md5* md5, byte* hash)
md5->buffLen = 0;
}
XMEMSET(&local[md5->buffLen], 0, MD5_PAD_SIZE - md5->buffLen);

/* put lengths in bits */
md5->hiLen = (md5->loLen >> (8*sizeof(md5->loLen) - 3)) +
md5->hiLen = (md5->loLen >> (8*sizeof(md5->loLen) - 3)) +
(md5->hiLen << 3);
md5->loLen = md5->loLen << 3;

Expand All @@ -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)
Expand Down
37 changes: 29 additions & 8 deletions wolfcrypt/src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -1436,26 +1436,45 @@ 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);

/* 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) { }

Expand All @@ -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)

Expand Down
12 changes: 5 additions & 7 deletions wolfcrypt/src/sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/wolfcrypt/des3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/wolfcrypt/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
40 changes: 39 additions & 1 deletion wolfssl/wolfcrypt/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -922,10 +922,48 @@ 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
#define KEIL_INTRINSICS
#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
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/wolfcrypt/sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down