From 398d1d44d25b1c31fe882150115f332cdb57c629 Mon Sep 17 00:00:00 2001 From: Silke Hofstra Date: Thu, 20 Sep 2018 16:40:22 +0200 Subject: [PATCH] pkg: add libhydrogen --- pkg/libhydrogen/Makefile | 15 +++ pkg/libhydrogen/Makefile.dep | 1 + pkg/libhydrogen/Makefile.include | 1 + pkg/libhydrogen/Makefile.libhydrogen | 3 + pkg/libhydrogen/doc.txt | 30 ++++++ .../0001-Add-support-for-RIOT-OS.patch | Bin 0 -> 788 bytes tests/pkg_libhydrogen/Makefile | 14 +++ tests/pkg_libhydrogen/main.c | 88 ++++++++++++++++++ tests/pkg_libhydrogen/tests/01-run.py | 18 ++++ 9 files changed, 170 insertions(+) create mode 100644 pkg/libhydrogen/Makefile create mode 100644 pkg/libhydrogen/Makefile.dep create mode 100644 pkg/libhydrogen/Makefile.include create mode 100644 pkg/libhydrogen/Makefile.libhydrogen create mode 100644 pkg/libhydrogen/doc.txt create mode 100644 pkg/libhydrogen/patches/0001-Add-support-for-RIOT-OS.patch create mode 100644 tests/pkg_libhydrogen/Makefile create mode 100644 tests/pkg_libhydrogen/main.c create mode 100755 tests/pkg_libhydrogen/tests/01-run.py diff --git a/pkg/libhydrogen/Makefile b/pkg/libhydrogen/Makefile new file mode 100644 index 0000000000..12abf19121 --- /dev/null +++ b/pkg/libhydrogen/Makefile @@ -0,0 +1,15 @@ +PKG_NAME = libhydrogen +PKG_URL = https://github.com/jedisct1/libhydrogen +PKG_VERSION = 39eb529905ce118b674a7723c0d2b48074b9986d +PKG_LICENSE = ISC + +# This warning is triggered on non-32bit platforms +CFLAGS += -Wno-type-limits + +.PHONY: all + +all: git-download + "$(MAKE)" -C $(PKG_BUILDDIR) \ + -f $(RIOTPKG)/libhydrogen/Makefile.$(PKG_NAME) + +include $(RIOTBASE)/pkg/pkg.mk diff --git a/pkg/libhydrogen/Makefile.dep b/pkg/libhydrogen/Makefile.dep new file mode 100644 index 0000000000..3941d5a187 --- /dev/null +++ b/pkg/libhydrogen/Makefile.dep @@ -0,0 +1 @@ +USEMODULE += random diff --git a/pkg/libhydrogen/Makefile.include b/pkg/libhydrogen/Makefile.include new file mode 100644 index 0000000000..ff9e750134 --- /dev/null +++ b/pkg/libhydrogen/Makefile.include @@ -0,0 +1 @@ +INCLUDES += -I$(PKGDIRBASE)/libhydrogen diff --git a/pkg/libhydrogen/Makefile.libhydrogen b/pkg/libhydrogen/Makefile.libhydrogen new file mode 100644 index 0000000000..eee65bb350 --- /dev/null +++ b/pkg/libhydrogen/Makefile.libhydrogen @@ -0,0 +1,3 @@ +MODULE = libhydrogen + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/libhydrogen/doc.txt b/pkg/libhydrogen/doc.txt new file mode 100644 index 0000000000..2555e9eb16 --- /dev/null +++ b/pkg/libhydrogen/doc.txt @@ -0,0 +1,30 @@ +/** + * @defgroup pkg_libhydrogen LibHydrogen cryptographic library + * @ingroup pkg + * @brief A lightweight, secure, easy-to-use crypto library suitable for constrained environments. + * + * # LibHydrogen RIOT package + * + * The Hydrogen library is a small, easy-to-use, hard-to-misuse cryptographic + * library. It provides functions for random numbers, generic hashing, key + * derivation, secret-key encryption, public-key signatures, key exchange and + * password hashing. + * + * Full documentation can be found on the [LibHydrogen wiki](https://github.com/jedisct1/libhydrogen/wiki). + * + * ## Usage + * + * Add it as a package in your application's Makefile: + * + * ```makefile + * USEPKG += libhydrogen + * ``` + * + * Include the LibHydrogen header in your code: + * + * ```c + * #include "hydrogen.h" + * ``` + * + * @see https://github.com/jedisct1/libhydrogen + */ diff --git a/pkg/libhydrogen/patches/0001-Add-support-for-RIOT-OS.patch b/pkg/libhydrogen/patches/0001-Add-support-for-RIOT-OS.patch new file mode 100644 index 0000000000000000000000000000000000000000..2bc841db0f64e501125692e63aebc4e4ceef878e GIT binary patch literal 788 zcmaKp(QeZ)6o&8p6hA_mTBXUHw8@feRIS*iRT?W=E4V-?N@II5w04y^tOLfg<8&&J z39u|n$3Fgi&gaWYZxAM{JPxBI9>x(1SQr*@lv5gpCw`QOp$NIiSx5uC(FzN`g?|D{ z)BQw1sZTB~CdERoKXY7ZQJX5qS>1+{dc7+>-i*n4Zg`4i*$nKRJtm-j3_nVTK{}#v zs6~-Qv--pflj6hM>GJi}M@$(*-E6nIG7!4L?QFipd_joox&(5wT_0DuVtV71_zpjS z^T#0YA>^8)D06kk*`Q63s^*oETGc(LPY9Djz;*AWL4Mrjt-3Lhit!ypP~?6-^1Ps+ z3Ab8&N~6)JE$BIc*jn(MGMT_ll0gK=uGWB!%Li8J?5U4TDrtIOv}ApPc2wLnl>$8_ zcqAasOTLx@j0>qa>$N_zcNe#d+5D!Dqa(aHoMc&}`zK*@-Z1rGx-RmS5S{c4GUQ6Qx)bcCWqT5s_rGNTF{41o;jipt1 zg&)`R>3KBDt}p)c+=2DmlJjUgL)TLFes(hqtWbOK%f!9?Pkmo|<=FlmNZ|RgM+x}} DZ@KXB literal 0 HcmV?d00001 diff --git a/tests/pkg_libhydrogen/Makefile b/tests/pkg_libhydrogen/Makefile new file mode 100644 index 0000000000..4335d5144b --- /dev/null +++ b/tests/pkg_libhydrogen/Makefile @@ -0,0 +1,14 @@ +include ../Makefile.tests_common + +# AVR boards: require avr-gcc >= 7.0 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60040) +# MSP430 boards: invalid alignment of 'hydro_random_context' +BOARD_BLACKLIST := arduino-duemilanove arduino-mega2560 arduino-uno \ + jiminy-mega256rfr2 mega-xplained waspmote-pro \ + chronos msb-430 msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1 + +TEST_ON_CI_WHITELIST += all + +USEPKG += libhydrogen +USEMODULE += embunit + +include $(RIOTBASE)/Makefile.include diff --git a/tests/pkg_libhydrogen/main.c b/tests/pkg_libhydrogen/main.c new file mode 100644 index 0000000000..486e0514b5 --- /dev/null +++ b/tests/pkg_libhydrogen/main.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2018 Silke Hofstra + * + * 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. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Test the libhydrogen package + * + * @author Silke Hofstra + * + * @} + */ + +#include "embUnit.h" +#include "hydrogen.h" + +static char context[] = "examples"; +static char message[] = "0123456789abcdef"; + +/* This performs setup, but should never fail */ +static void test_hydro_init(void) +{ + TEST_ASSERT(hydro_init() == 0); +} + +/* Test public-key signatures */ +static void test_hydro_signverify(void) +{ + hydro_sign_keypair key_pair; + + hydro_sign_keygen(&key_pair); + + uint8_t signature[hydro_sign_BYTES]; + + hydro_sign_create(signature, message, sizeof message, context, key_pair.sk); + + int res = hydro_sign_verify(signature, message, sizeof message, context, key_pair.pk); + + TEST_ASSERT(res == 0); +} + +/* Test secret-key encryption */ +static void test_hydro_secretbox_encryptdecrypt(void) +{ + uint8_t key[hydro_secretbox_KEYBYTES]; + uint8_t ciphertext[hydro_secretbox_HEADERBYTES + sizeof message]; + + hydro_secretbox_keygen(key); + hydro_secretbox_encrypt(ciphertext, message, sizeof message, 0, context, key); + + char decrypted[sizeof message]; + int res = hydro_secretbox_decrypt( + decrypted, + ciphertext, + hydro_secretbox_HEADERBYTES + sizeof message, + 0, + context, + key + ); + + TEST_ASSERT(res == 0); +} + +Test *tests_libhydrogen(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(test_hydro_init), + new_TestFixture(test_hydro_signverify), + new_TestFixture(test_hydro_secretbox_encryptdecrypt), + }; + EMB_UNIT_TESTCALLER(libhydrogen_tests, NULL, NULL, fixtures); + return (Test *)&libhydrogen_tests; +} + +int main(void) +{ + TESTS_START(); + TESTS_RUN(tests_libhydrogen()); + TESTS_END(); + return 0; +} diff --git a/tests/pkg_libhydrogen/tests/01-run.py b/tests/pkg_libhydrogen/tests/01-run.py new file mode 100755 index 0000000000..a9078c0d97 --- /dev/null +++ b/tests/pkg_libhydrogen/tests/01-run.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2017 Freie Universität Berlin +# +# 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. + +import sys +from testrunner import run + + +def testfunc(child): + child.expect_exact('OK (3 tests)') + + +if __name__ == "__main__": + sys.exit(run(testfunc))