mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-28 10:02:14 +00:00
ADD: Block random function
This commit is contained in:
parent
d65b35b371
commit
7d7a28510e
1 changed files with 38 additions and 0 deletions
38
src/platform/urandom.pas
Normal file
38
src/platform/urandom.pas
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
unit uRandom;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
|
||||
procedure Random(ABlock: PByte; ACount: Integer);
|
||||
|
||||
implementation
|
||||
|
||||
{$IF DEFINED(MSWINDOWS)}
|
||||
uses JwaWinCrypt;
|
||||
{$ENDIF}
|
||||
|
||||
procedure Random(ABlock: PByte; ACount: Integer);
|
||||
var
|
||||
I: Integer;
|
||||
{$IF DEFINED(MSWINDOWS)}
|
||||
Result: Boolean;
|
||||
phProv: HCRYPTPROV = 0;
|
||||
{$ENDIF}
|
||||
begin
|
||||
{$IF DEFINED(MSWINDOWS)}
|
||||
Result:= CryptAcquireContext(phProv, nil, nil, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
|
||||
if Result then begin
|
||||
Result:= CryptGenRandom(phProv, ACount, ABlock);
|
||||
CryptReleaseContext(phProv, 0);
|
||||
end;
|
||||
if not Result then
|
||||
{$ENDIF}
|
||||
for I:= 0 to ACount - 1 do ABlock[I]:= Byte(System.Random(256));
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue