<s>
CryptGenRandom	B-Algorithm
is	O
a	O
deprecated	O
cryptographically	B-Algorithm
secure	I-Algorithm
pseudorandom	I-Algorithm
number	I-Algorithm
generator	I-Algorithm
function	O
that	O
is	O
included	O
in	O
Microsoft	O
CryptoAPI	O
.	O
</s>
<s>
In	O
Win32	B-Library
programs	O
,	O
Microsoft	O
recommends	O
its	O
use	O
anywhere	O
random	O
number	O
generation	O
is	O
needed	O
.	O
</s>
<s>
A	O
2007	O
paper	O
from	O
Hebrew	O
University	O
suggested	O
security	O
problems	O
in	O
the	O
Windows	B-Application
2000	I-Application
implementation	O
of	O
CryptGenRandom	B-Algorithm
(	O
assuming	O
the	O
attacker	O
has	O
control	O
of	O
the	O
machine	O
)	O
.	O
</s>
<s>
Microsoft	O
later	O
acknowledged	O
that	O
the	O
same	O
problems	O
exist	O
in	O
Windows	B-Application
XP	I-Application
,	O
but	O
not	O
in	O
Vista	B-Application
.	O
</s>
<s>
Microsoft	O
released	O
a	O
fix	O
for	O
the	O
bug	O
with	O
Windows	B-Application
XP	I-Application
Service	O
Pack	O
3	O
in	O
mid-2008	O
.	O
</s>
<s>
The	O
Win32	B-Library
API	I-Library
includes	O
comprehensive	O
support	O
for	O
cryptographic	O
security	O
,	O
including	O
native	O
TLS	B-Protocol
support	O
(	O
via	O
the	O
SCHANNEL	O
API	B-General_Concept
)	O
and	O
code	O
signing	O
.	O
</s>
<s>
These	O
capabilities	O
are	O
built	O
on	O
native	O
Windows	O
libraries	O
for	O
cryptographic	O
operations	O
,	O
such	O
as	O
RSA	B-Architecture
and	O
AES	B-Algorithm
key	I-Algorithm
generation	O
.	O
</s>
<s>
These	O
libraries	O
in	O
turn	O
rely	O
on	O
a	O
cryptographically	B-Algorithm
secure	I-Algorithm
pseudorandom	I-Algorithm
number	I-Algorithm
generator	I-Algorithm
(	O
CSPRNG	B-Algorithm
)	O
.	O
</s>
<s>
CryptGenRandom	B-Algorithm
is	O
the	O
standard	O
CSPRNG	B-Algorithm
for	O
the	O
Win32	B-Library
programming	O
environment	O
.	O
</s>
<s>
Microsoft-provided	O
cryptography	O
providers	O
share	O
the	O
same	O
implementation	O
of	O
CryptGenRandom	B-Algorithm
,	O
currently	O
based	O
on	O
an	O
internal	O
function	O
called	O
RtlGenRandom	B-Algorithm
.	O
</s>
<s>
 [ RtlGenRandom ] 	O
generates	O
as	O
specified	O
in	O
FIPS	O
186-2	O
appendix	O
3.1	O
with	O
SHA-1	B-Algorithm
as	O
the	O
G	O
function	O
.	O
</s>
<s>
An	O
MD4	B-Algorithm
hash	I-Algorithm
of	O
the	O
user	O
's	O
environment	O
block	O
,	O
which	O
includes	O
username	O
,	O
computer	O
name	O
,	O
and	O
search	O
path	O
.	O
</s>
<s>
The	O
security	O
of	O
a	O
cryptosystem	O
's	O
CSPRNG	B-Algorithm
is	O
significant	O
because	O
it	O
is	O
the	O
origin	O
for	O
dynamic	O
key	O
material	O
.	O
</s>
<s>
Keys	O
needed	O
"	O
on	O
the	O
fly	O
"	O
,	O
such	O
as	O
the	O
AES	B-Algorithm
TLS	B-Protocol
session	O
keys	O
that	O
protect	O
HTTPS	B-Protocol
sessions	O
with	O
bank	O
websites	O
,	O
originate	O
from	O
CSPRNGs	B-Algorithm
.	O
</s>
<s>
Because	O
CryptGenRandom	B-Algorithm
is	O
the	O
de	O
facto	O
standard	O
CSPRNG	B-Algorithm
in	O
Win32	B-Library
environments	O
,	O
its	O
security	O
is	O
critical	O
for	O
Windows	O
users	O
.	O
</s>
<s>
The	O
specifics	O
of	O
CryptGenRandom	B-Algorithm
's	O
algorithm	O
have	O
not	O
been	O
officially	O
published	O
.	O
</s>
<s>
A	O
cryptanalysis	O
of	O
CryptGenRandom	B-Algorithm
,	O
published	O
in	O
November	O
2007	O
by	O
Leo	O
Dorrendorf	O
and	O
others	O
from	O
the	O
Hebrew	O
University	O
of	O
Jerusalem	O
and	O
University	O
of	O
Haifa	O
,	O
found	O
significant	O
weaknesses	O
in	O
the	O
Windows	B-Application
2000	I-Application
implementation	O
of	O
the	O
algorithm	O
.	O
</s>
<s>
However	O
,	O
the	O
Hebrew	O
University	O
team	O
notes	O
that	O
an	O
attacker	O
only	O
need	O
steal	O
the	O
state	O
bits	O
once	O
in	O
order	O
to	O
persistently	O
violate	O
the	O
security	O
of	O
a	O
CryptGenRandom	B-Algorithm
instance	O
.	O
</s>
<s>
The	O
paper	O
's	O
attacks	O
are	O
based	O
on	O
the	O
fact	O
that	O
CryptGenRandom	B-Algorithm
uses	O
the	O
stream	O
cipher	O
RC4	B-Algorithm
,	O
which	O
can	O
be	O
run	O
backwards	O
once	O
its	O
state	O
is	O
known	O
.	O
</s>
<s>
They	O
also	O
take	O
advantage	O
of	O
the	O
fact	O
that	O
CryptGenRandom	B-Algorithm
runs	O
in	O
user	B-Operating_System
mode	I-Operating_System
,	O
allowing	O
anyone	O
who	O
gains	O
access	O
to	O
the	O
operating	O
system	O
at	O
user	O
level	O
,	O
for	O
example	O
by	O
exploiting	O
a	O
buffer	B-General_Concept
overflow	I-General_Concept
,	O
to	O
get	O
CryptGenRandom	B-Algorithm
's	O
state	O
information	O
for	O
that	O
process	O
.	O
</s>
<s>
Finally	O
,	O
CryptGenRandom	B-Algorithm
refreshes	O
its	O
seed	O
from	O
entropy	O
infrequently	O
.	O
</s>
<s>
This	O
problem	O
is	O
aggravated	O
by	O
the	O
fact	O
that	O
each	O
Win32	B-Library
process	O
has	O
its	O
own	O
instance	O
of	O
CryptGenRandom	B-Algorithm
state	O
;	O
while	O
this	O
means	O
that	O
a	O
compromise	O
of	O
one	O
process	O
does	O
not	O
transitively	O
compromise	O
every	O
other	O
process	O
,	O
it	O
may	O
also	O
increase	O
the	O
longevity	O
of	O
any	O
successful	O
break	O
.	O
</s>
<s>
Because	O
the	O
details	O
of	O
the	O
CryptGenRandom	B-Algorithm
algorithm	O
are	O
not	O
public	O
,	O
Dorrendorf	O
's	O
team	O
used	O
reverse	O
engineering	O
tools	O
to	O
discern	O
how	O
the	O
algorithm	O
works	O
.	O
</s>
<s>
Their	O
paper	O
is	O
the	O
first	O
published	O
record	O
of	O
how	O
the	O
Windows	O
cryptographic	B-Algorithm
random	I-Algorithm
number	I-Algorithm
generator	I-Algorithm
operates	O
.	O
</s>
<s>
Windows	B-Application
2000	I-Application
,	O
XP	B-Application
and	O
2003	O
have	O
all	O
successfully	O
undergone	O
EAL4+	O
evaluations	O
,	O
including	O
the	O
CryptGenRandom( )	O
and	O
FIPSGenRandom( )	O
implementations	O
.	O
</s>
<s>
Windows	O
developers	O
have	O
several	O
alternative	O
means	O
of	O
accessing	O
the	O
CryptGenRandom	B-Algorithm
functionality	O
;	O
these	O
alternatives	O
invoke	O
the	O
same	O
algorithm	O
and	O
share	O
the	O
same	O
security	O
characteristics	O
,	O
but	O
may	O
have	O
other	O
advantages	O
.	O
</s>
<s>
Historically	O
,	O
we	O
always	O
told	O
developers	O
not	O
to	O
use	O
functions	O
such	O
as	O
rand	O
to	O
generate	O
keys	O
,	O
nonces	O
and	O
passwords	O
,	O
rather	O
they	O
should	O
use	O
functions	O
like	O
CryptGenRandom	B-Algorithm
,	O
which	O
creates	O
cryptographically	O
secure	O
random	O
numbers	O
.	O
</s>
<s>
The	O
problem	O
with	O
CryptGenRandom	B-Algorithm
is	O
you	O
need	O
to	O
pull	O
in	O
CryptoAPI	O
(	O
CryptAcquireContext	O
and	O
such	O
)	O
which	O
is	O
fine	O
if	O
you	O
're	O
using	O
other	O
crypto	O
functions	O
.	O
</s>
<s>
On	O
a	O
default	O
Windows	B-Application
XP	I-Application
and	O
later	O
install	O
,	O
CryptGenRandom	B-Algorithm
calls	O
into	O
a	O
function	O
named	O
ADVAPI32	O
!	O
RtlGenRandom	B-Algorithm
,	O
which	O
does	O
not	O
require	O
you	O
load	O
all	O
the	O
CryptAPI	O
stuff	O
.	O
</s>
<s>
Programmers	O
using	O
.NET	B-Application
should	O
use	O
the	O
RNGCryptoServiceProvider	O
Class	O
.	O
</s>
<s>
The	O
CNG	O
is	O
a	O
long	O
term	O
replacement	O
for	O
the	O
deprecated	O
Crypto	O
API	B-General_Concept
.	O
</s>
<s>
the	O
Microsoft	O
C++	O
library	O
function	O
rand_s	O
uses	O
RtlGenRandom	B-Algorithm
and	O
is	O
recommended	O
by	O
Microsoft	O
for	O
secure	O
applications	O
.	O
</s>
<s>
the	O
Python	B-Language
function	O
urandom	B-Application
in	O
the	O
os	O
module	O
,	O
which	O
uses	O
/dev/urandom	B-Application
on	O
Unix-like	B-Operating_System
systems	I-Operating_System
,	O
calls	O
CryptGenRandom	B-Algorithm
on	O
Windows	O
systems	O
.	O
</s>
<s>
the	O
Java	B-Language
JCA	O
Provider	O
"	O
SunMSCAPI	O
"	O
available	O
with	O
OpenJDK	O
and	O
Oracle	O
distributions	O
of	O
the	O
JRE	O
on	O
Windows	O
provides	O
a	O
SecureRandom	O
implementation	O
with	O
the	O
algorithm	O
name	O
Windows-PRNG	O
.	O
</s>
<s>
This	O
class	O
forwards	O
all	O
queries	O
for	O
random	O
or	O
seed	O
bytes	O
as	O
well	O
as	O
setting	O
additional	O
seed	O
bytes	O
to	O
native	O
CryptGenRandom	B-Algorithm
.	O
</s>
