📄 sha_asm.asm
字号:
reg_i_15 textequ <esi>
reg_i_16 textequ <edi>
ENDM
.code
ALIGN 16
SHA_Compile_p5 PROC
__this textequ <[esp+32+4+4+324]> ; pusha + 2 * ret addr in between
_w textequ <esp+8>
_t textequ <[esp+4]>
INIT_REG_ALIAS
count = 0
REPEAT 16
mov reg_accu, [reg_base+count*4]
bswap reg_accu
IF count eq 0
mov reg_i_16, reg_accu
ELSEIF count eq 1
mov reg_i_15, reg_accu
ELSEIF count eq 13
mov reg_i_3, reg_accu
ELSEIF count eq 14
mov reg_i_2, reg_accu
ELSEIF count eq 15
mov reg_i_1, reg_accu
ENDIF
mov [_w+count*4], reg_accu
count = count + 1
ENDM
count = 16
REPEAT 64
xor reg_i_3, reg_i_16 ; w[i-16]^w[i-3]
reg_i_14 textequ reg_i_16 ; we forget w[i-16]
IF count le 77
mov reg_i_14, [_w+(count-14)*4]
xor reg_i_3, reg_i_14
ELSE
xor reg_i_3, [_w+(count-14)*4]
ENDIF
xor reg_i_3, [_w+(count-8)*4]
rol reg_i_3, 1
mov [_w+count*4], reg_i_3
;now we prepare for the next iteration
reg_i_0 textequ reg_i_3
reg_i_3 textequ reg_i_2
reg_i_2 textequ reg_i_1
reg_i_1 textequ reg_i_0
reg_i_16 textequ reg_i_15
reg_i_15 textequ reg_i_14
count = count + 1
ENDM
reg_a textequ reg_accu
reg_b textequ reg_i_1
reg_c textequ reg_i_2
reg_d textequ reg_i_3
reg_e textequ reg_i_15
reg_temp1 textequ reg_i_16
reg_temp2 textequ reg_base
mov reg_temp2, __this
mov reg_a, [reg_temp2+m_nHash0]
mov reg_b, [reg_temp2+m_nHash1]
mov reg_c, [reg_temp2+m_nHash2]
mov reg_d, [reg_temp2+m_nHash3]
mov reg_e, [reg_temp2+m_nHash4]
count = 0
REPEAT 20
RND_CH 05a827999H
ENDM
REPEAT 20
RND_PARITY 06ed9eba1H
ENDM
REPEAT 20
RND_MAJ 08f1bbcdcH
ENDM
REPEAT 20
RND_PARITY 0ca62c1d6H
ENDM
mov reg_temp2, __this
add [reg_temp2+m_nHash0], reg_a
add [reg_temp2+m_nHash1], reg_b
add [reg_temp2+m_nHash2], reg_c
add [reg_temp2+m_nHash3], reg_d
add [reg_temp2+m_nHash4], reg_e
ret
SHA_Compile_p5 ENDP
ALIGN 16
SHA_Add_p5 PROC PUBLIC, _this:DWORD, _Data:DWORD, _nLength:DWORD
pusha
__this textequ <[esp+36+324]> ; different offset due to pusha
__Data textequ <[esp+40+324]>
__nLength textequ <[esp+44+324]>
sub esp, 324
mov ecx, __nLength
and ecx, ecx
jz get_out
xor edx, edx
mov ebp, __Data
mov edi, __this
mov ebx, [edi+m_nCount0]
mov eax, ebx
add ebx, ecx
mov [edi+m_nCount0], ebx
adc [edi+m_nCount1], edx
and eax, 63
jnz partial_buffer
full_blocks: mov ecx, __nLength
and ecx, ecx
jz get_out
sub ecx, 64
jb end_of_stream
mov __nLength, ecx
call SHA_Compile_p5
mov ebp, __Data
add ebp, 64
mov __Data, ebp
jmp full_blocks
end_of_stream: mov edi, __this
mov esi, ebp
lea edi, [edi+m_nBuffer]
add ecx, 64
rep movsb
jmp get_out
partial_buffer: add ecx, eax ; eax = offset in buffer, ecx = _nLength
cmp ecx, 64
jb short_stream ; we can't fill the buffer
mov ecx, -64
add ecx, eax
add __nLength, ecx ; _nlength += (offset-64)
@@: mov bl, [ebp]
inc ebp
mov byte ptr [edi+m_nBuffer+64+ecx], bl
inc ecx
jnz @B ; offset = 64
mov __Data, ebp
lea ebp, [edi+m_nBuffer]
call SHA_Compile_p5
mov ebp, __Data
jmp full_blocks
short_stream: sub ecx, eax ; --> ecx=_nLength
mov esi, ebp
lea edi, [edi+m_nBuffer+eax]
rep movsb
get_out: add esp, 324
popa
ret
SHA_Add_p5 ENDP
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -