lcore.org gitweb
/
lcore.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
increase amount of seeding from /dev/urandom
[lcore.git]
/
lcorernd.pas
diff --git
a/lcorernd.pas
b/lcorernd.pas
index 64759e83fc95d67508cae7ac4256d587cc9f4100..8f79856745c7580f669f268a3f51a0c2dfab41af 100644
(file)
--- a/
lcorernd.pas
+++ b/
lcorernd.pas
@@
-111,7
+111,7
@@
function randominteger(i:longint):longint;
function randombits(b:integer):longint;
\r
\r
{generate a version 4 random uuid}
\r
function randombits(b:integer):longint;
\r
\r
{generate a version 4 random uuid}
\r
-function generate_uuid:string;
\r
+function generate_uuid:
ansi
string;
\r
\r
{$ifndef nolcorernd}
\r
\r
\r
{$ifndef nolcorernd}
\r
\r
@@
-130,20
+130,39
@@
var
\r
implementation
\r
\r
\r
implementation
\r
\r
+{$include pgtypes.inc}
\r
+
\r
{$ifndef nolcorernd}
\r
uses
\r
{$ifndef nolcorernd}
\r
uses
\r
- {$ifdef
win32
}windows,activex,{$endif}
\r
+ {$ifdef
mswindows
}windows,activex,{$endif}
\r
{$ifdef unix}
\r
{$ifdef ver1_0}
\r
linux,
\r
{$else}
\r
{$ifdef unix}
\r
{$ifdef ver1_0}
\r
linux,
\r
{$else}
\r
- baseunix,unix,unixutil,
\r
+ baseunix,unix,unixutil,
sockets,
\r
{$endif}
\r
{$endif}
\r
fastmd5,sysutils;
\r
\r
{$ifdef unix}{$include unixstuff.inc}{$endif}
\r
\r
{$endif}
\r
{$endif}
\r
fastmd5,sysutils;
\r
\r
{$ifdef unix}{$include unixstuff.inc}{$endif}
\r
\r
+procedure rdtsc(buf: pointer);
\r
+asm
\r
+ {$ifdef cpux86}
\r
+ mov ecx, buf
\r
+ db $0f; db $31 {rdtsc}
\r
+ mov [ecx], edx
\r
+ mov [ecx+4], eax
\r
+ {$endif}
\r
+
\r
+ {$ifdef cpux64}
\r
+ mov rcx, buf
\r
+ rdtsc
\r
+ mov [rcx], edx
\r
+ mov [rcx+4], eax
\r
+ {$endif}
\r
+end;
\r
+
\r
type
\r
{hashtype must be array of bytes}
\r
hashtype=tmd5;
\r
type
\r
{hashtype must be array of bytes}
\r
hashtype=tmd5;
\r
@@
-165,7
+184,7
@@
var
pool:array[0..(pooldwords+seeddwords-1)] of wordtype;
\r
reseedcountdown:integer;
\r
\r
pool:array[0..(pooldwords+seeddwords-1)] of wordtype;
\r
reseedcountdown:integer;
\r
\r
-{$ifdef
win32
}
\r
+{$ifdef
mswindows
}
\r
function collect_seeding(var output;const bufsize:integer):integer;
\r
var
\r
l:packed record
\r
function collect_seeding(var output;const bufsize:integer):integer;
\r
var
\r
l:packed record
\r
@@
-178,7
+197,6
@@
var
cursor:tpoint;
\r
hs:theapstatus;
\r
end absolute output;
\r
cursor:tpoint;
\r
hs:theapstatus;
\r
end absolute output;
\r
- rdtsc_0,rdtsc_1:integer;
\r
begin
\r
result := 0;
\r
if (bufsize < sizeof(l)) then exit;
\r
begin
\r
result := 0;
\r
if (bufsize < sizeof(l)) then exit;
\r
@@
-194,15
+212,8
@@
begin
queryperformancecounter(tlargeinteger(l.qpcbuf));
\r
\r
{RDTSC}
\r
queryperformancecounter(tlargeinteger(l.qpcbuf));
\r
\r
{RDTSC}
\r
- {$ifdef cpu386}
\r
- asm
\r
- db $0F; db $31
\r
- mov rdtsc_0,eax
\r
- mov rdtsc_1,edx
\r
- end;
\r
- l.rdtscbuf[0] := rdtsc_0;
\r
- l.rdtscbuf[1] := rdtsc_1;
\r
- {$endif}
\r
+ rdtsc(@l.rdtscbuf);
\r
+
\r
{GETSYSTEMTIME}
\r
getsystemtime(tsystemtime(l.systemtimebuf));
\r
\r
{GETSYSTEMTIME}
\r
getsystemtime(tsystemtime(l.systemtimebuf));
\r
\r
@@
-248,12
+259,11
@@
var
f:file;
\r
a:integer;
\r
l:packed record
\r
f:file;
\r
a:integer;
\r
l:packed record
\r
- devrnd:array[0..
3
] of integer;
\r
+ devrnd:array[0..
7
] of integer;
\r
rdtscbuf:array[0..1] of integer;
\r
tv:ttimeval;
\r
pid:integer;
\r
end absolute output;
\r
rdtscbuf:array[0..1] of integer;
\r
tv:ttimeval;
\r
pid:integer;
\r
end absolute output;
\r
- rdtsc_0,rdtsc_1:integer;
\r
\r
begin
\r
result := 0;
\r
\r
begin
\r
result := 0;
\r
@@
-280,15
+290,7
@@
begin
move(wtmpcached,l.devrnd,sizeof(l.devrnd));
\r
end;
\r
{get more randomness in case there's no /dev/random}
\r
move(wtmpcached,l.devrnd,sizeof(l.devrnd));
\r
end;
\r
{get more randomness in case there's no /dev/random}
\r
- {$ifdef cpu386}{$ASMMODE intel}
\r
- asm
\r
- db $0F; db $31
\r
- mov rdtsc_0,eax
\r
- mov rdtsc_1,edx
\r
- end;
\r
- l.rdtscbuf[0] := rdtsc_0;
\r
- l.rdtscbuf[1] := rdtsc_1;
\r
- {$endif}
\r
+ rdtsc(@l.rdtscbuf);
\r
\r
gettimeofday(l.tv);
\r
l.pid := getpid;
\r
\r
gettimeofday(l.tv);
\r
l.pid := getpid;
\r
@@
-402,12
+404,12
@@
begin
end;
\r
\r
const
\r
end;
\r
\r
const
\r
- ch:array[0..15] of char='0123456789abcdef';
\r
+ ch:array[0..15] of
ansi
char='0123456789abcdef';
\r
\r
\r
-function generate_uuid:string;
\r
+function generate_uuid:
ansi
string;
\r
var
\r
buf:array[0..7] of word;
\r
var
\r
buf:array[0..7] of word;
\r
-function inttohex(w:word):string;
\r
+function inttohex(w:word):
ansi
string;
\r
begin
\r
result := ch[w shr 12] + ch[(w shr 8) and $f] + ch[(w shr 4) and $f] + ch[w and $f];
\r
end;
\r
begin
\r
result := ch[w shr 12] + ch[(w shr 8) and $f] + ch[(w shr 4) and $f] + ch[w and $f];
\r
end;
\r