Skip to content

Commit

Permalink
Merge pull request Mbed-TLS#8 from ARMmbed/msp430-build
Browse files Browse the repository at this point in the history
Msp430 build and test scripts
  • Loading branch information
gilles-peskine-arm authored Jul 3, 2017
2 parents 910f668 + bd088e7 commit e059bc3
Show file tree
Hide file tree
Showing 30 changed files with 3,026 additions and 1,902 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ massif-*

# CMake generates *.dir/ folders for in-tree builds (used by MSVC projects), ignore all of those:
*.dir/

# Enable inclusion of 3rd party driverlib
tests/msp430/driverlib
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,30 @@ To accept the Contributor’s Licence Agreement (CLA), individual contributors c
3. Write a test which shows that the bug was fixed or that the feature works as expected.
4. Send a pull request and bug us until it gets merged and published. Contributions may need some modifications, so work with us to get your change accepted. We will include your name in the ChangeLog :)

MSP430 notes
------------

### Compiling

The MSP430 port is currently only compiled via the Makefiles. The targets which are currently relevant for this platform are:

- library,
- tests.

All of the above should be buildable using the IAR compiler, while the library should also be buildable for the desktop platforms using GCC toolchain. The following conditions must be met in order to handle the MSP430 platform:

- The IAR compiler is present in the system,
- the GCC suite is present in the system,
- a POSIX environment (such as MSYS or Cygwin) is available with all the compilers reachable via the commandline.

### Tests

Currently only the test suites are handled for the MSP430 platform.
The tests directory is configured so that the test suites can be built for the MSP430 platform. The binaries for that purpose require special run-time code that enables communication with the test programs while they are executed on the target device. This requires the following:

- a proper chip deployed on the development board,
- the UART and JTAG connections set up between the board and the hosting desktop,
- the test suite binaries being enriched with the runtime code that pipes the I/O via the UART connection.

The UART integration is currently handled via the driverlib code that is provided with the IAR compiler examples suite, though it is distributed under the BSD license and therefore is not included in this distribution. In order for the tests to build and run, the ./tests/msp430/driverlib directory must be filled with the appropriate code obtained from the IAR compiler distribution.

4 changes: 2 additions & 2 deletions include/mbedtls/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_
* multiple calls, which speeds up things a bit. It can
* be set to NULL if the extra performance is unneeded.
*/
int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *N, mbedtls_mpi *_RR );
int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *, mbedtls_mpi *_RR );

/**
* \brief Fill an MPI X with size bytes of random
Expand Down Expand Up @@ -664,7 +664,7 @@ int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B
* MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is <= 1,
MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N.
*/
int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N );
int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi * );

/**
* \brief Miller-Rabin primality test
Expand Down
8 changes: 4 additions & 4 deletions include/mbedtls/ecp.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ typedef struct
*/
typedef struct
{
mbedtls_mpi X; /*!< the point's X coordinate */
mbedtls_mpi Y; /*!< the point's Y coordinate */
mbedtls_mpi Z; /*!< the point's Z coordinate */
mbedtls_mpi ecp_X; /*!< the point's X coordinate */
mbedtls_mpi ecp_Y; /*!< the point's Y coordinate */
mbedtls_mpi ecp_Z; /*!< the point's Z coordinate */
}
mbedtls_ecp_point;

Expand Down Expand Up @@ -129,7 +129,7 @@ typedef struct
mbedtls_mpi A; /*!< 1. A in the equation, or 2. (A + 2) / 4 */
mbedtls_mpi B; /*!< 1. B in the equation, or 2. unused */
mbedtls_ecp_point G; /*!< generator of the (sub)group used */
mbedtls_mpi N; /*!< 1. the order of G, or 2. unused */
mbedtls_mpi N_order; /*!< 1. the order of G, or 2. unused */
size_t pbits; /*!< number of bits in P */
size_t nbits; /*!< number of bits in 1. P, or 2. private keys */
unsigned int h; /*!< internal: 1 if the constants are static */
Expand Down
2 changes: 1 addition & 1 deletion include/mbedtls/hmac_drbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef struct
/* Working state: the key K is not stored explicitely,
* but is implied by the HMAC context */
mbedtls_md_context_t md_ctx; /*!< HMAC context (inc. K) */
unsigned char V[MBEDTLS_MD_MAX_SIZE]; /*!< V in the spec */
unsigned char V_arr[MBEDTLS_MD_MAX_SIZE]; /*!< V in the spec */
int reseed_counter; /*!< reseed counter */

/* Administrative state */
Expand Down
212 changes: 78 additions & 134 deletions library/Makefile
Original file line number Diff line number Diff line change
@@ -1,169 +1,113 @@
IAR_PATH ?= C:/Program Files (x86)/IAR Systems/Embedded Workbench 7.4

# Also see "include/mbedtls/config.h"
ifeq ($(DESKTOP),1)

CFLAGS ?= -O2
WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement
LDFLAGS ?=
CC = gcc
AR = ar

LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -D_FILE_OFFSET_BITS=64
LOCAL_LDFLAGS =
CFLAGS = -O2
WARNING_CFLAGS = -Wall -W -Wdeclaration-after-statement
LOCAL_CFLAGS += -DMBEDTLS_PLATFORM_C
ARFLAGS = -rcs

ifdef DEBUG
LOCAL_CFLAGS += -g3
endif

# MicroBlaze specific options:
# CFLAGS += -mno-xl-soft-mul -mxl-barrel-shift
OBJEXT=.o
STATEXT=.a

# To compile on Plan9:
# CFLAGS += -D_BSD_EXTENSION
else

# if were running on Windows build for Windows
ifdef WINDOWS
WINDOWS_BUILD=1
endif
CC = icc430
AR = xar

# To compile as a shared library:
ifdef SHARED
# all code is position-indep with mingw, avoid warning about useless flag
ifndef WINDOWS_BUILD
LOCAL_CFLAGS += -fPIC -fpic
endif
endif
CFLAGS = --no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --debug -D__MSP430F5359__ -e --double=32 --dlib_config "$(IAR_PATH)/430/lib/dlib/dl430xlsfn.h" --library_module --core=430X --data_model=small -On --multiplier=32 --hw_workaround=CPU40 --code_model=large
WARNING_CFLAGS =
ARFLAGS =

SOEXT_TLS=so.10
SOEXT_X509=so.0
SOEXT_CRYPTO=so.0
ifdef DEBUG
LOCAL_CFLAGS += --debug
endif

DLEXT=so
# OSX shared library extension:
# DLEXT=dylib
OBJEXT=.r43
STATEXT=.r43

# Windows shared library extension:
ifdef WINDOWS_BUILD
DLEXT=dll
endif

OBJS_CRYPTO= aes.o aesni.o arc4.o \
asn1parse.o asn1write.o base64.o \
bignum.o blowfish.o camellia.o \
ccm.o cipher.o cipher_wrap.o \
cmac.o ctr_drbg.o des.o \
dhm.o ecdh.o ecdsa.o \
ecjpake.o ecp.o \
ecp_curves.o entropy.o entropy_poll.o \
error.o gcm.o havege.o \
hmac_drbg.o md.o md2.o \
md4.o md5.o md_wrap.o \
memory_buffer_alloc.o oid.o \
padlock.o pem.o pk.o \
pk_wrap.o pkcs12.o pkcs5.o \
pkparse.o pkwrite.o platform.o \
ripemd160.o rsa.o sha1.o \
sha256.o sha512.o threading.o \
timing.o version.o \
version_features.o xtea.o

OBJS_X509= certs.o pkcs11.o x509.o \
x509_create.o x509_crl.o x509_crt.o \
x509_csr.o x509write_crt.o x509write_csr.o

OBJS_TLS= debug.o net_sockets.o \
ssl_cache.o ssl_ciphersuites.o \
ssl_cli.o ssl_cookie.o \
ssl_srv.o ssl_ticket.o \
ssl_tls.o

.SILENT:

.PHONY: all static shared clean

ifndef SHARED
all: static
else
all: shared static
endif
LOCAL_CFLAGS += $(WARNING_CFLAGS) -I../include -D_FILE_OFFSET_BITS=64
LOCAL_LDFLAGS =

OBJS_CRYPTO= aes$(OBJEXT) aesni$(OBJEXT) arc4$(OBJEXT) \
asn1parse$(OBJEXT) asn1write$(OBJEXT) base64$(OBJEXT) \
bignum$(OBJEXT) blowfish$(OBJEXT) camellia$(OBJEXT) \
ccm$(OBJEXT) cipher$(OBJEXT) cipher_wrap$(OBJEXT) \
cmac$(OBJEXT) ctr_drbg$(OBJEXT) des$(OBJEXT) \
dhm$(OBJEXT) ecdh$(OBJEXT) ecdsa$(OBJEXT) \
ecjpake$(OBJEXT) ecp$(OBJEXT) \
ecp_curves$(OBJEXT) entropy$(OBJEXT) entropy_poll$(OBJEXT) \
error$(OBJEXT) gcm$(OBJEXT) havege$(OBJEXT) \
hmac_drbg$(OBJEXT) md$(OBJEXT) md2$(OBJEXT) \
md4$(OBJEXT) md5$(OBJEXT) md_wrap$(OBJEXT) \
memory_buffer_alloc$(OBJEXT) oid$(OBJEXT) \
padlock$(OBJEXT) pem$(OBJEXT) pk$(OBJEXT) \
pk_wrap$(OBJEXT) pkcs12$(OBJEXT) pkcs5$(OBJEXT) \
pkparse$(OBJEXT) pkwrite$(OBJEXT) platform$(OBJEXT) \
ripemd160$(OBJEXT) rsa$(OBJEXT) sha1$(OBJEXT) \
sha256$(OBJEXT) sha512$(OBJEXT) threading$(OBJEXT) \
timing$(OBJEXT) version$(OBJEXT) \
version_features$(OBJEXT) xtea$(OBJEXT)

OBJS_X509= certs$(OBJEXT) pkcs11$(OBJEXT) x509$(OBJEXT) \
x509_create$(OBJEXT) x509_crl$(OBJEXT) x509_crt$(OBJEXT) \
x509_csr$(OBJEXT) x509write_crt$(OBJEXT) x509write_csr$(OBJEXT)

OBJS_TLS= debug$(OBJEXT) net_sockets$(OBJEXT) \
ssl_cache$(OBJEXT) ssl_ciphersuites$(OBJEXT) \
ssl_cli$(OBJEXT) ssl_cookie$(OBJEXT) \
ssl_srv$(OBJEXT) ssl_ticket$(OBJEXT) \
ssl_tls$(OBJEXT)

.PHONY: all static clean

static: libmbedcrypto.a libmbedx509.a libmbedtls.a
all: static

shared: libmbedcrypto.$(DLEXT) libmbedx509.$(DLEXT) libmbedtls.$(DLEXT)
static: libmbedcrypto$(STATEXT) libmbedx509$(STATEXT) libmbedtls$(STATEXT)

# tls
libmbedtls.a: $(OBJS_TLS)
echo " AR $@"
$(AR) -rc $@ $(OBJS_TLS)
echo " RL $@"
$(AR) -s $@
@echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS_TLS)

libmbedtls.$(SOEXT_TLS): $(OBJS_TLS) libmbedx509.so
echo " LD $@"
$(CC) -shared -Wl,-soname,$@ -L. -lmbedcrypto -lmbedx509 $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_TLS)

libmbedtls.so: libmbedtls.$(SOEXT_TLS)
echo " LN $@ -> $<"
ln -sf $< $@

libmbedtls.dylib: $(OBJS_TLS)
echo " LD $@"
$(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_TLS)

libmbedtls.dll: $(OBJS_TLS) libmbedx509.dll
echo " LD $@"
$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_TLS) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -lmbedx509 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
libmbedtls.r43: $(OBJS_TLS)
@echo " AR43 $@"
$(AR) $(ARFLAGS) -o $@ $(OBJS_TLS)

# x509
libmbedx509.a: $(OBJS_X509)
echo " AR $@"
$(AR) -rc $@ $(OBJS_X509)
echo " RL $@"
$(AR) -s $@

libmbedx509.$(SOEXT_X509): $(OBJS_X509) libmbedcrypto.so
echo " LD $@"
$(CC) -shared -Wl,-soname,$@ -L. -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_X509)

libmbedx509.so: libmbedx509.$(SOEXT_X509)
echo " LN $@ -> $<"
ln -sf $< $@

libmbedx509.dylib: $(OBJS_X509)
echo " LD $@"
$(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_X509)
@echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS_X509)

libmbedx509.dll: $(OBJS_X509) libmbedcrypto.dll
echo " LD $@"
$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_X509) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
libmbedx509.r43: $(OBJS_X509)
@echo " AR43 $@"
$(AR) $(ARFLAGS) -o $@ $(OBJS_X509)

# crypto
libmbedcrypto.a: $(OBJS_CRYPTO)
echo " AR $@"
$(AR) -rc $@ $(OBJS_CRYPTO)
echo " RL $@"
$(AR) -s $@
@echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS_CRYPTO)

libmbedcrypto.$(SOEXT_CRYPTO): $(OBJS_CRYPTO)
echo " LD $@"
$(CC) -shared -Wl,-soname,$@ $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_CRYPTO)

libmbedcrypto.so: libmbedcrypto.$(SOEXT_CRYPTO)
echo " LN $@ -> $<"
ln -sf $< $@

libmbedcrypto.dylib: $(OBJS_CRYPTO)
echo " LD $@"
$(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_CRYPTO)

libmbedcrypto.dll: $(OBJS_CRYPTO)
echo " LD $@"
$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_CRYPTO) -lws2_32 -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
libmbedcrypto.r43: $(OBJS_CRYPTO)
@echo " AR43 $@"
$(AR) $(ARFLAGS) -o $@ $(OBJS_CRYPTO)

.c.o:
echo " CC $<"
@echo " CC $<"
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $<

%.r43: %.c
@echo " CC43 $<"
$(CC) $< -o $@ $(LOCAL_CFLAGS) $(CFLAGS)

clean:
ifndef WINDOWS
rm -f *.o libmbed*
else
del /Q /F *.o libmbed*
endif
rm -f *.r43 *.d43 *.o libmbed*
2 changes: 1 addition & 1 deletion library/ecdh.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
goto cleanup;
}

MBEDTLS_MPI_CHK( mbedtls_mpi_copy( z, &P.X ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( z, &P.ecp_X ) );

cleanup:
mbedtls_ecp_point_free( &P );
Expand Down
Loading

0 comments on commit e059bc3

Please sign in to comment.