
Thanks to ALL of you for the precious tips and advices, BUT I conclude that the INTEL's code is really wrong OR it's made to inform wrong result in proposital way.
Let me explain:
1- The code is running CLEAR. I made a lot of modifications in ASM and VB2010 - all of them crashes the execution. Just ONE way can provide SOME right results (no crash at all).
2- Gunther, I can inform to VB2010 if I want to pass parameters as POINTER or VALUE. The INTEL code gets both: pointer to VOID* and value for INT. I tried to change the order from left to right in the parameters command-line and ALL tries made the program crash. The sent order is the SAME the source is planned to receive.
3- I have here 2 machines: one Windows 7 x64 (not SSE4x compatible) but another one Windows 8.1 x64 100% SSE4.x compatible. Both gave me the SAME results in the SHA call, so, I conclude that something is wrong. It couldn't happened...
4- I had tried also to pad the original message to SHA as required by FIPS140 (in BITS!! :icon_eek:). None effect.
5- In despite of to make changes in code (eg. pad or not the message), the most interesting thing is that the result are THE SAME, in VALID SIZE, and ramdomly acceptable (any change in the original message caused the SHA change its bytes entirely). But the results are NOT the expected ones if compared to valid SHA512 results (I had utilized two different sources: .NET library and an online SHA service).
6- The tips that all of you gave me were fundamental to compile the ASM and call from VB.
Thank YOU all. I couldn't make it alone... It's the main success to me: the fact of get a original LIB YASM source code and change it to a valid DLL file and call it from Visual Basic 2010/2012.
Congratulations to all of you and your efforts were really, really appreciated by me.Just to help SOMEONE with similar problem, basically the correct procedures to have INTEL code running here as DLL file were (considering it were compiled by YASM/NASM):
a) make both DLL entry and function PUBLIC in the source code:
Global DllMain
Global sha512_sse4
b) create the DLL entry in MS WINDOWS format within the source code (__FastCall syntax since it's a x64 code):
..start:
global DllMain:function
DllMain:
mov eax,1
ret
c) create the .DEF file (Export)
LIBRARY HASH
EXPORTS sha512_sse4
d) compile it and link utilizing the following commands:
vsyasm -f x64 -D WINABI sha512_sse4.asm
link /entry:DllMain /MACHINE:X64 /NODEFAULTLIB /def:hash.def /DLL /export:sha512_sse4 /export:DllMain /subsystem:windows sha512_sse4.obj /out:"hash.dll"
These procedures CAN create a valid x64 DLL using YASM or a compatible compiler.In the Visual Basic 2010 code I made the following steps:
a) I had declared a SUB call to the ASM function (it's NOT a function call since the ASM code does NOT return a value but changes a pointed entried variable):
Declare Sub sha512_sse4 Lib "hash.dll" (ByVal sMensagem As IntPtr, ByVal ssha As IntPtr, ByVal stamanhomensagem As UInteger)
Interesting to note that all parameters are sent BY VALUE since the next commands can get the Memory Pointers of each of them (see IntPtr above).
b) I build all parameters and after, transformed them to POINTERS to be viewed by an original C++ code - a way to make unmanaged code (C++/C) interface with a managed one (C# or VB):
Dim VarSized64bits As UInteger = (novamensagem.Trim.Length Mod 64) + 1
Dim Mess2Sha As IntPtr = Marshal.StringToHGlobalAuto(Original_String_Message)
Dim ReturnSHA(64) As Byte << an array of 64 bytes = 512 bits
Dim MessFromSha As IntPtr = Marshal.AllocHGlobal(64) ' pointer to ReturnSHA
Marshal.Copy(ReturnSHA, 0, MessFromSha, 64) ' filled by ...
sha512_sse4(Mess2Sha, MessFromSha, VarSized64bits) ' call to the %@&^#% INTEL's code
Marshal.Copy(MessFromSha, ReturnSHA, 0, 64) ' Get the result and move it to array of bytes.
' Free allocated memory.
Marshal.FreeHGlobal(Mess2Sha)
Marshal.FreeHGlobal(MessFromSha)
One day I will return to that code... I'm really tired since I'm facing on it around 2 or 3 weeks.
I understand the INTEL code HAS some problem. I can't believe the problem is about parameters order or so forth, since ANY change on the above crashes the IDE.
Again, all of you have been TOO MUCH kind with me. Thank YOU very much.
