707 lines
19 KiB
Plaintext
707 lines
19 KiB
Plaintext
;
|
|
; fdef_asm.cppasm Assembler code for fast arithmetic
|
|
; Requires C preprocessor to correctly include C_asm_shared.inc and symcrypt_magic.in
|
|
;
|
|
; Copyright (c) Microsoft Corporation. Licensed under the MIT license.
|
|
;
|
|
|
|
TITLE "Fdef_asm"
|
|
.686P
|
|
; .XMM // Do not use XMM in x86 code; there are environments where it is not available
|
|
|
|
;
|
|
; FPO documentation:
|
|
; The .FPO provides debugging information.
|
|
; This stuff not well documented,
|
|
; but here is the information I've gathered about the arguments to .FPO
|
|
;
|
|
; In order:
|
|
; cdwLocals: Size of local variables, in DWords
|
|
; cdwParams: Size of parameters, in DWords. Given that this is all about
|
|
; stack stuff, I'm assuming this is only about parameters passed
|
|
; on the stack.
|
|
; cbProlog : Number of bytes in the prolog code. We have interleaved the
|
|
; prolog code with work for better performance. Most uses of
|
|
; .FPO seem to set this value to 0 anyway, which is what we
|
|
; will do.
|
|
; cbRegs : # registers saved in the prolog.
|
|
; fUseBP : 0 if EBP is not used as base pointer, 1 if EBP is used as base pointer
|
|
; cbFrame : Type of frame.
|
|
; 0 = FPO frame (no frame pointer)
|
|
; 1 = Trap frame (result of a CPU trap event)
|
|
; 2 = TSS frame
|
|
;
|
|
; Having looked at various occurrences of .FPO in the Windows code it
|
|
; seems to be used fairly sloppy, with lots of arguments left 0 even when
|
|
; they probably shouldn't be according to the spec.
|
|
;
|
|
|
|
|
|
|
|
_TEXT SEGMENT PARA PUBLIC USE32 'CODE'
|
|
ASSUME CS:_TEXT, DS:FLAT, SS:FLAT
|
|
|
|
#include "C_asm_shared.inc"
|
|
#include "symcrypt_magic.inc"
|
|
|
|
PUBLIC @SymCryptFdefRawAddAsm@16
|
|
PUBLIC @SymCryptFdefRawSubAsm@16
|
|
PUBLIC @SymCryptFdefMaskedCopyAsm@16
|
|
PUBLIC @SymCryptFdefRawMulAsm@20
|
|
PUBLIC @SymCryptFdefMontgomeryReduceAsm@12
|
|
|
|
|
|
BEFORE_PROC MACRO
|
|
;
|
|
; Our current x86 compiler inserts 5 0xcc bytes before every function
|
|
; and starts every function with a 2-byte NOP.
|
|
; This supports hot-patching.
|
|
;
|
|
DB 5 dup (0cch)
|
|
ENDM
|
|
|
|
|
|
|
|
|
|
|
|
BEFORE_PROC
|
|
@SymCryptFdefRawAddAsm@16 PROC
|
|
;UINT32
|
|
;SYMCRYPT_CALL
|
|
;SymCryptFdefRawAdd(
|
|
; _In_reads_bytes_(nDigits * SYMCRYPT_FDEF_DIGIT_SIZE ) PCUINT32 pSrc1,
|
|
; _In_reads_bytes_(nDigits * SYMCRYPT_FDEF_DIGIT_SIZE ) PCUINT32 pSrc2,
|
|
; _Out_writes_bytes_(nDigits * SYMCRYPT_FDEF_DIGIT_SIZE ) PUINT32 pDst,
|
|
; UINT32 nDigits )
|
|
|
|
.FPO(2,2,0,2,0,0)
|
|
|
|
SymCryptFdefRawAddAsmFrame struct 4, NONUNIQUE
|
|
|
|
SaveEdi dd ?
|
|
SaveEbx dd ?
|
|
ReturnAddress dd ?
|
|
pDst dd ?
|
|
nDigits dd ?
|
|
|
|
SymCryptFdefRawAddAsmFrame ends
|
|
|
|
; ecx = pSrc1
|
|
; edx = pSrc2
|
|
|
|
mov edi,edi
|
|
push ebx
|
|
push edi
|
|
|
|
mov edi, [esp + SymCryptFdefRawAddAsmFrame.pDst]
|
|
mov ebx, [esp + SymCryptFdefRawAddAsmFrame.nDigits]
|
|
|
|
xor eax,eax ; Cy = 0
|
|
|
|
SymCryptFdefRawAddAsmLoop:
|
|
mov eax, [ecx]
|
|
adc eax, [edx]
|
|
mov [edi], eax
|
|
|
|
mov eax, [ecx + 4]
|
|
adc eax, [edx + 4]
|
|
mov [edi + 4], eax
|
|
|
|
mov eax, [ecx + 8]
|
|
adc eax, [edx + 8]
|
|
mov [edi + 8], eax
|
|
|
|
mov eax, [ecx + 12]
|
|
adc eax, [edx + 12]
|
|
mov [edi + 12], eax
|
|
|
|
lea ecx, [ecx + 16]
|
|
lea edx, [edx + 16]
|
|
lea edi, [edi + 16]
|
|
|
|
dec ebx
|
|
jnz SymCryptFdefRawAddAsmLoop
|
|
|
|
mov eax, 0
|
|
adc eax, eax
|
|
|
|
pop edi
|
|
pop ebx
|
|
ret 8
|
|
|
|
@SymCryptFdefRawAddAsm@16 ENDP
|
|
|
|
|
|
BEFORE_PROC
|
|
@SymCryptFdefRawSubAsm@16 PROC
|
|
;UINT32
|
|
;SYMCRYPT_CALL
|
|
;SymCryptFdefRawSub(
|
|
; _In_reads_bytes_(nDigits * SYMCRYPT_FDEF_DIGIT_SIZE ) PCUINT32 pSrc1,
|
|
; _In_reads_bytes_(nDigits * SYMCRYPT_FDEF_DIGIT_SIZE ) PCUINT32 pSrc2,
|
|
; _Out_writes_bytes_(nDigits * SYMCRYPT_FDEF_DIGIT_SIZE ) PUINT32 pDst,
|
|
; UINT32 nDigits )
|
|
|
|
.FPO(2,2,0,2,0,0)
|
|
|
|
SymCryptFdefRawSubAsmFrame struct 4, NONUNIQUE
|
|
|
|
SaveEdi dd ?
|
|
SaveEbx dd ?
|
|
ReturnAddress dd ?
|
|
pDst dd ?
|
|
nDigits dd ?
|
|
|
|
SymCryptFdefRawSubAsmFrame ends
|
|
|
|
; ecx = pSrc1
|
|
; edx = pSrc2
|
|
|
|
mov edi,edi
|
|
push ebx
|
|
push edi
|
|
|
|
mov edi, [esp + SymCryptFdefRawSubAsmFrame.pDst]
|
|
mov ebx, [esp + SymCryptFdefRawSubAsmFrame.nDigits]
|
|
|
|
xor eax,eax ; Cy = 0
|
|
|
|
SymCryptFdefRawSubAsmLoop:
|
|
mov eax, [ecx]
|
|
sbb eax, [edx]
|
|
mov [edi], eax
|
|
|
|
mov eax, [ecx + 4]
|
|
sbb eax, [edx + 4]
|
|
mov [edi + 4], eax
|
|
|
|
mov eax, [ecx + 8]
|
|
sbb eax, [edx + 8]
|
|
mov [edi + 8], eax
|
|
|
|
mov eax, [ecx + 12]
|
|
sbb eax, [edx + 12]
|
|
mov [edi + 12], eax
|
|
|
|
lea ecx, [ecx + 16]
|
|
lea edx, [edx + 16]
|
|
lea edi, [edi + 16]
|
|
|
|
dec ebx
|
|
jnz SymCryptFdefRawSubAsmLoop
|
|
|
|
mov eax, 0
|
|
adc eax, eax
|
|
|
|
pop edi
|
|
pop ebx
|
|
ret 8
|
|
|
|
@SymCryptFdefRawSubAsm@16 ENDP
|
|
|
|
|
|
BEFORE_PROC
|
|
@SymCryptFdefMaskedCopyAsm@16 PROC
|
|
;VOID
|
|
;SYMCRYPT_CALL
|
|
;SymCryptFdefMaskedCopy(
|
|
; _In_reads_bytes_( nDigits * SYMCRYPT_FDEF_DIGIT_SIZE ) PCBYTE pbSrc,
|
|
; _InOut_writes_bytes_( nDigits * SYMCRYPT_FDEF_DIGIT_SIZE ) PBYTE pbDst,
|
|
; UINT32 nDigits,
|
|
; UINT32 mask )
|
|
|
|
.FPO(3,2,0,3,0,0)
|
|
|
|
SymCryptFdefMaskedCopyAsmFrame struct 4, NONUNIQUE
|
|
SaveEdi dd ?
|
|
SaveEsi dd ?
|
|
SaveEbx dd ?
|
|
Returnaddress dd ?
|
|
nDigits dd ?
|
|
vMask dd ?
|
|
SymCryptFdefMaskedCopyAsmFrame ends
|
|
|
|
mov edi,edi
|
|
push ebx
|
|
push esi
|
|
push edi
|
|
|
|
mov esi, [esp + SymCryptFdefMaskedCopyAsmFrame.vMask]
|
|
mov edi, [esp + SymCryptFdefMaskedCopyAsmFrame.nDigits]
|
|
|
|
SymCryptFdefMaskedCopyAsmLoop:
|
|
mov eax, [ecx]
|
|
mov ebx, [edx]
|
|
xor eax, ebx
|
|
and eax, esi
|
|
xor eax, ebx
|
|
mov [edx], eax
|
|
|
|
mov eax, [ecx + 4]
|
|
mov ebx, [edx + 4]
|
|
xor eax, ebx
|
|
and eax, esi
|
|
xor eax, ebx
|
|
mov [edx + 4], eax
|
|
|
|
mov eax, [ecx + 8]
|
|
mov ebx, [edx + 8]
|
|
xor eax, ebx
|
|
and eax, esi
|
|
xor eax, ebx
|
|
mov [edx + 8], eax
|
|
|
|
mov eax, [ecx + 12]
|
|
mov ebx, [edx + 12]
|
|
xor eax, ebx
|
|
and eax, esi
|
|
xor eax, ebx
|
|
mov [edx + 12], eax
|
|
|
|
add ecx, 16
|
|
add edx, 16
|
|
sub edi, 1
|
|
jnz SymCryptFdefMaskedCopyAsmLoop
|
|
|
|
; No return value
|
|
pop edi
|
|
pop esi
|
|
pop ebx
|
|
ret 8
|
|
|
|
@SymCryptFdefMaskedCopyAsm@16 ENDP
|
|
|
|
|
|
|
|
BEFORE_PROC
|
|
@SymCryptFdefRawMulAsm@20 PROC
|
|
|
|
.FPO( 6, 3, 0, 4, 0, 0)
|
|
|
|
;VOID
|
|
;SYMCRYPT_CALL
|
|
;SymCryptFdefRawMul(
|
|
; _In_reads_(nWords1) PCUINT32 pSrc1,
|
|
; UINT32 nDigits1,
|
|
; _In_reads_(nWords2) PCUINT32 pSrc2,
|
|
; UINT32 nDigits2,
|
|
; _Out_writes_(nWords1 + nWords2) PUINT32 pDst )
|
|
SymCryptFdefRawMulAsmFrame struct 4, NONUNIQUE
|
|
|
|
nWords1 dd ?
|
|
pSrc1 dd ?
|
|
SaveEbp dd ?
|
|
SaveEsi dd ?
|
|
SaveEdi dd ?
|
|
SaveEbx dd ?
|
|
ReturnAddress dd ?
|
|
pSrc2 dd ?
|
|
nDigits2 dd ?
|
|
pDst dd ?
|
|
SymCryptFdefRawMulAsmFrame ends
|
|
|
|
; Basic code structure:
|
|
; for each word in Src1:
|
|
; Dst += Src2 * word
|
|
; Register assignments
|
|
;
|
|
; eax = tmp/lower half of mult
|
|
; ebx = multiplicant
|
|
; ecx = loop counter, initialized to nDigits2
|
|
; edx = upper half of mult
|
|
; esi = running pointer into Src2
|
|
; edi = dst
|
|
; ebp = carry
|
|
;
|
|
; esp + pSrc1 running pointer into Src1
|
|
; esp +
|
|
|
|
|
|
mov edi,edi
|
|
push ebx
|
|
push esi
|
|
push edi
|
|
push ebp
|
|
sub esp, SymCryptFdefRawMulAsmFrame.SaveEbp
|
|
|
|
; ecx = pSrc1
|
|
; edx = nDigits1
|
|
|
|
mov esi,[esp + SymCryptFdefRawMulAsmFrame.pSrc2]
|
|
|
|
mov ebx, [ecx] ; ebx = pSrc1[0]
|
|
add ecx, 4
|
|
mov [esp + SymCryptFdefRawMulAsmFrame.pSrc1], ecx
|
|
|
|
xor ebp, ebp ; carry = 0
|
|
|
|
mov edi,[esp + SymCryptFdefRawMulAsmFrame.pDst]
|
|
|
|
shl edx, 2 ; convert nDigits1 to nWords1
|
|
sub edx, 1 ; the first word is outside the outer loop, decremented here
|
|
mov [esp + SymCryptFdefRawMulAsmFrame.nWords1], edx
|
|
|
|
mov ecx,[esp + SymCryptFdefRawMulAsmFrame.nDigits2]
|
|
|
|
SymCryptFdefRawMulAsmLoop1:
|
|
mov eax, [esi]
|
|
mul ebx
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi], eax
|
|
mov ebp, edx
|
|
|
|
mov eax, [esi + 4]
|
|
mul ebx
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi + 4], eax
|
|
mov ebp, edx
|
|
|
|
mov eax, [esi + 8]
|
|
mul ebx
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi + 8], eax
|
|
mov ebp, edx
|
|
|
|
mov eax, [esi + 12]
|
|
mul ebx
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi + 12], eax
|
|
mov ebp, edx
|
|
|
|
add esi, 16
|
|
add edi, 16
|
|
sub ecx,1
|
|
jnz SymCryptFdefRawMulAsmLoop1
|
|
|
|
mov [edi], edx ; write last word; no overflow because Dst is at least 2 digits long
|
|
|
|
|
|
SymCryptFdefRawMulAsmLoopOuter:
|
|
|
|
mov esi, [esp + SymCryptFdefRawMulAsmFrame.pSrc2]
|
|
|
|
; Fetch next Src1 word & increment pointer
|
|
mov eax, [esp + SymCryptFdefRawMulAsmFrame.pSrc1]
|
|
mov ebx, [eax]
|
|
add eax, 4
|
|
mov [esp + SymCryptFdefRawMulAsmFrame.pSrc1], eax
|
|
|
|
xor ebp, ebp
|
|
|
|
; increment pDst & set in edi
|
|
mov edi, [esp + SymCryptFdefRawMulAsmFrame.pDst]
|
|
add edi, 4
|
|
mov [esp + SymCryptFdefRawMulAsmFrame.pDst], edi
|
|
|
|
mov ecx, [esp + SymCryptFdefRawMulAsmFrame.nDigits2]
|
|
|
|
SymCryptFdefRawMulAsmLoop2:
|
|
mov eax, [esi]
|
|
mul ebx
|
|
add eax, [edi]
|
|
adc edx, 0
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi], eax
|
|
mov ebp, edx
|
|
|
|
mov eax, [esi + 4]
|
|
mul ebx
|
|
add eax, [edi + 4]
|
|
adc edx, 0
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi + 4], eax
|
|
mov ebp, edx
|
|
|
|
mov eax, [esi + 8]
|
|
mul ebx
|
|
add eax, [edi + 8]
|
|
adc edx, 0
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi + 8], eax
|
|
mov ebp, edx
|
|
|
|
mov eax, [esi + 12]
|
|
mul ebx
|
|
add eax, [edi + 12]
|
|
adc edx, 0
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi + 12], eax
|
|
mov ebp, edx
|
|
|
|
add esi, 16
|
|
add edi, 16
|
|
sub ecx,1
|
|
jnz SymCryptFdefRawMulAsmLoop2
|
|
|
|
mov [edi], edx
|
|
|
|
mov eax,[esp + SymCryptFdefRawMulAsmFrame.nWords1]
|
|
sub eax, 1
|
|
mov [esp + SymCryptFdefRawMulAsmFrame.nWords1], eax
|
|
|
|
jnz SymCryptFdefRawMulAsmLoopOuter
|
|
|
|
|
|
add esp, SymCryptFdefRawMulAsmFrame.SaveEbp
|
|
pop ebp
|
|
pop edi
|
|
pop esi
|
|
pop ebx
|
|
ret 12
|
|
|
|
@SymCryptFdefRawMulAsm@20 ENDP
|
|
|
|
|
|
BEFORE_PROC
|
|
@SymCryptFdefMontgomeryReduceAsm@12 PROC
|
|
|
|
.FPO( 8, 1, 0, 4, 0, 0)
|
|
|
|
;VOID
|
|
;SymCryptFdefMontgomeryReduceAsm(
|
|
; _In_ PCSYMCRYPT_MODULUS pmMod,
|
|
; _Inout_ PUINT32 pSrc,
|
|
; _Out_ PUINT32 pDst )
|
|
|
|
SymCryptFdefMontgomeryReduceAsmFrame struct 4, NONUNIQUE
|
|
|
|
HighCarry dd ?
|
|
pSrc dd ?
|
|
pModValue dd ?
|
|
nWords dd ?
|
|
SaveEbp dd ? ; # words still to process in outer loop
|
|
SaveEsi dd ?
|
|
SaveEdi dd ?
|
|
SaveEbx dd ?
|
|
ReturnAddress dd ?
|
|
pDst dd ?
|
|
SymCryptFdefMontgomeryReduceAsmFrame ends
|
|
|
|
mov edi,edi
|
|
push ebx
|
|
push esi
|
|
push edi
|
|
push ebp
|
|
|
|
sub esp, SymCryptFdefMontgomeryReduceAsmFrame.SaveEbp
|
|
|
|
; ecx = pmMod
|
|
; edx = pSrc
|
|
|
|
mov eax, [ecx + SymCryptModulusNdigitsOffsetX86]
|
|
shl eax, 2
|
|
mov [esp + SymCryptFdefMontgomeryReduceAsmFrame.nWords], eax
|
|
|
|
lea esi, [ecx + SymCryptModulusValueOffsetX86]
|
|
mov [esp + SymCryptFdefMontgomeryReduceAsmFrame.pModValue], esi
|
|
|
|
mov [esp + SymCryptFdefMontgomeryReduceAsmFrame.pSrc], edx
|
|
mov edi, edx
|
|
|
|
xor eax,eax
|
|
mov [esp + SymCryptFdefMontgomeryReduceAsmFrame.HighCarry], eax ; set high-carry to zero
|
|
|
|
SymCryptFdefMontgomeryReduceOuterLoop:
|
|
; eax = <undef>
|
|
; ebx = <undef>
|
|
; ecx = <undef>
|
|
; edx = <undef>
|
|
; esi = start of mod value
|
|
; edi = pSrc + 4 * loop iteration count
|
|
; ebp = <undef>
|
|
|
|
; compute multiplier for this outer loop iteration.
|
|
mov ebx, [esi - SymCryptModulusValueOffsetX86 + SymCryptModulusInv64OffsetX86 ]
|
|
imul ebx, [edi] ; word we want to zero out, ebx = multiplier for this inner loop
|
|
|
|
mov ecx, [esi - SymCryptModulusValueOffsetX86 + SymCryptModulusNdigitsOffsetX86] ; ecx = nDigits
|
|
xor ebp, ebp ; set carry = 0
|
|
|
|
SymCryptFdefMontgomeryReduceInnerLoop:
|
|
; eax = mul scratch
|
|
; ebx = multiplier
|
|
; ecx = digit counter
|
|
; edx = mul scratch
|
|
; esi = running pointer to mod value
|
|
; edi = running pointer to input/scratch
|
|
; ebp = carry (32 bits)
|
|
|
|
mov eax, [esi]
|
|
mul ebx
|
|
add eax, [edi]
|
|
adc edx, 0
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi], eax
|
|
mov ebp, edx
|
|
|
|
mov eax, [esi + 4]
|
|
mul ebx
|
|
add eax, [edi + 4]
|
|
adc edx, 0
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi + 4], eax
|
|
mov ebp, edx
|
|
|
|
mov eax, [esi + 8]
|
|
mul ebx
|
|
add eax, [edi + 8]
|
|
adc edx, 0
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi + 8], eax
|
|
mov ebp, edx
|
|
|
|
mov eax, [esi + 12]
|
|
mul ebx
|
|
add eax, [edi + 12]
|
|
adc edx, 0
|
|
add eax, ebp
|
|
adc edx, 0
|
|
mov [edi + 12], eax
|
|
mov ebp, edx
|
|
|
|
add esi, 16
|
|
add edi, 16
|
|
sub ecx,1
|
|
jnz SymCryptFdefMontgomeryReduceInnerLoop
|
|
|
|
; Process the last high-word result with the high carry
|
|
xor eax, eax
|
|
add ebp,[esp + SymCryptFdefMontgomeryReduceAsmFrame.HighCarry]
|
|
adc eax, eax ; eax was 0, so this is equal to adc eax, 0
|
|
add ebp,[edi]
|
|
adc eax, 0
|
|
mov [edi], ebp
|
|
mov [esp + SymCryptFdefMontgomeryReduceAsmFrame.HighCarry], eax
|
|
|
|
mov esi, [esp + SymCryptFdefMontgomeryReduceAsmFrame.pModValue]
|
|
|
|
mov edi, [esp + SymCryptFdefMontgomeryReduceAsmFrame.pSrc]
|
|
add edi, 4
|
|
mov [esp + SymCryptFdefMontgomeryReduceAsmFrame.pSrc], edi
|
|
|
|
mov eax, [esp + SymCryptFdefMontgomeryReduceAsmFrame.nWords]
|
|
sub eax, 1
|
|
mov [esp + SymCryptFdefMontgomeryReduceAsmFrame.nWords], eax
|
|
|
|
jnz SymCryptFdefMontgomeryReduceOuterLoop
|
|
|
|
; At this point:
|
|
; esi = pModValue
|
|
; edi = pSrc
|
|
; Additional 1-bit carry word for the pSrc value is in the HighCarry stack variable.
|
|
; Cy = 0
|
|
|
|
|
|
mov ecx, [esi - SymCryptModulusValueOffsetX86 + SymCryptModulusNdigitsOffsetX86] ; loop counter
|
|
mov edx, [esp + SymCryptFdefMontgomeryReduceAsmFrame.pDst];
|
|
|
|
; ecx = nDigits
|
|
|
|
; Save some values for the copy loop
|
|
mov ebx, ecx ; nDigits
|
|
mov ebp, edx ; pDst
|
|
|
|
; Carry = 0 from previous sub eax,1 of the outer loop counter
|
|
SymCryptFdefMontgomeryReduceAsmSubLoop:
|
|
; edi = running pointer into pSrc result
|
|
; esi = running ptr into modulus value
|
|
; edx = running ptr into pDst
|
|
|
|
mov eax,[edi]
|
|
sbb eax,[esi]
|
|
mov [edx], eax
|
|
|
|
mov eax,[edi + 4]
|
|
sbb eax,[esi + 4]
|
|
mov [edx + 4], eax
|
|
|
|
mov eax,[edi + 8]
|
|
sbb eax,[esi + 8]
|
|
mov [edx + 8], eax
|
|
|
|
mov eax,[edi + 12]
|
|
sbb eax,[esi + 12]
|
|
mov [edx + 12], eax
|
|
|
|
lea edi, [edi + 16]
|
|
lea esi, [esi + 16]
|
|
lea edx, [edx + 16]
|
|
dec ecx
|
|
jnz SymCryptFdefMontgomeryReduceAsmSubLoop
|
|
|
|
mov ecx, [esp + SymCryptFdefMontgomeryReduceAsmFrame.HighCarry]
|
|
sbb ecx, 0
|
|
; eax = mask for masked copy
|
|
|
|
|
|
mov edi, [esp + SymCryptFdefMontgomeryReduceAsmFrame.pSrc]
|
|
|
|
; ecx = mask
|
|
SymCryptFdefMontgomeryReduceAsmMaskedCopyLoop:
|
|
; ebx = loop counter
|
|
; ebp = pDst
|
|
; edi = pSrc
|
|
; ecx = mask
|
|
|
|
mov eax, [edi]
|
|
mov edx, [ebp]
|
|
xor eax, edx
|
|
and eax, ecx
|
|
xor eax, edx
|
|
mov [ebp], eax
|
|
|
|
mov eax, [edi + 4]
|
|
mov edx, [ebp + 4]
|
|
xor eax, edx
|
|
and eax, ecx
|
|
xor eax, edx
|
|
mov [ebp + 4], eax
|
|
|
|
mov eax, [edi + 8]
|
|
mov edx, [ebp + 8]
|
|
xor eax, edx
|
|
and eax, ecx
|
|
xor eax, edx
|
|
mov [ebp + 8], eax
|
|
|
|
mov eax, [edi + 12]
|
|
mov edx, [ebp + 12]
|
|
xor eax, edx
|
|
and eax, ecx
|
|
xor eax, edx
|
|
mov [ebp + 12], eax
|
|
|
|
add edi, 16
|
|
add ebp, 16
|
|
sub ebx, 1
|
|
jnz SymCryptFdefMontgomeryReduceAsmMaskedCopyLoop
|
|
|
|
; Done, no return value
|
|
|
|
add esp, SymCryptFdefMontgomeryReduceAsmFrame.SaveEbp
|
|
pop ebp
|
|
pop edi
|
|
pop esi
|
|
pop ebx
|
|
|
|
ret 4
|
|
|
|
@SymCryptFdefMontgomeryReduceAsm@12 ENDP
|
|
|
|
_TEXT ENDS
|
|
|
|
END
|
|
|
|
|