RSA - 9


mov ebx,[res]

18.2

add ebx,[j]

mov ecx,BIGNUM_DWORD

sub ecx,[i]

cmp ecx,0

je @_mul_2

@_mul_1:

mov eax,[esi]

mov edx,[edi]

mul edx

add [ebx],eax

adc [ebx+4],edx

pushfd

cmp ecx,1

je @_mul_1_1

popfd

adc dword ptr[ebx+8],0

pushfd

@_mul_1_1:

popfd

add esi,4

add ebx,4

loop @_mul_1

@_mul_2:

mov eax,[esi]

mov edx,[edi]

mul edx

add [ebx],eax

popad

end;

end;

end;

procedure BN_a_shl_k(var a: TBigNum; k: Integer; var res: TBigNum);

var i,j: Integer;

var d,u: Cardinal;

begin

for j := 0 to BIGNUM_DWORD do res[j] := a[j];

if (k<=0) then Exit;

for j := 0 to BIGNUM_DWORD do res[j] := 0;

i := k div 32;

18.2

if (i>BIGNUM_DWORD) then Exit;

for j := i to BIGNUM_DWORD do

res[j] := a[j-i];

i := k mod 32;

if (i=0) then Exit;

d := 0;

for j := 0 to BIGNUM_DWORD do

begin

u := res[j] shr (32-i);

res[j] := (res[j] shl i) + d;

d := u;

end;

end;

procedure BN_a_shr_k(var a: TBigNum; k: Integer;

var res: TBigNum);

var i,j: Integer;

var d,u: Cardinal;

begin

for j := 0 to BIGNUM_DWORD do res[j] := a[j];

if (k<=0) then Exit;

for j := 0 to BIGNUM_DWORD do res[j] := 0;

i := k div 32;

if (i>BIGNUM_DWORD) then Exit;

for j := i to BIGNUM_DWORD do

res[j-i] := a[j];

i := k mod 32;

if (i=0) then Exit;

u := 0;

for j := BIGNUM_DWORD downto 0 do

begin

d := res[j] shl (32-i);

res[j] := (res[j] shr i) + u;

u := d;

end;

end;

function BN_a_upbit(var a: TBigNum): Integer;

var i,j: Integer;

begin

i := BIGNUM_DWORD;

while (i>=0) and (a[i]=0) do Dec(i);

18.2

Result := 0;

if (i<0) then Exit;

j := 31;

while (j>0) and (a[i] and (1 shl j) = 0) do Dec(j);

Result := i*32 + j + 1;

end;

procedure BN_a_setbit_k(var a: TBigNum; k: Integer);

begin

if (k<0) or (k>32*BIGNUM_DWORD-1) then

begin

Exit;

end;

a[k shr 5] := a[k shr 5] or (1 shl (k and 31));