Then
SHA256_LShift = ((lValue And SHA256_m_lOnBits(31 - (iShiftBits + 1))) * SHA256_m_l2Power(iShiftBits)) or &H80000000
Else
SHA256_LShift = ((lValue And SHA256_m_lOnBits(31 - iShiftBits)) * SHA256_m_l2Power(iShiftBits))
End If
End Function
Private Function SHA256_RShift(byVal lValue, byVal iShiftBits)
If iShiftBits = 0 Then
SHA256_RShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And &H80000000 Then
SHA256_RShift = 1
Else
SHA256_RShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 or iShiftBits > 31 Then
Err.Raise 6
End If
SHA256_RShift = (lValue And &H7FFFFFFE) \ SHA256_m_l2Power(iShiftBits)
If (lValue And &H80000000) Then
SHA256_RShift = (SHA256_RShift or (&H40000000 \ SHA256_m_l2Power(iShiftBits - 1)))
End If
End Function
Private Function SHA256_AddUnsigned(byVal lX, byVal lY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim lResult
lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000
lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 or lY4 Then
If lResult And &H40000000 Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If
SHA256_AddUnsigned = lResult
End Function
Private Function SHA256_CH(x, y, z)
SHA256_Ch = ((x And y) Xor ((Not x) And z))
End Function
Private Function SHA256_Maj(x, y, z)
SHA256_Maj = ((x And y) Xor (x And z) Xor (y And z))
End Function
Private Function SHA256_S(x, n)
SHA256_S = (SHA256_RShift(x, (n And SHA256_m_lOnBits(4))) or SHA256_LShift(x, (32 - (n And SHA256_m_lOnBits(4)))))
End Function
Private Function SHA256_R(x, n)
SHA256_R = SHA256_RShift(x, cLng(n And SHA256_m_lOnBits(4)))
End Function
Private Function SHA256_Sigma0(x)
SHA256_Sigma0 = (SHA256_S(x, 2) Xor SHA256_S(x, 13) Xor SHA256_S(x, 22))
End Function
Private Function SHA256_Sigma1(x)
SHA256_Sigma1 = (SHA256_S(x, 6) Xor SHA256_S(x, 11) Xor SHA256_S(x, 25))
End Function
Private Function SHA256_Gamma0(x)
SHA256_Gamma0 = (SHA256_S(x, 7) Xor SHA256_S(x, 18) Xor SHA256_R(x, 3))
End Function
Private Function SHA256_Gamma1(x)
SHA256_Gamma1 = (SHA256_S(x, 17) Xor SHA256_S(x, 19) Xor SHA256_R(x, 10))
End Function
Private Function SHA256_ConvertToWordArray(byVal sMessage)
Dim lMessageLength
Dim lNumberOfWords
Dim lWordArray()
Dim lBytePosition
Dim lByteCount
Dim lWordCount
Dim lByte
Const MODULUS_BITS = 512
Const CONGRUENT_BITS = 448
lMessageLength = Len(sMessage)
lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
ReDim lWordArray(lNumberOfWords - 1)
lBytePosition = 0
lByteCount = 0
Do Until lByteCount >= lMessageLength
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (3 - (lByteCount Mod BYTES_TO_A_WORD)) * BITS_TO_A_BYTE
lByte = AscB(Mid(sMessage, lByteCount + 1, 1))
lWordArray(lWordCount) = lWordArray(