Announcement

Collapse
No announcement yet.

Im stucked with SSL connection... Help?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Im stucked with SSL connection... Help?

    Im trying to follow the MSNP15 Protocol to connect to MSN Messenger and programatically retrieve my contact list, but im getting stucked in the part where i need to make a SSL connection and send the XML identification.

    Help?

    Here is the pages i am using as reference:

    http://msnpiki.msnfanatic.com/index.php/MSNP15:SSO (English)
    http://www.enye-sec.org/pepelux/?p=11 (Spanish, very messy)

    I will appreciate any guidance on this or pointers to online examples, as well as open source examples.

    Thanx!!


    Code:
    #COMPILE EXE
    #DIM ALL
    
    $EmailAddress = "[email protected]"
    $Password     = "examplepassword"
    
    
    '=================================================================
    FUNCTION WriteMsnPort(FF AS LONG, TCPLine AS STRING, OPT AsIs AS LONG) AS STRING
     STATIC CurTran AS LONG
     LOCAL Index    AS LONG
     LOCAL Buffer   AS STRING
     LOCAL Answer   AS STRING
     ERRCLEAR
     IF INSTR(TCPLine, "%TRN") THEN
      INCR CurTran
      REPLACE "%TRN" WITH FORMAT$(CurTran) IN TCPLine
     END IF
     IF ISTRUE(VARPTR(AsIs)) THEN
      IF AsIs THEN
       'MSGBOX ">>" & TCPLine
       TCP SEND #FF, TCPLine & $CRLF
      ELSE
       GOTO ByParts
      END IF
     ELSE
      ByParts:
      TcpLine = TcpLine & $CRLF
      FOR Index = 1 TO PARSECOUNT(Tcpline, $CRLF)
       IF ISTRUE(LEN(PARSE$(TCPLine, $CRLF, Index))) THEN
         'msgbox ">>" & PARSE$(TCPLine, $CRLF, Index) & $CRLF
         TCP PRINT #FF, PARSE$(TCPLine, $CRLF, Index)
       END IF
      NEXT Index
     END IF
    
    
     Keepreading:
      TCP LINE #FF, Buffer
      Answer = (Answer & Buffer) & $CRLF
      IF EOF(FF) THEN GOTO ReceiveDone
      GOTO KeepReading
     ReceiveDone:
    
     'MSGBOX "<<" & Answer
    
     FUNCTION = Answer
    END FUNCTION
    '=================================================================
    FUNCTION XMLSkeleton AS STRING
    
    FUNCTION = _
    "<Envelope xmlns=""http://schemas.xmlsoap.org/soap/envelope/""" & $CRLF & _
    "   xmlns:wsse=""http://schemas.xmlsoap.org/ws/2003/06/secext""" & $CRLF & _
    "   xmlns:saml=""urn:oasis:names:tc:SAML:1.0:assertion""" & $CRLF & _
    "   xmlns:wsp=""http://schemas.xmlsoap.org/ws/2002/12/policy""" & $CRLF & _
    "   xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd""" & $CRLF & _
    "   xmlns:wsa=""http://schemas.xmlsoap.org/ws/2004/03/addressing""" & $CRLF & _
    "   xmlns:wssc=""http://schemas.xmlsoap.org/ws/2004/04/sc""" & $CRLF & _
    "   xmlns:wst=""http://schemas.xmlsoap.org/ws/2004/04/trust"">" & $CRLF & _
    "   <Header>" & $CRLF & _
    "       <ps:AuthInfo" & $CRLF & _
    "           xmlns:ps=""http://schemas.microsoft.com/Passport/SoapServices/PPCRL""" & $CRLF & _
    "           Id=""PPAuthInfo"">" & $CRLF & _
    "           <ps:HostingApp>{7108E71A-9926-4FCB-BCC9-9A9D3F32E423}</ps:HostingApp>" & $CRLF & _
    "           <ps:BinaryVersion>4</ps:BinaryVersion>" & $CRLF & _
    "           <ps:UIVersion>1</ps:UIVersion>" & $CRLF & _
    "           <ps:Cookies></ps:Cookies>" & $CRLF & _
    "           <ps:RequestParams>AQAAAAIAAABsYwQAAAAxMDMz</ps:RequestParams>" & $CRLF & _
    "       </ps:AuthInfo>" & $CRLF & _
    "       <wsse:Security>" & $CRLF & _
    "           <wsse:UsernameToken Id=""user"">" & $CRLF & _
    "               <wsse:Username><<<MyEmailAddress>>></wsse:Username>" & $CRLF & _
    "               <wsse:Password><<<MyPassword>>></wsse:Password>" & $CRLF & _
    "           </wsse:UsernameToken>" & $CRLF & _
    "       </wsse:Security>" & $CRLF & _
    "   </Header>" & $CRLF & _
    "   <Body>" & $CRLF & _
    "       <ps:RequestMultipleSecurityTokens" & $CRLF & _
    "           xmlns:ps=""http://schemas.microsoft.com/Passport/SoapServices/PPCRL""" & $CRLF & _
    "           Id=""RSTS"">" & $CRLF & _
    "           <wst:RequestSecurityToken Id=""RST0"">" & $CRLF & _
    "               <wst:RequestType>http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue</wst:RequestType>" & $CRLF & _
    "               <wsp:AppliesTo>" & $CRLF & _
    "                   <wsa:EndpointReference>" & $CRLF & _
    "                       <wsa:Address>http://Passport.NET/tb</wsa:Address>" & $CRLF & _
    "                   </wsa:EndpointReference>" & $CRLF & _
    "               </wsp:AppliesTo>" & $CRLF & _
    "           </wst:RequestSecurityToken>" & $CRLF & _
    "           <wst:RequestSecurityToken Id=""RSTn"">" & $CRLF & _
    "               <wst:RequestType>http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue</wst:RequestType>" & $CRLF & _
    "               <wsp:AppliesTo>" & $CRLF & _
    "                   <wsa:EndpointReference>" & $CRLF & _
    "                       <wsa:Address>domain</wsa:Address>" & $CRLF & _
    "                   </wsa:EndpointReference>" & $CRLF & _
    "               </wsp:AppliesTo>" & $CRLF & _
    "               <wsse:PolicyReference URI=""<<<MBI_KEY_OLD>>>""></wsse:PolicyReference>" & $CRLF & _
    "           </wst:RequestSecurityToken>" & $CRLF & _
    "       </ps:RequestMultipleSecurityTokens>" & $CRLF & _
    "   </Body>" & $CRLF & _
    "</Envelope>"
    
    END FUNCTION
    
    '=================================================================
    
    FUNCTION PBMAIN () AS LONG
    
    
    LOCAL Hserver1   AS LONG
    LOCAL HServer2   AS LONG
    LOCAL FF1        AS LONG
    LOCAL FF2        AS LONG
    LOCAL NextServer AS STRING
    LOCAL Result     AS STRING
    LOCAL XML        AS STRING
    LOCAL Key        AS STRING
    
    
    
    FF1 = FREEFILE
    ERRCLEAR
    TCP OPEN PORT 1863 AT "207.46.96.153" AS #FF1
    
    Result     = WriteMsnPort(FF1, "VER %TRN MSNP15 CVR0")
    Result     = WriteMsnPort(FF1, "CVR %TRN 0x0C0A winnt 5.1 i686 MSNMSGR 8.1.0178 MSFT " & $EmailAddress )
    NextServer = PARSE$(WriteMsnPort(FF1, "USR %TRN SSO I " & $EmailAddress), " ", 4)
    
    TCP CLOSE #FF1
    
    ERRCLEAR
    FF1 = FREEFILE
    TCP OPEN PORT VAL(PARSE$(NextServer, ":", 2)) AT PARSE$(NextServer, ":", 1) AS #FF1
    
    Result     = WriteMsnPort(FF1, "VER %TRN MSNP15 CVR0")
    Result     = WriteMsnPort(FF1, "CVR %TRN 0x0C0A winnt 5.1 i686 MSNMSGR 8.1.0178 MSFT " & $EmailAddress)
    Result     = WriteMsnPort(FF1, "USR %TRN SSO I " & $EmailAddress)
    
    Key = TRIM$(MID$(Result, INSTR(-1, Result, " "), 256), ANY " " & $CRLF)
    
    XML = XMLSkeleton()
    
    REPLACE "<<<MyEmailAddress>>>" WITH $emailaddress IN XML
    REPLACE "<<<MyPassword>>>"     WITH $Password     IN XML
    REPLACE "<<<MBI_KEY_OLD>>>"    WITH Key           IN XML
    
    
    '=THIS IS THE PART IM HAVING PROBLEMS WITH=====================
    
    ERRCLEAR
    FF2 = FREEFILE
    'TCP OPEN PORT 80 AT "https://login.live.com/RST.srf" AS #FF2  'How could i connect to this???
    TCP OPEN PORT 80 AT "https://login.live.com" AS #FF2
    
    MSGBOX STR$(ERR)
    
    Result     = WriteMsnPort(FF2, XML, 1)
    
    MSGBOX Result
    
    '==============================================================
    
    
    TCP CLOSE #FF1
    TCP CLOSE #FF2
    
    
    
    END FUNCTION

    #2
    Try using the SSL Port 443 and make sure your firewall will allow you to use Port 443.
    sigpic

    RBenjamin at e-commerce-engineering.com

    www.e-commerce-engineering.com

    Comment


      #3
      Originally posted by Roy Benjamin View Post
      Try using the SSL Port 443 and make sure your firewall will allow you to use Port 443.
      Yes, it works when i connect to:


      But how do i connect to:


      ??

      Much worse, this is the first time i try SSL connections. Judging by
      old posts (2005), seems like almost no PB'ers have tried them?? lots
      of unanswered threads.

      Oh, and to make things worse, the only reference to some code i need
      to translate to PB is this:


      Or this:


      Both in languages i dont know anything about... Im going to need lots of help
      here... Please guys!!!!

      I will put the final results in the Source code forum!!

      Comment


        #4
        Ok there is absolutely nothing i can do now. Im going to have to wait and
        see if somebody knows about this.

        Comment


          #5
          You can't do it with PB's built-in TCP functions, which don't support SSL. Search for my posts in this forum, you'll find several examples using the MSXML COM interface, which fully supports SSL .
          --pdf

          Comment


            #6
            Originally posted by Paul Franks View Post
            You can't do it with PB's built-in TCP functions, which don't support SSL. Search for my posts in this forum, you'll find several examples using the MSXML COM interface, which fully supports SSL .
            Thanx paul. I am realizing this task is beyond my knowledge and i would need
            to learn many things in order to accomplish it. A visual example would help a lot,
            otherwise i will need to read for days before i find whats necessary.

            I made a search for your posts, but now knowing exactly what i am looking for,
            is nearly imposible.

            BTW, im clueless about COM.

            Comment


              #7
              NO. I wont give up. I already made the code for the POST, now i just need to
              send it using SSL. Lots of work but ill do it.

              Comment


                #8
                There's a very basic GET example here:



                Fully supports SSL, just start the URL with "https". Quite easy to change from GET to POST, too.
                --pdf

                Comment


                  #9
                  Originally posted by Paul Franks View Post
                  There's a very basic GET example here:



                  Fully supports SSL, just start the URL with "https". Quite easy to change from GET to POST, too.
                  Thanx paul, you are very kind. But its not easy for me at all, im at 0 here.
                  i am just learning. How do i define this headers?
                  Code:
                  POST /RST.srf HTTP/1.1
                  Accept: text/*
                  User-Agent: Vega
                  Host: loginnet.passport.com
                  Content-Length: ##
                  Connection: Keep-Alive
                  Cache-Control: no-cache

                  Comment


                    #10
                    Wow this is quite easy... why was i so afraid of COM??

                    Added:
                    Ahhhhhh So thats how COM works!!! it creates templates for functions without the need of declaring variable types!!
                    wow... a new worls is suddenly opening before my eyes.

                    I used the "Msxml2.DOMDocument" here, right? Where do i browse what other commands besides "open" and "save" can i use?
                    Last edited by Elias Montoya; 10 Feb 2008, 10:27 PM.

                    Comment


                      #11
                      Looks like this is a SOAP request. See this thread for some SOAP suds:

                      --pdf

                      Comment


                        #12
                        Also be sure to read this post all the way through to avoid the possibility of memory leaks:



                        You can glean a lot of information about the interface's methods by generating the include file for it using PB's wonderful COM browser tool. But be sure to read the MSDN docs, and Jose Roca's excellent COM tutorials.
                        --pdf

                        Comment


                          #13
                          Great! This is already working! Thanx paul! Now i need to take care of the last Hard part... after that, everything gets easier:



                          Here is the C++ version:


                          I will appreciate any help in translating this, i dont know much that languages,
                          otherwise i will do it, but it will take longer.

                          Comment


                            #14
                            Ahh I found an easier one (Since i dont know Pyton):

                            Code:
                            'Working MSNP15 MBI MODULE
                            'Coded By Mario Achkar [[url]http://www.c2wn.com][/url]
                            'Enjoy
                            'Use mbi_encrypt(key,hashnonce)
                            'Special thanks : thesteve , oleavr
                            Imports System.Security.Cryptography
                            Imports System.Text
                            Module MBI
                                Private Const CRYPT_MODE_CBC = 1
                                Private Const CALC_3DES = 26115
                                Private Const CALG_SHA1 = 32772
                                Public Function MakeDWord(ByVal worker As String, Optional ByVal BigEndian As Boolean = True) As String
                                    Dim mdi As String, mdi1 As String, X As Integer
                                    mdi = Replace(Space(8), " ", "0") : mdi1 = Hex(worker)
                                    Mid(mdi, Len(mdi) - Len(mdi1) + 1, Len(mdi1)) = mdi1
                                    MakeDWord = ""
                                    If BigEndian = True Then
                                        For X = 1 To 8 Step 2
                                            MakeDWord = Chr(Val("&H" & Mid(mdi, X, 2))) & MakeDWord
                                        Next X
                                    Else
                                        For X = 1 To 8 Step 2
                                            MakeDWord += Chr(Val("&H" & Mid(mdi, X, 2)))
                                        Next X
                                    End If
                                End Function
                                Public Function MBI_Encrypt(ByVal key As String, ByVal nonce As String) As String
                                    Dim key1() As Byte, key2 As String, key3 As String, hash() As Byte, alg2 As HMACSHA1
                                    Dim alg3 As TripleDESCryptoServiceProvider, iv(), gg() As Byte
                                    Dim akm As ICryptoTransform, blob As String, kk(71) As Byte
                                    key1 = Convert.FromBase64String(key)
                                    key2 = derive_key(key1, "WS-SecureConversationSESSION KEY HASH")
                                    key3 = derive_key(key1, "WS-SecureConversationSESSION KEY ENCRYPTION")
                                    alg2 = HMACSHA1.Create
                                    alg2.Key = Encoding.Default.GetBytes(key2)
                                    hash = alg2.ComputeHash(Encoding.Default.GetBytes(nonce))
                                    Randomize()
                                    iv = Encoding.Default.GetBytes(Mid(Convert.ToBase64String(Encoding.Default.GetBytes(Rnd())), 4, 8))
                                    alg3 = TripleDESCryptoServiceProvider.Create
                                    alg3.Key = Encoding.Default.GetBytes(key3)
                                    alg3.Mode = CipherMode.CBC
                                    alg3.IV = iv
                                    akm = alg3.CreateEncryptor
                                    gg = Encoding.Default.GetBytes(nonce & Chr(8) & Chr(8) & Chr(8) & Chr(8) & Chr(8) & Chr(8) & Chr(8) & Chr(8))
                                    akm.TransformBlock(gg, 0, gg.Length, kk, 0)
                                    blob = MakeDWord(28) & MakeDWord(CRYPT_MODE_CBC) & MakeDWord(CALC_3DES) & MakeDWord(CALG_SHA1) & MakeDWord(iv.Length) & MakeDWord(hash.Length) & MakeDWord(kk.Length) & _
                                    Encoding.Default.GetString(iv) & Encoding.Default.GetString(hash) & Encoding.Default.GetString(kk)
                                    Return Convert.ToBase64String(Encoding.Default.GetBytes(blob))
                                End Function
                                Private Function derive_key(ByVal key() As Byte, ByVal magic As String) As String
                                    Dim alg1 As HMACSHA1, hash1(), hash2(), hash3(), hash4() As Byte, magicb() As Byte
                                    magicb = Encoding.Default.GetBytes(magic)
                                    alg1 = HMACSHA1.Create
                                    alg1.Key = key
                                    hash1 = alg1.ComputeHash(magicb)
                                    hash2 = alg1.ComputeHash(Encoding.Default.GetBytes(Encoding.Default.GetString(hash1) & magic))
                                    hash3 = alg1.ComputeHash(hash1)
                                    hash4 = alg1.ComputeHash(Encoding.Default.GetBytes(Encoding.Default.GetString(hash3) & magic))
                                    Return Encoding.Default.GetString(hash2) & Mid(Encoding.Default.GetString(hash4), 1, 4)
                                End Function
                            End Module
                            This should be easier to translate to PB, but im very tired, im posting it here
                            in case somebody wants to give it a try and translate it at least in part while
                            i spend some quality time with my pillow... If not. I will translate it tomorrow.

                            Ok, i have to go, my pillow is yelling at me.

                            Comment


                              #15
                              All of the encryption routines were ported to PB long ago, and used to be maintained at http://www.pbcrypto.com

                              The link doesn't appear to be working anymore, hopefully someone here has copies of the required functions for you.

                              Try looking here:

                              Last edited by Paul Franks; 10 Feb 2008, 11:26 PM.
                              --pdf

                              Comment


                                #16
                                Must be something really simple, What am i doing wrong here?

                                Code:
                                #COMPILE EXE
                                #DIM ALL
                                
                                MACRO CreateObject(id) = NEW DISPATCH IN id
                                
                                FUNCTION PBMAIN () AS LONG
                                
                                 LOCAL Hasher AS DISPATCH
                                 LOCAL Hash   AS VARIANT
                                 LOCAL Result AS VARIANT
                                
                                 LET Hasher = CreateObject("HMACSHA1")
                                
                                 Hash   = "ExampleLinetoHash"
                                
                                 OBJECT CALL Hasher.ComputeHash(Hash) TO Result
                                
                                 MSGBOX VARIANT$(Result)
                                
                                 SET Hasher = NOTHING
                                
                                END FUNCTION
                                Last edited by Elias Montoya; 11 Feb 2008, 11:36 AM.

                                Comment


                                  #17
                                  Beats me... i cant figure this one out.

                                  Comment


                                    #18
                                    HMACSHA1 is a .NET class, not a COM object. Does not compute...

                                    I don't know which COM object to use here, assuming one exists. You might need to use the functions mentioned above.
                                    --pdf

                                    Comment


                                      #19
                                      The sha1? I already have it, will i get same results?

                                      I think i will install VB .NET to compare results.


                                      Added:
                                      COM class, .NET class... They look the same in the COm browser.
                                      how can i tell the difference?
                                      Last edited by Elias Montoya; 11 Feb 2008, 08:10 PM.

                                      Comment


                                        #20
                                        I wont give up but i think i will give it a rest. Whan i cant figure out here
                                        is this part:

                                        Code:
                                                alg1.Key = key
                                                hash1 = alg1.ComputeHash(magicb)
                                        Seems like it computes the SHA1 Hash using some kind of a key, but the
                                        following code doesnt seem to use it:

                                        Code:
                                        #Compile Exe
                                        #Register None
                                        #Dim All
                                        #Include "Win32Api.Inc"
                                        
                                        $FileNm = "Win322.hlp"
                                        
                                           Type SHA
                                              H0 As Long
                                              H1 As Long
                                              H2 As Long
                                              H3 As Long
                                              H4 As Long
                                           End Type
                                        
                                           Function CalcSHA (Str As String, SHA As SHA) As Long
                                              #Register None
                                        
                                              Dim lStr As Long, nq As Long, n As Long, adrW As Long, adrWW As Long
                                              Dim H0 As Long, H1 As Long, H2 As Long, H3 As Long, H4 As Long, W(0 : 79) As Long
                                              Dim A As Long, B As Long, C As Long, D As Long, E As Long, TEMP As Long
                                        
                                              lStr = Len(Str)
                                              nq = Fix((lStr + 8) / 64) + 1
                                              n = 16 * nq
                                              ReDim WW(0 To n - 1) As Long
                                        
                                              WW(n - 1) = lStr * 8
                                              adrW = VarPtr(W(0))
                                              adrWW = VarPtr(WW(0))
                                              A = StrPtr(Str)
                                        
                                              ! PUSH EDI
                                              ! PUSH ESI
                                        
                                              ! MOV EDI, adrWW
                                              ! MOV ESI, A
                                              ! MOV ECX, lStr
                                              ! REP MOVSB
                                        
                                              ! MOV CL, &H80
                                              ! MOV [EDI], CL
                                        
                                              ! MOV EDI, adrWW
                                              ! MOV ECX, 2
                                         CalcSHA_Lbl1:
                                              ! MOV AX, [EDI]
                                              ! MOV DX, [EDI + 2]
                                              ! MOV [EDI], DH
                                              ! MOV [EDI + 1], DL
                                              ! MOV [EDI + 2], AH
                                              ! MOV [EDI + 3], AL
                                              ! ADD EDI, 4
                                              ! INC ECX
                                              ! CMP ECX, n
                                              ! JNE CalcSHA_Lbl1
                                        
                                              ! MOV H0, &H67452301&
                                              ! MOV H1, &HEFCDAB89&
                                              ! MOV H2, &H98BADCFE&
                                              ! MOV H3, &H10325476&
                                              ! MOV H4, &HC3D2E1F0&
                                        
                                         CalcSHA_Lbl2:
                                        
                                              ! MOV EDI, adrW
                                              ! MOV ESI, adrWW
                                              ! MOV ECX, 64
                                              ! REP MOVSB
                                              ! MOV adrWW, ESI
                                        
                                              ! MOV ECX, 0
                                         CalcSHA_Lbl3:
                                              ! MOV ESI, ECX
                                              ! ADD ESI, ESI
                                              ! ADD ESI, ESI
                                              ! ADD ESI, adrW
                                        
                                              ! MOV EAX, [ESI + 52]
                                              ! XOR EAX, [ESI + 32]
                                              ! XOR EAX, [ESI + 8]
                                              ! XOR EAX, [ESI]
                                        
                                              ! MOV EDX, EAX
                                              ! SHL EAX, 1
                                              ! SHR EDX, 31
                                              ! OR  EAX, EDX
                                              ! MOV [ESI + 64], EAX
                                        
                                              ! INC ECX
                                              ! CMP ECX, 64
                                              ! JNE CalcSHA_Lbl3
                                        
                                              ! MOV EAX, H0
                                              ! MOV A, EAX
                                              ! MOV EAX, H1
                                              ! MOV B, EAX
                                              ! MOV EAX, H2
                                              ! MOV C, EAX
                                              ! MOV EAX, H3
                                              ! MOV D, EAX
                                              ! MOV EAX, H4
                                              ! MOV E, EAX
                                        
                                              ! MOV EDI, 0
                                         CalcSHA_Lbl4:
                                              ! CMP EDI, 19
                                              ! JA CalcSHA_Lbl5
                                        
                                              ! MOV ECX, B
                                              ! AND ECX, C
                                              ! MOV EAX, B
                                              ! NOT EAX
                                              ! AND EAX, D
                                              ! OR  ECX, EAX
                                              ! ADD ECX, &H5A827999&
                                              ! JMP CalcSHA_Lbl8
                                        
                                         CalcSHA_Lbl5:
                                              ! CMP EDI, 39
                                              ! JA CalcSHA_Lbl6
                                        
                                              ! MOV ECX, B
                                              ! XOR ECX, C
                                              ! XOR ECX, D
                                              ! ADD ECX, &H6ED9EBA1&
                                              ! JMP CalcSHA_Lbl8
                                        
                                         CalcSHA_Lbl6:
                                              ! CMP EDI, 59
                                              ! JA CalcSHA_Lbl7
                                        
                                              ! MOV EAX, B
                                              ! AND EAX, C
                                              ! MOV ECX, B
                                              ! AND ECX, D
                                              ! MOV EDX, C
                                              ! AND EDX, D
                                              ! OR  ECX, EAX
                                              ! OR  ECX, EDX
                                              ! ADD ECX, &H8F1BBCDC&
                                              ! JMP CalcSHA_Lbl8
                                        
                                         CalcSHA_Lbl7:
                                              ! MOV ECX, B
                                              ! XOR ECX, C
                                              ! XOR ECX, D
                                              ! ADD ECX, &HCA62C1D6&
                                        
                                         CalcSHA_Lbl8:
                                              ! MOV EAX, A
                                              ! MOV EDX, EAX
                                              ! SHL EAX, 5
                                              ! SHR EDX, 27
                                              ! OR  EAX, EDX
                                              ! ADD EAX, E
                                              ! ADD ECX, EAX
                                        
                                              ! MOV ESI, EDI
                                              ! ADD ESI, ESI
                                              ! ADD ESI, ESI
                                              ! ADD ESI, adrW
                                              ! MOV ESI, [ESI]
                                              ! MOV TEMP, ESI
                                        
                                              ! ADD Temp, ECX
                                              ! MOV EAX, D
                                              ! MOV E, EAX
                                              ! MOV EAX, C
                                              ! MOV D, EAX
                                              ! MOV EAX, B
                                              ! MOV EDX, EAX
                                              ! SHL EAX, 30
                                              ! SHR EDX, 2
                                              ! OR  EAX, EDX
                                              ! MOV C, EAX
                                              ! MOV EAX, A
                                              ! MOV B, EAX
                                              ! MOV EAX, TEMP
                                              ! MOV A, EAX
                                        
                                              ! INC EDI
                                              ! CMP EDI, 80
                                              ! JNE CalcSHA_Lbl4
                                        
                                              ! MOV EAX, A
                                              ! ADD H0, EAX
                                              ! MOV EAX, B
                                              ! ADD H1, EAX
                                              ! MOV EAX, C
                                              ! ADD H2, EAX
                                              ! MOV EAX, D
                                              ! ADD H3, EAX
                                              ! MOV EAX, E
                                              ! ADD H4, EAX
                                        
                                              ! SUB nq, 1
                                              ! JNE CalcSHA_Lbl2
                                        
                                              ! POP ESI
                                              ! POP EDI
                                        
                                              SHA.H0 = H0: SHA.H1 = H1: SHA.H2 = H2: SHA.H3 = H3: SHA.H4 = H4
                                        
                                           End Function
                                        
                                           Function tSHA (SHA As SHA) As String
                                              Function = Hex$(SHA.H0, 8) + " " + Hex$(SHA.H1, 8) + " " + Hex$(SHA.H2, 8) + " " + _
                                                         Hex$(SHA.H3, 8) + " " + Hex$(SHA.H4, 8)
                                           End Function
                                           Function PbMain
                                        
                                              Dim SHA As SHA
                                        
                                              ' Control samples from official document
                                              CalcSHA "abc", SHA
                                              If tSHA(SHA) <> "A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D" Then MsgBox "Error-1"
                                        
                                              CalcSHA "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", SHA
                                              If tSHA(SHA) <> "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1" Then MsgBox "Error-2"
                                        
                                              ' Test of speed
                                              Dim R As String, Tmp As String, t1 As Single, t2 As Single
                                              Open $FileNm For Binary As #1
                                              Tmp = Space$(Lof(1)): Get$ #1, Lof(1), Tmp: Close #1
                                        
                                              t1 = Timer: CalcSHA Tmp, SHA: t2 = Timer
                                              MsgBox Format$(Len(Tmp) / 1024 / (t2 - t1), "# Kb per second")
                                        
                                           End Function

                                        Comment

                                        Working...
                                        X
                                        😀
                                        🥰
                                        🤢
                                        😎
                                        😡
                                        👍
                                        👎