VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsHashing"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'---------------------------------------------------------------------------------------
' Module    : clsHashing
' Date      : 6/23/2004
' Author    : YobGuls
' Purpose   :
'---------------------------------------------------------------------------------------

Option Explicit

Private clsFunctions As New clsFunctions

Public Function CalcHashBuf(ByVal buf As String) As String
Dim pos As Long, sublen As Long
Dim hashbuf(&H10 + 5) As Long
hashbuf(0) = &H67452301
hashbuf(1) = &HEFCDAB89
hashbuf(2) = &H98BADCFE
hashbuf(3) = &H10325476
hashbuf(4) = &HC3D2E1F0
For pos = 0 To Len(buf) Step &H40
    sublen = Len(buf) - pos
    If sublen > &H40 Then sublen = &H40
    Dim t As String
    t = Mid$(buf, pos + 1, sublen) & String(&H40 - sublen, Chr$(0))
    Dim i As Long
    For i = 0 To 15
        hashbuf(5 + i) = clsFunctions.GetDWORD(Mid$(t, i * 4 + 1, 4))
    Next i
    Call DataHash(hashbuf)
Next pos
CalcHashBuf = clsFunctions.MakeDWORD(hashbuf(0)) & _
    clsFunctions.MakeDWORD(hashbuf(1)) & _
    clsFunctions.MakeDWORD(hashbuf(2)) & _
    clsFunctions.MakeDWORD(hashbuf(3)) & _
    clsFunctions.MakeDWORD(hashbuf(4))
End Function
Private Sub DataHash(ByRef param() As Long)
Dim buf(&H50) As Long
Dim a As Long, b As Long, C As Long, D As Long, E As Long, G As Long
Dim i As Long
Dim p As Long
p = UBound(param) - 5
If p > &H40 Then p = &H40
For i = 0 To p - 1
    buf(i) = param(i + 5)
Next
For i = &H10 To &H4F
    G = buf(i - &H10) Xor buf(i - &H8) Xor buf(i - &HE) Xor buf(i - &H3)
    buf(i) = clsFunctions.RoL(1, G)
Next
a = param(0)
b = param(1)
C = param(2)
D = param(3)
E = param(4)
For i = 0 To 79
    G = buf(i)
    G = clsFunctions.Add(G, E)
    G = clsFunctions.Add(G, clsFunctions.RoL(a, 5))
    Select Case i
        Case Is < 20
            G = clsFunctions.Add(G, ((b And C) Or ((Not b) And D)))
            G = clsFunctions.Add(G, &H5A827999)
        Case Is < 40
            G = clsFunctions.Add(G, (D Xor C Xor b))
            G = clsFunctions.Add(G, &H6ED9EBA1)
        Case Is < 60
            G = clsFunctions.Add(G, (C And b) Or (D And C) Or (D And b))
            G = clsFunctions.Add(G, &H8F1BBCDC)
        Case Is < 80
            G = clsFunctions.Add(G, (D Xor C Xor b))
            G = clsFunctions.Add(G, &HCA62C1D6)
        Case Else
            Exit Sub
    End Select
    E = D
    D = C
    C = clsFunctions.RoL(b, 30)
    b = a
    a = G
Next
param(0) = clsFunctions.Add(param(0), a)
param(1) = clsFunctions.Add(param(1), b)
param(2) = clsFunctions.Add(param(2), C)
param(3) = clsFunctions.Add(param(3), D)
param(4) = clsFunctions.Add(param(4), E)
End Sub
Public Function UDPChecksum(ByVal buffer As String, ByVal size As Long) As Long
Dim a&, b&, n&, q&, sum&
For n = 0 To size - 1
    a = a + ((n + 1) * Asc(Mid$(buffer, n + 1, 1)))
    b = b + ((n + 2) * Asc(Mid$(buffer, n + 1, 1)))
Next n
q = a
While (q > &HFF)
    q = (q / &H100) + (q Mod &H100)
Wend
sum = q
q = b
While (q > &HFF)
    q = (q / &H100) + (q Mod &H100)
Wend
sum = sum + (clsFunctions.LShift(&HFF - q, 8))
UDPChecksum = sum
End Function

