forked from wolfSSL/wolfssl
Merge pull request #1117 from dgarske/gcc_arm
Added simple GCC ARM Makefile example
This commit is contained in:
440
IDE/GCC-ARM/Header/user_settings.h
Executable file
440
IDE/GCC-ARM/Header/user_settings.h
Executable file
@ -0,0 +1,440 @@
|
|||||||
|
/* user_settings.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Custom wolfSSL user settings for GCC ARM */
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_USER_SETTINGS_H
|
||||||
|
#define WOLFSSL_USER_SETTINGS_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Platform */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
#undef WOLFSSL_GENERAL_ALIGNMENT
|
||||||
|
#define WOLFSSL_GENERAL_ALIGNMENT 4
|
||||||
|
|
||||||
|
#undef SINGLE_THREADED
|
||||||
|
#define SINGLE_THREADED
|
||||||
|
|
||||||
|
#undef WOLFSSL_SMALL_STACK
|
||||||
|
#define WOLFSSL_SMALL_STACK
|
||||||
|
|
||||||
|
#undef WOLFSSL_USER_IO
|
||||||
|
#define WOLFSSL_USER_IO
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Math Configuration */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
#undef USE_FAST_MATH
|
||||||
|
#define USE_FAST_MATH
|
||||||
|
|
||||||
|
#undef SIZEOF_LONG_LONG
|
||||||
|
#define SIZEOF_LONG_LONG 8
|
||||||
|
|
||||||
|
#ifdef USE_FAST_MATH
|
||||||
|
#undef TFM_TIMING_RESISTANT
|
||||||
|
#define TFM_TIMING_RESISTANT
|
||||||
|
|
||||||
|
/* Optimizations (on M0 UMULL is not supported, need another assembly solution) */
|
||||||
|
//#define TFM_ARM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Crypto */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* RSA */
|
||||||
|
#undef NO_RSA
|
||||||
|
#if 1
|
||||||
|
#ifdef USE_FAST_MATH
|
||||||
|
/* Maximum math bits (Max RSA key bits * 2) */
|
||||||
|
#undef FP_MAX_BITS
|
||||||
|
#define FP_MAX_BITS 4096
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* half as much memory but twice as slow */
|
||||||
|
#undef RSA_LOW_MEM
|
||||||
|
//#define RSA_LOW_MEM
|
||||||
|
|
||||||
|
/* Enables blinding mode, to prevent timing attacks */
|
||||||
|
#undef WC_RSA_BLINDING
|
||||||
|
#define WC_RSA_BLINDING
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define NO_RSA
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ECC */
|
||||||
|
#if 1
|
||||||
|
#undef HAVE_ECC
|
||||||
|
#define HAVE_ECC
|
||||||
|
|
||||||
|
/* Manually define enabled curves */
|
||||||
|
#undef ECC_USER_CURVES
|
||||||
|
#define ECC_USER_CURVES
|
||||||
|
|
||||||
|
//#define HAVE_ECC192
|
||||||
|
//#define HAVE_ECC224
|
||||||
|
#undef NO_ECC256
|
||||||
|
//#define HAVE_ECC384
|
||||||
|
//#define HAVE_ECC521
|
||||||
|
|
||||||
|
/* Fixed point cache (speeds repeated operations against same private key) */
|
||||||
|
#undef FP_ECC
|
||||||
|
//#define FP_ECC
|
||||||
|
#ifdef FP_ECC
|
||||||
|
/* Bits / Entries */
|
||||||
|
#undef FP_ENTRIES
|
||||||
|
#define FP_ENTRIES 2
|
||||||
|
#undef FP_LUT
|
||||||
|
#define FP_LUT 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Optional ECC calculation method */
|
||||||
|
/* Note: doubles heap usage, but slightly faster */
|
||||||
|
#undef ECC_SHAMIR
|
||||||
|
#define ECC_SHAMIR
|
||||||
|
|
||||||
|
/* Reduces heap usage, but slower */
|
||||||
|
#undef ECC_TIMING_RESISTANT
|
||||||
|
#define ECC_TIMING_RESISTANT
|
||||||
|
|
||||||
|
/* Use alternate ECC size for ECC math */
|
||||||
|
#ifdef USE_FAST_MATH
|
||||||
|
#ifdef NO_RSA
|
||||||
|
/* if not using RSA set FP_MAX_BITS to 256*2 */
|
||||||
|
#undef FP_MAX_BITS
|
||||||
|
#define FP_MAX_BITS 512
|
||||||
|
#else
|
||||||
|
#undef ALT_ECC_SIZE
|
||||||
|
#define ALT_ECC_SIZE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_ECC256
|
||||||
|
#undef TFM_ECC256
|
||||||
|
#define TFM_ECC256
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* AES */
|
||||||
|
#undef NO_AES
|
||||||
|
#if 1
|
||||||
|
#undef HAVE_AES_CBC
|
||||||
|
#define HAVE_AES_CBC
|
||||||
|
|
||||||
|
#undef HAVE_AESGCM
|
||||||
|
#define HAVE_AESGCM
|
||||||
|
|
||||||
|
#undef HAVE_AESCCM
|
||||||
|
#define HAVE_AESCCM
|
||||||
|
|
||||||
|
/* GCM Method: GCM_SMALL, GCM_WORD32 or GCM_TABLE */
|
||||||
|
#undef GCM_SMALL
|
||||||
|
#define GCM_SMALL
|
||||||
|
#else
|
||||||
|
#define NO_AES
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ChaCha20 / Poly1305 */
|
||||||
|
#undef HAVE_CHACHA
|
||||||
|
#undef HAVE_POLY1305
|
||||||
|
#if 0
|
||||||
|
#define HAVE_CHACHA
|
||||||
|
#define HAVE_POLY1305
|
||||||
|
|
||||||
|
/* Needed for Poly1305 */
|
||||||
|
#undef HAVE_ONE_TIME_AUTH
|
||||||
|
#define HAVE_ONE_TIME_AUTH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Ed25519 / Curve25519 */
|
||||||
|
#undef HAVE_CURVE25519
|
||||||
|
#undef HAVE_ED25519
|
||||||
|
#if 0
|
||||||
|
#define HAVE_CURVE25519
|
||||||
|
#define HAVE_ED25519 /* ED25519 Requires SHA512 */
|
||||||
|
|
||||||
|
/* Optionally use small math (less flash usage, but much slower) */
|
||||||
|
#if 1
|
||||||
|
#define CURVED25519_SMALL
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Hashing */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Sha */
|
||||||
|
#undef NO_SHA
|
||||||
|
#if 1
|
||||||
|
/* 1k smaller, but 25% slower */
|
||||||
|
//#define USE_SLOW_SHA
|
||||||
|
#else
|
||||||
|
#define NO_SHA
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Sha256 */
|
||||||
|
#undef NO_SHA256
|
||||||
|
#if 1
|
||||||
|
#else
|
||||||
|
#define NO_SHA256
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Sha512 */
|
||||||
|
#undef WOLFSSL_SHA512
|
||||||
|
#if 0
|
||||||
|
#define WOLFSSL_SHA512
|
||||||
|
|
||||||
|
/* Sha384 */
|
||||||
|
#undef WOLFSSL_SHA384
|
||||||
|
#if 0
|
||||||
|
#define WOLFSSL_SHA384
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* over twice as small, but 50% slower */
|
||||||
|
#define USE_SLOW_SHA2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* MD5 */
|
||||||
|
#undef NO_MD5
|
||||||
|
#if 1
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define NO_MD5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef WOLFSSL_SHA3
|
||||||
|
#if 0
|
||||||
|
#define WOLFSSL_SHA3
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* HKDF */
|
||||||
|
#undef HAVE_HKDF
|
||||||
|
#if 0
|
||||||
|
#define HAVE_HKDF
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Benchmark / Test */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Use reduced benchmark / test sizes */
|
||||||
|
#undef BENCH_EMBEDDED
|
||||||
|
#define BENCH_EMBEDDED
|
||||||
|
|
||||||
|
#undef USE_CERT_BUFFERS_2048
|
||||||
|
#define USE_CERT_BUFFERS_2048
|
||||||
|
|
||||||
|
//#undef USE_CERT_BUFFERS_1024
|
||||||
|
//#define USE_CERT_BUFFERS_1024
|
||||||
|
|
||||||
|
#undef USE_CERT_BUFFERS_256
|
||||||
|
#define USE_CERT_BUFFERS_256
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Debugging */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#undef DEBUG_WOLFSSL
|
||||||
|
//#define DEBUG_WOLFSSL
|
||||||
|
|
||||||
|
/* Use this to measure / print heap usage */
|
||||||
|
#if 0
|
||||||
|
#undef USE_WOLFSSL_MEMORY
|
||||||
|
#define USE_WOLFSSL_MEMORY
|
||||||
|
|
||||||
|
#undef WOLFSSL_TRACK_MEMORY
|
||||||
|
//#define WOLFSSL_TRACK_MEMORY
|
||||||
|
|
||||||
|
#undef WOLFSSL_DEBUG_MEMORY
|
||||||
|
//#define WOLFSSL_DEBUG_MEMORY
|
||||||
|
#else
|
||||||
|
#undef NO_WOLFSSL_MEMORY
|
||||||
|
#define NO_WOLFSSL_MEMORY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DEBUG_WOLFSSL
|
||||||
|
#undef NO_ERROR_STRINGS
|
||||||
|
#define NO_ERROR_STRINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Port */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/* Override Current Time */
|
||||||
|
/* Allows custom "custom_time()" function to be used for benchmark */
|
||||||
|
#define WOLFSSL_USER_CURRTIME
|
||||||
|
#define USER_TICKS
|
||||||
|
extern unsigned long my_time(unsigned long* timer);
|
||||||
|
#define XTIME my_time
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* RNG */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Size of returned HW RNG value */
|
||||||
|
#define CUSTOM_RAND_TYPE unsigned int
|
||||||
|
|
||||||
|
/* Seed source */
|
||||||
|
extern unsigned int custom_rand_generate(void);
|
||||||
|
#undef CUSTOM_RAND_GENERATE
|
||||||
|
#define CUSTOM_RAND_GENERATE custom_rand_generate
|
||||||
|
|
||||||
|
/* Choose RNG method */
|
||||||
|
#if 0
|
||||||
|
/* Use built-in P-RNG (SHA256 based) with HW RNG */
|
||||||
|
/* P-RNG + HW RNG (P-RNG is ~8K) */
|
||||||
|
#undef HAVE_HASHDRBG
|
||||||
|
#define HAVE_HASHDRBG
|
||||||
|
#else
|
||||||
|
#undef WC_NO_HASHDRBG
|
||||||
|
#define WC_NO_HASHDRBG
|
||||||
|
|
||||||
|
/* Bypass P-RNG and use only HW RNG */
|
||||||
|
extern int custom_rand_generate_block(unsigned char* output, unsigned int sz);
|
||||||
|
#undef CUSTOM_RAND_GENERATE_BLOCK
|
||||||
|
#define CUSTOM_RAND_GENERATE_BLOCK custom_rand_generate_block
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Enable Features */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
#if 0
|
||||||
|
#undef WOLFSSL_TLS13
|
||||||
|
#define WOLFSSL_TLS13
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef KEEP_PEER_CERT
|
||||||
|
//#define KEEP_PEER_CERT
|
||||||
|
|
||||||
|
#undef HAVE_COMP_KEY
|
||||||
|
//#define HAVE_COMP_KEY
|
||||||
|
|
||||||
|
#undef HAVE_TLS_EXTENSIONS
|
||||||
|
#define HAVE_TLS_EXTENSIONS
|
||||||
|
|
||||||
|
#undef HAVE_SUPPORTED_CURVES
|
||||||
|
#define HAVE_SUPPORTED_CURVES
|
||||||
|
|
||||||
|
#undef WOLFSSL_BASE64_ENCODE
|
||||||
|
#define WOLFSSL_BASE64_ENCODE
|
||||||
|
|
||||||
|
/* TLS Session Cache */
|
||||||
|
#if 0
|
||||||
|
#define SMALL_SESSION_CACHE
|
||||||
|
#else
|
||||||
|
#define NO_SESSION_CACHE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* Disable Features */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
#undef NO_WOLFSSL_SERVER
|
||||||
|
//#define NO_WOLFSSL_SERVER
|
||||||
|
|
||||||
|
#undef NO_WOLFSSL_CLIENT
|
||||||
|
//#define NO_WOLFSSL_CLIENT
|
||||||
|
|
||||||
|
#undef NO_CRYPT_TEST
|
||||||
|
//#define NO_CRYPT_TEST
|
||||||
|
|
||||||
|
#undef NO_CRYPT_BENCHMARK
|
||||||
|
//#define NO_CRYPT_BENCHMARK
|
||||||
|
|
||||||
|
/* In-lining of misc.c functions */
|
||||||
|
/* If defined, must include wolfcrypt/src/misc.c in build */
|
||||||
|
/* Slower, but about 1k smaller */
|
||||||
|
#undef NO_INLINE
|
||||||
|
//#define NO_INLINE
|
||||||
|
|
||||||
|
#undef NO_FILESYSTEM
|
||||||
|
#define NO_FILESYSTEM
|
||||||
|
|
||||||
|
#undef NO_WRITEV
|
||||||
|
#define NO_WRITEV
|
||||||
|
|
||||||
|
#undef NO_MAIN_DRIVER
|
||||||
|
#define NO_MAIN_DRIVER
|
||||||
|
|
||||||
|
#undef NO_DEV_RANDOM
|
||||||
|
#define NO_DEV_RANDOM
|
||||||
|
|
||||||
|
#undef NO_DSA
|
||||||
|
#define NO_DSA
|
||||||
|
|
||||||
|
#undef NO_DH
|
||||||
|
#define NO_DH
|
||||||
|
|
||||||
|
#undef NO_DES3
|
||||||
|
#define NO_DES3
|
||||||
|
|
||||||
|
#undef NO_RC4
|
||||||
|
#define NO_RC4
|
||||||
|
|
||||||
|
#undef NO_OLD_TLS
|
||||||
|
#define NO_OLD_TLS
|
||||||
|
|
||||||
|
#undef NO_HC128
|
||||||
|
#define NO_HC128
|
||||||
|
|
||||||
|
#undef NO_RABBIT
|
||||||
|
#define NO_RABBIT
|
||||||
|
|
||||||
|
#undef NO_PSK
|
||||||
|
#define NO_PSK
|
||||||
|
|
||||||
|
#undef NO_MD4
|
||||||
|
#define NO_MD4
|
||||||
|
|
||||||
|
#undef NO_PWDBASED
|
||||||
|
#define NO_PWDBASED
|
||||||
|
|
||||||
|
#undef NO_CODING
|
||||||
|
//#define NO_CODING
|
||||||
|
|
||||||
|
#undef NO_ASN_TIME
|
||||||
|
//#define NO_ASN_TIME
|
||||||
|
|
||||||
|
#undef NO_CERTS
|
||||||
|
//#define NO_CERTS
|
||||||
|
|
||||||
|
#undef NO_SIG_WRAPPER
|
||||||
|
//#define NO_SIG_WRAPPER
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_USER_SETTINGS_H */
|
||||||
|
|
16
IDE/GCC-ARM/Makefile
Executable file
16
IDE/GCC-ARM/Makefile
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
BUILD_DIR = ./Build
|
||||||
|
|
||||||
|
all: WolfSSLStaticLib WolfCryptTest WolfCryptBench WolfSSLClient
|
||||||
|
|
||||||
|
WolfCryptTest:
|
||||||
|
$(MAKE) -f Makefile.test
|
||||||
|
WolfCryptBench:
|
||||||
|
$(MAKE) -f Makefile.bench
|
||||||
|
WolfSSLClient:
|
||||||
|
$(MAKE) -f Makefile.client
|
||||||
|
WolfSSLStaticLib:
|
||||||
|
$(MAKE) -f Makefile.static
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(BUILD_DIR)/*.elf $(BUILD_DIR)/*.hex $(BUILD_DIR)/*.map
|
||||||
|
rm -f $(BUILD_DIR)/*.o $(BUILD_DIR)/*.sym $(BUILD_DIR)/*.disasm
|
7
IDE/GCC-ARM/Makefile.bench
Executable file
7
IDE/GCC-ARM/Makefile.bench
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
# Project name
|
||||||
|
BIN = WolfCryptBench
|
||||||
|
SRC_C = ./Source/benchmark_main.c
|
||||||
|
|
||||||
|
all: build_hex
|
||||||
|
|
||||||
|
include Makefile.common
|
7
IDE/GCC-ARM/Makefile.client
Normal file
7
IDE/GCC-ARM/Makefile.client
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Project name
|
||||||
|
BIN = WolfSSLClient
|
||||||
|
SRC_C = ./Source/tls_client.c
|
||||||
|
|
||||||
|
all: build_hex
|
||||||
|
|
||||||
|
include Makefile.common
|
108
IDE/GCC-ARM/Makefile.common
Executable file
108
IDE/GCC-ARM/Makefile.common
Executable file
@ -0,0 +1,108 @@
|
|||||||
|
# Set to @ if you want to suppress command echo
|
||||||
|
CMD_ECHO =
|
||||||
|
|
||||||
|
# Important directories
|
||||||
|
BUILD_DIR = ./Build
|
||||||
|
|
||||||
|
# Toolchain location and prefix
|
||||||
|
TOOLCHAIN = /opt/gcc-arm-none-eabi/bin/arm-none-eabi-
|
||||||
|
|
||||||
|
INC = -I./Header \
|
||||||
|
-I./Source \
|
||||||
|
-I../..
|
||||||
|
|
||||||
|
# Memory Map
|
||||||
|
SRC_LD = -T./linker.ld
|
||||||
|
|
||||||
|
# Defines
|
||||||
|
DEF = -DWOLFSSL_USER_SETTINGS
|
||||||
|
|
||||||
|
# Compiler and linker flags
|
||||||
|
ARCHFLAGS = -mcpu=cortex-m0 -mthumb -mabi=aapcs
|
||||||
|
DBGFLAGS = -ggdb
|
||||||
|
ASFLAGS = $(ARCHFLAGS)
|
||||||
|
|
||||||
|
# CC: Place functions and data into separate sections to allow dead code removal
|
||||||
|
# by the linker (-f*-sections). Enable link time optimization (-flto)
|
||||||
|
CFLAGS = $(ARCHFLAGS) -std=gnu99 -Wall -Wno-cpp \
|
||||||
|
-ffunction-sections -fdata-sections \
|
||||||
|
-Os -flto $(DBGFLAGS)
|
||||||
|
|
||||||
|
# LD: Remove unused sections
|
||||||
|
LDFLAGS = $(ARCHFLAGS) -Wl,--gc-sections
|
||||||
|
|
||||||
|
# LD: Link with newlib-nano implementation
|
||||||
|
LDFLAGS += --specs=nano.specs --specs=nosys.specs
|
||||||
|
|
||||||
|
# LD: generate map
|
||||||
|
LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(BIN).map $(DBGFLAGS)
|
||||||
|
|
||||||
|
# LD: Entry point
|
||||||
|
LDFLAGS += -Wl,-ereset_handler
|
||||||
|
|
||||||
|
# Math lib (for DH)
|
||||||
|
LIBS = -lm
|
||||||
|
|
||||||
|
SRC_C += ./Source/armtarget.c
|
||||||
|
SRC_C += $(wildcard ../../src/*.c ../../wolfcrypt/src/*.c ../../wolfcrypt/benchmark/*.c ../../wolfcrypt/test/*.c)
|
||||||
|
FILENAMES_C = $(notdir $(SRC_C))
|
||||||
|
FILENAMES_C := $(filter-out evp.c, $(FILENAMES_C))
|
||||||
|
OBJS_C = $(addprefix $(BUILD_DIR)/, $(FILENAMES_C:.c=.o))
|
||||||
|
vpath %.c $(dir $(SRC_C))
|
||||||
|
|
||||||
|
# Tools selection
|
||||||
|
CC = $(TOOLCHAIN)gcc
|
||||||
|
AS = $(TOOLCHAIN)gcc
|
||||||
|
LD = $(TOOLCHAIN)gcc
|
||||||
|
AR = $(TOOLCHAIN)ar
|
||||||
|
NM = $(TOOLCHAIN)nm
|
||||||
|
OBJCOPY = $(TOOLCHAIN)objcopy
|
||||||
|
OBJDUMP = $(TOOLCHAIN)objdump
|
||||||
|
SIZE = $(TOOLCHAIN)size
|
||||||
|
|
||||||
|
build_hex: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).hex
|
||||||
|
@echo ""
|
||||||
|
$(CMD_ECHO) @$(SIZE) $(BUILD_DIR)/$(BIN).elf
|
||||||
|
|
||||||
|
build_static: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).a
|
||||||
|
@echo ""
|
||||||
|
$(CMD_ECHO) @$(SIZE) $(BUILD_DIR)/$(BIN).a
|
||||||
|
|
||||||
|
$(BUILD_DIR):
|
||||||
|
$(CMD_ECHO) mkdir -p $(BUILD_DIR)
|
||||||
|
|
||||||
|
$(BUILD_DIR)/$(BIN).hex: $(BUILD_DIR)/$(BIN).elf
|
||||||
|
@echo "Generating HEX binary: $(notdir $@)"
|
||||||
|
$(CMD_ECHO) $(OBJCOPY) -O ihex $< $@
|
||||||
|
|
||||||
|
$(BUILD_DIR)/%.o: %.s
|
||||||
|
@echo "Compiling ASM file: $(notdir $<)"
|
||||||
|
$(CMD_ECHO) $(AS) $(ASFLAGS) $(DEF) $(INC) -c -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD_DIR)/%.o: %.c
|
||||||
|
@echo "Compiling C file: $(notdir $<)"
|
||||||
|
$(CMD_ECHO) $(CC) $(CFLAGS) $(DEF) $(INC) -c -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD_DIR)/$(BIN).elf: $(OBJS_ASM) $(OBJS_C)
|
||||||
|
@echo "Linking ELF binary: $(notdir $@)"
|
||||||
|
$(CMD_ECHO) $(LD) $(LDFLAGS) $(SRC_LD) -o $@ $^ $(LIBS)
|
||||||
|
|
||||||
|
@echo "Generating name list: $(BIN).sym"
|
||||||
|
$(CMD_ECHO) $(NM) -n $@ > $(BUILD_DIR)/$(BIN).sym
|
||||||
|
|
||||||
|
@echo "Generating disassembly: $(BIN).disasm"
|
||||||
|
$(CMD_ECHO) $(OBJDUMP) -S $@ > $(BUILD_DIR)/$(BIN).disasm
|
||||||
|
|
||||||
|
$(BUILD_DIR)/$(BIN).a: $(OBJS_ASM) $(OBJS_C)
|
||||||
|
@echo "Building static library: $(notdir $@)"
|
||||||
|
$(CMD_ECHO) $(AR) -r $@ $^
|
||||||
|
|
||||||
|
@echo "Generating name list: $(BIN).sym"
|
||||||
|
$(CMD_ECHO) $(NM) -n $@ > $(BUILD_DIR)/$(BIN).sym
|
||||||
|
|
||||||
|
@echo "Generating disassembly: $(BIN).disasm"
|
||||||
|
$(CMD_ECHO) $(OBJDUMP) -S $@ > $(BUILD_DIR)/$(BIN).disasm
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(BUILD_DIR)/*.elf $(BUILD_DIR)/*.hex $(BUILD_DIR)/*.map
|
||||||
|
rm -f $(BUILD_DIR)/*.o $(BUILD_DIR)/*.sym $(BUILD_DIR)/*.disasm
|
6
IDE/GCC-ARM/Makefile.static
Executable file
6
IDE/GCC-ARM/Makefile.static
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
# Project name
|
||||||
|
BIN = libwolfssl
|
||||||
|
|
||||||
|
all: build_static
|
||||||
|
|
||||||
|
include Makefile.common
|
7
IDE/GCC-ARM/Makefile.test
Executable file
7
IDE/GCC-ARM/Makefile.test
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
# Project name
|
||||||
|
BIN = WolfCryptTest
|
||||||
|
SRC_C = ./Source/test_main.c
|
||||||
|
|
||||||
|
all: build_hex
|
||||||
|
|
||||||
|
include Makefile.common
|
65
IDE/GCC-ARM/README.md
Executable file
65
IDE/GCC-ARM/README.md
Executable file
@ -0,0 +1,65 @@
|
|||||||
|
# Example Project for GCC ARM
|
||||||
|
|
||||||
|
This example is for Cortex M series, but can be adopted for other architectures.
|
||||||
|
|
||||||
|
## Design
|
||||||
|
|
||||||
|
* All library options are defined in `Header/user_settings.h`.
|
||||||
|
* The memory map is located in the linker file in `linker.ld`.
|
||||||
|
* Entry point function is `reset_handler` in `armtarget.c`.
|
||||||
|
* The RTC and RNG hardware interface needs implemented for real production applications in `armtarget.c`
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
1. Make sure you have `gcc-arm-none-eabi` installed.
|
||||||
|
2. Modify the `Makefile.common`:
|
||||||
|
* Use correct toolchain path `TOOLCHAIN`.
|
||||||
|
* Use correct architecture 'ARCHFLAGS' (default is cortex-m0 / thumb). See [GCC ARM Options](https://gcc.gnu.org/onlinedocs/gcc-4.7.3/gcc/ARM-Options.html) `-mcpu=name`.
|
||||||
|
3. Use `make` and it will build the static library and wolfCrypt test/benchmark and wolfSSL TLS client targets as `.elf` and `.hex` in `/Build`.
|
||||||
|
|
||||||
|
### Building for Raspberry Pi
|
||||||
|
|
||||||
|
Example `Makefile.common` changes for Rasperry Pi with Cortex-A53:
|
||||||
|
|
||||||
|
1. Change ARCHFLAGS to `ARCHFLAGS = -mcpu=cortex-a53 -mthumb -mabi=aapcs` to specify Cortex-A53.
|
||||||
|
2. Comment out `SRC_LD`, since custom memory map is not applicable.
|
||||||
|
3. Clear `TOOLCHAIN`, so it will use default `gcc`. Set `TOOLCHAIN = `
|
||||||
|
4. Comment out `LDFLAGS += --specs=nano.specs --specs=nosys.specs` to disable newlib-nano.
|
||||||
|
|
||||||
|
Note: To comment out a line in a Makefile use place `#` in front of line.
|
||||||
|
|
||||||
|
### Example Build
|
||||||
|
|
||||||
|
```
|
||||||
|
make clean && make
|
||||||
|
|
||||||
|
text data bss dec hex filename
|
||||||
|
50076 2508 44 52628 cd94 ./Build/WolfCryptTest.elf
|
||||||
|
|
||||||
|
text data bss dec hex filename
|
||||||
|
39155 2508 60 41723 a2fb ./Build/WolfCryptBench.elf
|
||||||
|
|
||||||
|
text data bss dec hex filename
|
||||||
|
70368 464 36 70868 114d4 ./Build/WolfSSLClient.elf
|
||||||
|
```
|
||||||
|
|
||||||
|
## Performace Tuning Options
|
||||||
|
|
||||||
|
These settings are located in `Header/user_settings.h`.
|
||||||
|
|
||||||
|
* `DEBUG_WOLFSSL`: Undefine this to disable debug logging.
|
||||||
|
* `NO_ERROR_STRINGS`: Disables error strings to save code space.
|
||||||
|
* `NO_INLINE`: Disabling inline function saves about 1KB, but is slower.
|
||||||
|
* `WOLFSSL_SMALL_STACK`: Enables stack reduction techniques to allocate stack sections over 100 bytes from heap.
|
||||||
|
* `USE_FAST_MATH`: Uses stack based math, which is faster than the heap based math.
|
||||||
|
* `ALT_ECC_SIZE`: If using fast math and RSA/DH you can define this to reduce your ECC memory consumption.
|
||||||
|
* `FP_MAX_BITS`: Is the maximum math size (key size * 2). Used only with `USE_FAST_MATH`.
|
||||||
|
* `ECC_TIMING_RESISTANT`: Enables timing resistance for ECC and uses slightly less memory.
|
||||||
|
* `ECC_SHAMIR`: Doubles heap usage, but slightly faster
|
||||||
|
* `RSA_LOW_MEM`: Half as much memory but twice as slow. Uses Non-CRT method for private key.
|
||||||
|
AES GCM: `GCM_SMALL`, `GCM_WORD32` or `GCM_TABLE`: Tunes performance and flash/memory usage.
|
||||||
|
* `CURVED25519_SMALL`: Enables small versions of Ed/Curve (FE/GE math).
|
||||||
|
* `USE_SLOW_SHA`: Enables smaller/slower version of SHA.
|
||||||
|
* `USE_SLOW_SHA2`: Over twice as small, but 50% slower
|
||||||
|
* `USE_CERT_BUFFERS_1024` or `USE_CERT_BUFFERS_2048`: Size of RSA certs / keys to test with.
|
||||||
|
* `BENCH_EMBEDDED`: Define this if using the wolfCrypt test/benchmark and using a low memory target.
|
280
IDE/GCC-ARM/Source/armtarget.c
Executable file
280
IDE/GCC-ARM/Source/armtarget.c
Executable file
@ -0,0 +1,280 @@
|
|||||||
|
/* armtarget.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2017 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "user_settings.h"
|
||||||
|
#include <wolfssl/ssl.h>
|
||||||
|
#include <wolfssl/wolfcrypt/random.h> /* for CUSTOM_RAND_TYPE */
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* Test to determine if ARM Cortex M */
|
||||||
|
#if defined(__arm__) && defined(__ARM_ARCH) && (__ARM_ARCH == 6 || __ARM_ARCH == 7)
|
||||||
|
#define CORTEX_M_SERIES
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef CORTEX_M_SERIES
|
||||||
|
/* Memory initialization */
|
||||||
|
extern uint32_t __data_load_start__[];
|
||||||
|
extern uint32_t __data_start__[];
|
||||||
|
extern uint32_t __data_end__[];
|
||||||
|
|
||||||
|
extern uint32_t __bss_start__[];
|
||||||
|
extern uint32_t __bss_end__[];
|
||||||
|
|
||||||
|
extern uint32_t __stack_process_end__[];
|
||||||
|
|
||||||
|
extern uint32_t __heap_start__[];
|
||||||
|
extern uint32_t __heap_end__[];
|
||||||
|
|
||||||
|
/* Copy memory: src=Source, dst_beg=Destination Begin, dst_end=Destination End */
|
||||||
|
void memcpy32(uint32_t* src, uint32_t* dst_beg, uint32_t* dst_end)
|
||||||
|
{
|
||||||
|
while (dst_beg < dst_end) {
|
||||||
|
*dst_beg++ = *src++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Zero address in range */
|
||||||
|
void meminit32(uint32_t* start, uint32_t* end)
|
||||||
|
{
|
||||||
|
while (start < end) {
|
||||||
|
*start++ = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* CORTEX_M_SERIES */
|
||||||
|
|
||||||
|
/* Entry Point */
|
||||||
|
void reset_handler(void)
|
||||||
|
{
|
||||||
|
#ifdef CORTEX_M_SERIES
|
||||||
|
/* Init sections */
|
||||||
|
memcpy32(__data_load_start__, __data_start__, __data_end__);
|
||||||
|
meminit32(__bss_start__, __bss_end__);
|
||||||
|
|
||||||
|
/* Init heap */
|
||||||
|
__heap_start__[0] = 0;
|
||||||
|
__heap_start__[1] = ((uint32_t)__heap_end__ - (uint32_t)__heap_start__);
|
||||||
|
#endif /* CORTEX_M_SERIES */
|
||||||
|
|
||||||
|
/* Start main */
|
||||||
|
extern int main(void);
|
||||||
|
main();
|
||||||
|
|
||||||
|
/* Application has ended, so busy wait */
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CORTEX_M_SERIES
|
||||||
|
// Vector Exception/Interrupt Handlers
|
||||||
|
static void Default_Handler(void)
|
||||||
|
{
|
||||||
|
/* If we get here then need to implement real IRQ handler */
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((section(".sys"))) __attribute__ ((used))
|
||||||
|
void HardFault_HandlerC( uint32_t *hardfault_args )
|
||||||
|
{
|
||||||
|
/* These are volatile to try and prevent the compiler/linker optimizing them
|
||||||
|
away as the variables never actually get used. If the debugger won't show the
|
||||||
|
values of the variables, make them global my moving their declaration outside
|
||||||
|
of this function. */
|
||||||
|
volatile uint32_t stacked_r0;
|
||||||
|
volatile uint32_t stacked_r1;
|
||||||
|
volatile uint32_t stacked_r2;
|
||||||
|
volatile uint32_t stacked_r3;
|
||||||
|
volatile uint32_t stacked_r12;
|
||||||
|
volatile uint32_t stacked_lr;
|
||||||
|
volatile uint32_t stacked_pc;
|
||||||
|
volatile uint32_t stacked_psr;
|
||||||
|
volatile uint32_t _CFSR;
|
||||||
|
volatile uint32_t _HFSR;
|
||||||
|
volatile uint32_t _DFSR;
|
||||||
|
volatile uint32_t _AFSR;
|
||||||
|
volatile uint32_t _BFAR;
|
||||||
|
volatile uint32_t _MMAR;
|
||||||
|
|
||||||
|
stacked_r0 = ((uint32_t)hardfault_args[0]);
|
||||||
|
stacked_r1 = ((uint32_t)hardfault_args[1]);
|
||||||
|
stacked_r2 = ((uint32_t)hardfault_args[2]);
|
||||||
|
stacked_r3 = ((uint32_t)hardfault_args[3]);
|
||||||
|
stacked_r12 = ((uint32_t)hardfault_args[4]);
|
||||||
|
stacked_lr = ((uint32_t)hardfault_args[5]);
|
||||||
|
stacked_pc = ((uint32_t)hardfault_args[6]);
|
||||||
|
stacked_psr = ((uint32_t)hardfault_args[7]);
|
||||||
|
|
||||||
|
// Configurable Fault Status Register
|
||||||
|
// Consists of MMSR, BFSR and UFSR
|
||||||
|
_CFSR = (*((volatile uint32_t *)(0xE000ED28)));
|
||||||
|
|
||||||
|
// Hard Fault Status Register
|
||||||
|
_HFSR = (*((volatile uint32_t *)(0xE000ED2C)));
|
||||||
|
|
||||||
|
// Debug Fault Status Register
|
||||||
|
_DFSR = (*((volatile uint32_t *)(0xE000ED30)));
|
||||||
|
|
||||||
|
// Auxiliary Fault Status Register
|
||||||
|
_AFSR = (*((volatile uint32_t *)(0xE000ED3C)));
|
||||||
|
|
||||||
|
// Read the Fault Address Registers. These may not contain valid values.
|
||||||
|
// Check BFARVALID/MMARVALID to see if they are valid values
|
||||||
|
// MemManage Fault Address Register
|
||||||
|
_MMAR = (*((volatile uint32_t *)(0xE000ED34)));
|
||||||
|
// Bus Fault Address Register
|
||||||
|
_BFAR = (*((volatile uint32_t *)(0xE000ED38)));
|
||||||
|
|
||||||
|
printf ("\n\nHard fault handler (all numbers in hex):\n");
|
||||||
|
printf ("R0 = %lx\n", stacked_r0);
|
||||||
|
printf ("R1 = %lx\n", stacked_r1);
|
||||||
|
printf ("R2 = %lx\n", stacked_r2);
|
||||||
|
printf ("R3 = %lx\n", stacked_r3);
|
||||||
|
printf ("R12 = %lx\n", stacked_r12);
|
||||||
|
printf ("LR [R14] = %lx subroutine call return address\n", stacked_lr);
|
||||||
|
printf ("PC [R15] = %lx program counter\n", stacked_pc);
|
||||||
|
printf ("PSR = %lx\n", stacked_psr);
|
||||||
|
printf ("CFSR = %lx\n", _CFSR);
|
||||||
|
printf ("HFSR = %lx\n", _HFSR);
|
||||||
|
printf ("DFSR = %lx\n", _DFSR);
|
||||||
|
printf ("AFSR = %lx\n", _AFSR);
|
||||||
|
printf ("MMAR = %lx\n", _MMAR);
|
||||||
|
printf ("BFAR = %lx\n", _BFAR);
|
||||||
|
|
||||||
|
// Break into the debugger
|
||||||
|
__asm("BKPT #0\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((section(".sys"))) __attribute__( ( naked ) )
|
||||||
|
void HardFault_Handler(void)
|
||||||
|
{
|
||||||
|
__asm volatile
|
||||||
|
(
|
||||||
|
" movs r0,#4 \n" /* load bit mask into R0 */
|
||||||
|
" mov r1, lr \n" /* load link register into R1 */
|
||||||
|
" tst r0, r1 \n" /* compare with bitmask */
|
||||||
|
" beq _MSP \n" /* if bitmask is set: stack pointer is in PSP. Otherwise in MSP */
|
||||||
|
" mrs r0, psp \n" /* otherwise: stack pointer is in PSP */
|
||||||
|
" b _GetPC \n" /* go to part which loads the PC */
|
||||||
|
"_MSP: \n" /* stack pointer is in MSP register */
|
||||||
|
" mrs r0, msp \n" /* load stack pointer into R0 */
|
||||||
|
"_GetPC: \n" /* find out where the hard fault happened */
|
||||||
|
" ldr r1,[r0,#20] \n" /* load program counter into R1. R1 contains address of the next instruction where the hard fault happened */
|
||||||
|
" ldr r2, =HardFault_HandlerC \n"
|
||||||
|
" bx r2 \n"
|
||||||
|
" bx lr \n" /* decode more information. R0 contains pointer to stack frame */
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vectors
|
||||||
|
typedef void (*vector_entry)(void);
|
||||||
|
const vector_entry vectors[] __attribute__ ((section(".vectors"),used)) =
|
||||||
|
{
|
||||||
|
/* Interrupt Vector Table Function Pointers */
|
||||||
|
// Address Vector IRQ Source module Source description
|
||||||
|
(vector_entry)__stack_process_end__, // ARM core Initial Supervisor SP
|
||||||
|
reset_handler, // 0x0000_0004 1 - ARM core Initial Program Counter
|
||||||
|
Default_Handler, // 0x0000_0008 2 - ARM core Non-maskable Interrupt (NMI)
|
||||||
|
HardFault_Handler, // 0x0000_000C 3 - ARM core Hard Fault
|
||||||
|
Default_Handler, // 0x0000_0010 4 -
|
||||||
|
HardFault_Handler, // 0x0000_0014 5 - ARM core Bus Fault
|
||||||
|
HardFault_Handler, // 0x0000_0018 6 - ARM core Usage Fault
|
||||||
|
Default_Handler, // 0x0000_001C 7 -
|
||||||
|
Default_Handler, // 0x0000_0020 8 -
|
||||||
|
Default_Handler, // 0x0000_0024 9 -
|
||||||
|
Default_Handler, // 0x0000_0028 10 -
|
||||||
|
Default_Handler, // 0x0000_002C 11 - ARM core Supervisor call (SVCall)
|
||||||
|
Default_Handler, // 0x0000_0030 12 - ARM core Debug Monitor
|
||||||
|
Default_Handler, // 0x0000_0034 13 -
|
||||||
|
Default_Handler, // 0x0000_0038 14 - ARM core Pendable request for system service (PendableSrvReq)
|
||||||
|
Default_Handler, // 0x0000_003C 15 - ARM core System tick timer (SysTick)
|
||||||
|
|
||||||
|
/* remainder go below */
|
||||||
|
};
|
||||||
|
#endif /* CORTEX_M_SERIES */
|
||||||
|
|
||||||
|
|
||||||
|
/* TIME CODE */
|
||||||
|
/* TODO: Implement real RTC */
|
||||||
|
static int gTimeMs;
|
||||||
|
static int hw_get_time_sec(void)
|
||||||
|
{
|
||||||
|
return ++gTimeMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long my_time(unsigned long* timer)
|
||||||
|
{
|
||||||
|
(void)timer;
|
||||||
|
return hw_get_time_sec();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int LowResTimer(void)
|
||||||
|
{
|
||||||
|
return hw_get_time_sec();
|
||||||
|
}
|
||||||
|
|
||||||
|
double current_time(int reset)
|
||||||
|
{
|
||||||
|
double time;
|
||||||
|
int timeMs = gTimeMs;
|
||||||
|
(void)reset;
|
||||||
|
time = (timeMs / 1000); // sec
|
||||||
|
time += (double)(timeMs % 1000) / 1000; // ms
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* RNG CODE */
|
||||||
|
/* TODO: Implement real RNG */
|
||||||
|
static int gCounter;
|
||||||
|
int hw_rand(void)
|
||||||
|
{
|
||||||
|
return ++gCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int custom_rand_generate(void)
|
||||||
|
{
|
||||||
|
return hw_rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
int custom_rand_generate_block(unsigned char* output, unsigned int sz)
|
||||||
|
{
|
||||||
|
uint32_t i = 0;
|
||||||
|
|
||||||
|
while (i < sz)
|
||||||
|
{
|
||||||
|
/* If not aligned or there is odd/remainder */
|
||||||
|
if( (i + sizeof(CUSTOM_RAND_TYPE)) > sz ||
|
||||||
|
((uint32_t)&output[i] % sizeof(CUSTOM_RAND_TYPE)) != 0
|
||||||
|
) {
|
||||||
|
/* Single byte at a time */
|
||||||
|
output[i++] = (unsigned char)custom_rand_generate();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Use native 8, 16, 32 or 64 copy instruction */
|
||||||
|
*((CUSTOM_RAND_TYPE*)&output[i]) = custom_rand_generate();
|
||||||
|
i += sizeof(CUSTOM_RAND_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
47
IDE/GCC-ARM/Source/benchmark_main.c
Executable file
47
IDE/GCC-ARM/Source/benchmark_main.c
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
/* benchmark_main.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
#include <wolfssl/wolfcrypt/logging.h>
|
||||||
|
#include <wolfcrypt/benchmark/benchmark.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
typedef struct func_args {
|
||||||
|
int argc;
|
||||||
|
char** argv;
|
||||||
|
int return_code;
|
||||||
|
} func_args;
|
||||||
|
|
||||||
|
static func_args args = { 0 } ;
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
wolfCrypt_Init();
|
||||||
|
|
||||||
|
printf("\nBenchmark Test\n");
|
||||||
|
benchmark_test(&args);
|
||||||
|
printf("Benchmark Test: Return code %d\n", args.return_code);
|
||||||
|
|
||||||
|
wolfCrypt_Cleanup();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
47
IDE/GCC-ARM/Source/test_main.c
Executable file
47
IDE/GCC-ARM/Source/test_main.c
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
/* test_main.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2017 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
#include <wolfssl/wolfcrypt/logging.h>
|
||||||
|
#include <wolfcrypt/test/test.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
typedef struct func_args {
|
||||||
|
int argc;
|
||||||
|
char** argv;
|
||||||
|
int return_code;
|
||||||
|
} func_args;
|
||||||
|
|
||||||
|
static func_args args = { 0 } ;
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
wolfCrypt_Init();
|
||||||
|
|
||||||
|
printf("\nCrypt Test\n");
|
||||||
|
wolfcrypt_test(&args);
|
||||||
|
printf("Crypt Test: Return code %d\n", args.return_code);
|
||||||
|
|
||||||
|
wolfCrypt_Cleanup();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
198
IDE/GCC-ARM/Source/tls_client.c
Executable file
198
IDE/GCC-ARM/Source/tls_client.c
Executable file
@ -0,0 +1,198 @@
|
|||||||
|
/* tls_client.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2017 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
#include <wolfssl/ssl.h>
|
||||||
|
#include <wolfssl/wolfcrypt/logging.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define MAXSZ 1024
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* TLS CLIENT */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
static int CbIORecv(WOLFSSL *ssl, char *buf, int sz, void *ctx)
|
||||||
|
{
|
||||||
|
int ret = WOLFSSL_CBIO_ERR_GENERAL;
|
||||||
|
|
||||||
|
(void)ssl;
|
||||||
|
(void)ctx;
|
||||||
|
|
||||||
|
/* TODO: Exchange data over your own transport */
|
||||||
|
#warning TODO: Implement your own recv data transport
|
||||||
|
#if 0
|
||||||
|
ret = usart_read_buffer_wait(&cdc_uart_module, buf, sz);
|
||||||
|
if (ret == STATUS_ERR_TIMEOUT)
|
||||||
|
return WOLFSSL_CBIO_ERR_WANT_READ;
|
||||||
|
|
||||||
|
return (ret == STATUS_OK) ? sz : WOLFSSL_CBIO_ERR_GENERAL;
|
||||||
|
#else
|
||||||
|
return ret;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static int CbIOSend(WOLFSSL *ssl, char *buf, int sz, void *ctx)
|
||||||
|
{
|
||||||
|
int ret = WOLFSSL_CBIO_ERR_GENERAL;
|
||||||
|
|
||||||
|
(void)ssl;
|
||||||
|
(void)ctx;
|
||||||
|
|
||||||
|
/* TODO: Exchange data over your own transport */
|
||||||
|
#warning TODO: Implement your own send data transport
|
||||||
|
#if 0
|
||||||
|
ret = usart_write_buffer_wait(&cdc_uart_module, buf, sz);
|
||||||
|
if (ret == STATUS_ERR_TIMEOUT)
|
||||||
|
return WOLFSSL_CBIO_ERR_WANT_WRITE;
|
||||||
|
|
||||||
|
return (ret == STATUS_OK) ? sz : WOLFSSL_CBIO_ERR_GENERAL;
|
||||||
|
#else
|
||||||
|
return ret;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tls_client(void)
|
||||||
|
{
|
||||||
|
char msg[] = "Hello WolfSSL!\r\n";
|
||||||
|
char reply[MAXSZ];
|
||||||
|
int ret, msgSz, error;
|
||||||
|
WOLFSSL* ssl = NULL;
|
||||||
|
WOLFSSL_CTX* ctx = NULL;
|
||||||
|
|
||||||
|
if ((ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL) {
|
||||||
|
printf("CTXnew failed.\n");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* ECDHE-ECDSA */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/*--------------------*/
|
||||||
|
/* for peer auth use: */
|
||||||
|
/*--------------------*/
|
||||||
|
// wolfSSL_CTX_load_verify_buffer(ctx, rsa_key_der_1024,
|
||||||
|
// sizeof_rsa_key_der_1024, SSL_FILETYPE_ASN1);
|
||||||
|
// wolfSSL_CTX_load_verify_buffer(ctx, server_cert_der_1024,
|
||||||
|
// sizeof_server_cert_der_1024, SSL_FILETYPE_ASN1);
|
||||||
|
/*---------------------*/
|
||||||
|
/* for no peer auth: */
|
||||||
|
/*---------------------*/
|
||||||
|
wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
|
||||||
|
/*---------------------*/
|
||||||
|
/* end peer auth option*/
|
||||||
|
/*---------------------*/
|
||||||
|
if ((ret = wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-ECDSA-AES128-SHA256")) != SSL_SUCCESS) {
|
||||||
|
wolfSSL_CTX_free(ctx);
|
||||||
|
printf("CTXset_cipher_list failed, error: %d\n", ret);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* END CIPHER SUITE OPTIONS */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
wolfSSL_SetIORecv(ctx, CbIORecv);
|
||||||
|
wolfSSL_SetIOSend(ctx, CbIOSend);
|
||||||
|
|
||||||
|
if ((ssl = wolfSSL_new(ctx)) == NULL) {
|
||||||
|
error = wolfSSL_get_error(ssl, 0);
|
||||||
|
printf("wolfSSL_new failed %d\n", error);
|
||||||
|
wolfSSL_CTX_free(ctx);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* non blocking accept and connect */
|
||||||
|
ret = SSL_FAILURE;
|
||||||
|
|
||||||
|
while (ret != SSL_SUCCESS) {
|
||||||
|
/* client connect */
|
||||||
|
ret = wolfSSL_connect(ssl);
|
||||||
|
error = wolfSSL_get_error(ssl, 0);
|
||||||
|
if (ret != SSL_SUCCESS) {
|
||||||
|
if (error != SSL_ERROR_WANT_READ && error != SSL_ERROR_WANT_WRITE) {
|
||||||
|
/* Fail */
|
||||||
|
printf("wolfSSL connect failed with return code %d\n", error);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Success */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read and write */
|
||||||
|
while (1) {
|
||||||
|
/* client send/read */
|
||||||
|
msgSz = sizeof(msg);
|
||||||
|
ret = wolfSSL_write(ssl, msg, msgSz);
|
||||||
|
error = wolfSSL_get_error(ssl, 0);
|
||||||
|
if (ret != msgSz) {
|
||||||
|
if (error != SSL_ERROR_WANT_READ && error != SSL_ERROR_WANT_WRITE) {
|
||||||
|
/* Write failed */
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Write succeeded */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
ret = wolfSSL_read(ssl, reply, sizeof(reply) - 1);
|
||||||
|
error = wolfSSL_get_error(ssl, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
if (error != SSL_ERROR_WANT_READ && error != SSL_ERROR_WANT_WRITE) {
|
||||||
|
/* Can put print here, the server enters a loop waiting to read
|
||||||
|
* a confirmation message at this point */
|
||||||
|
// printf("client read failed\n");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Can put print here, the server enters a loop waiting to read
|
||||||
|
* a confirmation message at this point */
|
||||||
|
reply[ret] = '\0';
|
||||||
|
// printf("Client Received Reply: %s\n", reply);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
wolfSSL_shutdown(ssl);
|
||||||
|
wolfSSL_free(ssl);
|
||||||
|
wolfSSL_CTX_free(ctx);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
wolfSSL_Init();
|
||||||
|
|
||||||
|
ret = tls_client();
|
||||||
|
|
||||||
|
wolfSSL_Cleanup();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
17
IDE/GCC-ARM/include.am
Normal file
17
IDE/GCC-ARM/include.am
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# vim:ft=automake
|
||||||
|
# included from Top Level Makefile.am
|
||||||
|
# All paths should be given relative to the root
|
||||||
|
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Header/user_settings.h
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Source/armtarget.c
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Source/benchmark_main.c
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Source/test_main.c
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Source/tls_client.c
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/linker.ld
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Makefile
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Makefile.bench
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Makefile.client
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Makefile.common
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Makefile.test
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/Makefile.static
|
||||||
|
EXTRA_DIST+= IDE/GCC-ARM/README.md
|
30
IDE/GCC-ARM/linker.ld
Executable file
30
IDE/GCC-ARM/linker.ld
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
FLASH (wx) : ORIGIN = 0x00000000, LENGTH = 256K
|
||||||
|
RAM (wx) : ORIGIN = 0x20000000, LENGTH = 64K
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
__vectors_start__ = .;
|
||||||
|
.vectors : { *(.vectors) } > FLASH
|
||||||
|
__vectors_end__ = __vectors_start__ + 0x400;
|
||||||
|
.sys : { *(.sys*) } > FLASH
|
||||||
|
.text : { *(.text*) } > FLASH
|
||||||
|
.rodata : { *(.text*) } > FLASH
|
||||||
|
|
||||||
|
__data_load_start__ = .;
|
||||||
|
__data_start__ = .;
|
||||||
|
.data : { *(.data*) } > RAM
|
||||||
|
__data_end__ = __data_start__ + SIZEOF(.data);
|
||||||
|
|
||||||
|
__bss_start__ = .;
|
||||||
|
.bss : { *(.bss*) } > RAM
|
||||||
|
__bss_end__ = __bss_start__ + SIZEOF(.bss);
|
||||||
|
|
||||||
|
__heap_start__ = .;
|
||||||
|
.heap : { *(.heap*) } > RAM
|
||||||
|
__heap_end__ = __heap_start__ + SIZEOF(.heap);
|
||||||
|
|
||||||
|
end = .;
|
||||||
|
}
|
@ -12,5 +12,6 @@ include IDE/ARDUINO/include.am
|
|||||||
include IDE/INTIME-RTOS/include.am
|
include IDE/INTIME-RTOS/include.am
|
||||||
include IDE/OPENSTM32/include.am
|
include IDE/OPENSTM32/include.am
|
||||||
include IDE/VS-ARM/include.am
|
include IDE/VS-ARM/include.am
|
||||||
|
include IDE/GCC-ARM/include.am
|
||||||
|
|
||||||
EXTRA_DIST+= IDE/IAR-EWARM IDE/MDK-ARM IDE/MDK5-ARM IDE/MYSQL IDE/LPCXPRESSO IDE/HEXIWEAR
|
EXTRA_DIST+= IDE/IAR-EWARM IDE/MDK-ARM IDE/MDK5-ARM IDE/MYSQL IDE/LPCXPRESSO IDE/HEXIWEAR
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(CUSTOM_RAND_GENERATE) && !defined(CUSTOM_RAND_TYPE)
|
#if !defined(CUSTOM_RAND_TYPE)
|
||||||
/* To maintain compatibility the default is byte */
|
/* To maintain compatibility the default is byte */
|
||||||
#define CUSTOM_RAND_TYPE byte
|
#define CUSTOM_RAND_TYPE byte
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user