News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

EasyCode with NASM/YASM

Started by David BS, July 11, 2014, 01:46:56 PM

Previous topic - Next topic

David BS

Ops!  Now I see H0 is a kind of SHA initialization (read carefully your message).

I believe the INTEL routine is too poor...  It could preview all these situations and provide the correct mechanism to allow programmers just to call it.

Again, you made a GREAT job qWord!  Thanks!!

David BS

qWord, just one more question:

The Sha512Auto does not return the correct value, since it multiplies the original message length for the DefaultCharSize (in VB2010/2012 = 16 bits).  Why that kind of math? I mean, since each character is really 1-byte in VB, why exactly are you doing here?

If I understand you, are you trying to make a routine to get, for instance, UNICODE strings (2-byte)?

Kindest regards and thanks!!


qWord

Quote from: David BS on July 19, 2014, 01:07:04 AMI mean, since each character is really 1-byte in VB, why exactly are you doing here?
AFAICS Unicode is the default for VB .Net - because the algorithm requires the size in bytes, such calculation must be done.

Regardless that, I add a function that accepts SAFEARRAYs as parameter, such marshaling is simplified (at least I guess that). An other function for testing SSSE3 support is also added.
Imports System.Runtime.InteropServices.Marshal
Imports System.Runtime.InteropServices

Module Module1
    Declare Function supports_SSSE3 Lib "\yasm\hash.dll" () As Boolean

    ' The hash-array must have a size of 64 byte.
    Declare Function sha512_from_array Lib "\yasm\hash.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI2)> ByRef data() As Char, <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI1)> ByRef hash() As Byte) As Boolean
    Declare Function sha512_from_array Lib "\yasm\hash.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI1)> ByRef data() As Byte, <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI1)> ByRef hash() As Byte) As Boolean
    Declare Function sha512_from_array Lib "\yasm\hash.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_I1)> ByRef data() As SByte, <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI1)> ByRef hash() As Byte) As Boolean
    Declare Function sha512_from_array Lib "\yasm\hash.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI2)> ByRef data() As UShort, <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI1)> ByRef hash() As Byte) As Boolean
    Declare Function sha512_from_array Lib "\yasm\hash.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_I2)> ByRef data() As Short, <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI1)> ByRef hash() As Byte) As Boolean
    Declare Function sha512_from_array Lib "\yasm\hash.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI4)> ByRef data() As UInteger, <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI1)> ByRef hash() As Byte) As Boolean
    Declare Function sha512_from_array Lib "\yasm\hash.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_I4)> ByRef data() As Integer, <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI1)> ByRef hash() As Byte) As Boolean
    Declare Function sha512_from_array Lib "\yasm\hash.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI8)> ByRef data() As ULong, <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI1)> ByRef hash() As Byte) As Boolean
    Declare Function sha512_from_array Lib "\yasm\hash.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_I8)> ByRef data() As Long, <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_UI1)> ByRef hash() As Byte) As Boolean

    Sub Main()

        If supports_SSSE3() Then
            Dim str As String = ""
            Dim sha512(63) As Byte

            sha512_from_array(str, sha512)
            Console.WriteLine("msg = '" & str & "'")
            Console.Write("hash = ")
            For i = 0 To sha512.GetUpperBound(0)
                Console.Write("{0:X2}", sha512(i))
            Next
            Console.WriteLine("")
            Console.WriteLine("")

            Console.WriteLine("Unicode string: ")
            str = "Some Text foo nil ..."
            sha512_from_array(str, sha512)
            Console.WriteLine("msg = '" & str & "'")
            Console.Write("hash = ")
            For i = 0 To sha512.GetUpperBound(0)
                Console.Write("{0:X2}", sha512(i))
            Next
            Console.WriteLine("")
            Console.WriteLine("")

            Console.WriteLine("ANSI string: ")
            str = "Some Text foo nil ..."
            sha512_from_array(Text.Encoding.ASCII.GetBytes(str), sha512)
            Console.WriteLine("msg = '" & str & "'")
            Console.Write("hash = ")
            For i = 0 To sha512.GetUpperBound(0)
                Console.Write("{0:X2}", sha512(i))
            Next
            Console.WriteLine("")

        Else
            Console.WriteLine("SSSE3 not supported by CPU")
        End If
        Console.ReadKey()

    End Sub

End Module


regards, qWord
MREAL macros - when you need floating point arithmetic while assembling!

David BS

 :biggrin:

Thank you very much qWord!
I'm alerady testing for SS3 thru CPUID (in MASM mode) but certainly your code is really welcome. :greenclp:
Have a terrific weekend.

Kindest regards from Rio. :t

qWord

Quote from: David BS on July 20, 2014, 10:37:23 PMI'm alerady testing for SS3 thru CPUID
You must test for SSSE3 and not SSE3 as I mistakenly wrote in one of my previous posts.
MREAL macros - when you need floating point arithmetic while assembling!

David BS

 :biggrin:
No problem at all... I had already seen it.
Thanks!!

David BS

Hi qWord!   

Could you help me a little bit again?
The DLL I have to check SSE3, SSE4.1 and so forth DOES NOT execute in x64 application.

I had studied your code above (check SSE3 in SHA512) but I'm getting success to convert it (compile).
Can you help me to get the STRUC (eax, ebx,ecd,edx) from CPUID in a single DLL file (may be JWASM or YASM/NASM compatible).

Thank you for any help. Again.
Kindest regards.