Added KeccakHash (aka SHA-3) class + make sure that "public" functions and classes are actually exported from the DLL.
This commit is contained in:
parent
906ecb7ab2
commit
6b3f9fef73
@ -16,6 +16,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Global.cpp" />
|
||||
<ClCompile Include="src\KeccakHash.cpp" />
|
||||
<ClCompile Include="src\OSSupport_Win32.cpp" />
|
||||
<ClCompile Include="src\UpdateChecker.cpp" />
|
||||
<ClCompile Include="src\Version.cpp" />
|
||||
@ -24,6 +25,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\MUtils\Exception.h" />
|
||||
<ClInclude Include="include\MUtils\Global.h" />
|
||||
<ClInclude Include="include\MUtils\KeccakHash.h" />
|
||||
<ClInclude Include="include\MUtils\OSSupport.h" />
|
||||
<CustomBuild Include="include\Mutils\UpdateChecker.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\$(ProjectName)\MOC_%(Filename).cpp" "%(FullPath)"</Command>
|
||||
@ -43,6 +45,7 @@
|
||||
<ProjectGuid>{55405FE1-149F-434C-9D72-4B64348D2A08}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>MUtilities</RootNamespace>
|
||||
<ProjectName>MUtilities</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
@ -80,18 +83,18 @@
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\</IntDir>
|
||||
<TargetName>libMUtils32-1</TargetName>
|
||||
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<TargetName>MUtils32-1</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\</IntDir>
|
||||
<TargetName>libMUtils32-1</TargetName>
|
||||
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<TargetName>MUtils32-1</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Static|Win32'">
|
||||
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\</IntDir>
|
||||
<TargetName>libMUtils32-1</TargetName>
|
||||
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<TargetName>MUtils32-1</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
@ -99,7 +102,7 @@
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_DLL;QT_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;MUTILS_DLL_EXPORT;_DEBUG;_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_DLL;QT_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)\include;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
@ -119,7 +122,7 @@
|
||||
<Optimization>Full</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_DLL;QT_NO_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;MUTILS_DLL_EXPORT;NDEBUG;_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_DLL;QT_NO_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
|
||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
@ -147,7 +150,7 @@
|
||||
<Optimization>Full</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_NODLL;QT_NO_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;MUTILS_DLL_EXPORT;NDEBUG;_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_NODLL;QT_NO_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
|
||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
|
@ -36,6 +36,9 @@
|
||||
<ClCompile Include="src\Version.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\KeccakHash.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\CriticalSection_Win32.h">
|
||||
@ -53,6 +56,9 @@
|
||||
<ClInclude Include="include\MUtils\Version.h">
|
||||
<Filter>Public Headers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\MUtils\KeccakHash.h">
|
||||
<Filter>Public Headers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="include\Mutils\UpdateChecker.h">
|
||||
|
@ -28,22 +28,40 @@ class QProcess;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//MUtils API
|
||||
#ifdef _MSC_VER
|
||||
# ifdef MUTILS_DLL_EXPORT
|
||||
# define MUTILS_API __declspec(dllexport)
|
||||
# else
|
||||
# define MUTILS_API __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
# define MUTILS_API
|
||||
#endif
|
||||
|
||||
//Helper Macros
|
||||
#define MUTILS_MAKE_STRING_HELPER(X) #X
|
||||
#define MUTILS_MAKE_STRING(X) MUTILS_MAKE_STRING_HELPER(X)
|
||||
#define MUTILS_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" MUTILS_MAKE_STRING(__LINE__) ") : warning: " TXT))
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace MUtils
|
||||
{
|
||||
//Temp Folder
|
||||
const QString &temp_folder(void);
|
||||
MUTILS_API const QString& temp_folder(void);
|
||||
|
||||
//Process Utils
|
||||
void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true);
|
||||
MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true);
|
||||
|
||||
//Random
|
||||
void seed_rand(void);
|
||||
QString rand_str(const bool &bLong = false);
|
||||
quint32 next_rand32(void);
|
||||
quint64 next_rand64(void);
|
||||
MUTILS_API void seed_rand(void);
|
||||
MUTILS_API QString rand_str(const bool &bLong = false);
|
||||
MUTILS_API quint32 next_rand32(void);
|
||||
MUTILS_API quint64 next_rand64(void);
|
||||
|
||||
//Version
|
||||
const char* buildDate(void);
|
||||
MUTILS_API const char* buildDate(void);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
113
include/MUtils/KeccakHash.h
Normal file
113
include/MUtils/KeccakHash.h
Normal file
@ -0,0 +1,113 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// MuldeR's Utilities for Qt
|
||||
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
// http://www.gnu.org/licenses/lgpl-2.1.txt
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/***************************************************************************
|
||||
** **
|
||||
** QKeccakHash, an API wrapper bringing the optimized implementation of **
|
||||
** Keccak (http://keccak.noekeon.org/) to Qt. **
|
||||
** Copyright (C) 2013 Emanuel Eichhammer **
|
||||
** **
|
||||
** This program is free software: you can redistribute it and/or modify **
|
||||
** it under the terms of the GNU General Public License as published by **
|
||||
** the Free Software Foundation, either version 3 of the License, or **
|
||||
** (at your option) any later version. **
|
||||
** **
|
||||
** This program is distributed in the hope that it will be useful, **
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
|
||||
** GNU General Public License for more details. **
|
||||
** **
|
||||
** You should have received a copy of the GNU General Public License **
|
||||
** along with this program. If not, see http://www.gnu.org/licenses/. **
|
||||
** **
|
||||
****************************************************************************
|
||||
** Author: Emanuel Eichhammer **
|
||||
** Website/Contact: http://www.WorksLikeClockwork.com/ **
|
||||
** Date: 12.01.12 **
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
//MUtils
|
||||
#include <MUtils/Global.h>
|
||||
|
||||
//Qt
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QFile>
|
||||
|
||||
namespace MUtils
|
||||
{
|
||||
// Section from KeccakSponge.h
|
||||
// needed here, since hashState needs to be explicitly 32-byte aligned and therefore can't be
|
||||
// transformed into a class (in order to forward declarate) like in the other hash wrappers.
|
||||
namespace KeccakImpl
|
||||
{
|
||||
#define KeccakPermutationSize 1600
|
||||
#define KeccakPermutationSizeInBytes (KeccakPermutationSize/8)
|
||||
#define KeccakMaximumRate 1536
|
||||
#define KeccakMaximumRateInBytes (KeccakMaximumRate/8)
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define ALIGN __attribute__ ((aligned(32)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define ALIGN __declspec(align(32))
|
||||
#else
|
||||
#define ALIGN
|
||||
#endif
|
||||
|
||||
ALIGN typedef struct spongeStateStruct
|
||||
{
|
||||
ALIGN unsigned char state[KeccakPermutationSizeInBytes];
|
||||
ALIGN unsigned char dataQueue[KeccakMaximumRateInBytes];
|
||||
unsigned int rate;
|
||||
unsigned int capacity;
|
||||
unsigned int bitsInQueue;
|
||||
unsigned int fixedOutputLength;
|
||||
int squeezing;
|
||||
unsigned int bitsAvailableForSqueezing;
|
||||
}
|
||||
spongeState;
|
||||
typedef spongeState hashState;
|
||||
}
|
||||
// End Section from KeccakSponge.h
|
||||
|
||||
class MUTILS_API KeccakHash
|
||||
{
|
||||
public:
|
||||
enum HashBits {hb224, hb256, hb384, hb512};
|
||||
|
||||
KeccakHash();
|
||||
~KeccakHash();
|
||||
|
||||
static bool selfTest(void);
|
||||
|
||||
bool init(HashBits hashBits=hb256);
|
||||
bool addData(const QByteArray &data);
|
||||
bool addData(const char *data, int size);
|
||||
const QByteArray &finalize();
|
||||
|
||||
protected:
|
||||
bool m_initialized;
|
||||
KeccakImpl::hashState *m_state;
|
||||
QByteArray m_hashResult;
|
||||
};
|
||||
};
|
@ -21,6 +21,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
//MUtils
|
||||
#include <MUtils/Global.h>
|
||||
|
||||
//Qt
|
||||
#include <QString>
|
||||
#include <QDate>
|
||||
|
||||
@ -50,16 +54,16 @@ namespace MUtils
|
||||
network_type_t;
|
||||
|
||||
//Get known Folder
|
||||
const QString &known_folder(known_folder_t folder_id);
|
||||
MUTILS_API const QString &known_folder(known_folder_t folder_id);
|
||||
|
||||
//Current Date
|
||||
QDate current_date(void);
|
||||
MUTILS_API QDate current_date(void);
|
||||
|
||||
//Network Status
|
||||
int network_status(void);
|
||||
MUTILS_API int network_status(void);
|
||||
|
||||
//Error handling
|
||||
void fatal_exit(const char* const errorMessage);
|
||||
MUTILS_API void fatal_exit(const char* const errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
//MUtils
|
||||
#include <MUtils/Global.h>
|
||||
|
||||
//Qt
|
||||
#include <QThread>
|
||||
#include <QDate>
|
||||
|
||||
@ -28,7 +32,7 @@
|
||||
|
||||
namespace MUtils
|
||||
{
|
||||
class UpdateCheckerInfo
|
||||
class MUTILS_API UpdateCheckerInfo
|
||||
{
|
||||
friend class UpdateChecker;
|
||||
|
||||
@ -54,7 +58,7 @@ namespace MUtils
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
class UpdateChecker : public QThread
|
||||
class MUTILS_API UpdateChecker : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -21,106 +21,126 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
//MUtils
|
||||
#include <MUtils/Global.h>
|
||||
|
||||
//Qt
|
||||
#include <QString>
|
||||
#include <QDate>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define MUTILS_MAKE_STRING_HELPER(X) #X
|
||||
#define MUTILS_MAKE_STRING(X) MUTILS_MAKE_STRING_HELPER(X)
|
||||
#define MUTILS_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" MUTILS_MAKE_STRING(__LINE__) ") : warning: " TXT))
|
||||
#include <QTime>
|
||||
|
||||
namespace MUtils
|
||||
{
|
||||
namespace Version
|
||||
class MUTILS_API Version
|
||||
{
|
||||
//Raw Build date
|
||||
const char *const BUILD_DATE = __DATE__;
|
||||
public:
|
||||
//Get Build Date
|
||||
static const QDate build_date(const char *const date_str = build_date_raw());
|
||||
|
||||
//Get Build Data
|
||||
const QDate build_date(const char *const raw_date = BUILD_DATE);
|
||||
//Get Build Time
|
||||
static const QTime build_time(const char *const time_str = build_time_raw());
|
||||
|
||||
//Compiler detection
|
||||
#if defined(__INTEL_COMPILER)
|
||||
#if (__INTEL_COMPILER >= 1500)
|
||||
static const char *COMPILER_VERS = "ICL 15." MUTILS_MAKE_STRING(__INTEL_COMPILER_BUILD_DATE);
|
||||
#elif (__INTEL_COMPILER >= 1400)
|
||||
static const char *COMPILER_VERS = "ICL 14." MUTILS_MAKE_STRING(__INTEL_COMPILER_BUILD_DATE);
|
||||
#elif (__INTEL_COMPILER >= 1300)
|
||||
static const char *COMPILER_VERS = "ICL 13." MUTILS_MAKE_STRING(__INTEL_COMPILER_BUILD_DATE);
|
||||
#elif (__INTEL_COMPILER >= 1200)
|
||||
static const char *COMPILER_VERS = "ICL 12." MUTILS_MAKE_STRING(__INTEL_COMPILER_BUILD_DATE);
|
||||
#elif (__INTEL_COMPILER >= 1100)
|
||||
static const char *COMPILER_VERS = "ICL 11.x";
|
||||
#elif (__INTEL_COMPILER >= 1000)
|
||||
static const char *COMPILER_VERS = "ICL 10.x";
|
||||
#else
|
||||
#error Compiler is not supported!
|
||||
#endif
|
||||
#elif defined(_MSC_VER)
|
||||
#if (_MSC_VER == 1800)
|
||||
#if (_MSC_FULL_VER == 180021005)
|
||||
static const char *COMPILER_VERS = "MSVC 2013";
|
||||
#elif (_MSC_FULL_VER == 180030501)
|
||||
static const char *COMPILER_VERS = "MSVC 2013.2";
|
||||
#elif (_MSC_FULL_VER == 180030723)
|
||||
static const char *COMPILER_VERS = "MSVC 2013.3";
|
||||
#elif (_MSC_FULL_VER == 180031101)
|
||||
static const char *COMPILER_VERS = "MSVC 2013.4";
|
||||
static const char *const compiler_version(void)
|
||||
{
|
||||
#if defined(__INTEL_COMPILER)
|
||||
#if (__INTEL_COMPILER >= 1500)
|
||||
static const char *const COMPILER_VERS = "ICL 15." MUTILS_MAKE_STRING(__INTEL_COMPILER_BUILD_DATE);
|
||||
#elif (__INTEL_COMPILER >= 1400)
|
||||
static const char *const COMPILER_VERS = "ICL 14." MUTILS_MAKE_STRING(__INTEL_COMPILER_BUILD_DATE);
|
||||
#elif (__INTEL_COMPILER >= 1300)
|
||||
static const char *const COMPILER_VERS = "ICL 13." MUTILS_MAKE_STRING(__INTEL_COMPILER_BUILD_DATE);
|
||||
#elif (__INTEL_COMPILER >= 1200)
|
||||
static const char *const COMPILER_VERS = "ICL 12." MUTILS_MAKE_STRING(__INTEL_COMPILER_BUILD_DATE);
|
||||
#elif (__INTEL_COMPILER >= 1100)
|
||||
static const char *const COMPILER_VERS = "ICL 11.x";
|
||||
#elif (__INTEL_COMPILER >= 1000)
|
||||
static const char *const COMPILER_VERS = "ICL 10.x";
|
||||
#else
|
||||
#error Compiler version is not supported yet!
|
||||
#error Compiler is not supported!
|
||||
#endif
|
||||
#elif (_MSC_VER == 1700)
|
||||
#if (_MSC_FULL_VER == 170050727)
|
||||
static const char *COMPILER_VERS = "MSVC 2012";
|
||||
#elif (_MSC_FULL_VER == 170051106)
|
||||
static const char *COMPILER_VERS = "MSVC 2012.1";
|
||||
#elif (_MSC_FULL_VER == 170060315)
|
||||
static const char *COMPILER_VERS = "MSVC 2012.2";
|
||||
#elif (_MSC_FULL_VER == 170060610)
|
||||
static const char *COMPILER_VERS = "MSVC 2012.3";
|
||||
#elif (_MSC_FULL_VER == 170061030)
|
||||
static const char *COMPILER_VERS = "MSVC 2012.4";
|
||||
#elif defined(_MSC_VER)
|
||||
#if (_MSC_VER == 1800)
|
||||
#if (_MSC_FULL_VER == 180021005)
|
||||
static const char *const COMPILER_VERS = "MSVC 2013";
|
||||
#elif (_MSC_FULL_VER == 180030501)
|
||||
static const char *const COMPILER_VERS = "MSVC 2013.2";
|
||||
#elif (_MSC_FULL_VER == 180030723)
|
||||
static const char *const COMPILER_VERS = "MSVC 2013.3";
|
||||
#elif (_MSC_FULL_VER == 180031101)
|
||||
static const char *const COMPILER_VERS = "MSVC 2013.4";
|
||||
#else
|
||||
#error Compiler version is not supported yet!
|
||||
#endif
|
||||
#elif (_MSC_VER == 1700)
|
||||
#if (_MSC_FULL_VER == 170050727)
|
||||
static const char *const COMPILER_VERS = "MSVC 2012";
|
||||
#elif (_MSC_FULL_VER == 170051106)
|
||||
static const char *const COMPILER_VERS = "MSVC 2012.1";
|
||||
#elif (_MSC_FULL_VER == 170060315)
|
||||
static const char *const COMPILER_VERS = "MSVC 2012.2";
|
||||
#elif (_MSC_FULL_VER == 170060610)
|
||||
static const char *const COMPILER_VERS = "MSVC 2012.3";
|
||||
#elif (_MSC_FULL_VER == 170061030)
|
||||
static const char *const COMPILER_VERS = "MSVC 2012.4";
|
||||
#else
|
||||
#error Compiler version is not supported yet!
|
||||
#endif
|
||||
#elif (_MSC_VER == 1600)
|
||||
#if (_MSC_FULL_VER >= 160040219)
|
||||
static const char *const COMPILER_VERS = "MSVC 2010-SP1";
|
||||
#else
|
||||
static const char *const COMPILER_VERS = "MSVC 2010";
|
||||
#endif
|
||||
#elif (_MSC_VER == 1500)
|
||||
#if (_MSC_FULL_VER >= 150030729)
|
||||
static const char *const COMPILER_VERS = "MSVC 2008-SP1";
|
||||
#else
|
||||
static const char *const COMPILER_VERS = "MSVC 2008";
|
||||
#endif
|
||||
#else
|
||||
#error Compiler version is not supported yet!
|
||||
#endif
|
||||
#elif (_MSC_VER == 1600)
|
||||
#if (_MSC_FULL_VER >= 160040219)
|
||||
static const char *COMPILER_VERS = "MSVC 2010-SP1";
|
||||
#else
|
||||
static const char *COMPILER_VERS = "MSVC 2010";
|
||||
#endif
|
||||
#elif (_MSC_VER == 1500)
|
||||
#if (_MSC_FULL_VER >= 150030729)
|
||||
static const char *COMPILER_VERS = "MSVC 2008-SP1";
|
||||
#else
|
||||
static const char *COMPILER_VERS = "MSVC 2008";
|
||||
#error Compiler is not supported!
|
||||
#endif
|
||||
#else
|
||||
#error Compiler is not supported!
|
||||
#endif
|
||||
|
||||
// Note: /arch:SSE and /arch:SSE2 are only available for the x86 platform
|
||||
#if !defined(_M_X64) && defined(_M_IX86_FP)
|
||||
#if (_M_IX86_FP == 1)
|
||||
MUTILS_COMPILER_WARNING("SSE instruction set is enabled!")
|
||||
#elif (_M_IX86_FP == 2)
|
||||
MUTILS_COMPILER_WARNING("SSE2 (or higher) instruction set is enabled!")
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#error Compiler is not supported!
|
||||
#endif
|
||||
return COMPILER_VERS;
|
||||
}
|
||||
|
||||
//Architecture detection
|
||||
#if defined(_M_X64)
|
||||
static const char *COMPILER_ARCH = "x64";
|
||||
#elif defined(_M_IX86)
|
||||
static const char *COMPILER_ARCH = "x86";
|
||||
#else
|
||||
#error Architecture is not supported!
|
||||
#endif
|
||||
}
|
||||
static const char *const compiler_arch(void)
|
||||
{
|
||||
#if defined(_M_X64)
|
||||
static const char *const COMPILER_ARCH = "x64";
|
||||
#elif defined(_M_IX86)
|
||||
static const char *const COMPILER_ARCH = "x86";
|
||||
#else
|
||||
#error Architecture is not supported!
|
||||
#endif
|
||||
|
||||
return COMPILER_ARCH;
|
||||
}
|
||||
|
||||
private:
|
||||
//Raw Build date
|
||||
static const char *const build_date_raw(void)
|
||||
{
|
||||
static const char *const RAW_BUILD_DATE = __DATE__;
|
||||
return RAW_BUILD_DATE;
|
||||
}
|
||||
|
||||
//Raw Build date
|
||||
static const char *const build_time_raw(void)
|
||||
{
|
||||
static const char *const RAW_BUILD_TIME = __TIME__;
|
||||
return RAW_BUILD_TIME;
|
||||
}
|
||||
|
||||
//Disable construction
|
||||
Version(void) { throw 666; }
|
||||
Version(const Version&) { throw 666; }
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
2001
src/3rd_party/keccak_impl.h
vendored
Normal file
2001
src/3rd_party/keccak_impl.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
210
src/KeccakHash.cpp
Normal file
210
src/KeccakHash.cpp
Normal file
@ -0,0 +1,210 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// MuldeR's Utilities for Qt
|
||||
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
// http://www.gnu.org/licenses/lgpl-2.1.txt
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/***************************************************************************
|
||||
** **
|
||||
** MUtils::KeccakHash, an API wrapper bringing the optimized implementation of **
|
||||
** Keccak (http://keccak.noekeon.org/) to Qt. **
|
||||
** Copyright (C) 2013 Emanuel Eichhammer **
|
||||
** **
|
||||
** This program is free software: you can redistribute it and/or modify **
|
||||
** it under the terms of the GNU General Public License as published by **
|
||||
** the Free Software Foundation, either version 3 of the License, or **
|
||||
** (at your option) any later version. **
|
||||
** **
|
||||
** This program is distributed in the hope that it will be useful, **
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
|
||||
** GNU General Public License for more details. **
|
||||
** **
|
||||
** You should have received a copy of the GNU General Public License **
|
||||
** along with this program. If not, see http://www.gnu.org/licenses/. **
|
||||
** **
|
||||
****************************************************************************
|
||||
** Author: Emanuel Eichhammer **
|
||||
** Website/Contact: http://www.WorksLikeClockwork.com/ **
|
||||
** Date: 12.01.12 **
|
||||
****************************************************************************/
|
||||
|
||||
#include <MUtils/KeccakHash.h>
|
||||
#include <QDebug>
|
||||
|
||||
#include "3rd_party/keccak_impl.h"
|
||||
|
||||
MUtils::KeccakHash::KeccakHash()
|
||||
{
|
||||
m_initialized = false;
|
||||
m_state = (MUtils::KeccakImpl::hashState*) _aligned_malloc(sizeof(MUtils::KeccakImpl::hashState), 32);
|
||||
if(!m_state)
|
||||
{
|
||||
throw "[MUtils::KeccakHash] Error: _aligned_malloc() has failed, probably out of heap space!";
|
||||
}
|
||||
memset(m_state, 0, sizeof(MUtils::KeccakImpl::hashState));
|
||||
m_hashResult.clear();
|
||||
}
|
||||
|
||||
MUtils::KeccakHash::~KeccakHash()
|
||||
{
|
||||
m_hashResult.clear();
|
||||
|
||||
if(m_state)
|
||||
{
|
||||
_aligned_free(m_state);
|
||||
m_state = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool MUtils::KeccakHash::init(HashBits hashBits)
|
||||
{
|
||||
if(m_initialized)
|
||||
{
|
||||
qWarning("MUtils::KeccakHash has already been initialized!");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hashResult.clear();
|
||||
memset(m_state, 0, sizeof(MUtils::KeccakImpl::hashState));
|
||||
int hashBitLength = 0;
|
||||
|
||||
switch (hashBits)
|
||||
{
|
||||
case hb224: hashBitLength = 224; break;
|
||||
case hb256: hashBitLength = 256; break;
|
||||
case hb384: hashBitLength = 384; break;
|
||||
case hb512: hashBitLength = 512; break;
|
||||
default: throw "Invalid hash length!!";
|
||||
}
|
||||
|
||||
if(MUtils::KeccakImpl::Init(m_state, hashBitLength) != MUtils::KeccakImpl::SUCCESS)
|
||||
{
|
||||
qWarning("KeccakImpl::Init() has failed unexpectedly!");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hashResult.fill(char(0), hashBitLength/8);
|
||||
m_initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MUtils::KeccakHash::addData(const QByteArray &data)
|
||||
{
|
||||
return addData(data.constData(), data.size());
|
||||
}
|
||||
|
||||
bool MUtils::KeccakHash::addData(const char *data, int size)
|
||||
{
|
||||
if(!m_initialized)
|
||||
{
|
||||
qWarning("MUtils::KeccakHash has not been initialized yet!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(MUtils::KeccakImpl::Update(m_state, (MUtils::KeccakImpl::BitSequence*)data, size*8) != MUtils::KeccakImpl::SUCCESS)
|
||||
{
|
||||
qWarning("KeccakImpl::Update() has failed unexpectedly!");
|
||||
m_hashResult.clear();
|
||||
m_initialized = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const QByteArray &MUtils::KeccakHash::finalize()
|
||||
{
|
||||
if(!m_initialized)
|
||||
{
|
||||
qWarning("MUtils::KeccakHash has not been initialized yet!");
|
||||
m_hashResult.clear();
|
||||
return m_hashResult;
|
||||
}
|
||||
|
||||
if(MUtils::KeccakImpl::Final(m_state, (MUtils::KeccakImpl::BitSequence*)m_hashResult.data()) != MUtils::KeccakImpl::SUCCESS)
|
||||
{
|
||||
qWarning("KeccakImpl::Final() has failed unexpectedly!");
|
||||
m_hashResult.clear();
|
||||
}
|
||||
|
||||
m_initialized = false;
|
||||
return m_hashResult;
|
||||
}
|
||||
|
||||
bool MUtils::KeccakHash::selfTest(void)
|
||||
{
|
||||
MUtils::KeccakHash hash;
|
||||
const QByteArray input("The quick brown fox jumps over the lazy dog");
|
||||
bool passed[4] = {false, false, false, false};
|
||||
|
||||
if(hash.init(MUtils::KeccakHash::hb224))
|
||||
{
|
||||
if(hash.addData(input))
|
||||
{
|
||||
QByteArray result = hash.finalize();
|
||||
if(!result.isEmpty())
|
||||
{
|
||||
passed[0] = (_stricmp(result.toHex().constData(), "310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe") == 0);
|
||||
if(!passed[0]) qWarning("MUtils::KeccakHash self-test: Test #1 failed !!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(hash.init(MUtils::KeccakHash::hb256))
|
||||
{
|
||||
if(hash.addData(input))
|
||||
{
|
||||
QByteArray result = hash.finalize();
|
||||
if(!result.isEmpty())
|
||||
{
|
||||
passed[1] = (_stricmp(result.toHex().constData(), "4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15") == 0);
|
||||
if(!passed[1]) qWarning("MUtils::KeccakHash self-test: Test #2 failed !!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(hash.init(MUtils::KeccakHash::hb384))
|
||||
{
|
||||
if(hash.addData(input))
|
||||
{
|
||||
QByteArray result = hash.finalize();
|
||||
if(!result.isEmpty())
|
||||
{
|
||||
passed[2] = (_stricmp(result.toHex().constData(), "283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3") == 0);
|
||||
if(!passed[2]) qWarning("MUtils::KeccakHash self-test: Test #3 failed !!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(hash.init(MUtils::KeccakHash::hb512))
|
||||
{
|
||||
if(hash.addData(input))
|
||||
{
|
||||
QByteArray result = hash.finalize();
|
||||
if(!result.isEmpty())
|
||||
{
|
||||
passed[3] = (_stricmp(result.toHex().constData(), "d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609") == 0);
|
||||
if(!passed[3]) qWarning("MUtils::KeccakHash self-test: Test #4 failed !!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (passed[0] && passed[1] && passed[2] && passed[3]);
|
||||
}
|
@ -26,6 +26,10 @@
|
||||
#include <MUtils/Global.h>
|
||||
#include <MUtils/Exception.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define _snscanf(X, Y, Z, ...) _snscanf_s((X), (Y), (Z), __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char *g_months_lut[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
@ -46,31 +50,18 @@ static int month2int(const char *str)
|
||||
return ret;
|
||||
}
|
||||
|
||||
const QDate MUtils::Version::build_date(const char *const raw_date)
|
||||
const QDate MUtils::Version::build_date(const char *const date_str)
|
||||
{
|
||||
bool ok = true;
|
||||
int date[3] = {0, 0, 0};
|
||||
char temp_m[4], temp_d[3], temp_y[5];
|
||||
char month_s[4];
|
||||
|
||||
temp_m[0] = raw_date[0x0];
|
||||
temp_m[1] = raw_date[0x1];
|
||||
temp_m[2] = raw_date[0x2];
|
||||
temp_m[3] = 0x00;
|
||||
ok = ok && (_snscanf(&date_str[0x0], 3, "%s", &month_s) == 1);
|
||||
ok = ok && ((date[1] = month2int(month_s)) > 0);
|
||||
ok = ok && (_snscanf(&date_str[0x4], 2, "%d", &date[0]) == 1);
|
||||
ok = ok && (_snscanf(&date_str[0x7], 4, "%d", &date[2]) == 1);
|
||||
|
||||
temp_d[0] = raw_date[0x4];
|
||||
temp_d[1] = raw_date[0x5];
|
||||
temp_d[2] = 0x00;
|
||||
|
||||
temp_y[0] = raw_date[0x7];
|
||||
temp_y[1] = raw_date[0x8];
|
||||
temp_y[2] = raw_date[0x9];
|
||||
temp_y[3] = raw_date[0xA];
|
||||
temp_y[4] = 0x00;
|
||||
|
||||
date[0] = atoi(temp_y);
|
||||
date[1] = month2int(temp_m);
|
||||
date[2] = atoi(temp_d);
|
||||
|
||||
if(!((date[0] > 0) && (date[1] > 0) && (date[2] > 0)))
|
||||
if(!ok)
|
||||
{
|
||||
MUTILS_THROW("Internal error: Date format could not be recognized!");
|
||||
}
|
||||
@ -78,4 +69,21 @@ const QDate MUtils::Version::build_date(const char *const raw_date)
|
||||
return QDate(date[0], date[1], date[2]);
|
||||
}
|
||||
|
||||
static const QTime build_time(const char *const time_str)
|
||||
{
|
||||
bool ok = true;
|
||||
int time[3] = {0, 0, 0};
|
||||
|
||||
ok = ok && (_snscanf(&time_str[0x0], 2, "%d", &time[0]) == 1);
|
||||
ok = ok && (_snscanf(&time_str[0x3], 2, "%d", &time[1]) == 1);
|
||||
ok = ok && (_snscanf(&time_str[0x6], 2, "%d", &time[2]) == 1);
|
||||
|
||||
if(!ok)
|
||||
{
|
||||
MUTILS_THROW("Internal error: Time format could not be recognized!");
|
||||
}
|
||||
|
||||
return QTime(time[0], time[1], time[2]);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user