commit aa7e4cce8e7208a6128054d1917eba0a749fe1f7 Author: Jōshin Date: Tue Dec 25 19:44:59 2018 -0800 Initial diff --git a/README.md b/README.md new file mode 100644 index 0000000000..9d7469c59a --- /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 0000000000..9eb0e029c1 --- /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 0000000000..c06020dca1 --- /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 0000000000..8b660c4cd8 --- /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 0000000000..4f0ec721b3 --- /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); +}