From bb22805cbc68988b0a2f242f008690482bc378ba Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Wed, 26 Apr 2017 17:30:19 +0300 Subject: [PATCH] PhraseSet.FillPhraseSet moved out to unmanaged code --- .../WhiteRabbit.UnmanagedBridge.cpp | 14 +++++++------- .../WhiteRabbit.UnmanagedBridge.h | 4 +++- .../WhiteRabbit.UnmanagedBridge.vcxproj | 1 + dotnet/WhiteRabbit.UnmanagedBridge/constants.h | 3 +++ 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 dotnet/WhiteRabbit.UnmanagedBridge/constants.h diff --git a/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.cpp b/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.cpp index 320c742..26a2324 100644 --- a/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.cpp +++ b/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.cpp @@ -28,10 +28,10 @@ void WhiteRabbitUnmanagedBridge::MD5Unmanaged::ComputeMD5(unsigned __int32 * inp void WhiteRabbitUnmanagedBridge::MD5Unmanaged::FillPhraseSet(__int64* bufferPointer, __int64* allWordsPointer, __int32* wordIndexes, unsigned __int64* permutationsPointer, int permutationOffset, int numberOfCharacters, int numberOfWords) { - long* longBuffer = (long*)bufferPointer; + __int64* longBuffer = (__int64*)bufferPointer; auto currentPermutationPointer = permutationsPointer + permutationOffset; - for (auto i = 0; i < WhiteRabbitUnmanagedBridge::MD5Unmanaged::PhrasesPerSet; i++, currentPermutationPointer++) + for (auto i = 0; i < PHRASES_PER_SET; i++, currentPermutationPointer++) { auto permutation = *currentPermutationPointer; if (permutation == 0) @@ -48,7 +48,7 @@ void WhiteRabbitUnmanagedBridge::MD5Unmanaged::FillPhraseSet(__int64* bufferPoin longBuffer[1] |= currentWord[cumulativeWordOffsetX4 + 1]; longBuffer[2] ^= currentWord[cumulativeWordOffsetX4 + 2]; longBuffer[3] ^= currentWord[cumulativeWordOffsetX4 + 3]; - cumulativeWordOffsetX4 += (int)currentWord[127]; + cumulativeWordOffsetX4 += (__int32)currentWord[127]; } longBuffer += 4; @@ -56,15 +56,15 @@ void WhiteRabbitUnmanagedBridge::MD5Unmanaged::FillPhraseSet(__int64* bufferPoin auto length = numberOfCharacters + numberOfWords - 1; unsigned char* byteBuffer = ((unsigned char*)bufferPointer) + length; - for (auto i = 0; i < WhiteRabbitUnmanagedBridge::MD5Unmanaged::PhrasesPerSet; i++) + for (auto i = 0; i < PHRASES_PER_SET; i++) { *byteBuffer = 128; byteBuffer += 32; } - auto lengthInBits = (unsigned int)(length << 3); - unsigned int* uintBuffer = ((unsigned int*)bufferPointer) + 7; - for (auto i = 0; i < WhiteRabbitUnmanagedBridge::MD5Unmanaged::PhrasesPerSet; i++) + auto lengthInBits = (unsigned __int32)(length << 3); + unsigned int* uintBuffer = ((unsigned __int32*)bufferPointer) + 7; + for (auto i = 0; i < PHRASES_PER_SET; i++) { *uintBuffer = lengthInBits; uintBuffer += 8; diff --git a/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.h b/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.h index bd4c54d..1299040 100644 --- a/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.h +++ b/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.h @@ -2,6 +2,8 @@ #pragma once +#include "constants.h" + using namespace System; namespace WhiteRabbitUnmanagedBridge { @@ -9,7 +11,7 @@ namespace WhiteRabbitUnmanagedBridge { public ref class MD5Unmanaged { public: - literal int PhrasesPerSet = 16; + literal int PhrasesPerSet = PHRASES_PER_SET; static void ComputeMD5(unsigned int* input, unsigned int* output); static void FillPhraseSet(__int64* bufferPointer, __int64* allWordsPointer, __int32* wordIndexes, unsigned __int64* permutationsPointer, int permutationOffset, int numberOfCharacters, int numberOfWords); }; diff --git a/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.vcxproj b/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.vcxproj index f430937..4bdd091 100644 --- a/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.vcxproj +++ b/dotnet/WhiteRabbit.UnmanagedBridge/WhiteRabbit.UnmanagedBridge.vcxproj @@ -133,6 +133,7 @@ + diff --git a/dotnet/WhiteRabbit.UnmanagedBridge/constants.h b/dotnet/WhiteRabbit.UnmanagedBridge/constants.h new file mode 100644 index 0000000..12c14e7 --- /dev/null +++ b/dotnet/WhiteRabbit.UnmanagedBridge/constants.h @@ -0,0 +1,3 @@ +#pragma once + +#define PHRASES_PER_SET 16