From a66ee39974e363da4e630521af92ed1210e7c1d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Lind=C3=A9n?= Date: Sun, 28 Apr 2019 17:56:59 +0200 Subject: [PATCH] Add support for minimal builds --- CMakeLists.txt | 51 ++++++++++++++++++++++++++------------------- test/CMakeLists.txt | 48 ++++++++++++++++++++++-------------------- 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4370f6a8..3b814c92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.11) project("sodium") option(SODIUM_DISABLE_TESTS "Disable tests" OFF) +option(SODIUM_MINIMAL "Perform a minimal build, without deprecated functions and functions that high-level APIs depend on" OFF) add_library(${PROJECT_NAME} libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c @@ -15,10 +16,7 @@ add_library(${PROJECT_NAME} libsodium/src/libsodium/crypto_box/crypto_box.c libsodium/src/libsodium/crypto_box/crypto_box_easy.c libsodium/src/libsodium/crypto_box/crypto_box_seal.c - libsodium/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c - libsodium/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c - libsodium/src/libsodium/crypto_core/ed25519/core_ed25519.c libsodium/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c libsodium/src/libsodium/crypto_core/ed25519/ref10/fe_25_5/base.h libsodium/src/libsodium/crypto_core/ed25519/ref10/fe_25_5/base2.h @@ -83,14 +81,6 @@ add_library(${PROJECT_NAME} libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c libsodium/src/libsodium/crypto_pwhash/crypto_pwhash.c - libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c - libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h - libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c - libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c - libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.h - libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c - libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c - libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c libsodium/src/libsodium/crypto_scalarmult/crypto_scalarmult.c libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.h @@ -108,21 +98,16 @@ add_library(${PROJECT_NAME} libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_namespace.h libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.h - libsodium/src/libsodium/crypto_scalarmult/ed25519/ref10/scalarmult_ed25519_ref10.c libsodium/src/libsodium/crypto_secretbox/crypto_secretbox.c libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c - libsodium/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/secretbox_xsalsa20poly1305.c libsodium/src/libsodium/crypto_secretstream/xchacha20poly1305/secretstream_xchacha20poly1305.c libsodium/src/libsodium/crypto_shorthash/crypto_shorthash.c libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphash24_ref.c libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphash_ref.h - libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphashx24_ref.c libsodium/src/libsodium/crypto_shorthash/siphash24/shorthash_siphash24.c - libsodium/src/libsodium/crypto_shorthash/siphash24/shorthash_siphashx24.c libsodium/src/libsodium/crypto_sign/crypto_sign.c libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c - libsodium/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign_ed25519_ref10.h @@ -154,11 +139,6 @@ add_library(${PROJECT_NAME} libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u1.h libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u4.h libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u8.h - libsodium/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012_ref.c - libsodium/src/libsodium/crypto_stream/salsa2012/stream_salsa2012.c - libsodium/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208_ref.c - libsodium/src/libsodium/crypto_stream/salsa208/stream_salsa208.c - libsodium/src/libsodium/crypto_stream/xchacha20/stream_xchacha20.c libsodium/src/libsodium/crypto_stream/xsalsa20/stream_xsalsa20.c libsodium/src/libsodium/crypto_verify/sodium/verify.c libsodium/src/libsodium/include/sodium.h @@ -242,6 +222,33 @@ add_library(${PROJECT_NAME} libsodium/src/libsodium/sodium/version.c ) +if(NOT SODIUM_MINIMAL) + target_sources(${PROJECT_NAME} + PRIVATE + libsodium/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c + libsodium/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c + libsodium/src/libsodium/crypto_core/ed25519/core_ed25519.c + libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c + libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h + libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c + libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c + libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.h + libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c + libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c + libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c + libsodium/src/libsodium/crypto_scalarmult/ed25519/ref10/scalarmult_ed25519_ref10.c + libsodium/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c + libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphashx24_ref.c + libsodium/src/libsodium/crypto_shorthash/siphash24/shorthash_siphashx24.c + libsodium/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c + libsodium/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012_ref.c + libsodium/src/libsodium/crypto_stream/salsa2012/stream_salsa2012.c + libsodium/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208_ref.c + libsodium/src/libsodium/crypto_stream/salsa208/stream_salsa208.c + libsodium/src/libsodium/crypto_stream/xchacha20/stream_xchacha20.c + ) +endif() + set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99 @@ -257,8 +264,10 @@ target_include_directories(${PROJECT_NAME} target_compile_definitions(${PROJECT_NAME} PUBLIC $<$>:SODIUM_STATIC> + $<$:SODIUM_LIBRARY_MINIMAL> PRIVATE $<$:SODIUM_DLL_EXPORT> + $<$:MINIMAL> ) set(VERSION 1.0.17) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 660dcb09..dbdc99d6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -104,10 +104,6 @@ make_test(test_codecs ${PROJECT_SOURCE_DIR}/libsodium/test/default/codecs.c ) -make_test(test_core_ed25519 - ${PROJECT_SOURCE_DIR}/libsodium/test/default/core_ed25519.c -) - make_test(test_core1 ${PROJECT_SOURCE_DIR}/libsodium/test/default/core1.c ) @@ -196,14 +192,6 @@ make_test(test_pwhash_argon2id ${PROJECT_SOURCE_DIR}/libsodium/test/default/pwhash_argon2id.c ) -make_test(test_pwhash_scrypt - ${PROJECT_SOURCE_DIR}/libsodium/test/default/pwhash_scrypt.c -) - -make_test(test_pwhash_scrypt_ll - ${PROJECT_SOURCE_DIR}/libsodium/test/default/pwhash_scrypt_ll.c -) - make_test(test_randombytes ${PROJECT_SOURCE_DIR}/libsodium/test/default/randombytes.c ) @@ -212,10 +200,6 @@ make_test(test_scalarmult ${PROJECT_SOURCE_DIR}/libsodium/test/default/scalarmult.c ) -make_test(test_scalarmult_ed25519 - ${PROJECT_SOURCE_DIR}/libsodium/test/default/scalarmult_ed25519.c -) - make_test(test_scalarmult2 ${PROJECT_SOURCE_DIR}/libsodium/test/default/scalarmult2.c ) @@ -272,10 +256,6 @@ make_test(test_sign ${PROJECT_SOURCE_DIR}/libsodium/test/default/sign.c ) -make_test(test_siphashx24 - ${PROJECT_SOURCE_DIR}/libsodium/test/default/siphashx24.c -) - make_test(test_sodium_core ${PROJECT_SOURCE_DIR}/libsodium/test/default/sodium_core.c ) @@ -316,6 +296,28 @@ make_test(test_verify1 ${PROJECT_SOURCE_DIR}/libsodium/test/default/verify1.c ) -make_test(test_xchacha20 - ${PROJECT_SOURCE_DIR}/libsodium/test/default/xchacha20.c -) +if(NOT SODIUM_MINIMAL) + make_test(test_core_ed25519 + ${PROJECT_SOURCE_DIR}/libsodium/test/default/core_ed25519.c + ) + + make_test(test_pwhash_scrypt + ${PROJECT_SOURCE_DIR}/libsodium/test/default/pwhash_scrypt.c + ) + + make_test(test_pwhash_scrypt_ll + ${PROJECT_SOURCE_DIR}/libsodium/test/default/pwhash_scrypt_ll.c + ) + + make_test(test_scalarmult_ed25519 + ${PROJECT_SOURCE_DIR}/libsodium/test/default/scalarmult_ed25519.c + ) + + make_test(test_siphashx24 + ${PROJECT_SOURCE_DIR}/libsodium/test/default/siphashx24.c + ) + + make_test(test_xchacha20 + ${PROJECT_SOURCE_DIR}/libsodium/test/default/xchacha20.c + ) +endif()