52 changed files with 4134 additions and 1028 deletions
@ -0,0 +1,106 @@
|
||||
|
||||
function(check_compiler_flag RESULT FLAG) |
||||
|
||||
if(DEFINED CHECK_COMPILER_FLAG_${FLAG}) |
||||
if(CHECK_COMPILER_FLAG_${FLAG}) |
||||
set(${RESULT} "${FLAG}" PARENT_SCOPE) |
||||
else() |
||||
set(${RESULT} "" PARENT_SCOPE) |
||||
endif() |
||||
return() |
||||
endif() |
||||
|
||||
set(compile_test_file "${CMAKE_CURRENT_BINARY_DIR}/compile_flag_test.cpp") |
||||
file(WRITE ${compile_test_file} "__attribute__((const)) int main(){ return 0; }\n") |
||||
try_compile(CHECK_COMPILER_FLAG ${CMAKE_BINARY_DIR} ${compile_test_file} COMPILE_DEFINITIONS "${FLAG}" OUTPUT_VARIABLE ERRORLOG) |
||||
|
||||
string(REGEX MATCH "warning:" HAS_WARNING "${ERRORLOG}") |
||||
|
||||
if(NOT CHECK_COMPILER_FLAG) |
||||
message(STATUS "Checking compiler flag: ${FLAG} - unsupported") |
||||
set(${RESULT} "" PARENT_SCOPE) |
||||
set("CHECK_COMPILER_FLAG_${FLAG}" 0 CACHE INTERNAL "...") |
||||
elseif(NOT HAS_WARNING STREQUAL "") |
||||
message(STATUS "Checking compiler flag: ${FLAG} - unsupported (warning)") |
||||
set(${RESULT} "" PARENT_SCOPE) |
||||
set("CHECK_COMPILER_FLAG_${FLAG}" 0 CACHE INTERNAL "...") |
||||
else() |
||||
message(STATUS "Checking compiler flag: ${FLAG}") |
||||
set(${RESULT} "${FLAG}" PARENT_SCOPE) |
||||
set("CHECK_COMPILER_FLAG_${FLAG}" 1 CACHE INTERNAL "...") |
||||
endif() |
||||
|
||||
endfunction(check_compiler_flag) |
||||
|
||||
function(add_cxxflag FLAG) |
||||
|
||||
check_compiler_flag(RESULT "${FLAG}") |
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RESULT}" PARENT_SCOPE) |
||||
|
||||
endfunction(add_cxxflag) |
||||
|
||||
function(try_link_library LIBRARY_NAME LIBRARY_FILE ERROR_VAR) |
||||
# See if we can link a simple program with the library using the configured c++ compiler. |
||||
set(link_test_file "${CMAKE_CURRENT_BINARY_DIR}/link_test.cpp") |
||||
file(WRITE ${link_test_file} "int main(){}\n") |
||||
if(CMAKE_THREAD_LIBS_INIT) |
||||
list(APPEND LIBRARY_FILE "${CMAKE_THREAD_LIBS_INIT}") |
||||
endif() |
||||
try_compile(CHECK_${LIBRARY_NAME}_LINK "${CMAKE_BINARY_DIR}" "${link_test_file}" CMAKE_FLAGS "-DLINK_LIBRARIES=${LIBRARY_FILE}" OUTPUT_VARIABLE ERRORLOG) |
||||
set(${ERROR_VAR} "${ERRORLOG}" PARENT_SCOPE) |
||||
endfunction(try_link_library) |
||||
|
||||
############################################################################## |
||||
# Check that a a library actually works for the current configuration. |
||||
function(check_link_library LIBRARY_NAME LIBRARY_VARIABLE) |
||||
|
||||
set(lib_current "${${LIBRARY_VARIABLE}}") |
||||
set(found_var "ARX_CLL_${LIBRARY_NAME}_FOUND") |
||||
set(working_var "ARX_CLL_${LIBRARY_NAME}_WORKING") |
||||
|
||||
if(CHECK_${LIBRARY_NAME}_LINK) |
||||
set(lib_found "${${found_var}}") |
||||
set(lib_working "${${working_var}}") |
||||
if((lib_current STREQUAL lib_found) OR (lib_current STREQUAL lib_working)) |
||||
set("${LIBRARY_VARIABLE}" "${lib_working}" PARENT_SCOPE) |
||||
return() |
||||
endif() |
||||
endif() |
||||
|
||||
set("${found_var}" "${lib_current}" CACHE INTERNAL "...") |
||||
|
||||
message(STATUS "Checking ${LIBRARY_NAME}: ${lib_current}") |
||||
|
||||
# Check if we can link to the full path found by find_package. |
||||
try_link_library(${LIBRARY_NAME} "${lib_current}" ERRORLOG1) |
||||
|
||||
if(CHECK_${LIBRARY_NAME}_LINK) |
||||
set("${working_var}" "${lib_current}" CACHE INTERNAL "...") |
||||
return() |
||||
endif() |
||||
|
||||
# Check if the linker is smarter than cmake and try to link with only the library name. |
||||
string(REGEX REPLACE "(^|;)[^;]*/lib([^;/]*)\\.so" "\\1-l\\2" LIBRARY_FILE "${lib_current}") |
||||
try_link_library(${LIBRARY_NAME} "${LIBRARY_FILE}" ERRORLOG2) |
||||
|
||||
if(CHECK_${LIBRARY_NAME}_LINK) |
||||
message(STATUS " -> using ${LIBRARY_FILE} instead") |
||||
set("${LIBRARY_VARIABLE}" "${LIBRARY_FILE}" PARENT_SCOPE) |
||||
set("${working_var}" "${LIBRARY_FILE}" CACHE INTERNAL "...") |
||||
return() |
||||
endif() |
||||
|
||||
# Force cmake to search again, as the cached library doesn't work. |
||||
unset(FIND_PACKAGE_MESSAGE_DETAILS_${ARGV2} CACHE) |
||||
unset(FIND_PACKAGE_MESSAGE_DETAILS_${LIBRARY_NAME} CACHE) |
||||
|
||||
message(FATAL_ERROR "\n${ERRORLOG1}\n\n${ERRORLOG2}\n\n!! No suitable (32- vs. 64-bit) version of ${LIBRARY_NAME} found; tried ${lib_current} and ${LIBRARY_FILE}\nusing compiler ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS}\n") |
||||
|
||||
endfunction(check_link_library) |
||||
|
||||
function(force_recheck_library LIBRARY_NAME) |
||||
unset(FIND_PACKAGE_MESSAGE_DETAILS_${ARGV1} CACHE) |
||||
unset(FIND_PACKAGE_MESSAGE_DETAILS_${LIBRARY_NAME} CACHE) |
||||
unset(CHECK_${LIBRARY_NAME}_LINK CACHE) |
||||
endfunction() |
||||
@ -0,0 +1,22 @@
|
||||
|
||||
# Try to find the LZMA library and include path for lzma.h from xz-utils. |
||||
# Once done this will define |
||||
# |
||||
# LZMA_FOUND |
||||
# LZMA_INCLUDE_DIR - where to find lzma.h |
||||
# LZMA_LIBRARIES - liblzma.so |
||||
|
||||
find_path(LZMA_INCLUDE_DIR lzma.h DOC "The directory where lzma.h resides") |
||||
find_library(LZMA_LIBRARY lzma DOC "The LZMA library") |
||||
|
||||
mark_as_advanced(LZMA_INCLUDE_DIR) |
||||
mark_as_advanced(LZMA_LIBRARY) |
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set LZMA_FOUND to TRUE if |
||||
# all listed variables are TRUE |
||||
include(FindPackageHandleStandardArgs) |
||||
find_package_handle_standard_args(LZMA DEFAULT_MSG LZMA_LIBRARY LZMA_INCLUDE_DIR) |
||||
|
||||
if(LZMA_FOUND) |
||||
set(LZMA_LIBRARIES ${LZMA_LIBRARY}) |
||||
endif(LZMA_FOUND) |
||||
@ -0,0 +1,47 @@
|
||||
cmake_minimum_required(VERSION 2.8) |
||||
|
||||
# CMake script that reads a VERSION file and the current git history and the calls configure_file(). |
||||
# This is used by version_file() in VersionString.cmake |
||||
|
||||
if((NOT DEFINED INPUT) OR (NOT DEFINED OUTPUT) OR (NOT DEFINED VERSION_FILE) OR (NOT DEFINED GIT_DIR)) |
||||
message(SEND_ERROR "Invalid arguments.") |
||||
endif() |
||||
|
||||
file(READ "${VERSION_FILE}" BASE_VERSION) |
||||
string(STRIP "${BASE_VERSION}" BASE_VERSION) |
||||
|
||||
if(EXISTS "${GIT_DIR}") |
||||
|
||||
file(READ "${GIT_DIR}/HEAD" GIT_HEAD) |
||||
string(STRIP "${GIT_HEAD}" GIT_HEAD) |
||||
|
||||
unset(GIT_COMMIT) |
||||
|
||||
if("${GIT_HEAD}" MATCHES "^ref\\:") |
||||
|
||||
# Remove the first for characters from GIT_HEAD to get GIT_REF. |
||||
# We can't use a length of -1 for string(SUBSTRING) as cmake < 2.8.5 doesn't support it. |
||||
string(LENGTH "${GIT_HEAD}" GIT_HEAD_LENGTH) |
||||
math(EXPR GIT_REF_LENGTH "${GIT_HEAD_LENGTH} - 4") |
||||
string(SUBSTRING "${GIT_HEAD}" 4 ${GIT_REF_LENGTH} GIT_REF) |
||||
|
||||
string(STRIP "${GIT_REF}" GIT_REF) |
||||
|
||||
file(READ "${GIT_DIR}/${GIT_REF}" GIT_HEAD) |
||||
string(STRIP "${GIT_HEAD}" GIT_HEAD) |
||||
endif() |
||||
|
||||
string(REGEX MATCH "[0-9A-Za-z]+" GIT_COMMIT "${GIT_HEAD}") |
||||
|
||||
# Create variables for all prefixes of the git comit ID. |
||||
if(GIT_COMMIT) |
||||
string(TOLOWER "${GIT_COMMIT}" GIT_COMMIT) |
||||
string(LENGTH "${GIT_COMMIT}" GIT_COMMIT_LENGTH) |
||||
foreach(i RANGE "${GIT_COMMIT_LENGTH}") |
||||
string(SUBSTRING "${GIT_COMMIT}" 0 ${i} GIT_COMMIT_PREFIX_${i}) |
||||
endforeach() |
||||
endif() |
||||
|
||||
endif() |
||||
|
||||
configure_file("${INPUT}" "${OUTPUT}" ESCAPE_QUOTES) |
||||
@ -0,0 +1,41 @@
|
||||
|
||||
# Create a rule to generate a version string at compile time. |
||||
# |
||||
# SRC is processed using the configure_file() cmake command |
||||
# at build to produce DST with the following variable available: |
||||
# |
||||
# - BASE_VERSION: The contents of the file specified by VERSION_FILE. |
||||
# - GIT_COMMIT: The current git commit. This variable is not defined if there is no GIT_DIR directory. |
||||
# - SHORT_GIT_COMMIT: The first 10 characters of the git commit. |
||||
# For the exact syntax of SRC see the documentation of the configure_file() cmake command. |
||||
# |
||||
# The version file is regenerated whenever VERSION_FILE or the current commit changes. |
||||
function(version_file SRC DST VERSION_FILE GIT_DIR) |
||||
|
||||
get_filename_component(ABS_SRC "${SRC}" ABSOLUTE) |
||||
get_filename_component(ABS_DST "${DST}" ABSOLUTE) |
||||
get_filename_component(ABS_VERSION_FILE "${VERSION_FILE}" ABSOLUTE) |
||||
get_filename_component(ABS_GIT_DIR "${GIT_DIR}" ABSOLUTE) |
||||
|
||||
add_custom_command( |
||||
OUTPUT |
||||
"${DST}" |
||||
COMMAND |
||||
${CMAKE_COMMAND} |
||||
"-DINPUT=${ABS_SRC}" |
||||
"-DOUTPUT=${ABS_DST}" |
||||
"-DVERSION_FILE=${ABS_VERSION_FILE}" |
||||
"-DGIT_DIR=${ABS_GIT_DIR}" |
||||
-P "${CMAKE_MODULE_PATH}/VersionScript.cmake" |
||||
MAIN_DEPENDENCY |
||||
"${SRC}" |
||||
DEPENDS |
||||
"${GIT_DIR}/HEAD" |
||||
"${GIT_DIR}/logs/HEAD" |
||||
"${VERSION_FILE}" |
||||
"${CMAKE_MODULE_PATH}/VersionScript.cmake" |
||||
COMMENT "" |
||||
VERBATIM |
||||
) |
||||
|
||||
endfunction(version_file) |
||||
@ -0,0 +1,14 @@
|
||||
|
||||
# Look for wine compilers |
||||
find_program(Clang clang) |
||||
mark_as_advanced(Clang) |
||||
find_program(ClangXX clang++) |
||||
mark_as_advanced(ClangXX) |
||||
|
||||
if((NOT Clang) OR (NOT ClangXX)) |
||||
message(FATAL_ERROR "clang not found (found: c compiler \"${Clang}\", c++ compiler \"${ClangXX}\")") |
||||
endif() |
||||
|
||||
# which compilers to use for C and C++ |
||||
set(CMAKE_C_COMPILER "${Clang}") |
||||
set(CMAKE_CXX_COMPILER "${ClangXX}") |
||||
@ -0,0 +1,18 @@
|
||||
|
||||
# Look for wine compilers |
||||
find_program(Ekopath pathcc) |
||||
mark_as_advanced(Ekopath) |
||||
find_program(EkopathXX pathCC) |
||||
mark_as_advanced(EkopathXX) |
||||
|
||||
if((NOT Ekopath) OR (NOT EkopathXX)) |
||||
message(FATAL_ERROR "ekopath not found (found: c compiler \"${Ekopath}\", c++ compiler \"${EkopathXX}\")") |
||||
endif() |
||||
|
||||
# which compilers to use for C and C++ |
||||
set(CMAKE_C_COMPILER "${Ekopath}") |
||||
set(CMAKE_CXX_COMPILER "${EkopathXX}") |
||||
|
||||
# tell cmake that ekopath supports -isystem |
||||
set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ") |
||||
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ") |
||||
@ -0,0 +1,78 @@
|
||||
|
||||
# the name of the target operating system |
||||
set(CMAKE_SYSTEM_NAME Windows) |
||||
|
||||
# Look for mingw32 compilers |
||||
if(DEFINED MINGW32_ROOT) |
||||
set(MinGW32_ROOT "${MINGW32_ROOT}" CACHE INTERNAL) |
||||
else() |
||||
find_path(MinGW32_ROOT mingw |
||||
PATH_SUFFIXES |
||||
i686-pc-mingw32 |
||||
i586-pc-mingw32 |
||||
i486-pc-mingw32 |
||||
i386-pc-mingw32 |
||||
i686-mingw32 |
||||
i586-mingw32 |
||||
i486-mingw32 |
||||
i386-mingw32 |
||||
mingw32 |
||||
PATHS |
||||
/usr |
||||
/usr/local |
||||
) |
||||
endif() |
||||
mark_as_advanced(MinGW32_ROOT) |
||||
|
||||
find_program(MinGW32_GCC NAMES |
||||
i686-pc-mingw32-gcc |
||||
i586-pc-mingw32-gcc |
||||
i486-pc-mingw32-gcc |
||||
i386-pc-mingw32-gcc |
||||
i686-mingw32-gcc |
||||
i586-mingw32-gcc |
||||
i486-mingw32-gcc |
||||
i386-mingw32-gcc |
||||
) |
||||
mark_as_advanced(MinGW32_GCC) |
||||
find_program(MinGW32_GXX NAMES |
||||
i686-pc-mingw32-g++ |
||||
i586-pc-mingw32-g++ |
||||
i486-pc-mingw32-g++ |
||||
i386-pc-mingw32-g++ |
||||
i686-mingw32-g++ |
||||
i586-mingw32-g++ |
||||
i486-mingw32-g++ |
||||
i386-mingw32-g++ |
||||
) |
||||
mark_as_advanced(MinGW32_GXX) |
||||
find_program(MinGW32_RC NAMES |
||||
i686-pc-mingw32-windres |
||||
i586-pc-mingw32-windres |
||||
i486-pc-mingw32-windres |
||||
i386-pc-mingw32-windres |
||||
i686-mingw32-windres |
||||
i586-mingw32-windres |
||||
i486-mingw32-windres |
||||
i386-mingw32-windres |
||||
) |
||||
mark_as_advanced(MinGW32_RC) |
||||
|
||||
if((NOT MinGW32_GCC) OR (NOT MinGW32_GXX) OR (NOT MinGW32_RC) OR (NOT MinGW32_ROOT)) |
||||
message(FATAL_ERROR "mingw32 not found (found gcc=\"${MinGW32_GCC}\", g++=\"${MinGW32_GXX}\" rc=\"${MinGW32_RC}\" root=\"${MinGW32_ROOT}\")") |
||||
endif() |
||||
|
||||
# which compilers to use for C and C++ |
||||
set(CMAKE_C_COMPILER "${MinGW32_GCC}") |
||||
set(CMAKE_CXX_COMPILER "${MinGW32_GXX}") |
||||
set(CMAKE_RC_COMPILER "${MinGW32_RC}") |
||||
|
||||
# here is the target environment located |
||||
set(CMAKE_FIND_ROOT_PATH "${MinGW32_ROOT}") |
||||
|
||||
# adjust the default behaviour of the find_xxx() commands: |
||||
# search headers and libraries in the target environment, search |
||||
# programs in the host environment |
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY FIRST) |
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE FIRST) |
||||
@ -1,120 +0,0 @@
|
||||
// arc4.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
// The ARC4 algorithm was first revealed in an anonymous email to the
|
||||
// cypherpunks mailing list. This file originally contained some
|
||||
// code copied from this email. The code has since been rewritten in order
|
||||
// to clarify the copyright status of this file. It should now be
|
||||
// completely in the public domain.
|
||||
|
||||
#include "pch.h" |
||||
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 |
||||
#include "arc4.h" |
||||
|
||||
NAMESPACE_BEGIN(CryptoPP) |
||||
namespace Weak1 { |
||||
|
||||
void ARC4_TestInstantiations() |
||||
{ |
||||
ARC4 x; |
||||
} |
||||
|
||||
ARC4_Base::~ARC4_Base() |
||||
{ |
||||
m_x = m_y = 0; |
||||
} |
||||
|
||||
void ARC4_Base::UncheckedSetKey(const byte *key, unsigned int keyLen, const NameValuePairs ¶ms) |
||||
{ |
||||
AssertValidKeyLength(keyLen); |
||||
|
||||
m_x = 1; |
||||
m_y = 0; |
||||
|
||||
unsigned int i; |
||||
for (i=0; i<256; i++) |
||||
m_state[i] = i; |
||||
|
||||
unsigned int keyIndex = 0, stateIndex = 0; |
||||
for (i=0; i<256; i++) |
||||
{ |
||||
unsigned int a = m_state[i]; |
||||
stateIndex += key[keyIndex] + a; |
||||
stateIndex &= 0xff; |
||||
m_state[i] = m_state[stateIndex]; |
||||
m_state[stateIndex] = a; |
||||
if (++keyIndex >= keyLen) |
||||
keyIndex = 0; |
||||
} |
||||
|
||||
int discardBytes = params.GetIntValueWithDefault("DiscardBytes", GetDefaultDiscardBytes()); |
||||
DiscardBytes(discardBytes); |
||||
} |
||||
|
||||
template <class T> |
||||
static inline unsigned int MakeByte(T &x, T &y, byte *s) |
||||
{ |
||||
unsigned int a = s[x]; |
||||
y = (y+a) & 0xff; |
||||
unsigned int b = s[y]; |
||||
s[x] = b; |
||||
s[y] = a; |
||||
x = (x+1) & 0xff; |
||||
return s[(a+b) & 0xff]; |
||||
} |
||||
|
||||
void ARC4_Base::GenerateBlock(byte *output, size_t size) |
||||
{ |
||||
while (size--) |
||||
*output++ = MakeByte(m_x, m_y, m_state); |
||||
} |
||||
|
||||
void ARC4_Base::ProcessData(byte *outString, const byte *inString, size_t length) |
||||
{ |
||||
if (length == 0) |
||||
return; |
||||
|
||||
byte *const s = m_state; |
||||
unsigned int x = m_x; |
||||
unsigned int y = m_y; |
||||
|
||||
if (inString == outString) |
||||
{ |
||||
do |
||||
{ |
||||
*outString++ ^= MakeByte(x, y, s); |
||||
} while (--length); |
||||
} |
||||
else |
||||
{ |
||||
do |
||||
{ |
||||
*outString++ = *inString++ ^ MakeByte(x, y, s); |
||||
} |
||||
while(--length); |
||||
} |
||||
|
||||
m_x = x; |
||||
m_y = y; |
||||
} |
||||
|
||||
void ARC4_Base::DiscardBytes(size_t length) |
||||
{ |
||||
if (length == 0) |
||||
return; |
||||
|
||||
byte *const s = m_state; |
||||
unsigned int x = m_x; |
||||
unsigned int y = m_y; |
||||
|
||||
do |
||||
{ |
||||
MakeByte(x, y, s); |
||||
} |
||||
while(--length); |
||||
|
||||
m_x = x; |
||||
m_y = y; |
||||
} |
||||
|
||||
} |
||||
NAMESPACE_END |
||||
@ -1,71 +0,0 @@
|
||||
#ifndef CRYPTOPP_ARC4_H |
||||
#define CRYPTOPP_ARC4_H |
||||
|
||||
#include "strciphr.h" |
||||
|
||||
NAMESPACE_BEGIN(CryptoPP) |
||||
|
||||
namespace Weak1 { |
||||
|
||||
//! _
|
||||
class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation |
||||
{ |
||||
public: |
||||
~ARC4_Base(); |
||||
|
||||
static const char *StaticAlgorithmName() {return "ARC4";} |
||||
|
||||
void GenerateBlock(byte *output, size_t size); |
||||
void DiscardBytes(size_t n); |
||||
|
||||
void ProcessData(byte *outString, const byte *inString, size_t length); |
||||
|
||||
bool IsRandomAccess() const {return false;} |
||||
bool IsSelfInverting() const {return true;} |
||||
bool IsForwardTransformation() const {return true;} |
||||
|
||||
typedef SymmetricCipherFinal<ARC4_Base> Encryption; |
||||
typedef SymmetricCipherFinal<ARC4_Base> Decryption; |
||||
|
||||
protected: |
||||
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); |
||||
virtual unsigned int GetDefaultDiscardBytes() const {return 0;} |
||||
|
||||
FixedSizeSecBlock<byte, 256> m_state; |
||||
byte m_x, m_y; |
||||
}; |
||||
|
||||
//! <a href="http://www.weidai.com/scan-mirror/cs.html#RC4">Alleged RC4</a>
|
||||
DOCUMENTED_TYPEDEF(SymmetricCipherFinal<ARC4_Base>, ARC4) |
||||
|
||||
//! _
|
||||
class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base |
||||
{ |
||||
public: |
||||
static const char *StaticAlgorithmName() {return "MARC4";} |
||||
|
||||
typedef SymmetricCipherFinal<MARC4_Base> Encryption; |
||||
typedef SymmetricCipherFinal<MARC4_Base> Decryption; |
||||
|
||||
protected: |
||||
unsigned int GetDefaultDiscardBytes() const {return 256;} |
||||
}; |
||||
|
||||
//! Modified ARC4: it discards the first 256 bytes of keystream which may be weaker than the rest
|
||||
DOCUMENTED_TYPEDEF(SymmetricCipherFinal<MARC4_Base>, MARC4) |
||||
|
||||
} |
||||
#if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1 |
||||
namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak
|
||||
#else |
||||
using namespace Weak1; // import Weak1 into CryptoPP with warning
|
||||
#ifdef __GNUC__ |
||||
#warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning." |
||||
#else |
||||
#pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning.") |
||||
#endif |
||||
#endif |
||||
|
||||
NAMESPACE_END |
||||
|
||||
#endif |
||||
@ -1,240 +0,0 @@
|
||||
|
||||
#include <boost/utility/enable_if.hpp> |
||||
#include <boost/integer.hpp> |
||||
#include <boost/integer/static_log2.hpp> |
||||
#include <boost/integer/static_min_max.hpp> |
||||
#include <boost/integer_traits.hpp> |
||||
|
||||
namespace boost { |
||||
template <class T> |
||||
class integer_traits<const T> : public integer_traits<T> { }; |
||||
} |
||||
|
||||
template <size_t N, class Type = void, class Enable = void> |
||||
struct is_power_of_two { |
||||
static const bool value = false; |
||||
}; |
||||
template <size_t N, class Type> |
||||
struct is_power_of_two<N, Type, typename boost::enable_if_c<(N & (N - 1)) == 0>::type> { |
||||
static const bool value = true; |
||||
typedef Type type; |
||||
}; |
||||
|
||||
template <size_t N, class Enable = void> |
||||
struct log_next_power_of_two { |
||||
static const size_t value = boost::static_log2<N>::value + 1; |
||||
}; |
||||
template <size_t N> |
||||
struct log_next_power_of_two<N, typename boost::enable_if<is_power_of_two<N> >::type> { |
||||
static const size_t value = boost::static_log2<N>::value; |
||||
}; |
||||
|
||||
template <size_t N, class Enable = void> |
||||
struct next_power_of_two { |
||||
static const size_t value = size_t(1) << (boost::static_log2<N>::value + 1); |
||||
}; |
||||
template <size_t N> |
||||
struct next_power_of_two<N, typename boost::enable_if<is_power_of_two<N> >::type> { |
||||
static const size_t value = N; |
||||
}; |
||||
|
||||
|
||||
struct fast_integers { |
||||
|
||||
private: |
||||
|
||||
template <size_t Bits, class Dummy = void> struct _impl { }; |
||||
template <class Dummy> struct _impl<8, Dummy> { typedef uint_fast8_t type; }; |
||||
template <class Dummy> struct _impl<16, Dummy> { typedef uint_fast16_t type; }; |
||||
template <class Dummy> struct _impl<32, Dummy> { typedef uint_fast32_t type; }; |
||||
template <class Dummy> struct _impl<64, Dummy> { typedef uint_fast64_t type; }; |
||||
template <class Dummy> struct _impl<128, Dummy> { typedef __uint128_t type; }; |
||||
|
||||
public: |
||||
|
||||
template <size_t Bits> |
||||
struct bits : public _impl<boost::static_unsigned_max<8, next_power_of_two<Bits>::value>::value> { }; |
||||
|
||||
}; |
||||
|
||||
struct exact_integers { |
||||
|
||||
private: |
||||
|
||||
template <size_t Bits, class Dummy = void> struct _impl { }; |
||||
template <class Dummy> struct _impl<8, Dummy> { typedef uint8_t type; }; |
||||
template <class Dummy> struct _impl<16, Dummy> { typedef uint16_t type; }; |
||||
template <class Dummy> struct _impl<32, Dummy> { typedef uint32_t type; }; |
||||
template <class Dummy> struct _impl<64, Dummy> { typedef uint64_t type; }; |
||||
template <class Dummy> struct _impl<128, Dummy> { typedef __uint128_t type; }; |
||||
|
||||
public: |
||||
|
||||
template <size_t Bits> |
||||
struct bits : public _impl<boost::static_unsigned_max<8, next_power_of_two<Bits>::value>::value> { }; |
||||
|
||||
}; |
||||
|
||||
struct bitset_types { |
||||
|
||||
template <size_t Bits> |
||||
struct bits { |
||||
typedef std::bitset<Bits> type; |
||||
}; |
||||
|
||||
}; |
||||
|
||||
|
||||
/*!
|
||||
* Converter that rearranges bits in an integer. |
||||
* |
||||
* Conversion is reduced to a minimal number of mask & shift operations at compile-time.
|
||||
* |
||||
* Usage: |
||||
* |
||||
* bitset_converter<> is an empty converter list (cannot be used without adding at least one mappings). |
||||
* (list)::add::map<from, to> maps the from'th input bit to the to'th output bit. |
||||
* |
||||
* Convenience function to add a continous region of mappings: |
||||
* bitset_converter<>::add::value<to2> is equivalent to bitset_converter<>::add::map<0, to2> |
||||
* (list)::add::map<from, to>::add::value<to2> is equivalent to ::add::map<from, to>::add::map<from + 1, to2> |
||||
* |
||||
* Inut bits without a corresponding "from" entry are ignored. |
||||
* Output bit without a corresponding "to" entry are always zero. |
||||
* |
||||
* The same input/output bit can appear in multiple mappings. |
||||
* |
||||
* Invoke the converter: (list)::convert(integer) |
||||
* |
||||
* Limitations: |
||||
* |
||||
* Input bits must fit in a native integer type provided by in_types::bits<bits>. |
||||
* |
||||
* Output bits must fit in an integer type selected by out_types::bits<bits>. |
||||
* |
||||
* Example: |
||||
* |
||||
* // Create a converter that swaps the first two bits, keeps the next one and ignores all others.
|
||||
* typedef bitset_converter<>::add::map<0, 1>::add::map<1, 0>::add::value<2> Converter; |
||||
* |
||||
* // Convert something.
|
||||
* Converter::convert(3); |
||||
*
|
||||
*/ |
||||
template <class out_types = fast_integers, class in_types = fast_integers> |
||||
struct bitset_converter { |
||||
|
||||
private: |
||||
|
||||
typedef ptrdiff_t shift_type; |
||||
typedef size_t index_type; |
||||
|
||||
template <class Combiner, class Entry> |
||||
struct IterateEntries { |
||||
static const typename Combiner::type value = Combiner::template combine<Entry, (IterateEntries<Combiner, typename Entry::next>::value)>::value; |
||||
}; |
||||
template <class Combiner> struct IterateEntries<Combiner, void> { static const typename Combiner::type value = Combiner::base; }; |
||||
template <class Type, Type Base> struct Combiner { typedef Type type; static const Type base = Base; }; |
||||
|
||||
template<class Getter, class Type> |
||||
struct MaxCombiner : public Combiner<Type, boost::integer_traits<Type>::const_min> { |
||||
template <class Entry, Type accumulator> |
||||
struct combine { static const Type value = boost::static_signed_max<Getter::template get<Entry>::value, accumulator>::value; }; |
||||
}; |
||||
|
||||
template<class Getter, class Type> |
||||
struct MinCombiner : public Combiner<Type, boost::integer_traits<Type>::const_max> { |
||||
template <class Entry, Type accumulator> |
||||
struct combine { static const Type value = boost::static_signed_min<Getter::template get<Entry>::value, accumulator>::value; }; |
||||
}; |
||||
|
||||
struct ShiftGetter { template<class Entry> struct get { static const shift_type value = Entry::shift; }; }; |
||||
struct FromGetter { template<class Entry> struct get { static const index_type value = Entry::from; }; }; |
||||
struct ToGetter { template<class Entry> struct get { static const index_type value = Entry::to; }; }; |
||||
|
||||
template<shift_type Shift, class Type> |
||||
struct ShiftMaskCombiner : public Combiner<Type, Type(0)> { |
||||
template <class Entry, Type mask> |
||||
struct combine { static const Type value = mask | ( (Entry::shift == Shift) ? (Type(1) << Entry::from) : Type(0) ); }; |
||||
}; |
||||
|
||||
template<class List> |
||||
struct Builder; |
||||
|
||||
template<index_type From, index_type To, class Next = void> |
||||
struct Entry { |
||||
|
||||
typedef Entry<From, To, Next> This; |
||||
|
||||
static const index_type from = From; |
||||
static const index_type to = To; |
||||
typedef Next next; |
||||
|
||||
static const shift_type shift = shift_type(from) - shift_type(to); |
||||
|
||||
static const shift_type max_shift = IterateEntries<MaxCombiner<ShiftGetter, shift_type>, This>::value; |
||||
static const shift_type min_shift = IterateEntries<MinCombiner<ShiftGetter, shift_type>, This>::value; |
||||
|
||||
static const index_type in_bits = IterateEntries<MaxCombiner<FromGetter, index_type>, This>::value + 1; |
||||
typedef typename in_types::template bits<in_bits>::type in_type; |
||||
|
||||
static const index_type out_bits = IterateEntries<MaxCombiner<ToGetter, index_type>, This>::value + 1; |
||||
typedef typename out_types::template bits<out_bits>::type out_type; |
||||
|
||||
template<shift_type Shift> |
||||
struct ShiftMask { static const in_type value = IterateEntries<ShiftMaskCombiner<Shift, in_type>, This>::value; }; |
||||
|
||||
template <shift_type Shift> |
||||
inline static typename boost::enable_if_c<(Shift >= shift_type(0)), out_type>::type evaluate(in_type value) { |
||||
return out_type((value & ShiftMask<Shift>::value) >> Shift); |
||||
} |
||||
template <shift_type Shift> |
||||
inline static typename boost::enable_if_c<(Shift < shift_type(0)), out_type>::type evaluate(in_type value) { |
||||
return out_type(value & ShiftMask<Shift>::value) << (-Shift);
|
||||
} |
||||
|
||||
template<shift_type Shift, class Enable = void> |
||||
struct NextShift { static const shift_type value = Shift + 1; }; |
||||
template<shift_type Shift> |
||||
struct NextShift<Shift, typename boost::enable_if_c<Shift != max_shift && ShiftMask<Shift + 1>::value == in_type(0)>::type > { |
||||
static const shift_type value = NextShift<Shift + 1>::value; |
||||
}; |
||||
|
||||
template <shift_type Shift> |
||||
inline static typename boost::enable_if_c<(NextShift<Shift>::value != max_shift + 1), out_type>::type map(in_type value) { |
||||
return evaluate<Shift>(value) | (map<NextShift<Shift>::value>(value)); |
||||
} |
||||
template <shift_type Shift> |
||||
inline static typename boost::enable_if_c<(NextShift<Shift>::value == max_shift + 1), out_type>::type map(in_type value) { |
||||
return evaluate<Shift>(value); |
||||
} |
||||
|
||||
public: |
||||
|
||||
typedef Builder<This> add; |
||||
|
||||
static out_type convert(in_type value) { |
||||
return map<min_shift>(value); |
||||
} |
||||
|
||||
}; |
||||
|
||||
template<class List> |
||||
struct Builder { |
||||
|
||||
template<index_type From, index_type To> |
||||
struct map : public Entry<From, To, List> { }; |
||||
|
||||
template<index_type To, class Current = List> |
||||
struct value : public Entry<Current::from + 1, To, Current> { }; |
||||
|
||||
template<index_type To> |
||||
struct value<To, void> : public Entry<0, To> { }; |
||||
|
||||
}; |
||||
|
||||
public: |
||||
|
||||
typedef Builder<void> add; |
||||
|
||||
}; |
||||
@ -1,189 +0,0 @@
|
||||
|
||||
#include "src/SetupHeaderFormat.hpp" |
||||
|
||||
#include <iostream> |
||||
#include <iomanip> |
||||
|
||||
using std::cout; |
||||
using std::endl; |
||||
using std::setfill; |
||||
using std::setw; |
||||
using std::hex; |
||||
using std::dec; |
||||
|
||||
/*
|
||||
|
||||
template <size_t N> |
||||
void testlog() { |
||||
cout << " lnpot: " << setfill(' ') << setw(3) << log_next_power_of_two<N>::value; |
||||
} |
||||
|
||||
template <> |
||||
void testlog<0>() { |
||||
cout << " lnpot: " << setfill(' ') << setw(3) << 0; |
||||
} |
||||
|
||||
template <size_t N> |
||||
void test() { |
||||
|
||||
cout << setfill(' ') << setw(5) << N; |
||||
cout << ' ' << hex << setfill('0') << setw(4) << N << dec; |
||||
cout << ": pot=" << is_power_of_two<N>::value; |
||||
cout << " npot: " << setfill(' ') << setw(5) << next_power_of_two<N>::value; |
||||
testlog<N>(); |
||||
cout << " ebits: " << setfill(' ') << setw(3) << StoredEnumType<N>::bits; |
||||
cout << " rebits: " << setfill(' ') << setw(3) << (sizeof(typename StoredEnumType<N>::type) * 8); |
||||
cout << " fbits: " << setfill(' ') << setw(5) << StoredFlagType<N>::bits; |
||||
cout << " rfbits: " << setfill(' ') << setw(5) << (sizeof(typename StoredFlagType<N>::type) * 8); |
||||
|
||||
cout << endl; |
||||
} |
||||
|
||||
#define TEST0(D) test<0##D>(); |
||||
|
||||
#define TEST1(D) \ |
||||
TEST0(D##0) \
|
||||
TEST0(D##1) \
|
||||
TEST0(D##2) \
|
||||
TEST0(D##3) \
|
||||
TEST0(D##4) \
|
||||
TEST0(D##5) \
|
||||
TEST0(D##6) \
|
||||
TEST0(D##7) \
|
||||
|
||||
#define TEST2(D) \ |
||||
TEST1(D##0) \
|
||||
TEST1(D##1) \
|
||||
TEST1(D##2) \
|
||||
TEST1(D##3) \
|
||||
TEST1(D##4) \
|
||||
TEST1(D##5) \
|
||||
TEST1(D##6) \
|
||||
TEST1(D##7) \
|
||||
|
||||
#define TEST3(D) \ |
||||
TEST2(D##0) \
|
||||
TEST2(D##1) \
|
||||
TEST2(D##2) \
|
||||
TEST2(D##3) \
|
||||
TEST2(D##4) \
|
||||
TEST2(D##5) \
|
||||
TEST2(D##6) \
|
||||
TEST2(D##7) \
|
||||
|
||||
enum TestEnum { |
||||
|
||||
A, |
||||
B, |
||||
C, |
||||
D, |
||||
E, |
||||
F, |
||||
G, |
||||
H, |
||||
I, |
||||
J, |
||||
K, |
||||
L, |
||||
M, |
||||
N, |
||||
O, |
||||
P, |
||||
Q, |
||||
R, |
||||
S, |
||||
T, |
||||
U, |
||||
V, |
||||
W, |
||||
X, |
||||
Y, |
||||
Z, |
||||
|
||||
TestEnum__End |
||||
}; |
||||
ENUM_SIZE_AUTO(TestEnum); |
||||
|
||||
STORED_ENUM_MAP(TestEnumMap, A, |
||||
A, // 0
|
||||
B, // 1
|
||||
C, // 2
|
||||
D, // 2
|
||||
E, // 2
|
||||
F, // 2
|
||||
G, // 2
|
||||
H, // 2
|
||||
I, // 2
|
||||
J, // 2
|
||||
K, // 2
|
||||
L, // 2
|
||||
M, // 2
|
||||
N, // 2
|
||||
O, // 2
|
||||
P, // 2
|
||||
Q, // 2
|
||||
R, // 2
|
||||
S, // 2
|
||||
T, // 2
|
||||
U, // 2
|
||||
V, // 2
|
||||
W, // 2
|
||||
X, // 2
|
||||
Y, // 2
|
||||
Z, // 2
|
||||
); |
||||
*/ |
||||
|
||||
volatile size_t i; |
||||
|
||||
typedef BitsetConverter |
||||
::add::map<0, 0> |
||||
::add::map<1, 1> |
||||
::add::map<2, 2> |
||||
::add::map<3, 3> |
||||
::add::map<4, 4> |
||||
::add::map<5, 5> |
||||
::add::map<6, 6> |
||||
::add::map<7, 7> |
||||
::add::map<8, 8> |
||||
::add::map<9, 9> |
||||
::add::map<10, 10> |
||||
::add::map<11, 11> |
||||
::add::map<12, 12> |
||||
::add::map<13, 13> |
||||
::add::map<14, 14> |
||||
::add::map<15, 15> |
||||
::add::map<16, 16> |
||||
::add::map<17, 17> |
||||
::add::map<18, 18> |
||||
::add::map<19, 19> |
||||
::add::map<20, 20> |
||||
IdentityConverter; |
||||
|
||||
static void test2(size_t i) { |
||||
|
||||
size_t out = IdentityConverter::convert(i); |
||||
|
||||
cout << i << " = " << std::bitset<64>(i) << " -> " << out << " = " << std::bitset<64>(out) << endl; |
||||
|
||||
} |
||||
|
||||
int main() { |
||||
|
||||
//TEST3()
|
||||
|
||||
/*
|
||||
test2(0); |
||||
test2(1); |
||||
test2(2); |
||||
test2(3); |
||||
test2(4); |
||||
test2(5); |
||||
test2(6); |
||||
test2(7); |
||||
test2(8);*/ |
||||
|
||||
|
||||
return IdentityConverter::convert(i); |
||||
} |
||||
|
||||
Loading…
Reference in new issue