690 lines
12 KiB
NASM
690 lines
12 KiB
NASM
; Don't even think of reading this code
|
|
; It was automatically generated by bn-586.pl
|
|
; Which is a perl program used to generate the x86 assember for
|
|
; any of elf, a.out, BSDI,Win32, or Solaris
|
|
; eric <eay@cryptsoft.com>
|
|
;
|
|
TITLE bn-586.asm
|
|
.386
|
|
.model FLAT
|
|
_TEXT SEGMENT
|
|
PUBLIC _bn_mul_add_words
|
|
|
|
_bn_mul_add_words PROC NEAR
|
|
push ebp
|
|
push ebx
|
|
push esi
|
|
push edi
|
|
;
|
|
xor esi, esi
|
|
mov edi, DWORD PTR 20[esp]
|
|
mov ecx, DWORD PTR 28[esp]
|
|
mov ebx, DWORD PTR 24[esp]
|
|
and ecx, 4294967288
|
|
mov ebp, DWORD PTR 32[esp]
|
|
push ecx
|
|
jz $L000maw_finish
|
|
L001maw_loop:
|
|
mov DWORD PTR [esp],ecx
|
|
; Round 0
|
|
mov eax, DWORD PTR [ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR [edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR [edi],eax
|
|
mov esi, edx
|
|
; Round 4
|
|
mov eax, DWORD PTR 4[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 4[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 4[edi],eax
|
|
mov esi, edx
|
|
; Round 8
|
|
mov eax, DWORD PTR 8[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 8[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 8[edi],eax
|
|
mov esi, edx
|
|
; Round 12
|
|
mov eax, DWORD PTR 12[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 12[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 12[edi],eax
|
|
mov esi, edx
|
|
; Round 16
|
|
mov eax, DWORD PTR 16[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 16[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 16[edi],eax
|
|
mov esi, edx
|
|
; Round 20
|
|
mov eax, DWORD PTR 20[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 20[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 20[edi],eax
|
|
mov esi, edx
|
|
; Round 24
|
|
mov eax, DWORD PTR 24[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 24[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 24[edi],eax
|
|
mov esi, edx
|
|
; Round 28
|
|
mov eax, DWORD PTR 28[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 28[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 28[edi],eax
|
|
mov esi, edx
|
|
;
|
|
mov ecx, DWORD PTR [esp]
|
|
add ebx, 32
|
|
add edi, 32
|
|
sub ecx, 8
|
|
jnz L001maw_loop
|
|
$L000maw_finish:
|
|
mov ecx, DWORD PTR 32[esp]
|
|
and ecx, 7
|
|
jnz $L002maw_finish2
|
|
jmp $L003maw_end
|
|
$L002maw_finish2:
|
|
; Tail Round 0
|
|
mov eax, DWORD PTR [ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR [edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
dec ecx
|
|
mov DWORD PTR [edi],eax
|
|
mov esi, edx
|
|
jz $L003maw_end
|
|
; Tail Round 1
|
|
mov eax, DWORD PTR 4[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 4[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
dec ecx
|
|
mov DWORD PTR 4[edi],eax
|
|
mov esi, edx
|
|
jz $L003maw_end
|
|
; Tail Round 2
|
|
mov eax, DWORD PTR 8[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 8[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
dec ecx
|
|
mov DWORD PTR 8[edi],eax
|
|
mov esi, edx
|
|
jz $L003maw_end
|
|
; Tail Round 3
|
|
mov eax, DWORD PTR 12[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 12[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
dec ecx
|
|
mov DWORD PTR 12[edi],eax
|
|
mov esi, edx
|
|
jz $L003maw_end
|
|
; Tail Round 4
|
|
mov eax, DWORD PTR 16[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 16[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
dec ecx
|
|
mov DWORD PTR 16[edi],eax
|
|
mov esi, edx
|
|
jz $L003maw_end
|
|
; Tail Round 5
|
|
mov eax, DWORD PTR 20[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 20[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
dec ecx
|
|
mov DWORD PTR 20[edi],eax
|
|
mov esi, edx
|
|
jz $L003maw_end
|
|
; Tail Round 6
|
|
mov eax, DWORD PTR 24[ebx]
|
|
mul ebp
|
|
add eax, esi
|
|
mov esi, DWORD PTR 24[edi]
|
|
adc edx, 0
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 24[edi],eax
|
|
mov esi, edx
|
|
$L003maw_end:
|
|
mov eax, esi
|
|
pop ecx
|
|
pop edi
|
|
pop esi
|
|
pop ebx
|
|
pop ebp
|
|
ret
|
|
_bn_mul_add_words ENDP
|
|
_TEXT ENDS
|
|
_TEXT SEGMENT
|
|
PUBLIC _bn_mul_words
|
|
|
|
_bn_mul_words PROC NEAR
|
|
push ebp
|
|
push ebx
|
|
push esi
|
|
push edi
|
|
;
|
|
xor esi, esi
|
|
mov edi, DWORD PTR 20[esp]
|
|
mov ebx, DWORD PTR 24[esp]
|
|
mov ebp, DWORD PTR 28[esp]
|
|
mov ecx, DWORD PTR 32[esp]
|
|
and ebp, 4294967288
|
|
jz $L004mw_finish
|
|
L005mw_loop:
|
|
; Round 0
|
|
mov eax, DWORD PTR [ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR [edi],eax
|
|
mov esi, edx
|
|
; Round 4
|
|
mov eax, DWORD PTR 4[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 4[edi],eax
|
|
mov esi, edx
|
|
; Round 8
|
|
mov eax, DWORD PTR 8[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 8[edi],eax
|
|
mov esi, edx
|
|
; Round 12
|
|
mov eax, DWORD PTR 12[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 12[edi],eax
|
|
mov esi, edx
|
|
; Round 16
|
|
mov eax, DWORD PTR 16[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 16[edi],eax
|
|
mov esi, edx
|
|
; Round 20
|
|
mov eax, DWORD PTR 20[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 20[edi],eax
|
|
mov esi, edx
|
|
; Round 24
|
|
mov eax, DWORD PTR 24[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 24[edi],eax
|
|
mov esi, edx
|
|
; Round 28
|
|
mov eax, DWORD PTR 28[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 28[edi],eax
|
|
mov esi, edx
|
|
;
|
|
add ebx, 32
|
|
add edi, 32
|
|
sub ebp, 8
|
|
jz $L004mw_finish
|
|
jmp L005mw_loop
|
|
$L004mw_finish:
|
|
mov ebp, DWORD PTR 28[esp]
|
|
and ebp, 7
|
|
jnz $L006mw_finish2
|
|
jmp $L007mw_end
|
|
$L006mw_finish2:
|
|
; Tail Round 0
|
|
mov eax, DWORD PTR [ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR [edi],eax
|
|
mov esi, edx
|
|
dec ebp
|
|
jz $L007mw_end
|
|
; Tail Round 1
|
|
mov eax, DWORD PTR 4[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 4[edi],eax
|
|
mov esi, edx
|
|
dec ebp
|
|
jz $L007mw_end
|
|
; Tail Round 2
|
|
mov eax, DWORD PTR 8[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 8[edi],eax
|
|
mov esi, edx
|
|
dec ebp
|
|
jz $L007mw_end
|
|
; Tail Round 3
|
|
mov eax, DWORD PTR 12[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 12[edi],eax
|
|
mov esi, edx
|
|
dec ebp
|
|
jz $L007mw_end
|
|
; Tail Round 4
|
|
mov eax, DWORD PTR 16[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 16[edi],eax
|
|
mov esi, edx
|
|
dec ebp
|
|
jz $L007mw_end
|
|
; Tail Round 5
|
|
mov eax, DWORD PTR 20[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 20[edi],eax
|
|
mov esi, edx
|
|
dec ebp
|
|
jz $L007mw_end
|
|
; Tail Round 6
|
|
mov eax, DWORD PTR 24[ebx]
|
|
mul ecx
|
|
add eax, esi
|
|
adc edx, 0
|
|
mov DWORD PTR 24[edi],eax
|
|
mov esi, edx
|
|
$L007mw_end:
|
|
mov eax, esi
|
|
pop edi
|
|
pop esi
|
|
pop ebx
|
|
pop ebp
|
|
ret
|
|
_bn_mul_words ENDP
|
|
_TEXT ENDS
|
|
_TEXT SEGMENT
|
|
PUBLIC _bn_sqr_words
|
|
|
|
_bn_sqr_words PROC NEAR
|
|
push ebp
|
|
push ebx
|
|
push esi
|
|
push edi
|
|
;
|
|
mov esi, DWORD PTR 20[esp]
|
|
mov edi, DWORD PTR 24[esp]
|
|
mov ebx, DWORD PTR 28[esp]
|
|
and ebx, 4294967288
|
|
jz $L008sw_finish
|
|
L009sw_loop:
|
|
; Round 0
|
|
mov eax, DWORD PTR [edi]
|
|
mul eax
|
|
mov DWORD PTR [esi],eax
|
|
mov DWORD PTR 4[esi],edx
|
|
; Round 4
|
|
mov eax, DWORD PTR 4[edi]
|
|
mul eax
|
|
mov DWORD PTR 8[esi],eax
|
|
mov DWORD PTR 12[esi],edx
|
|
; Round 8
|
|
mov eax, DWORD PTR 8[edi]
|
|
mul eax
|
|
mov DWORD PTR 16[esi],eax
|
|
mov DWORD PTR 20[esi],edx
|
|
; Round 12
|
|
mov eax, DWORD PTR 12[edi]
|
|
mul eax
|
|
mov DWORD PTR 24[esi],eax
|
|
mov DWORD PTR 28[esi],edx
|
|
; Round 16
|
|
mov eax, DWORD PTR 16[edi]
|
|
mul eax
|
|
mov DWORD PTR 32[esi],eax
|
|
mov DWORD PTR 36[esi],edx
|
|
; Round 20
|
|
mov eax, DWORD PTR 20[edi]
|
|
mul eax
|
|
mov DWORD PTR 40[esi],eax
|
|
mov DWORD PTR 44[esi],edx
|
|
; Round 24
|
|
mov eax, DWORD PTR 24[edi]
|
|
mul eax
|
|
mov DWORD PTR 48[esi],eax
|
|
mov DWORD PTR 52[esi],edx
|
|
; Round 28
|
|
mov eax, DWORD PTR 28[edi]
|
|
mul eax
|
|
mov DWORD PTR 56[esi],eax
|
|
mov DWORD PTR 60[esi],edx
|
|
;
|
|
add edi, 32
|
|
add esi, 64
|
|
sub ebx, 8
|
|
jnz L009sw_loop
|
|
$L008sw_finish:
|
|
mov ebx, DWORD PTR 28[esp]
|
|
and ebx, 7
|
|
jz $L010sw_end
|
|
; Tail Round 0
|
|
mov eax, DWORD PTR [edi]
|
|
mul eax
|
|
mov DWORD PTR [esi],eax
|
|
dec ebx
|
|
mov DWORD PTR 4[esi],edx
|
|
jz $L010sw_end
|
|
; Tail Round 1
|
|
mov eax, DWORD PTR 4[edi]
|
|
mul eax
|
|
mov DWORD PTR 8[esi],eax
|
|
dec ebx
|
|
mov DWORD PTR 12[esi],edx
|
|
jz $L010sw_end
|
|
; Tail Round 2
|
|
mov eax, DWORD PTR 8[edi]
|
|
mul eax
|
|
mov DWORD PTR 16[esi],eax
|
|
dec ebx
|
|
mov DWORD PTR 20[esi],edx
|
|
jz $L010sw_end
|
|
; Tail Round 3
|
|
mov eax, DWORD PTR 12[edi]
|
|
mul eax
|
|
mov DWORD PTR 24[esi],eax
|
|
dec ebx
|
|
mov DWORD PTR 28[esi],edx
|
|
jz $L010sw_end
|
|
; Tail Round 4
|
|
mov eax, DWORD PTR 16[edi]
|
|
mul eax
|
|
mov DWORD PTR 32[esi],eax
|
|
dec ebx
|
|
mov DWORD PTR 36[esi],edx
|
|
jz $L010sw_end
|
|
; Tail Round 5
|
|
mov eax, DWORD PTR 20[edi]
|
|
mul eax
|
|
mov DWORD PTR 40[esi],eax
|
|
dec ebx
|
|
mov DWORD PTR 44[esi],edx
|
|
jz $L010sw_end
|
|
; Tail Round 6
|
|
mov eax, DWORD PTR 24[edi]
|
|
mul eax
|
|
mov DWORD PTR 48[esi],eax
|
|
mov DWORD PTR 52[esi],edx
|
|
$L010sw_end:
|
|
pop edi
|
|
pop esi
|
|
pop ebx
|
|
pop ebp
|
|
ret
|
|
_bn_sqr_words ENDP
|
|
_TEXT ENDS
|
|
_TEXT SEGMENT
|
|
PUBLIC _bn_div64
|
|
|
|
_bn_div64 PROC NEAR
|
|
push ebp
|
|
push ebx
|
|
push esi
|
|
push edi
|
|
mov edx, DWORD PTR 20[esp]
|
|
mov eax, DWORD PTR 24[esp]
|
|
mov ebx, DWORD PTR 28[esp]
|
|
div ebx
|
|
pop edi
|
|
pop esi
|
|
pop ebx
|
|
pop ebp
|
|
ret
|
|
_bn_div64 ENDP
|
|
_TEXT ENDS
|
|
_TEXT SEGMENT
|
|
PUBLIC _bn_add_words
|
|
|
|
_bn_add_words PROC NEAR
|
|
push ebp
|
|
push ebx
|
|
push esi
|
|
push edi
|
|
;
|
|
mov ebx, DWORD PTR 20[esp]
|
|
mov esi, DWORD PTR 24[esp]
|
|
mov edi, DWORD PTR 28[esp]
|
|
mov ebp, DWORD PTR 32[esp]
|
|
xor eax, eax
|
|
and ebp, 4294967288
|
|
jz $L011aw_finish
|
|
L012aw_loop:
|
|
; Round 0
|
|
mov ecx, DWORD PTR [esi]
|
|
mov edx, DWORD PTR [edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
mov DWORD PTR [ebx],ecx
|
|
; Round 1
|
|
mov ecx, DWORD PTR 4[esi]
|
|
mov edx, DWORD PTR 4[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
mov DWORD PTR 4[ebx],ecx
|
|
; Round 2
|
|
mov ecx, DWORD PTR 8[esi]
|
|
mov edx, DWORD PTR 8[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
mov DWORD PTR 8[ebx],ecx
|
|
; Round 3
|
|
mov ecx, DWORD PTR 12[esi]
|
|
mov edx, DWORD PTR 12[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
mov DWORD PTR 12[ebx],ecx
|
|
; Round 4
|
|
mov ecx, DWORD PTR 16[esi]
|
|
mov edx, DWORD PTR 16[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
mov DWORD PTR 16[ebx],ecx
|
|
; Round 5
|
|
mov ecx, DWORD PTR 20[esi]
|
|
mov edx, DWORD PTR 20[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
mov DWORD PTR 20[ebx],ecx
|
|
; Round 6
|
|
mov ecx, DWORD PTR 24[esi]
|
|
mov edx, DWORD PTR 24[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
mov DWORD PTR 24[ebx],ecx
|
|
; Round 7
|
|
mov ecx, DWORD PTR 28[esi]
|
|
mov edx, DWORD PTR 28[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
mov DWORD PTR 28[ebx],ecx
|
|
;
|
|
add esi, 32
|
|
add edi, 32
|
|
add ebx, 32
|
|
sub ebp, 8
|
|
jnz L012aw_loop
|
|
$L011aw_finish:
|
|
mov ebp, DWORD PTR 32[esp]
|
|
and ebp, 7
|
|
jz $L013aw_end
|
|
; Tail Round 0
|
|
mov ecx, DWORD PTR [esi]
|
|
mov edx, DWORD PTR [edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
dec ebp
|
|
mov DWORD PTR [ebx],ecx
|
|
jz $L013aw_end
|
|
; Tail Round 1
|
|
mov ecx, DWORD PTR 4[esi]
|
|
mov edx, DWORD PTR 4[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
dec ebp
|
|
mov DWORD PTR 4[ebx],ecx
|
|
jz $L013aw_end
|
|
; Tail Round 2
|
|
mov ecx, DWORD PTR 8[esi]
|
|
mov edx, DWORD PTR 8[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
dec ebp
|
|
mov DWORD PTR 8[ebx],ecx
|
|
jz $L013aw_end
|
|
; Tail Round 3
|
|
mov ecx, DWORD PTR 12[esi]
|
|
mov edx, DWORD PTR 12[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
dec ebp
|
|
mov DWORD PTR 12[ebx],ecx
|
|
jz $L013aw_end
|
|
; Tail Round 4
|
|
mov ecx, DWORD PTR 16[esi]
|
|
mov edx, DWORD PTR 16[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
dec ebp
|
|
mov DWORD PTR 16[ebx],ecx
|
|
jz $L013aw_end
|
|
; Tail Round 5
|
|
mov ecx, DWORD PTR 20[esi]
|
|
mov edx, DWORD PTR 20[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
dec ebp
|
|
mov DWORD PTR 20[ebx],ecx
|
|
jz $L013aw_end
|
|
; Tail Round 6
|
|
mov ecx, DWORD PTR 24[esi]
|
|
mov edx, DWORD PTR 24[edi]
|
|
add ecx, eax
|
|
mov eax, 0
|
|
adc eax, eax
|
|
add ecx, edx
|
|
adc eax, 0
|
|
mov DWORD PTR 24[ebx],ecx
|
|
$L013aw_end:
|
|
mov eax, eax
|
|
pop edi
|
|
pop esi
|
|
pop ebx
|
|
pop ebp
|
|
ret
|
|
_bn_add_words ENDP
|
|
_TEXT ENDS
|
|
END
|