Skip to content

Commit

Permalink
Merge pull request #17161 from kaspar030/update_pkg_relic
Browse files Browse the repository at this point in the history
pkg/relic: bump to current master
  • Loading branch information
MrKevinWeiss authored Nov 10, 2021
2 parents fc4a3d3 + 55d5cde commit ff8983c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 60 deletions.
6 changes: 4 additions & 2 deletions pkg/relic/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PKG_NAME=relic
PKG_URL=https://github.com/relic-toolkit/relic.git
PKG_VERSION=0b0442a8218df8d309266923f2dd5b9ae3b318ce
PKG_VERSION=e3f82e36250b228f3b4646781f6e06a8be497d18
PKG_LICENSE=LGPL-2.1

PKG_CUSTOM_PREPARED = $(BINDIR)/pkg-build/$(PKG_NAME)/include
Expand All @@ -11,7 +11,9 @@ include $(RIOTBASE)/pkg/pkg.mk

CMAKE_MINIMAL_VERSION = 3.6.0

CFLAGS += -Wno-gnu-zero-variadic-macro-arguments -Wno-unused-function -Wno-newline-eof
CFLAGS += -Wno-unused-function -Wno-old-style-definition -Wno-unused-parameter \
-Wno-pedantic -Wno-array-parameter -Wno-unused-but-set-variable \
-Wno-stringop-overflow

TOOLCHAIN_FILE = $(PKG_SOURCE_DIR)/xcompile-toolchain.cmake

Expand Down
15 changes: 8 additions & 7 deletions pkg/relic/patches/0001-use-modul-random-for-seeding.patch
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
From 7a93775269a7bfc8f01aef9bf4af9760b11504b2 Mon Sep 17 00:00:00 2001
From 14b985c86fd0f97b186adc445c224794c3c1b97b Mon Sep 17 00:00:00 2001
From: maksim-ka <42pema1bif@hft-stuttgart.de>
Date: Fri, 31 Jan 2020 15:15:46 +0100
Subject: [PATCH 1/2] use modul random for seeding

---
src/rand/relic_rand_core.c | 4 ++++
1 file changed, 4 insertions(+)
src/rand/relic_rand_core.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/rand/relic_rand_core.c b/src/rand/relic_rand_core.c
index 5f453802..3e62c7fd 100644
index 10f8929f..804b4455 100644
--- a/src/rand/relic_rand_core.c
+++ b/src/rand/relic_rand_core.c
@@ -159,6 +159,10 @@ void rand_init(void) {
@@ -171,6 +171,11 @@ void rand_init(void) {
}
}

+#elif SEED == RIOTRND && defined(MODULE_RANDOM)
+
+ random_bytes(buf,SEED_SIZE);
+ void random_bytes(uint8_t *buf, size_t size);
+ random_bytes(buf, RLC_RAND_SEED);
+
#endif

#endif /* RAND == UDEV */
--
2.24.1
2.33.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
From ce1cd836aafefa92c3138f3e923147a42e95c886 Mon Sep 17 00:00:00 2001
From: Kaspar Schleiser <kaspar@schleiser.de>
Date: Mon, 8 Nov 2021 22:37:38 +0100
Subject: [PATCH 2/2] add RIOT random support to cmake and relic_conf.h

---
cmake/rand.cmake | 1 +
include/relic_conf.h.in | 2 ++
2 files changed, 3 insertions(+)

diff --git a/cmake/rand.cmake b/cmake/rand.cmake
index ed90c769..9f79fd6d 100644
--- a/cmake/rand.cmake
+++ b/cmake/rand.cmake
@@ -12,6 +12,7 @@ message(" SEED=LIBC Use rand()/random() functions. (insecure!)")
message(" SEED=RDRND Use Intel RdRand instruction directly.")
message(" SEED=UDEV Use non-blocking /dev/urandom. (recommended)")
message(" SEED=WCGR Use Windows' CryptGenRandom. (recommended)\n")
+message(" SEED=RIOTRND Use RIOT's random module for seeding. (recommended on RIOT)")

# Choose the pseudo-random number generator.
set(RAND "HASHD" CACHE STRING "Pseudo-random number generator")
diff --git a/include/relic_conf.h.in b/include/relic_conf.h.in
index 1245edc0..4e807621 100644
--- a/include/relic_conf.h.in
+++ b/include/relic_conf.h.in
@@ -656,6 +656,8 @@
#define UDEV 3
/** Use Windows' CryptGenRandom. */
#define WCGR 4
+/** Use RIOT's random module for seeding */
+#define RIOTRND 5
/** Chosen random generator seeder. */
#cmakedefine SEED @SEED@

--
2.33.1

38 changes: 0 additions & 38 deletions pkg/relic/patches/0002-add-flag-to-help-message.patch

This file was deleted.

4 changes: 2 additions & 2 deletions tests/pkg_relic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(5*THREAD_STACKSIZE_DEFAULT\)
USEPKG += relic
USEMODULE += embunit

# -DWORD=32 : Specifies the word width of the target system. This is
# -DWSIZE=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=RIOTRND
export RELIC_CONFIG_FLAGS=-DARCH=NONE -DOPSYS=NONE -DQUIET=off -DWSIZE=32 -DFP_PRIME=255 -DWITH="BN;MD;DV;FP;EP;CP;BC;EC" -DSEED=RIOTRND

include $(RIOTBASE)/Makefile.include
2 changes: 2 additions & 0 deletions tests/pkg_relic/Makefile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ BOARD_INSUFFICIENT_MEMORY := \
nucleo-f030r8 \
nucleo-f031k6 \
nucleo-f042k6 \
nucleo-f303k8 \
nucleo-f334r8 \
nucleo-l011k4 \
nucleo-l031k6 \
nucleo-l053r8 \
Expand Down
22 changes: 11 additions & 11 deletions tests/pkg_relic/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void print_mem(void *mem, int len) {
static void setUp(void)
{
/* Initialize RELIC */
TEST_ASSERT_EQUAL_INT(STS_OK, core_init());
TEST_ASSERT_EQUAL_INT(RLC_OK, core_init());
}

static void tearDown(void)
Expand All @@ -44,18 +44,18 @@ static void tests_relic_ecdh(void)
*/

/* Select an elliptic curve configuration */
if (ec_param_set_any() == STS_OK) {
if (ec_param_set_any() == RLC_OK) {
#if (TEST_RELIC_SHOW_OUTPUT == 1)
ec_param_print();
#endif

bn_t privateA;
ec_t publicA;
uint8_t sharedKeyA[MD_LEN];
uint8_t sharedKeyA[RLC_MD_LEN];

bn_t privateB;
ec_t publicB;
uint8_t sharedKeyB[MD_LEN];
uint8_t sharedKeyB[RLC_MD_LEN];

bn_null(privateA);
ec_null(publicA);
Expand All @@ -70,7 +70,7 @@ static void tests_relic_ecdh(void)
ec_new(publicB);

/* User A generates private/public key pair */
TEST_ASSERT_EQUAL_INT(STS_OK, cp_ecdh_gen(privateA, publicA));
TEST_ASSERT_EQUAL_INT(RLC_OK, cp_ecdh_gen(privateA, publicA));

#if (TEST_RELIC_SHOW_OUTPUT == 1)
printf("User A\n");
Expand All @@ -83,7 +83,7 @@ static void tests_relic_ecdh(void)
#endif

/* User B generates private/public key pair */
TEST_ASSERT_EQUAL_INT(STS_OK, cp_ecdh_gen(privateB, publicB));
TEST_ASSERT_EQUAL_INT(RLC_OK, cp_ecdh_gen(privateB, publicB));

#if (TEST_RELIC_SHOW_OUTPUT == 1)
printf("User B\n");
Expand All @@ -98,23 +98,23 @@ static void tests_relic_ecdh(void)
/* In a protocol you would exchange the public keys now */

/* User A calculates shared secret */
TEST_ASSERT_EQUAL_INT(STS_OK, cp_ecdh_key(sharedKeyA, MD_LEN, privateA, publicB));
TEST_ASSERT_EQUAL_INT(RLC_OK, cp_ecdh_key(sharedKeyA, RLC_MD_LEN, privateA, publicB));

#if (TEST_RELIC_SHOW_OUTPUT == 1)
printf("\nshared key computed by user A: ");
print_mem(sharedKeyA, MD_LEN);
print_mem(sharedKeyA, RLC_MD_LEN);
#endif

/* User B calculates shared secret */
TEST_ASSERT_EQUAL_INT(STS_OK, cp_ecdh_key(sharedKeyB, MD_LEN, privateB, publicA));
TEST_ASSERT_EQUAL_INT(RLC_OK, cp_ecdh_key(sharedKeyB, RLC_MD_LEN, privateB, publicA));

#if (TEST_RELIC_SHOW_OUTPUT == 1)
printf("\nshared key computed by user B: ");
print_mem(sharedKeyB, MD_LEN);
print_mem(sharedKeyB, RLC_MD_LEN);
#endif

/* The secrets should be the same now */
TEST_ASSERT_EQUAL_INT(CMP_EQ, util_cmp_const(sharedKeyA, sharedKeyB, MD_LEN));
TEST_ASSERT_EQUAL_INT(RLC_EQ, util_cmp_const(sharedKeyA, sharedKeyB, RLC_MD_LEN));

bn_free(privateA);
ec_free(publicA);
Expand Down

0 comments on commit ff8983c

Please sign in to comment.