📄 ace_modes.asm
字号:
mov edi,esi ; destination address (our buffer)
neh_cfb ; execute VIA ACE operation
mov esi,eax ; restore the IV into the local
mov edi,[ebp-4] ; buffer
movsd
movsd
movsd
movsd
mov eax,[ebp+len] ; recover number of blocks remaining
mov ecx,buf_blocks ; blocks in buffer
cmp eax,ecx ; remaining blocks >= blocks in buffer
jae .4
mov ecx,eax ; no - move only remaining blocks
.4: sub eax,ecx ; compute new remaining block count
mov esi,[ebp-4] ; load local buffer address
mov edi,[ebp+obuf] ; load output address
.5: add esi,16
movaps xmm0,[esi] ; aligned move to xmm0
movups [edi],xmm0 ; unaligned move to output buffer
add edi,16 ; addresses
sub ecx,1 ; decrement block count
jne .5 ; and continue if some remain
mov [ebp+obuf],edi ; update output buffer position
mov esi,[ebp-4] ; store the IV
mov edi,[ebp+iv]
movaps xmm0,[esi]
movups [edi],xmm0
and eax,eax ; test remaining block count
jne .1 ; and continue if some remain
.6: mov esp,ebp
pop edi
pop esi
pop ebx
pop ebp
do_exit
; aes_rval aes_cfb_decrypt(const unsigned char *in, unsigned char *out,
; int len, unsigned char *iv, const aes_encrypt_ctx cx[1]);
do_name _aes_cfb_decrypt
push ebp
push ebx
push esi
push edi
mov ebp,esp
; claim stack space for 'buf_blocks' 16 byte blocks and
; extra space to allow for adjusting the base address
; for a 16 byte alignment (4 byte alignment is assumed
; so a maximum of 12 bytes extra is needed). The top 4
; bytes (at [ebp-4]) are hence used to store the aligned
; buffer address
sub esp,16 * buf_blocks + 32
mov edx,esp
add edx,12 ; move up 20 bytes, align the
and edx,~0x0000000f ; resulting address and store
mov [ebp-4],edx ; the resulting value
mov eax,[ebp+len] ; get the data length
and eax,eax
je .6 ; exit if zero
shr eax,4 ; convert to blocks
mov ebx,[ebp+iv]
movups xmm0,[ebx] ; move the IV into the local
movaps [edx],xmm0 ; buffer
neh_rekey
.1: mov [ebp+len],eax ; store remaining blocks
mov ecx,buf_blocks
cmp eax,ecx ; remaining blocks >= buffer Blocks
jae .2
mov ecx,eax ; no - process only remaining
.2: mov eax,ecx ; save block count in eax
mov esi,[ebp+ibuf] ; source data address
mov edi,[ebp-4] ; destination buffer address
.3: add edi,16
movups xmm0,[esi] ; unaligned move to xmm0
movaps [edi],xmm0 ; aligned move into buffer
add esi,16 ; addjust source and
sub ecx,1 ; reduce block count
jne short .3 ; until all blocks have been moved
mov [ebp+ibuf],esi ; update input buffer position
mov ebx,[ebp+ctx] ; get key address -> ebx
movzx ecx,byte[ebx+4*KS_LENGTH]
shr ecx,1 ; get control word address ->edx
%if (KEY_TYPE = NEH_LOAD)
lea edx,[_dec_load_table-80+ecx]
%elif (KEY_TYPE = NEH_GENERATE)
lea edx,[_dec_gen_table-80+ecx]
%else
lea edx,[_dec_hybrid_table-80+ecx]
%endif
mov ecx,eax ; restore block count into ecx
mov eax,[ebp-4] ; the local IV
mov esi,eax ; source address (our local buffer)
add esi,16 ; source address (our local buffer)
mov edi,esi ; destination address (our buffer)
neh_cfb ; execute VIA ACE operation
mov eax,[ebp+len] ; recover number of blocks remaining
mov ecx,buf_blocks ; blocks in buffer
cmp eax,ecx ; remaining blocks >= blocks in buffer
jae .4
mov ecx,eax ; no - move only remaining blocks
.4: sub eax,ecx ; compute new remaining block count
mov esi,[ebp-4] ; load local buffer address
mov edi,[ebp+obuf] ; load output address
.5: add esi,16
movaps xmm0,[esi] ; aligned move to xmm0
movups [edi],xmm0 ; unaligned move to output buffer
add edi,16 ; addresses
sub ecx,1 ; decrement block count
jne .5 ; and continue if some remain
mov [ebp+obuf],edi ; update output buffer position
mov esi,[ebp-4] ; store the IV
mov edi,[ebp+iv]
movaps xmm0,[esi]
movups [edi],xmm0
and eax,eax ; test remaining block count
jne .1 ; and continue if some remain
.6: mov esp,ebp
pop edi
pop esi
pop ebx
pop ebp
do_exit
; aes_rval aes_ofb_crypt(const unsigned char *in, unsigned char *out,
; int len, unsigned char *iv, const aes_encrypt_ctx cx[1]);
do_name _aes_ofb_crypt
push ebp
push ebx
push esi
push edi
mov ebp,esp
; claim stack space for 'buf_blocks' 16 byte blocks and
; extra space to allow for adjusting the base address
; for a 16 byte alignment (4 byte alignment is assumed
; so a maximum of 12 bytes extra is needed). The top 4
; bytes (at [ebp-4]) are hence used to store the aligned
; buffer address
sub esp,16 * buf_blocks + 32
mov edx,esp
add edx,12 ; move up 20 bytes, align the
and edx,~0x0000000f ; resulting address and store
mov [ebp-4],edx ; the resulting value
mov eax,[ebp+len] ; get the data length
and eax,eax
je .6 ; exit if zero
shr eax,4 ; convert to blocks
mov ebx,[ebp+iv]
movups xmm0,[ebx] ; move the IV into the local
movaps [edx],xmm0 ; buffer
neh_rekey
.1: mov [ebp+len],eax ; store remaining blocks
mov ecx,buf_blocks
cmp eax,ecx ; remaining blocks >= buffer Blocks
jae .2
mov ecx,eax ; no - process only remaining
.2: mov eax,ecx ; save block count in eax
mov esi,[ebp+ibuf] ; source data address
mov edi,[ebp-4] ; destination buffer address
.3: add edi,16
movups xmm0,[esi] ; unaligned move to xmm0
movaps [edi],xmm0 ; aligned move into buffer
add esi,16 ; addjust source and
sub ecx,1 ; reduce block count
jne short .3 ; until all blocks have been moved
mov [ebp+ibuf],esi ; update input buffer position
mov ebx,[ebp+ctx] ; get key address -> ebx
movzx ecx,byte[ebx+4*KS_LENGTH]
shr ecx,1 ; get control word address ->edx
%if (KEY_TYPE = NEH_LOAD)
lea edx,[_enc_load_table-80+ecx]
%elif (KEY_TYPE = NEH_GENERATE)
lea edx,[_enc_gen_table-80+ecx]
%else
lea edx,[_enc_hybrid_table-80+ecx]
%endif
mov ecx,eax ; restore block count into ecx
mov eax,[ebp-4] ; the local IV
mov esi,eax ; source address (our local buffer)
add esi,16 ; source address (our local buffer)
mov edi,esi ; destination address (our buffer)
neh_ofb ; execute VIA ACE operation
mov eax,[ebp+len] ; recover number of blocks remaining
mov ecx,buf_blocks ; blocks in buffer
cmp eax,ecx ; remaining blocks >= blocks in buffer
jae .4
mov ecx,eax ; no - move only remaining blocks
.4: sub eax,ecx ; compute new remaining block count
mov esi,[ebp-4] ; load local buffer address
mov edi,[ebp+obuf] ; load output address
.5: add esi,16
movaps xmm0,[esi] ; aligned move to xmm0
movups [edi],xmm0 ; unaligned move to output buffer
add edi,16 ; addresses
sub ecx,1 ; decrement block count
jne .5 ; and continue if some remain
mov [ebp+obuf],edi ; update output buffer position
mov esi,[ebp-4] ; store the IV
mov edi,[ebp+iv]
movaps xmm0,[esi]
movups [edi],xmm0
and eax,eax ; test remaining block count
jne .1 ; and continue if some remain
.6: mov esp,ebp
pop edi
pop esi
pop ebx
pop ebp
do_exit
; aes_rval aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf,
; int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]);
do_name _aes_ctr_crypt,24
push ebp
push ebx
push esi
push edi
mov ebp,esp
; claim stack space for 'buf_blocks' 16 byte blocks and
; extra space to allow for adjusting the base address
; for a 16 byte alignment (4 byte alignment is assumed
; so a maximum of 12 bytes extra is needed). The top 8
; bytes (at [ebp-4] and [[ebp-8]) are hence used to
; store the aligned buffer address and the block count
sub esp,16 * buf_blocks + 20
mov edx,esp
add edx,12 ; move up 20 bytes, align the
and edx,~0x0000000f ; resulting address and store
mov [ebp-4],edx ; the resulting value
mov eax,[ebp+len] ; get the data length
and eax,eax
je .6 ; exit if zero
shr eax,4 ; convert to blocks
neh_rekey
.1: mov [ebp+len],eax ; store remaining blocks
mov ecx,buf_blocks
cmp eax,ecx ; remaining blocks >= buffer Blocks
jae .2
mov ecx,eax ; no - process only remaining
.2: mov [ebp-8],ecx ; save block count to stack
mov edi,[ebp-4] ; destination buffer address
.3: mov esi,[ebp+ctr_ctr] ; source data address
movups xmm0,[esi] ; unaligned move to xmm0
movaps [edi],xmm0 ; aligned move into buffer
add edi,16
push edi ; save buffer pointer
push ecx ; and filled block count
push esi ; call for counter increment
mov eax,[ebp+ctr_fn]
call eax
add esp,4
pop ecx ; restore block count
pop edi ; and buffer pointer
sub ecx,1 ; reduce block count
jne short .3 ; until all blocks have been moved
mov ebx,[ebp+ctr_ctx] ; get key address -> ebx
movzx ecx,byte[ebx+4*KS_LENGTH]
shr ecx,1 ; get control word address ->edx
%if (KEY_TYPE = NEH_LOAD)
lea edx,[_enc_load_table-80+ecx]
%elif (KEY_TYPE = NEH_GENERATE)
lea edx,[_enc_gen_table-80+ecx]
%else
lea edx,[_enc_hybrid_table-80+ecx]
%endif
mov ecx,[ebp-8] ; restore block count into ecx
mov esi,[ebp-4] ; source address (our local buffer)
mov edi,esi ; destination address (our buffer)
neh_ecb ; execute VIA ACE operation
mov eax,[ebp+len] ; recover number of blocks remaining
mov ecx,buf_blocks ; blocks in buffer
cmp eax,ecx ; remaining blocks >= blocks in buffer
jae .4
mov ecx,eax ; no - move only remaining blocks
.4: sub eax,ecx ; compute new remaining block count
mov esi,[ebp-4] ; load local buffer address
mov edi,[ebp+obuf] ; load output address
.5: movaps xmm0,[esi] ; aligned move to xmm0
movups xmm1,[edi] ; unaligned move to output buffer
xorps xmm0,xmm1
movups [edi],xmm0
add esi,16
add edi,16 ; addresses
sub ecx,1 ; decrement block count
jne .5 ; and continue if some remain
mov [ebp+obuf],edi ; update output buffer position
and eax,eax ; test remaining block count
jne .1 ; and continue if some remain
.6: mov esp,ebp
pop edi
pop esi
pop ebx
pop ebp
do_exit 24
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -