Skip to content
This repository
tree: af25501aeb
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 77 lines (62 sloc) 2.159 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
unit ArcFour;

{
Inno Setup
Copyright (C) 1997-2004 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.

Interface to ISCrypt.dll (ARCFOUR encryption/decryption)

$jrsoftware: issrc/Projects/ArcFour.pas,v 1.2 2004/04/26 19:11:23 jr Exp $
}

interface

uses
  Windows;

type
  TArcFourContext = record
    state: array[0..255] of Byte;
    x, y: Byte;
  end;

function ArcFourInitFunctions(Module: HMODULE): Boolean;
procedure ArcFourInit(var Context: TArcFourContext; const Key;
  KeyLength: Cardinal);
procedure ArcFourCrypt(var Context: TArcFourContext; const InBuffer;
  var OutBuffer; Length: Cardinal);
procedure ArcFourDiscard(var Context: TArcFourContext; Bytes: Cardinal);

implementation

var
  _ISCryptGetVersion: function: Integer; stdcall;
  _ArcFourInit: procedure(var context: TArcFourContext; const key;
    key_length: Cardinal); stdcall;
  _ArcFourCrypt: procedure(var context: TArcFourContext; const in_buffer;
    var out_buffer; length: Cardinal); stdcall;

function ArcFourInitFunctions(Module: HMODULE): Boolean;
begin
  _ISCryptGetVersion := GetProcAddress(Module, 'ISCryptGetVersion');
  _ArcFourInit := GetProcAddress(Module, 'ArcFourInit');
  _ArcFourCrypt := GetProcAddress(Module, 'ArcFourCrypt');
  if Assigned(_ISCryptGetVersion) and Assigned(_ArcFourInit) and
     Assigned(_ArcFourCrypt) then begin
    { Verify that the DLL's version is what we expect }
    Result := (_ISCryptGetVersion = 1);
  end
  else begin
    Result := False;
    _ISCryptGetVersion := nil;
    _ArcFourInit := nil;
    _ArcFourCrypt := nil;
  end
end;

procedure ArcFourInit(var Context: TArcFourContext; const Key;
  KeyLength: Cardinal);
begin
  _ArcFourInit(Context, Key, KeyLength);
end;

procedure ArcFourCrypt(var Context: TArcFourContext; const InBuffer;
  var OutBuffer; Length: Cardinal);
begin
  _ArcFourCrypt(Context, InBuffer, OutBuffer, Length);
end;

procedure ArcFourDiscard(var Context: TArcFourContext; Bytes: Cardinal);
begin
  _ArcFourCrypt(Context, Pointer(nil)^, Pointer(nil)^, Bytes);
end;

end.
Something went wrong with that request. Please try again.