From 8679e717dbdd782d531e0ab647543e7277048a83 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 6 Mar 2017 09:47:09 +0100 Subject: [PATCH] + sodium_library_minimal() and SODIUM_LIBRARY_MINIMAL --- ChangeLog | 1 + builds/msvc/version.h | 3 +++ configure.ac | 2 ++ src/libsodium/include/sodium.h | 18 +++++++++++------- .../sodium/crypto_shorthash_siphash24.h | 2 ++ src/libsodium/include/sodium/version.h.in | 4 ++++ src/libsodium/sodium/version.c | 10 ++++++++++ test/default/sodium_version.c | 5 +++++ 8 files changed, 38 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4378578c..85e38f71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,6 +30,7 @@ function can especially be useful to write reproducible tests. - `contrib/Findsodium.cmake` was added as an example to include libsodium in a project using cmake. - Compatibility with gcc 2.x has been restored. + - Minimal builds can be checked using `sodium_library_minimal()`. * Version 1.0.11 - `sodium_init()` is now thread-safe, and can be safely called multiple diff --git a/builds/msvc/version.h b/builds/msvc/version.h index 3e6f2612..cc958cc1 100644 --- a/builds/msvc/version.h +++ b/builds/msvc/version.h @@ -22,6 +22,9 @@ int sodium_library_version_major(void); SODIUM_EXPORT int sodium_library_version_minor(void); +SODIUM_EXPORT +int sodium_library_minimal(void); + #ifdef __cplusplus } #endif diff --git a/configure.ac b/configure.ac index 31b1c53e..2dc6cb2e 100644 --- a/configure.ac +++ b/configure.ac @@ -102,6 +102,7 @@ AC_ARG_ENABLE(minimal, [ AS_IF([test "x$enableval" = "xyes"], [ enable_minimal="yes" + SODIUM_LIBRARY_MINIMAL_DEF="#define SODIUM_LIBRARY_MINIMAL 1" AC_DEFINE([MINIMAL], [1], [Define for a minimal build, without deprecated functions and functions that high-level APIs depend on]) ], [ enable_minimal="no" @@ -111,6 +112,7 @@ AC_ARG_ENABLE(minimal, enable_minimal="no" ]) AM_CONDITIONAL([MINIMAL], [test x$enable_minimal = xyes]) +AC_SUBST(SODIUM_LIBRARY_MINIMAL_DEF) AC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads], [use pthreads library, or --without-pthreads to disable threading support.]), diff --git a/src/libsodium/include/sodium.h b/src/libsodium/include/sodium.h index 02cfe6e6..043e0c3f 100644 --- a/src/libsodium/include/sodium.h +++ b/src/libsodium/include/sodium.h @@ -2,6 +2,8 @@ #ifndef sodium_H #define sodium_H +#include "sodium/version.h" + #include "sodium/core.h" #include "sodium/crypto_aead_aes256gcm.h" #include "sodium/crypto_aead_chacha20poly1305.h" @@ -11,7 +13,6 @@ #include "sodium/crypto_auth_hmacsha512.h" #include "sodium/crypto_auth_hmacsha512256.h" #include "sodium/crypto_box.h" -#include "sodium/crypto_box_curve25519xchacha20poly1305.h" #include "sodium/crypto_box_curve25519xsalsa20poly1305.h" #include "sodium/crypto_core_hsalsa20.h" #include "sodium/crypto_core_hchacha20.h" @@ -34,18 +35,13 @@ #include "sodium/crypto_scalarmult_curve25519.h" #include "sodium/crypto_secretbox.h" #include "sodium/crypto_secretbox_xsalsa20poly1305.h" -#include "sodium/crypto_secretbox_xchacha20poly1305.h" #include "sodium/crypto_shorthash.h" #include "sodium/crypto_shorthash_siphash24.h" #include "sodium/crypto_sign.h" #include "sodium/crypto_sign_ed25519.h" #include "sodium/crypto_stream.h" -#include "sodium/crypto_stream_aes128ctr.h" #include "sodium/crypto_stream_chacha20.h" #include "sodium/crypto_stream_salsa20.h" -#include "sodium/crypto_stream_salsa2012.h" -#include "sodium/crypto_stream_salsa208.h" -#include "sodium/crypto_stream_xchacha20.h" #include "sodium/crypto_stream_xsalsa20.h" #include "sodium/crypto_verify_16.h" #include "sodium/crypto_verify_32.h" @@ -58,6 +54,14 @@ #include "sodium/randombytes_sysrandom.h" #include "sodium/runtime.h" #include "sodium/utils.h" -#include "sodium/version.h" + +#ifndef SODIUM_LIBRARY_MINIMAL +# include "sodium/crypto_box_curve25519xchacha20poly1305.h" +# include "sodium/crypto_secretbox_xchacha20poly1305.h" +# include "sodium/crypto_stream_aes128ctr.h" +# include "sodium/crypto_stream_salsa2012.h" +# include "sodium/crypto_stream_salsa208.h" +# include "sodium/crypto_stream_xchacha20.h" +#endif #endif diff --git a/src/libsodium/include/sodium/crypto_shorthash_siphash24.h b/src/libsodium/include/sodium/crypto_shorthash_siphash24.h index c2d469ec..745ed48f 100644 --- a/src/libsodium/include/sodium/crypto_shorthash_siphash24.h +++ b/src/libsodium/include/sodium/crypto_shorthash_siphash24.h @@ -25,6 +25,7 @@ SODIUM_EXPORT int crypto_shorthash_siphash24(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k); +#ifndef SODIUM_LIBRARY_MINIMAL /* -- 128-bit output -- */ #define crypto_shorthash_siphashx24_BYTES 16U @@ -38,6 +39,7 @@ size_t crypto_shorthash_siphashx24_keybytes(void); SODIUM_EXPORT int crypto_shorthash_siphashx24(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k); +#endif #ifdef __cplusplus } diff --git a/src/libsodium/include/sodium/version.h.in b/src/libsodium/include/sodium/version.h.in index ef230efc..8a72044b 100644 --- a/src/libsodium/include/sodium/version.h.in +++ b/src/libsodium/include/sodium/version.h.in @@ -8,6 +8,7 @@ #define SODIUM_LIBRARY_VERSION_MAJOR @SODIUM_LIBRARY_VERSION_MAJOR@ #define SODIUM_LIBRARY_VERSION_MINOR @SODIUM_LIBRARY_VERSION_MINOR@ +@SODIUM_LIBRARY_MINIMAL_DEF@ #ifdef __cplusplus extern "C" { @@ -22,6 +23,9 @@ int sodium_library_version_major(void); SODIUM_EXPORT int sodium_library_version_minor(void); +SODIUM_EXPORT +int sodium_library_minimal(void); + #ifdef __cplusplus } #endif diff --git a/src/libsodium/sodium/version.c b/src/libsodium/sodium/version.c index 4083c812..4e584a6e 100644 --- a/src/libsodium/sodium/version.c +++ b/src/libsodium/sodium/version.c @@ -18,3 +18,13 @@ sodium_library_version_minor(void) { return SODIUM_LIBRARY_VERSION_MINOR; } + +int +sodium_library_minimal(void) +{ +#ifdef SODIUM_LIBRARY_MINIMAL + return 1; +#else + return 0; +#endif +} diff --git a/test/default/sodium_version.c b/test/default/sodium_version.c index 1f9e335a..2a8fddbd 100644 --- a/test/default/sodium_version.c +++ b/test/default/sodium_version.c @@ -8,6 +8,11 @@ main(void) printf("%d\n", sodium_version_string() != NULL); printf("%d\n", sodium_library_version_major() > 0); printf("%d\n", sodium_library_version_minor() >= 0); +#ifdef SODIUM_LIBRARY_MINIMAL + assert(sodium_library_minimal() == 1); +#else + assert(sodium_library_minimal() == 0); +#endif return 0; }