📄 sha256managed.cls
字号:
For i = 0 To 63
s0 = RRotate(a, 2) Xor RRotate(a, 13) Xor RRotate(a, 22)
Maj = ((a And b) Xor (a And c) Xor (b And c))
T2 = Helper.UAdd(s0, Maj)
s1 = RRotate(e, 6) Xor RRotate(e, 11) Xor RRotate(e, 25)
Ch = (e And f) Xor ((Not e) And g)
T1 = Helper.UAdd(Helper.UAdd(Helper.UAdd(Helper.UAdd(h, s1), Ch), mK(i)), mW(i))
h = g
g = f
f = e
e = Helper.UAdd(d, T1)
d = c
c = b
b = a
a = Helper.UAdd(T1, T2)
Next i
mState(0) = Helper.UAdd(mState(0), a)
mState(1) = Helper.UAdd(mState(1), b)
mState(2) = Helper.UAdd(mState(2), c)
mState(3) = Helper.UAdd(mState(3), d)
mState(4) = Helper.UAdd(mState(4), e)
mState(5) = Helper.UAdd(mState(5), f)
mState(6) = Helper.UAdd(mState(6), g)
mState(7) = Helper.UAdd(mState(7), h)
End Sub
''
' Runs when compiled. Must disable Integer overflow checks.
'
Private Sub TransformNative(ByRef Bytes() As Byte, ByVal Index As Long)
Dim i As Long
For i = 0 To 15
mW(i) = (Bytes(Index) * &H1000000) Or (Bytes(Index + 1) * &H10000) Or (Bytes(Index + 2) * &H100&) Or Bytes(Index + 3)
Index = Index + 4
Next i
Dim T1 As Long
Dim T2 As Long
For i = 16 To 63
T1 = mW(i - 15)
T2 = mW(i - 2)
mW(i) = (mW(i - 16) + mW(i - 7)) + _
(((((T1 And &HFFFFFF80) \ &H80&) And &H1FFFFFF) Or (T1 * &H2000000)) Xor _
((((T1 And &HFFFC0000) \ &H40000) And &H3FFF&) Or (T1 * &H4000&)) Xor _
((((T1 And &HFFFFFFF8) \ &H8&) And &H1FFFFFFF))) + _
(((((T2 And &HFFFE0000) \ &H20000) And &H7FFF&) Or (T2 * &H8000&)) Xor _
((((T2 And &HFFF80000) \ &H80000) And &H1FFF&) Or (T2 * &H2000&)) Xor _
((((T2 And &HFFFFFC00) \ &H400&) And &H3FFFFF)))
Next i
Dim a As Long
Dim b As Long
Dim c As Long
Dim d As Long
Dim e As Long
Dim f As Long
Dim g As Long
Dim h As Long
a = mState(0)
b = mState(1)
c = mState(2)
d = mState(3)
e = mState(4)
f = mState(5)
g = mState(6)
h = mState(7)
For i = 0 To 63
T1 = ((a And b) Xor (a And c) Xor (b And c)) + _
(((((a And &HFFFFFFFC) \ &H4&) And &H3FFFFFFF) Or (a * &H40000000)) Xor _
((((a And &HFFFFE000) \ &H2000&) And &H7FFFF) Or (a * &H80000)) Xor _
((((a And &HFFC00000) \ &H400000) And &H3FF) Or (a * &H400&)))
T2 = (h + mK(i) + mW(i)) + _
(((((e And &HFFFFFFC0) \ &H40&) And &H3FFFFFF) Or (e * &H4000000)) Xor _
((((e And &HFFFFF800) \ &H800&) And &H1FFFFF) Or (e * &H200000)) Xor _
((((e And &HFE000000) \ &H2000000) And &H7F) Or (e * &H80&))) + _
((e And f) Xor ((Not e) And g))
h = g
g = f
f = e
e = d + T2
d = c
c = b
b = a
a = T1 + T2
Next i
mState(0) = mState(0) + a
mState(1) = mState(1) + b
mState(2) = mState(2) + c
mState(3) = mState(3) + d
mState(4) = mState(4) + e
mState(5) = mState(5) + f
mState(6) = mState(6) + g
mState(7) = mState(7) + h
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Class Events
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Initialize()
Call CopyMemory(mK(0), ByVal modStaticClasses.SHA256.KPtr, 256)
Set mBase = Cor.NewHashAlgorithmBase(Me, True, True, 64)
Call Initialize
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' HashAlgorithm Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Get HashAlgorithm_CanReuseTransform() As Boolean
HashAlgorithm_CanReuseTransform = CanReuseTransform
End Property
Private Property Get HashAlgorithm_CanTransformMultipleBlocks() As Boolean
HashAlgorithm_CanTransformMultipleBlocks = CanTransformMultipleBlocks
End Property
Private Sub HashAlgorithm_Clear()
Call Clear
End Sub
Private Function HashAlgorithm_ComputeHash(Source As Variant, Optional Index As Variant, Optional Count As Variant) As Byte()
HashAlgorithm_ComputeHash = ComputeHash(Source, Index, Count)
End Function
Private Function HashAlgorithm_Equals(Value As Variant) As Boolean
HashAlgorithm_Equals = Equals(Value)
End Function
Private Function HashAlgorithm_GetHashCode() As Long
HashAlgorithm_GetHashCode = GetHashCode
End Function
Private Property Get HashAlgorithm_Hash() As Byte()
HashAlgorithm_Hash = Hash
End Property
Private Property Get HashAlgorithm_HashSize() As Long
HashAlgorithm_HashSize = HashSize
End Property
Private Sub HashAlgorithm_Initialize()
Call Initialize
End Sub
Private Property Get HashAlgorithm_InputBlockSize() As Long
HashAlgorithm_InputBlockSize = InputBlockSize
End Property
Private Property Get HashAlgorithm_OutputBlockSize() As Long
HashAlgorithm_OutputBlockSize = OutputBlockSize
End Property
Private Function HashAlgorithm_ToString() As String
HashAlgorithm_ToString = ToString
End Function
Private Function HashAlgorithm_TransformBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long, OutputBuffer() As Byte, ByVal OutputOffset As Long) As Long
HashAlgorithm_TransformBlock = TransformBlock(InputBuffer, InputOffset, InputCount, OutputBuffer, OutputOffset)
End Function
Private Function HashAlgorithm_TransformFinalBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long) As Byte()
HashAlgorithm_TransformFinalBlock = TransformFinalBlock(InputBuffer, InputOffset, InputCount)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ICryptoTransform Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Get ICryptoTransform_CanReuseTransform() As Boolean
ICryptoTransform_CanReuseTransform = CanReuseTransform
End Property
Private Property Get ICryptoTransform_CanTransformMultipleBlocks() As Boolean
ICryptoTransform_CanTransformMultipleBlocks = CanTransformMultipleBlocks
End Property
Private Property Get ICryptoTransform_InputBlockSize() As Long
ICryptoTransform_InputBlockSize = InputBlockSize
End Property
Private Property Get ICryptoTransform_OutputBlockSize() As Long
ICryptoTransform_OutputBlockSize = OutputBlockSize
End Property
Private Function ICryptoTransform_TransformBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long, OutputBuffer() As Byte, ByVal OutputOffset As Long) As Long
ICryptoTransform_TransformBlock = TransformBlock(InputBuffer, InputOffset, InputCount, OutputBuffer, OutputOffset)
End Function
Private Function ICryptoTransform_TransformFinalBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long) As Byte()
ICryptoTransform_TransformFinalBlock = TransformFinalBlock(InputBuffer, InputOffset, InputCount)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IHashAlgorithm Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub IHashAlgorithm_HashCore(Bytes() As Byte, ByVal Index As Long, ByVal Count As Long)
Call Transform(Bytes, Index)
End Sub
Private Function IHashAlgorithm_HashFinal(ByRef Buffer() As Byte, ByVal ByteCount As Long, ByVal MessageLength As Currency) As Byte()
IHashAlgorithm_HashFinal = HashFinal(Buffer, ByteCount, MessageLength)
End Function
Private Sub IHashAlgorithm_Initialize()
Call Initialize
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IObject Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IObject_Equals(Value As Variant) As Boolean
IObject_Equals = Equals(Value)
End Function
Private Function IObject_GetHashcode() As Long
IObject_GetHashcode = GetHashCode
End Function
Private Function IObject_ToString() As String
IObject_ToString = ToString
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' SHA256 Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Get SHA256_CanReuseTransform() As Boolean
SHA256_CanReuseTransform = CanReuseTransform
End Property
Private Property Get SHA256_CanTransformMultipleBlocks() As Boolean
SHA256_CanTransformMultipleBlocks = CanTransformMultipleBlocks
End Property
Private Sub SHA256_Clear()
Call Clear
End Sub
Private Function SHA256_ComputeHash(Source As Variant, Optional Index As Variant, Optional Count As Variant) As Byte()
SHA256_ComputeHash = ComputeHash(Source, Index, Count)
End Function
Private Function SHA256_Equals(Value As Variant) As Boolean
SHA256_Equals = Equals(Value)
End Function
Private Function SHA256_GetHashCode() As Long
SHA256_GetHashCode = GetHashCode
End Function
Private Property Get SHA256_Hash() As Byte()
SHA256_Hash = Hash
End Property
Private Property Get SHA256_HashSize() As Long
SHA256_HashSize = HashSize
End Property
Private Sub SHA256_Initialize()
Call Initialize
End Sub
Private Property Get SHA256_InputBlockSize() As Long
SHA256_InputBlockSize = InputBlockSize
End Property
Private Property Get SHA256_OutputBlockSize() As Long
SHA256_OutputBlockSize = OutputBlockSize
End Property
Private Function SHA256_ToString() As String
SHA256_ToString = ToString
End Function
Private Function SHA256_TransformBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long, OutputBuffer() As Byte, ByVal OutputOffset As Long) As Long
SHA256_TransformBlock = TransformBlock(InputBuffer, InputOffset, InputCount, OutputBuffer, OutputOffset)
End Function
Private Function SHA256_TransformFinalBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long) As Byte()
SHA256_TransformFinalBlock = TransformFinalBlock(InputBuffer, InputOffset, InputCount)
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -