From aa7e4cce8e7208a6128054d1917eba0a749fe1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Tue, 25 Dec 2018 19:44:59 -0800 Subject: [PATCH] Initial --- README.md | 4 ++++ include/ent/detail.h | 26 ++++++++++++++++++++++++++ include/ent/ent.h | 12 ++++++++++++ meson.build | 21 +++++++++++++++++++++ src/ent.c | 17 +++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 README.md create mode 100644 include/ent/detail.h create mode 100644 include/ent/ent.h create mode 100644 meson.build create mode 100644 src/ent.c diff --git a/README.md b/README.md new file mode 100644 index 000000000..9d7469c59 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +libent is a simple cross-platform entropy gathering library. It tries +to use the best available source of randomness, and is meant to be used +in applications that need high-quality entropy, e.g. for generating +cryptographic keys. diff --git a/include/ent/detail.h b/include/ent/detail.h new file mode 100644 index 000000000..9eb0e029c --- /dev/null +++ b/include/ent/detail.h @@ -0,0 +1,26 @@ +#ifndef _LIBENT_DETAIL_H +#define _LIBENT_DETAIL_H + +#if defined _WIN32 || defined __CYGWIN__ +# ifdef WIN_EXPORT +# ifdef __GNUC__ +# define ENT_EXPORT __attribute__ ((dllexport)) +# else +# define ENT_EXPORT __declspec(dllexport) +# endif +# else +# ifdef __GNUC__ +# define ENT_EXPORT __attribute__ ((dllimport)) +# else +# define ENT_EXPORT __declspec(dllimport) +# endif +# endif +#else +# if __GNUC__ >= 4 +# define ENT_EXPORT __attribute__ ((visibility ("default"))) +# else +# define ENT_EXPORT +# endif +#endif + +#endif /* _LIBENT_DETAIL_H */ diff --git a/include/ent/ent.h b/include/ent/ent.h new file mode 100644 index 000000000..c06020dca --- /dev/null +++ b/include/ent/ent.h @@ -0,0 +1,12 @@ +#ifndef _LIBENT_ENT_H +#define _LIBENT_ENT_H + +#include + +#include + +ENT_EXPORT +int +ent_getentropy(void *buf, size_t buflen); + +#endif /* _LIBENT_ENT_H */ diff --git a/meson.build b/meson.build new file mode 100644 index 000000000..8b660c4cd --- /dev/null +++ b/meson.build @@ -0,0 +1,21 @@ +project('libent', 'c', 'cpp', + default_options : ['c_std=c99', 'cpp_std=c++11'], + version : '0.0.1', + license : 'MIT') + +inc = include_directories('include') + +install_headers('include/ent/ent.h', subdir : 'ent') + +ent_sources = ['src/ent.c'] +libent = shared_library('ent', + ent_sources, + include_directories : inc, + install : true) + +pkg_mod = import('pkgconfig') +pkg_mod.generate(libraries : libent, + version : '0.0', + name : 'libent', + filebase : 'ent', + description : 'A library to get entropy.') diff --git a/src/ent.c b/src/ent.c new file mode 100644 index 000000000..4f0ec721b --- /dev/null +++ b/src/ent.c @@ -0,0 +1,17 @@ +#include + +#if defined __OPENBSD__ || (defined __linux__ && defined _DEFAULT_SOURCE) +# include +# define getentropy_impl getentropy +#elif defined __APPLE__ && defined __MACH__ +# include +# define getentropy_impl getentropy +#else +# error "Port: getentropy unimplemented" +#endif + +int +ent_getentropy(void *buf, size_t buflen) +{ + return getentropy_impl(buf, buflen); +}