Move sha256.c to lib/

Precompiled headers don't work if we're not a pure C++ project.
This commit is contained in:
Desour 2023-03-25 21:40:17 +01:00 committed by DS
parent 3120558dd1
commit cdbbac5b6d
9 changed files with 27 additions and 10 deletions

@ -277,6 +277,7 @@ find_package(Lua REQUIRED)
if(NOT USE_LUAJIT) if(NOT USE_LUAJIT)
add_subdirectory(lib/bitop) add_subdirectory(lib/bitop)
endif() endif()
add_subdirectory(lib/sha256)
if(BUILD_UNITTESTS OR BUILD_BENCHMARKS) if(BUILD_UNITTESTS OR BUILD_BENCHMARKS)
add_subdirectory(lib/catch2) add_subdirectory(lib/catch2)

14
lib/sha256/CMakeLists.txt Normal file

@ -0,0 +1,14 @@
project(sha256 C)
add_library(sha256 STATIC sha256.c)
target_include_directories(sha256 INTERFACE .)
INCLUDE(CheckIncludeFiles)
check_include_files(endian.h HAVE_ENDIAN_H)
configure_file(
"${PROJECT_SOURCE_DIR}/cmake_config.h.in"
"${PROJECT_BINARY_DIR}/cmake_config.h"
)
target_include_directories(sha256 PRIVATE "${PROJECT_BINARY_DIR}")

@ -0,0 +1,5 @@
// Filled in by the build system
#pragma once
#cmakedefine HAVE_ENDIAN_H

@ -56,17 +56,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "util/sha256.h" #include "sha256/sha256.h"
#if defined(_MSC_VER) && !defined(__clang__) && !defined(__attribute__) #if defined(_MSC_VER) && !defined(__clang__) && !defined(__attribute__)
#define __attribute__(a) #define __attribute__(a)
#endif #endif
/* pull HAVE_ENDIAN_H from Minetest */ #include "cmake_config.h" /* HAVE_ENDIAN_H */
#include "config.h"
#if !HAVE_ENDIAN_H
#undef HAVE_ENDIAN_H
#endif
/** endian.h **/ /** endian.h **/
/* /*

@ -565,6 +565,7 @@ if(BUILD_CLIENT)
${GMP_LIBRARY} ${GMP_LIBRARY}
${JSON_LIBRARY} ${JSON_LIBRARY}
${LUA_BIT_LIBRARY} ${LUA_BIT_LIBRARY}
sha256
${FREETYPE_LIBRARY} ${FREETYPE_LIBRARY}
${PLATFORM_LIBS} ${PLATFORM_LIBS}
# on Android, Minetest depends on SDL2 directly # on Android, Minetest depends on SDL2 directly
@ -637,6 +638,7 @@ if(BUILD_SERVER)
${JSON_LIBRARY} ${JSON_LIBRARY}
${LUA_LIBRARY} ${LUA_LIBRARY}
${LUA_BIT_LIBRARY} ${LUA_BIT_LIBRARY}
sha256
${GMP_LIBRARY} ${GMP_LIBRARY}
${PLATFORM_LIBS} ${PLATFORM_LIBS}
) )

@ -42,7 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "version.h" #include "version.h"
#include "util/hex.h" #include "util/hex.h"
#include "util/sha1.h" #include "util/sha1.h"
#include "util/sha256.h" #include <sha256/sha256.h>
#include "util/png.h" #include "util/png.h"
#include <cstdio> #include <cstdio>
@ -573,7 +573,7 @@ int ModApiUtil::l_sha256(lua_State *L)
auto data = readParam<std::string_view>(L, 1); auto data = readParam<std::string_view>(L, 1);
bool hex = !lua_isboolean(L, 2) || !readParam<bool>(L, 2); bool hex = !lua_isboolean(L, 2) || !readParam<bool>(L, 2);
std::string data_sha256; std::string data_sha256;
data_sha256.resize(SHA256_DIGEST_LENGTH); data_sha256.resize(SHA256_DIGEST_LENGTH);
SHA256(reinterpret_cast<const unsigned char*>(data.data()), data.size(), SHA256(reinterpret_cast<const unsigned char*>(data.data()), data.size(),

@ -13,7 +13,6 @@ set(UTIL_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/quicktune.cpp ${CMAKE_CURRENT_SOURCE_DIR}/quicktune.cpp
${CMAKE_CURRENT_SOURCE_DIR}/serialize.cpp ${CMAKE_CURRENT_SOURCE_DIR}/serialize.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sha1.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sha1.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sha256.c
${CMAKE_CURRENT_SOURCE_DIR}/string.cpp ${CMAKE_CURRENT_SOURCE_DIR}/string.cpp
${CMAKE_CURRENT_SOURCE_DIR}/srp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/srp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timetaker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/timetaker.cpp

@ -50,7 +50,7 @@
#include <mini-gmp.h> #include <mini-gmp.h>
#endif #endif
#include "util/sha256.h" #include <sha256/sha256.h>
#include "srp.h" #include "srp.h"
//#define CSRP_USE_SHA1 //#define CSRP_USE_SHA1