DCPcrypt CTS

Rozszerzenie funkcjonalności modułu DCPcrypt o tryb deszyfrowania CTS

type
  TDCP_helper = class helper for TDCP_blockcipher64
  public
    procedure DecryptCTS(const Indata; var Outdata; Size: longword);
  end;

procedure TDCP_helper.DecryptCTS(const Indata; var Outdata; Size: longword);
var
  i: longword;
  p1, p2: pointer;
  Temp: array[0..7] of byte;
  CV: array[0..7] of byte;
begin
  if not fInitialized then
    raise EDCP_blockcipher.Create('Cipher not initialized');
  GetIV(CV);
  p1 := @Indata;
  p2 := @Outdata;
  for i:= 1 to (Size div 8) do
  begin
    Move(p1^, p2^, 8);
    Move(p2^, Temp, 8);
    XorBlock(Temp, CV, 8);
    DecryptECB(p2^, p2^);
    XorBlock(p2^, CV, 8);
    Move(Temp, CV, 8);
    Inc(p1, 8);
    Inc(p2, 8);
  end;
  if not ((Size mod 8) = 0) then
  begin
    EncryptECB(CV,CV);
    Move(p1^,p2^,Size mod 8);
    XorBlock(p2^,CV,Size mod 8);
  end;
end;