ArcFour.pas 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. unit ArcFour;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2004 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Interface to ISCrypt.dll (ARCFOUR encryption/decryption)
  8. $jrsoftware: issrc/Projects/ArcFour.pas,v 1.2 2004/04/26 19:11:23 jr Exp $
  9. }
  10. interface
  11. uses
  12. Windows;
  13. type
  14. TArcFourContext = record
  15. state: array[0..255] of Byte;
  16. x, y: Byte;
  17. end;
  18. function ArcFourInitFunctions(Module: HMODULE): Boolean;
  19. procedure ArcFourInit(var Context: TArcFourContext; const Key;
  20. KeyLength: Cardinal);
  21. procedure ArcFourCrypt(var Context: TArcFourContext; const InBuffer;
  22. var OutBuffer; Length: Cardinal);
  23. procedure ArcFourDiscard(var Context: TArcFourContext; Bytes: Cardinal);
  24. implementation
  25. var
  26. _ISCryptGetVersion: function: Integer; stdcall;
  27. _ArcFourInit: procedure(var context: TArcFourContext; const key;
  28. key_length: Cardinal); stdcall;
  29. _ArcFourCrypt: procedure(var context: TArcFourContext; const in_buffer;
  30. var out_buffer; length: Cardinal); stdcall;
  31. function ArcFourInitFunctions(Module: HMODULE): Boolean;
  32. begin
  33. _ISCryptGetVersion := GetProcAddress(Module, 'ISCryptGetVersion');
  34. _ArcFourInit := GetProcAddress(Module, 'ArcFourInit');
  35. _ArcFourCrypt := GetProcAddress(Module, 'ArcFourCrypt');
  36. if Assigned(_ISCryptGetVersion) and Assigned(_ArcFourInit) and
  37. Assigned(_ArcFourCrypt) then begin
  38. { Verify that the DLL's version is what we expect }
  39. Result := (_ISCryptGetVersion = 1);
  40. end
  41. else begin
  42. Result := False;
  43. _ISCryptGetVersion := nil;
  44. _ArcFourInit := nil;
  45. _ArcFourCrypt := nil;
  46. end
  47. end;
  48. procedure ArcFourInit(var Context: TArcFourContext; const Key;
  49. KeyLength: Cardinal);
  50. begin
  51. _ArcFourInit(Context, Key, KeyLength);
  52. end;
  53. procedure ArcFourCrypt(var Context: TArcFourContext; const InBuffer;
  54. var OutBuffer; Length: Cardinal);
  55. begin
  56. _ArcFourCrypt(Context, InBuffer, OutBuffer, Length);
  57. end;
  58. procedure ArcFourDiscard(var Context: TArcFourContext; Bytes: Cardinal);
  59. begin
  60. _ArcFourCrypt(Context, Pointer(nil)^, Pointer(nil)^, Bytes);
  61. end;
  62. end.