1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pkg: add libhydrogen

This commit is contained in:
Silke Hofstra 2018-09-20 16:40:22 +02:00
parent ef4bd75412
commit 398d1d44d2
9 changed files with 170 additions and 0 deletions

15
pkg/libhydrogen/Makefile Normal file
View File

@ -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

View File

@ -0,0 +1 @@
USEMODULE += random

View File

@ -0,0 +1 @@
INCLUDES += -I$(PKGDIRBASE)/libhydrogen

View File

@ -0,0 +1,3 @@
MODULE = libhydrogen
include $(RIOTBASE)/Makefile.base

30
pkg/libhydrogen/doc.txt Normal file
View File

@ -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
*/

View File

@ -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

View File

@ -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 <silke@slxh.eu>
*
* @}
*/
#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;
}

View File

@ -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))