diff --git a/dist/tools/travis-scripts/get-pkg-list.py b/dist/tools/travis-scripts/get-pkg-list.py index ecae99d44d..d6babe42d8 100755 --- a/dist/tools/travis-scripts/get-pkg-list.py +++ b/dist/tools/travis-scripts/get-pkg-list.py @@ -30,6 +30,10 @@ known_mcu_groups = arm_mcu_groups + msp_mcu_groups + x86_mcu_groups + \ avr8_mcu_groups + static_tests_groups common_pkgs = ["pcregrep", "libpcre3", "python3"] + +# testing the relic pkg and its RIOT specific unit test requires cmake +common_pkgs = common_pkgs + ["cmake"] + arm_pkgs = ["gcc-arm-none-eabi"] msp_pkgs = ["gcc-msp430"] x86_pkgs = ["qemu-system-x86", "g++-multilib", "gcc-multilib", diff --git a/pkg/relic/0001-fixed-signedness-of-counter-variable.patch b/pkg/relic/0001-fixed-signedness-of-counter-variable.patch new file mode 100644 index 0000000000..c4dbd29175 --- /dev/null +++ b/pkg/relic/0001-fixed-signedness-of-counter-variable.patch @@ -0,0 +1,26 @@ +From 96f92673ac7b719f745958738e6652491bff2c3b Mon Sep 17 00:00:00 2001 +From: Oleg Hahm +Date: Sat, 28 Nov 2015 16:01:18 +0100 +Subject: fixed signedness of counter variable + +--- + src/cp/relic_cp_bdpe.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/cp/relic_cp_bdpe.c b/src/cp/relic_cp_bdpe.c +index c63621c..0a253a5 100644 +--- a/src/cp/relic_cp_bdpe.c ++++ b/src/cp/relic_cp_bdpe.c +@@ -160,7 +160,8 @@ int cp_bdpe_enc(uint8_t *out, int *out_len, dig_t in, bdpe_t pub) { + + int cp_bdpe_dec(dig_t *out, uint8_t *in, int in_len, bdpe_t prv) { + bn_t m, t, z; +- int i, size, result = STS_OK; ++ unsigned i; ++ int size, result = STS_OK; + + size = bn_size_bin(prv->n); + +-- +2.6.2 + diff --git a/pkg/relic/0002-don-t-redefine-ALIGN.patch b/pkg/relic/0002-don-t-redefine-ALIGN.patch new file mode 100644 index 0000000000..9cbc90ca04 --- /dev/null +++ b/pkg/relic/0002-don-t-redefine-ALIGN.patch @@ -0,0 +1,69 @@ +From 381a12925143ba4f6910c15ccb1fabb2a7c8c614 Mon Sep 17 00:00:00 2001 +From: Oleg Hahm +Date: Sat, 28 Nov 2015 15:54:24 +0100 +Subject: don't redefine ALIGN + +--- + include/relic_types.h | 9 +++++++-- + src/md/blake2.h | 10 +++------- + 2 files changed, 10 insertions(+), 9 deletions(-) + +diff --git a/include/relic_types.h b/include/relic_types.h +index afc4870..d9ef4f5 100644 +--- a/include/relic_types.h ++++ b/include/relic_types.h +@@ -129,9 +129,14 @@ typedef unsigned long long ull_t; + * Specification for aligned variables. + */ + #if ALIGN > 1 +-#define align __attribute__ ((aligned (ALIGN))) ++# if defined(_MSC_VER) ++# define ALIGNME(x) __declspec(align(x)) ++# else ++# define ALIGNME(x) __attribute__((aligned(x))) ++# endif + #else +-#define align /* empty*/ ++# define align /* empty*/ ++# define ALIGNME(x) /* empty*/ + #endif + + /** +diff --git a/src/md/blake2.h b/src/md/blake2.h +index f8aba83..48e314f 100644 +--- a/src/md/blake2.h ++++ b/src/md/blake2.h +@@ -17,11 +17,7 @@ + #include + #include + +-#if defined(_MSC_VER) +-#define ALIGN(x) __declspec(align(x)) +-#else +-#define ALIGN(x) __attribute__((aligned(x))) +-#endif ++#include "relic_types.h" + + #if defined(__cplusplus) + extern "C" { +@@ -61,7 +57,7 @@ extern "C" { + uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 + } blake2s_param; + +- ALIGN( 64 ) typedef struct __blake2s_state ++ ALIGNME( 64 ) typedef struct __blake2s_state + { + uint32_t h[8]; + uint32_t t[2]; +@@ -86,7 +82,7 @@ extern "C" { + uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64 + } blake2b_param; + +- ALIGN( 64 ) typedef struct __blake2b_state ++ ALIGNME( 64 ) typedef struct __blake2b_state + { + uint64_t h[8]; + uint64_t t[2]; +-- +2.6.2 + diff --git a/pkg/relic/0003-require-only-CMake-version-2.8.patch b/pkg/relic/0003-require-only-CMake-version-2.8.patch new file mode 100644 index 0000000000..d8be0d262f --- /dev/null +++ b/pkg/relic/0003-require-only-CMake-version-2.8.patch @@ -0,0 +1,23 @@ +From 814aec72218b194bdff51702fcecd3a06222efbd Mon Sep 17 00:00:00 2001 +From: Oleg Hahm +Date: Tue, 1 Dec 2015 17:42:16 +0100 +Subject: [PATCH 3/3] require only CMake version 2.8 + +--- + CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 8a26feb..2ca537a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,5 +1,5 @@ + project(RELIC C CXX) +-cmake_minimum_required(VERSION 3.1) ++cmake_minimum_required(VERSION 2.8) + + set(PROJECT_VERSION_MAJOR "0") + set(PROJECT_VERSION_MINOR "4") +-- +2.6.2 + diff --git a/pkg/relic/Makefile b/pkg/relic/Makefile new file mode 100644 index 0000000000..54234c534c --- /dev/null +++ b/pkg/relic/Makefile @@ -0,0 +1,44 @@ +RELIC_URL=http://github.com/relic-toolkit/relic.git +RELIC_BRANCH=master + +PKG_NAME=relic +PKG_URL=$(RELIC_URL) +PKG_VERSION=$(RELIC_BRANCH) +PKG_DIR=$(CURDIR)/$(PKG_NAME) + +ifneq ($(RIOTBOARD),) +include $(RIOTBOARD)/$(BOARD)/Makefile.include +endif + +ifneq ($(RIOTBASE),) +INCLUDES += -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/sys/net/include \ + -I$(RIOTBASE)/sys/posix/include -I$(RIOTBASE)/sys/posix/pnet/include +endif + +.PHONY: all clean reset + +all: $(PKG_DIR)/Makefile + "$(MAKE)" -C $(PKG_DIR) && \ + cp $(PKG_DIR)/lib/librelic_s.a $(BINDIR)$(PKG_NAME).a + +$(PKG_DIR)/comp-options.cmake: $(PKG_DIR)/.git/config + cd "$(PKG_DIR)" && perl ../generate-cmake-xcompile.perl > comp-options.cmake + +$(PKG_DIR)/Makefile: $(PKG_DIR)/comp-options.cmake + cd "$(PKG_DIR)" && COMP="$(filter-out -Werror=old-style-definition -Werror=strict-prototypes, $(CFLAGS) ) " cmake -DCMAKE_TOOLCHAIN_FILE=comp-options.cmake -DCHECK=off -DTESTS=0 -DBENCH=0 -DSHLIB=off -Wno-dev $(RELIC_CONFIG_FLAGS) . +$(PKG_DIR)/.git/config: + test -d "$(PKG_DIR)" || git clone "$(PKG_URL)" "$(PKG_DIR)"; \ + cd "$(PKG_DIR)" && git checkout -f "$(PKG_VERSION)" + cd "$(PKG_DIR)" && git am --ignore-whitespace $(CURDIR)/*.patch + ./fix-util_print_wo_args.sh . + ./fix-old-style-definitions.sh . + +clean:: + @echo "Cleaning up relic package..." + rm -rf "$(PKG_DIR)" + +distclean:: + rm -rf "$(PKG_DIR)" + +Makefile.include: + @true diff --git a/pkg/relic/Makefile.include b/pkg/relic/Makefile.include new file mode 100644 index 0000000000..fa0985b127 --- /dev/null +++ b/pkg/relic/Makefile.include @@ -0,0 +1 @@ +INCLUDES += -I$(RIOTBASE)/pkg/relic/relic/include diff --git a/pkg/relic/README.md b/pkg/relic/README.md new file mode 100644 index 0000000000..aa25d94f01 --- /dev/null +++ b/pkg/relic/README.md @@ -0,0 +1,9 @@ +# Configuration Options +You can pass along configuration flags for RELIC from your project makefile via: + +```export RELIC_CONFIG_FLAGS=-DARCH=NONE -DQUIET=off -DWORD=32 -DFP_PRIME=255 -DWITH="BN;MD;DV;FP;EP;CP;BC;EC" -DSEED=ZERO``` + +This should happen before the ```USEPKG``` line. + +# Usage +Just put ```USEPKG += relic``` in your Makefile and ```#include ```. \ No newline at end of file diff --git a/pkg/relic/fix-old-style-definitions.sh b/pkg/relic/fix-old-style-definitions.sh new file mode 100755 index 0000000000..36d9f1494c --- /dev/null +++ b/pkg/relic/fix-old-style-definitions.sh @@ -0,0 +1,2 @@ +#!/bin/sh +find ${1} -name "*.[ch]" | xargs sed -i 's/() {/(void) {/' diff --git a/pkg/relic/fix-util_print_wo_args.sh b/pkg/relic/fix-util_print_wo_args.sh new file mode 100755 index 0000000000..91a5b4c6ef --- /dev/null +++ b/pkg/relic/fix-util_print_wo_args.sh @@ -0,0 +1,2 @@ +#!/bin/sh +find ${1} -name "*.[ch]" | xargs sed -i 's/util_print("\(.*\)")/util_print("\1", NULL)/g' diff --git a/pkg/relic/generate-cmake-xcompile.perl b/pkg/relic/generate-cmake-xcompile.perl new file mode 100755 index 0000000000..34bc106ee6 --- /dev/null +++ b/pkg/relic/generate-cmake-xcompile.perl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +print "INCLUDE(CMakeForceCompiler)\n"; +print "\n"; +print "\n"; +print "SET(CMAKE_SYSTEM_NAME Generic)\n"; +print "SET(CMAKE_SYSTEM_VERSION 1)\n"; +print "\n"; +print "SET(CMAKE_C_COMPILER \"$ENV{CC}\" CACHE STRING \"\")\n"; +print "SET(CMAKE_CXX_COMPILER \"$ENV{CXX}\" CACHE STRING \"\")\n"; +print "SET(CMAKE_RANLIB \"echo\" CACHE STRING \"\")\n"; + +print "\n"; +print "# specify the cross compiler\n"; +print "CMAKE_FORCE_C_COMPILER(\${CMAKE_C_COMPILER} GNU)\n"; +print "CMAKE_FORCE_CXX_COMPILER(\${CMAKE_CXX_COMPILER} GNU)\n"; +print "SET(CMAKE_LINKER \"$ENV{LINK}\" CACHE STRING \"\")\n"; +print "\n"; +my $esc_c_flags = "$ENV{CFLAGS}"; +$esc_c_flags =~ s/"/\\"/g; +print "SET(CMAKE_C_FLAGS \"$esc_c_flags\" CACHE STRING \"\")\n"; +print "\n"; +print "SET(CMAKE_EXE_LINKER_FLAGS \"$ENV{LINKFLAGS}\" CACHE STRING \"\")\n"; + +print "\n"; +print "# search for programs in the build host directories\n"; +print "SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n"; +print "# for libraries and headers in the target directories\n"; +print "SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\n"; +print "SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\n"; diff --git a/tests/unittests/tests-relic/Makefile b/tests/unittests/tests-relic/Makefile new file mode 100644 index 0000000000..8f8032c936 --- /dev/null +++ b/tests/unittests/tests-relic/Makefile @@ -0,0 +1,6 @@ +MODULE = tests-relic + +# The following boards are known to fail or have not been tested. +BOARD_BLACKLIST := arduino-mega2560 chronos f4vi1 msb-430 msb-430h msbiot qemu-i386 redbee-econotag stm32f0discovery stm32f3discovery telosb wsn430-v1_3b wsn430-v1_4 z1 + +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-relic/Makefile.include b/tests/unittests/tests-relic/Makefile.include new file mode 100644 index 0000000000..795b814440 --- /dev/null +++ b/tests/unittests/tests-relic/Makefile.include @@ -0,0 +1,8 @@ +USEPKG += relic + +# -DWORD=32 : Specifies the word width of the target system. This is +# currently not automatically detected so adjusted to your target +# platform. + +# The rest of the parameters are configuration parameters for RELIC described in its documentation. +export RELIC_CONFIG_FLAGS=-DARCH=NONE -DOPSYS=NONE -DQUIET=off -DWORD=32 -DFP_PRIME=255 -DWITH="BN;MD;DV;FP;EP;CP;BC;EC" -DSEED=ZERO diff --git a/tests/unittests/tests-relic/tests-relic.c b/tests/unittests/tests-relic/tests-relic.c new file mode 100644 index 0000000000..832755b304 --- /dev/null +++ b/tests/unittests/tests-relic/tests-relic.c @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2014 Tobias Markmann + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + + +#define TEST_RELIC_SHOW_OUTPUT (0) /**< set if encoded/decoded string is displayed */ + +#if (TEST_RELIC_SHOW_OUTPUT == 1) +#include +#endif +#include +#include + +#include "relic.h" +#include "embUnit.h" + +void print_mem(void *mem, int len) { + int i; + unsigned char *p = (unsigned char *)mem; + for (i=0;i