From 07c0ac81c7fd8cd29a74bc1f53f8d4d5cf8541de Mon Sep 17 00:00:00 2001
From: Silke Hofstra <silke@slxh.eu>
Date: Sat, 13 Oct 2018 20:39:00 +0200
Subject: [PATCH] pkg: add libb2 (BLAKE2)

---
 pkg/libb2/Makefile         | 12 ++++++++++++
 pkg/libb2/Makefile.include |  2 ++
 pkg/libb2/Makefile.libb2   | 11 +++++++++++
 pkg/libb2/doc.txt          | 37 +++++++++++++++++++++++++++++++++++++
 pkg/libb2/include/config.h | 19 +++++++++++++++++++
 5 files changed, 81 insertions(+)
 create mode 100644 pkg/libb2/Makefile
 create mode 100644 pkg/libb2/Makefile.include
 create mode 100644 pkg/libb2/Makefile.libb2
 create mode 100644 pkg/libb2/doc.txt
 create mode 100644 pkg/libb2/include/config.h

diff --git a/pkg/libb2/Makefile b/pkg/libb2/Makefile
new file mode 100644
index 0000000000..16ac11aae1
--- /dev/null
+++ b/pkg/libb2/Makefile
@@ -0,0 +1,12 @@
+PKG_NAME    = libb2
+PKG_URL     = https://github.com/BLAKE2/libb2
+PKG_VERSION = 60ea749837362c226e8501718f505ab138e5c19d # v0.98
+PKG_LICENSE = CC0-1.0
+
+.PHONY: all
+
+all: git-download
+	"$(MAKE)" -C $(PKG_BUILDDIR)/src \
+			  -f $(RIOTPKG)/libb2/Makefile.$(PKG_NAME)
+
+include $(RIOTBASE)/pkg/pkg.mk
diff --git a/pkg/libb2/Makefile.include b/pkg/libb2/Makefile.include
new file mode 100644
index 0000000000..46c0687c0b
--- /dev/null
+++ b/pkg/libb2/Makefile.include
@@ -0,0 +1,2 @@
+INCLUDES += -I$(PKGDIRBASE)/libb2/src
+INCLUDES += -I$(RIOTPKG)/libb2/include
diff --git a/pkg/libb2/Makefile.libb2 b/pkg/libb2/Makefile.libb2
new file mode 100644
index 0000000000..ec993728f8
--- /dev/null
+++ b/pkg/libb2/Makefile.libb2
@@ -0,0 +1,11 @@
+MODULE = libb2
+
+# Compiling for native triggers this warning
+CFLAGS += -Wno-unused-function
+
+SRC := blake2s-ref.c \
+       blake2b-ref.c \
+       blake2sp.c \
+       blake2bp.c
+
+include $(RIOTBASE)/Makefile.base
diff --git a/pkg/libb2/doc.txt b/pkg/libb2/doc.txt
new file mode 100644
index 0000000000..7298bc9dfd
--- /dev/null
+++ b/pkg/libb2/doc.txt
@@ -0,0 +1,37 @@
+/**
+ * @defgroup pkg_libb2 BLAKE2 hashing library
+ * @ingroup  pkg
+ * @brief    C library providing BLAKE2b, BLAKE2s, BLAKE2bp, BLAKE2sp
+
+ *
+ * # BLAKE2 RIOT package
+ *
+ * BLAKE2 is a cryptographic hash function specified in RFC 7693.
+ * It claims to be faster than MD5, SHA-1, SHA-2, and SHA-3, yet at least as
+ * secure as the latest standard SHA-3.
+ *
+ * BLAKE2 comes in two flavors:
+ *
+ * - BLAKE2b (or just BLAKE2) is optimized for 64-bit platforms—including NEON-enabled ARMs—and
+ *   produces digests of any size between 1 and 64 bytes
+ * - BLAKE2s is optimized for 8- to 32-bit platforms and produces digests of
+ *   any size between 1 and 32 bytes
+ *
+ * For more information, see the [BLAKE2 website](https://blake2.net/).
+ *
+ * ## Usage
+ *
+ * Add it as a package in your application's Makefile:
+ *
+ * ```makefile
+ * USEPKG += libb2
+ * ```
+ *
+ * Include the BLAKE2 header in your code:
+ *
+ * ```c
+ * #include "blake2.h"
+ * ```
+ *
+ * @see https://github.com/BLAKE2/libb2
+ */
diff --git a/pkg/libb2/include/config.h b/pkg/libb2/include/config.h
new file mode 100644
index 0000000000..55cc6a0e8e
--- /dev/null
+++ b/pkg/libb2/include/config.h
@@ -0,0 +1,19 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Add no suffix to the functions */
+#define SUFFIX
+
+/* Test for a little-endian machine */
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define NATIVE_LITTLE_ENDIAN
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* CONFIG_H */
-- 
GitLab