)
for %%i in (Microsoft.NET,Java,Delphi,Python) do (
- for %%j in (native,wrapper,example) do (
+ for %%j in (native,library,wrapper,example) do (
for %%k in (bin,obj,out) do (
del /Q /S /F "%~dp0\bindings\%%i\%%j\%%k\*.*" 2> NUL
)
call "%MSVC_PATH%\vcvarsall.bat"
set "MSVC_PROJECTS=MHashLib.sln"
-::set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Python\native\MHashPy384_Native.sln"
+set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Python\native\MHashPy384_Native.sln"
set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Delphi\native\MHashDelphi384.sln"
-
-set "DOTNET_PROJECTS=bindings\Microsoft.NET\MHashDotNet384.sln"
-
for %%q in (%MSVC_PROJECTS%) do (
for %%p in (x86,x64) do (
"%~dp0\tools\cecho.exe" CYAN "\n----[ %%~nq (%%~p) ]----\n"
)
)
+set "DOTNET_PROJECTS=bindings\Microsoft.NET\MHashDotNet384.sln"
for %%q in (%DOTNET_PROJECTS%) do (
"%~dp0\tools\cecho.exe" CYAN "\n----[ %%~nq (%%~p) ]----\n"
MSBuild.exe /property:Platform="Any CPU" /property:Configuration=Release /target:Clean "%~dp0\%%~q"
if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
)
-
for %%q in (example) do (
echo pushd "%~dp0\bindings\Delphi\%%~q"
pushd "%~dp0\bindings\Delphi\%%~q"
:GenerateOutfileNameNext
set "OUT_PATH_BIN_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.bin-msvc-x86.zip"
set "OUT_PATH_BIN_X64=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.bin-msvc-x64.zip"
-set "OUT_PATH_NET_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.dotnet-x86.zip"
-set "OUT_PATH_NET_X64=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.dotnet-x64.zip"
-set "OUT_PATH_JNI_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.java-win-x86.zip"
-set "OUT_PATH_JNI_X64=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.java-win-x64.zip"
+set "OUT_PATH_NET_GEN=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.bin-dotnet.zip"
+set "OUT_PATH_JNI_GEN=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.bin-java.zip"
set "OUT_PATH_PYC_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.python-win-x86.zip"
set "OUT_PATH_PYC_X64=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.python-win-x64.zip"
set "OUT_PATH_PAS_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.delphi-win-x86.zip"
if exist "%OUT_PATH_BIN_X86%" goto GenerateOutfileNameNext
if exist "%OUT_PATH_BIN_X64%" goto GenerateOutfileNameNext
-if exist "%OUT_PATH_NET_X86%" goto GenerateOutfileNameNext
-if exist "%OUT_PATH_NET_X64%" goto GenerateOutfileNameNext
-if exist "%OUT_PATH_JNI_X86%" goto GenerateOutfileNameNext
-if exist "%OUT_PATH_JNI_X64%" goto GenerateOutfileNameNext
+if exist "%OUT_PATH_NET_GEN%" goto GenerateOutfileNameNext
+if exist "%OUT_PATH_JNI_GEN%" goto GenerateOutfileNameNext
if exist "%OUT_PATH_PYC_X86%" goto GenerateOutfileNameNext
if exist "%OUT_PATH_PYC_X64%" goto GenerateOutfileNameNext
if exist "%OUT_PATH_PAS_X86%" goto GenerateOutfileNameNext
"%~dp0\tools\cecho.exe" YELLOW "\n========[ PACKAGING ]========\n"
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_BIN_X86%" "%~dp0\bin\Win32\Release\mhash_384.x86.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_BIN_X64%" "%~dp0\bin\x64\.\Release\mhash_384.x64.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_BIN_X86%" "%~dp0\bin\Win32\Release\mhash_384.x86.exe" "%~dp0\include\mhash_384.h" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_BIN_X64%" "%~dp0\bin\x64\.\Release\mhash_384.x64.exe" "%~dp0\include\mhash_384.h" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_NET_X86%" "%~dp0\bindings\Microsoft.NET\wrapper\bin\x86\Release\MHashDotNet384.x86.dll" "%~dp0\bindings\Microsoft.NET\example\bin\x86\Release\MHashDotNet384.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_NET_X64%" "%~dp0\bindings\Microsoft.NET\wrapper\bin\x64\Release\MHashDotNet384.x64.dll" "%~dp0\bindings\Microsoft.NET\example\bin\x64\Release\MHashDotNet384.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_NET_GEN%" "%~dp0\bindings\Microsoft.NET\library\bin\Release\MHashDotNet384.dll" "%~dp0\bindings\Microsoft.NET\example\bin\Release\MHashDotNet384.Example.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_JNI_X86%" "%~dp0\bindings\Java\native\bin\x86\Release\MHashJava384.x86.dll" "%~dp0\bindings\Java\wrapper\out\MHashJava384-Wrapper.jar" "%~dp0\bindings\Java\example\out\MHashJava384-Example.jar" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_JNI_X64%" "%~dp0\bindings\Java\native\bin\x64\Release\MHashJava384.x64.dll" "%~dp0\bindings\Java\wrapper\out\MHashJava384-Wrapper.jar" "%~dp0\bindings\Java\example\out\MHashJava384-Example.jar" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_JNI_GEN%" "%~dp0\bindings\Java\library\out\MHashJava384.jar" "%~dp0\bindings\Java\example\out\MHashJava384-Example.jar" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X86%" "%~dp0\bindings\Python\native\bin\x86\Release\MHashPy384_Native.x86.pyd" "%~dp0\bindings\Python\wrapper\MHashPy384_Wrapper.py" "%~dp0\bindings\Python\wrapper\mhash.pth" "%~dp0\bindings\Python\example\MHashPy384_Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X64%" "%~dp0\bindings\Python\native\bin\x64\Release\MHashPy384_Native.x64.pyd" "%~dp0\bindings\Python\wrapper\MHashPy384_Wrapper.py" "%~dp0\bindings\Python\wrapper\mhash.pth" "%~dp0\bindings\Python\example\MHashPy384_Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
<ApplicationIcon>exe.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
- <StartupObject>MHashDotNet384.Example.App</StartupObject>
+ <StartupObject>MHashDotNet384.Example.Startup</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
using System.Collections.Generic;
using System.Configuration;
using System.Data;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Windows;
namespace MHashDotNet384.Example
public partial class App : Application
{
}
+
+ internal static class Startup
+ {
+ [STAThread()]
+ [System.Diagnostics.DebuggerNonUserCode()]
+ public static void Main()
+ {
+#if DEBUG
+ LaunchApplication();
+#else
+ try
+ {
+ AppDomain.CurrentDomain.UnhandledException += UnhandeledExceptionHandler;
+ LaunchApplication();
+ }
+ catch (Exception e)
+ {
+ UnhandeledExceptionHandler(e);
+ }
+#endif
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static void LaunchApplication()
+ {
+ App app = new App();
+ app.InitializeComponent();
+ app.Run();
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static void UnhandeledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
+ {
+ UnhandeledExceptionHandler(e.ExceptionObject as Exception);
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static void UnhandeledExceptionHandler(Exception e)
+ {
+ try
+ {
+ const String PREFIX = "A critical error has occurred, the application needs to terminate";
+ String text = String.IsNullOrWhiteSpace(e.Message) ? String.Concat(PREFIX, '!') : String.Concat(PREFIX, ":\n\n", e.Message);
+ MessageBox.Show(text, AppDomain.CurrentDomain.FriendlyName, MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ finally
+ {
+ Environment.Exit(666);
+ }
+ }
+ }
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ushort major, minor, patch;
- MHashDotNet384.MHash384.GetVersion(out major, out minor, out patch);
+ MHash384.GetVersion(out major, out minor, out patch);
Title += String.Format(" v{0:D}.{1:D}.{2:D}", major, minor, patch);
KeyDown += new KeyEventHandler(KeyDownHandler);
}
if(e.Key == Key.F12)
{
SetBusy(true);
+ e.Handled = true;
try
{
await Task.Run(() => MHash384.SelfTest());
// TestVector
private struct TestVector
{
+ private static readonly Encoding ENC_LATIN1 = Encoding.GetEncoding("ISO-8859-1");
+
public readonly uint itrations;
- public readonly String message;
+ public readonly ConstArray<byte> message;
public TestVector(uint itrations, String message)
{
this.itrations = itrations;
- this.message = message;
+ this.message = new ConstArray<byte>(ENC_LATIN1.GetBytes(message));
}
}
}
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public override String ToString()
{
ConstArray<byte> digest = this.Digest;
for (int i = 0; i < TEST_VECTOR.Length; ++i)
{
MHash384 mhash384 = new MHash384();
- ConstArray<byte> input = new ConstArray<byte>(Encoding.GetEncoding("ISO-8859-1").GetBytes(TEST_VECTOR[i].message));
for(int j = 0; j < TEST_VECTOR[i].itrations; ++j)
{
- mhash384.Update(input);
+ mhash384.Update(TEST_VECTOR[i].message);
}
- Trace.WriteLine(mhash384);
+ Trace.WriteLine(String.Format("TEST_VECTOR[{0:X}] = {1}", i, mhash384));
if (!mhash384.Digest.Equals(TEST_RESULT[i]))
{
throw new InvalidDataException("Test vector did NOT comapre equal!");
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MHASHJAVA384_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\..\..\..\include;$(PYTHON_INC)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\..\..\..\include;$(PYTHON_HOME_INC)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <AdditionalLibraryDirectories>$(PYTHON_LIB32);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>$(PYTHON_HOME_LIB32);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;MHASHJAVA384_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\..\..\..\include;$(PYTHON_INC)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\..\..\..\include;$(PYTHON_HOME_INC)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <AdditionalLibraryDirectories>$(PYTHON_LIB64);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>$(PYTHON_HOME_LIB64);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MHASHJAVA384_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\..\..\..\include;$(PYTHON_INC)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\..\..\..\include;$(PYTHON_HOME_INC)</AdditionalIncludeDirectories>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>No</GenerateDebugInformation>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
- <AdditionalLibraryDirectories>$(PYTHON_LIB32);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>$(PYTHON_HOME_LIB32);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;MHASHJAVA384_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\..\..\..\include;$(PYTHON_INC)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\..\..\..\include;$(PYTHON_HOME_INC)</AdditionalIncludeDirectories>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>No</GenerateDebugInformation>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
- <AdditionalLibraryDirectories>$(PYTHON_LIB64);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>$(PYTHON_HOME_LIB64);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
static PyObject *MHashPy384_Create(PyObject *const self, PyObject *const args)
{
- return PyLong_FromVoidPtr(new mhash::MHash384());
+ return PyLong_FromVoidPtr(new mhash_384::MHash384());
}
static PyObject *MHashPy384_Update(PyObject *const self, PyObject *const args)
const size_t sum = offset_val + len_val;
if ((sum >= offset_val) && (sum >= len_val) && (sum <= total_size))
{
- reinterpret_cast<mhash::MHash384*>(inst_ptr)->update(reinterpret_cast<uint8_t*>(PyBytes_AsString(data)) + offset_val, len_val);
+ reinterpret_cast<mhash_384::MHash384*>(inst_ptr)->update(reinterpret_cast<uint8_t*>(PyBytes_AsString(data)) + offset_val, len_val);
Py_RETURN_TRUE;
}
}
static PyObject *MHashPy384_Result(PyObject *const self, PyObject *const args)
{
- uint8_t buffer[MHASH_384_LEN];
+ uint8_t buffer[mhash_384::MHash384::HASH_LEN];
PyObject *instance = NULL;
if (PyArg_UnpackTuple(args, "MHash384_Update", 1, 1, &instance))
{
void *const inst_ptr = PyLong_AsVoidPtr(instance);
if (inst_ptr)
{
- reinterpret_cast<mhash::MHash384*>(inst_ptr)->finalize(buffer);
- return PyByteArray_FromStringAndSize(reinterpret_cast<const char*>(buffer), MHASH_384_LEN);
+ reinterpret_cast<mhash_384::MHash384*>(inst_ptr)->finalize(buffer);
+ return PyByteArray_FromStringAndSize(reinterpret_cast<const char*>(buffer), mhash_384::MHash384::HASH_LEN);
}
}
}
void *const inst_ptr = PyLong_AsVoidPtr(instance);
if (inst_ptr)
{
- delete reinterpret_cast<mhash::MHash384*>(inst_ptr);
+ delete reinterpret_cast<mhash_384::MHash384*>(inst_ptr);
Py_RETURN_TRUE;
}
}
static PyObject *MHashPy384_GetVer(PyObject *const self, PyObject *const args)
{
- return Py_BuildValue("(kkk)", MHASH_384_VERSION_MAJOR, MHASH_384_VERSION_MINOR, MHASH_384_VERSION_PATCH);
+ uint16_t major, minor, patch;
+ mhash_384::MHash384::version(major, minor, patch);
+ return Py_BuildValue("(kkk)", (uint32_t)major, (uint32_t)minor, (uint32_t)patch);
}
/* ------------------------------------------------------------------------*/