mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
change from botan to cryptopp
This commit is contained in:
parent
e0ce0fb279
commit
b9a02916cf
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -27,3 +27,6 @@
|
|||
url = https://github.com/madler/zlib.git
|
||||
branch = develop
|
||||
ignore = dirty
|
||||
[submodule "third-party/cryptopp"]
|
||||
path = third-party/cryptopp
|
||||
url = https://github.com/weidai11/cryptopp
|
||||
|
|
|
@ -4,6 +4,15 @@ project(${LIBRARY_NAME} VERSION ${LIBRARY_VERSION} LANGUAGES CXX C)
|
|||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party ${CMAKE_CURRENT_BINARY_DIR}/third-party)
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(cryptopp
|
||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../third-party/cryptopp
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/cryptopp
|
||||
INSTALL_COMMAND ""
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND "")
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/cryptopp ${CMAKE_CURRENT_BINARY_DIR}/cryptopp EXCLUDE_FROM_ALL)
|
||||
|
||||
if(APPLE)
|
||||
option(FRAMEWORK "Set to ON to package dylib and headers into a .framework, OSX only" OFF)
|
||||
endif()
|
||||
|
@ -75,8 +84,8 @@ include_directories(${XLNT_INCLUDE_DIR}
|
|||
${THIRD_PARTY_DIR}/libstudxml
|
||||
${THIRD_PARTY_DIR}/utfcpp/source
|
||||
${THIRD_PARTY_DIR}/pole
|
||||
${THIRD_PARTY_DIR}/botan
|
||||
${THIRD_PARTY_DIR}/zlib)
|
||||
${THIRD_PARTY_DIR}/zlib
|
||||
${THIRD_PARTY_DIR}/cryptopp)
|
||||
|
||||
file(GLOB ROOT_HEADERS ${XLNT_INCLUDE_DIR}/xlnt/*.hpp)
|
||||
file(GLOB CELL_HEADERS ${XLNT_INCLUDE_DIR}/xlnt/cell/*.hpp)
|
||||
|
@ -112,7 +121,7 @@ set(XLNT_SOURCES ${CELL_SOURCES} ${CHARTS_SOURCES} ${CHARTSHEET_SOURCES}
|
|||
${WORKSHEET_SOURCES} ${DETAIL_SOURCES})
|
||||
|
||||
if(NOT STATIC)
|
||||
add_library(xlnt SHARED ${XLNT_HEADERS} ${XLNT_SOURCES} $<TARGET_OBJECTS:xlnt.third-party>)
|
||||
add_library(xlnt SHARED ${XLNT_HEADERS} ${XLNT_SOURCES} $<TARGET_OBJECTS:xlnt.third-party> $<TARGET_OBJECTS:cryptopp-object>)
|
||||
target_compile_definitions(xlnt PRIVATE XLNT_SHARED=1)
|
||||
|
||||
if(MSVC)
|
||||
|
@ -142,7 +151,7 @@ if(NOT STATIC)
|
|||
)
|
||||
endif()
|
||||
else()
|
||||
add_library(xlnt STATIC ${XLNT_HEADERS} ${XLNT_SOURCES} $<TARGET_OBJECTS:xlnt.third-party>)
|
||||
add_library(xlnt STATIC ${XLNT_HEADERS} ${XLNT_SOURCES} $<TARGET_OBJECTS:xlnt.third-party> $<TARGET_OBJECTS:cryptopp-object>)
|
||||
target_compile_definitions(xlnt PUBLIC XLNT_STATIC=1)
|
||||
|
||||
if(MSVC)
|
||||
|
|
|
@ -27,7 +27,16 @@
|
|||
#pragma clang diagnostic ignored "-Wdocumentation"
|
||||
#pragma clang diagnostic ignored "-Wweak-vtables"
|
||||
#pragma clang diagnostic ignored "-Wconversion"
|
||||
#pragma clang diagnostic ignored "-Wundef"
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||
#pragma clang diagnostic ignored "-Wdeprecated"
|
||||
#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
|
||||
#pragma clang diagnostic ignored "-Wextra-semi"
|
||||
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||
|
||||
#include <botan_all.h>
|
||||
#include <aes.h>
|
||||
#include <base64.h>
|
||||
#include <modes.h>
|
||||
#include <sha.h>
|
||||
|
||||
#pragma clang diagnostic pop
|
|
@ -24,7 +24,7 @@
|
|||
#include <array>
|
||||
|
||||
#include <detail/constants.hpp>
|
||||
#include <detail/include_botan.hpp>
|
||||
#include <detail/include_cryptopp.hpp>
|
||||
#include <detail/include_libstudxml.hpp>
|
||||
#include <detail/pole.hpp>
|
||||
#include <detail/vector_streambuf.hpp>
|
||||
|
@ -129,34 +129,68 @@ struct crypto_helper
|
|||
const std::vector<std::uint8_t> &encrypted,
|
||||
cipher_chaining chaining, cipher_direction direction)
|
||||
{
|
||||
std::string cipher_name("AES-");
|
||||
cipher_name.append(std::to_string(key.size() * 8));
|
||||
cipher_name.append(chaining == cipher_chaining::ecb
|
||||
? "/ECB/NoPadding" : "/CBC/NoPadding");
|
||||
std::vector<std::uint8_t> destination(encrypted.size(), 0);
|
||||
|
||||
auto botan_direction = direction == cipher_direction::decryption
|
||||
? Botan::DECRYPTION : Botan::ENCRYPTION;
|
||||
Botan::Pipe pipe(Botan::get_cipher(cipher_name, key, iv, botan_direction));
|
||||
pipe.process_msg(encrypted);
|
||||
auto decrypted = pipe.read_all();
|
||||
if (direction == cipher_direction::encryption && chaining == cipher_chaining::cbc)
|
||||
{
|
||||
CryptoPP::AES::Decryption aesEncryption(key.data(), key.size());
|
||||
CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv.data());
|
||||
|
||||
return std::vector<std::uint8_t>(decrypted.begin(), decrypted.end());
|
||||
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::ArraySink(destination.data(), destination.size()));
|
||||
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(encrypted.data()), encrypted.size());
|
||||
stfEncryptor.MessageEnd();
|
||||
}
|
||||
else if (direction == cipher_direction::decryption && chaining == cipher_chaining::cbc)
|
||||
{
|
||||
CryptoPP::AES::Encryption aesEncryption(key.data(), key.size());
|
||||
CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv.data());
|
||||
|
||||
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::ArraySink(destination.data(), destination.size()));
|
||||
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(encrypted.data()), encrypted.size());
|
||||
stfEncryptor.MessageEnd();
|
||||
}
|
||||
else if (direction == cipher_direction::encryption && chaining == cipher_chaining::ecb)
|
||||
{
|
||||
CryptoPP::AES::Encryption aesEncryption(key.data(), key.size());
|
||||
CryptoPP::ECB_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv.data());
|
||||
|
||||
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::ArraySink(destination.data(), destination.size()));
|
||||
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(encrypted.data()), encrypted.size());
|
||||
stfEncryptor.MessageEnd();
|
||||
}
|
||||
else if (direction == cipher_direction::decryption && chaining == cipher_chaining::ecb)
|
||||
{
|
||||
CryptoPP::AES::Encryption aesEncryption(key.data(), key.size());
|
||||
CryptoPP::ECB_Mode_ExternalCipher::Decryption cbcEncryption(aesEncryption, iv.data());
|
||||
|
||||
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::ArraySink(destination.data(), destination.size()));
|
||||
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(encrypted.data()), encrypted.size());
|
||||
stfEncryptor.MessageEnd();
|
||||
}
|
||||
|
||||
return destination;
|
||||
}
|
||||
|
||||
static std::vector<std::uint8_t> decode_base64(const std::string &encoded)
|
||||
{
|
||||
Botan::Pipe pipe(new Botan::Base64_Decoder);
|
||||
pipe.process_msg(encoded);
|
||||
auto decoded = pipe.read_all();
|
||||
CryptoPP::Base64Decoder decoder;
|
||||
decoder.Put(reinterpret_cast<const std::uint8_t *>(encoded.data()), encoded.size());
|
||||
decoder.MessageEnd();
|
||||
|
||||
std::vector<std::uint8_t> decoded(decoder.MaxRetrievable(), 0);
|
||||
decoder.Get(decoded.data(), decoded.size());
|
||||
|
||||
return std::vector<std::uint8_t>(decoded.begin(), decoded.end());
|
||||
return decoded;
|
||||
}
|
||||
|
||||
static std::string encode_base64(const std::vector<std::uint8_t> &decoded)
|
||||
{
|
||||
Botan::Pipe pipe(new Botan::Base64_Encoder);
|
||||
pipe.process_msg(decoded);
|
||||
auto encoded = pipe.read_all();
|
||||
CryptoPP::Base64Decoder encoder;
|
||||
encoder.Put(reinterpret_cast<const std::uint8_t *>(decoded.data()), decoded.size());
|
||||
encoder.MessageEnd();
|
||||
|
||||
std::vector<std::uint8_t> encoded(encoder.MaxRetrievable(), 0);
|
||||
encoder.Get(encoded.data(), encoded.size());
|
||||
|
||||
return std::string(encoded.begin(), encoded.end());
|
||||
}
|
||||
|
@ -164,12 +198,22 @@ struct crypto_helper
|
|||
static std::vector<std::uint8_t> hash(hash_algorithm algorithm,
|
||||
const std::vector<std::uint8_t> &input)
|
||||
{
|
||||
Botan::Pipe pipe(new Botan::Hash_Filter(
|
||||
algorithm == hash_algorithm::sha512 ? "SHA-512" : "SHA-1"));
|
||||
pipe.process_msg(input);
|
||||
auto hash = pipe.read_all();
|
||||
|
||||
return std::vector<std::uint8_t>(hash.begin(), hash.end());
|
||||
std::vector<std::uint8_t> digest;
|
||||
|
||||
if (algorithm == hash_algorithm::sha512)
|
||||
{
|
||||
CryptoPP::SHA512 sha512;
|
||||
digest.resize(CryptoPP::SHA512::DIGESTSIZE, 0);
|
||||
sha512.CalculateDigest(digest.data(), input.data(), input.size());
|
||||
}
|
||||
else if (algorithm == hash_algorithm::sha1)
|
||||
{
|
||||
CryptoPP::SHA1 sha1;
|
||||
digest.resize(CryptoPP::SHA1::DIGESTSIZE, 0);
|
||||
sha1.CalculateDigest(digest.data(), input.data(), input.size());
|
||||
}
|
||||
|
||||
return digest;
|
||||
}
|
||||
|
||||
static std::vector<std::uint8_t> file(POLE::Storage &storage, const std::string &name)
|
||||
|
|
28
third-party/CMakeLists.txt
vendored
28
third-party/CMakeLists.txt
vendored
|
@ -1,11 +1,12 @@
|
|||
cmake_minimum_required(VERSION 3.1)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/common.cmake)
|
||||
project(${LIBRARY_NAME}.third-party VERSION ${LIBRARY_VERSION} LANGUAGES CXX C)
|
||||
|
||||
# Includes
|
||||
include_directories(libstudxml
|
||||
utfcpp/source
|
||||
botan
|
||||
zlib
|
||||
cryptopp
|
||||
${LIBRARY_SOURCE_DIR}/detail)
|
||||
|
||||
set(LIBSTUDXML
|
||||
|
@ -46,28 +47,6 @@ set(GENX
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/libstudxml/xml/details/genx/genx.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libstudxml/xml/details/genx/genx.h)
|
||||
|
||||
set(BOTAN
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/botan/botan_all.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/botan/botan_all_internal.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/botan/botan_all.h)
|
||||
|
||||
if(MSVC)
|
||||
set_source_files_properties(${BOTAN} PROPERTIES COMPILE_FLAGS "/wd\"4244\" /wd\"4267\"")
|
||||
else()
|
||||
set_source_files_properties(${BOTAN} PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations")
|
||||
endif()
|
||||
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(CPU "x64")
|
||||
else()
|
||||
set(CPU "x86")
|
||||
endif()
|
||||
|
||||
add_custom_command(OUTPUT ${BOTAN}
|
||||
COMMAND python configure.py --minimized-build --enable-modules=sha1,aes,filters,codec_filt,cbc,ecb,sha2_32,sha2_64 --without-sphinx --disable-shared --amalgamation --cpu=${CPU}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/botan
|
||||
COMMENT "Generating botan amalgamation")
|
||||
|
||||
set(ZLIB ${CMAKE_CURRENT_SOURCE_DIR}/zlib/adler32.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/zlib/compress.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/zlib/crc32.c
|
||||
|
@ -96,7 +75,7 @@ else()
|
|||
set_source_files_properties(${ZLIB} PROPERTIES COMPILE_FLAGS "/wd\"4018\"")
|
||||
endif()
|
||||
|
||||
add_library(xlnt.third-party OBJECT ${LIBSTUDXML} ${GENX} ${EXPAT} ${BOTAN} ${ZLIB})
|
||||
add_library(xlnt.third-party OBJECT ${LIBSTUDXML} ${GENX} ${EXPAT} ${ZLIB})
|
||||
target_compile_definitions(xlnt.third-party PRIVATE LIBSTUDXML_STATIC_LIB=1)
|
||||
|
||||
if(NOT STATIC)
|
||||
|
@ -109,7 +88,6 @@ if(MSVC)
|
|||
set_target_properties(xlnt.third-party PROPERTIES COMPILE_FLAGS "/MP")
|
||||
endif()
|
||||
|
||||
source_group(botan FILES ${BOTAN})
|
||||
source_group(libstudxml FILES ${LIBSTUDXML})
|
||||
source_group(libstudxml\\genx FILES ${GENX})
|
||||
source_group(libstudxml\\expat FILES ${EXPAT})
|
||||
|
|
1
third-party/botan
vendored
1
third-party/botan
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 7c9d431d11fe2f3e7e43f2f8585e9be4495135c5
|
1
third-party/cryptopp
vendored
Submodule
1
third-party/cryptopp
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 1a17ade299c3a05e5a63a8cb3f390d21845c21c6
|
Loading…
Reference in New Issue
Block a user