X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/9763940f8849e5c807566157829a1e6d2c9172ee..b60a32da0a15deb572474b1f66a6c63695ed7491:/lcorernd.pas?ds=sidebyside diff --git a/lcorernd.pas b/lcorernd.pas index 7dbd7f1..b435305 100644 --- a/lcorernd.pas +++ b/lcorernd.pas @@ -4,7 +4,9 @@ ----------------------------------------------------------------------------- } unit lcorernd; - +{$ifdef fpc} + {$mode delphi} +{$endif} interface {$include lcoreconfig.inc} @@ -143,6 +145,13 @@ uses {$endif} {$endif} fastmd5,sysutils; +{$endif} + +const + wordsizeshift=2; + wordsize=1 shl wordsizeshift; + +{$ifndef nolcorernd} {$ifdef unix}{$include unixstuff.inc}{$endif} @@ -168,26 +177,41 @@ type hashtype=tmd5; const - wordsizeshift=2; - wordsize=1 shl wordsizeshift; //wordsize check commented out for d3 compatibility //{ $if (wordsize <> sizeof(wordtype))}'wordsizeshift must be setcorrectly'{ $ifend} hashsize=sizeof(hashtype); halfhashsize=hashsize div 2; hashdwords=hashsize div wordsize; pooldwords=3*hashdwords; - seeddwords=32; + seeddwords=40; hashpasssize=48; {this number has to be small enough that hashing this size uses only one block transform} var - {the seed part of this buffer must be at least as big as the OS seed (windows: 104 bytes, unix: 36 bytes)} + //the seed part of this buffer must be at least as big as the OS seed (windows: 120 bytes for 32 bits, 160 bytes for 64 bits, unix: 36 bytes) pool:array[0..(pooldwords+seeddwords-1)] of wordtype; reseedcountdown:integer; {$ifdef mswindows} +var + systemfunction036:function(var v; c:cardinal): boolean; stdcall; + rtlgenrandominited:boolean; + +procedure initrtlgenrandom; +var + h:thandle; +begin + rtlgenrandominited := true; + systemfunction036 := nil; + h := loadlibrary('advapi32.dll'); + if (h <> 0) then begin + systemfunction036 := GetProcAddress(h,'SystemFunction036'); + end; +end; + function collect_seeding(var output;const bufsize:integer):integer; var l:packed record + rtlgenrandom:array[0..3] of longint; guid:array[0..3] of longint; qpcbuf:array[0..1] of longint; rdtscbuf:array[0..1] of longint; @@ -221,6 +245,10 @@ begin getcursorpos(l.cursor); l.hs := getheapstatus; + + {rtlgenrandom} + if not rtlgenrandominited then initrtlgenrandom; + if assigned(@systemfunction036) then systemfunction036(l.rtlgenrandom,sizeof(l.rtlgenrandom)); end; {$endif}