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

Initial HACL* package and tests

This commit is contained in:
Benjamin Beurdouche 2018-04-14 13:43:27 +02:00
parent 8395bde01d
commit 1d3207f38b
11 changed files with 199 additions and 0 deletions

12
pkg/hacl/Makefile Normal file
View File

@ -0,0 +1,12 @@
PKG_NAME=hacl
PKG_URL=https://github.com/mitls/hacl-c
PKG_VERSION=aac05f5094fc92569169d5a2af54c12387160634
PKG_LICENSE=MIT
.PHONY: all
all: git-download
@cp $(RIOTBASE)/pkg/hacl/src/* $(PKG_BUILDDIR)
"$(MAKE)" -C $(PKG_BUILDDIR) -f $(CURDIR)/Makefile.$(PKG_NAME)
include $(RIOTBASE)/pkg/pkg.mk

1
pkg/hacl/Makefile.dep Normal file
View File

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

5
pkg/hacl/Makefile.hacl Normal file
View File

@ -0,0 +1,5 @@
MODULE=hacl
include $(RIOTBASE)/Makefile.base
CFLAGS += -DKRML_NOUINT128 -Wno-unused-parameter

View File

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

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

@ -0,0 +1,30 @@
/**
* @defgroup pkg_hacl HACL* High Assurance Cryptographic Library
* @ingroup pkg
* @ingroup sys_crypto
* @brief Support for HACL* (High Assurance Cryptographic Library)
*
* # HACL* RIOT package
*
* ## Usage
*
* Just add it as a package in your application:
*
* ```makefile
* USEPKG += hacl
* ```
*
* And don't forget to include the header for the HACL* standard API:
*
* ```c
* #include <HACL.h>
* ```
* or for HACL*'s NaCl-compatible API:
*
* ```c
* #include <haclnacl.h>
* ```
*
* @see https://github.com/mitls/hacl-c
*/

View File

@ -0,0 +1,18 @@
/*
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
*
* 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.
*/
#include <stdint.h>
#include "random.h"
void randombytes(uint8_t *target, uint64_t n)
{
/* HACL* (haclnacl.c) needs uint64_t as "n" parameter, random provides uint32 */
random_bytes(target, n);
}

View File

@ -214,6 +214,7 @@ ifneq (, $(filter $(AVR_BOARDS), $(BOARD)))
LARGE_STACK_TESTS += tests-qDSA
endif
LARGE_STACK_TESTS += tests-hacl
LARGE_STACK_TESTS += tests-tweetnacl
ifneq (,$(filter $(LARGE_STACK_TESTS), $(UNIT_TESTS)))
CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(4*THREAD_STACKSIZE_DEFAULT+THREAD_EXTRA_STACKSIZE_PRINTF\)

View File

@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,2 @@
USEMODULE += random
USEPKG += hacl

View File

@ -0,0 +1,90 @@
/*
* Copyright (C) 2018 INRIA
*
* 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 unittests
* @{
*
* @file
* @brief HACL* crypto library tests
*
* @author Benjamin Beurdouche <benjamin.beurdouche@inria.fr>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Martin Landsmann <Martin.Landsmann@HAW-Hamburg.de>
*
* @}
*/
#include <string.h>
#include <haclnacl.h>
#include "embUnit.h"
#include "tests-hacl.h"
static const char message[] = "0123456789abcdef";
static char r[sizeof(message)];
#define MLEN (sizeof(message) + crypto_box_ZEROBYTES)
static unsigned char alice_pk[crypto_box_PUBLICKEYBYTES];
static unsigned char alice_sk[crypto_box_SECRETKEYBYTES];
static unsigned char bob_pk[crypto_box_PUBLICKEYBYTES];
static unsigned char bob_sk[crypto_box_SECRETKEYBYTES];
static unsigned char m[MLEN];
static unsigned char c[MLEN];
static const unsigned char n[crypto_box_NONCEBYTES];
static unsigned char result[MLEN];
static void setUp(void)
{
/* Initialize */
random_init(0);
}
static void test_hacl_01(void)
{
int res;
/* Creating keypair ALICE... */
crypto_box_keypair(alice_pk, alice_sk);
/* Creating keypair BOB... */
crypto_box_keypair(bob_pk, bob_sk);
memset(m, 0, crypto_box_ZEROBYTES);
memcpy(m + crypto_box_ZEROBYTES, message, MLEN - crypto_box_ZEROBYTES);
/* Encrypting using pk_bob... */
crypto_box(c, m, MLEN, n, bob_pk, alice_sk);
memset(result, '\0', sizeof(result));
/* Decrypting... */
res = crypto_box_open(result, c, MLEN, n, alice_pk, bob_sk);
TEST_ASSERT_EQUAL_INT(0, res);
memset(r, 0, sizeof(r));
memcpy(r, result + crypto_box_ZEROBYTES, MLEN - crypto_box_ZEROBYTES);
TEST_ASSERT_EQUAL_STRING((const char*)message, (const char*)r);
}
Test *tests_hacl_all(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_hacl_01)
};
EMB_UNIT_TESTCALLER(hacl_tests, setUp, NULL, fixtures);
return (Test*)&hacl_tests;
}
void tests_hacl(void)
{
TESTS_RUN(tests_hacl_all());
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2018 INRIA
*
* 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.
*/
/**
* @addtogroup unittests
* @{
*
* @file
* @brief Unittests for the ``hacl`` package
*
* @author Benjamin Beurdouche <benjamin.beurdouche@inria.fr>
*/
#ifndef TESTS_HACL_H
#define TESTS_HACL_H
#include "embUnit/embUnit.h"
#include "random.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief The entry point of this test suite.
*/
void tests_hacl(void);
#ifdef __cplusplus
}
#endif
#endif /* TESTS_HACL_H */
/** @} */