mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-03-07 14:18:15 +08:00
Linux equivs. Should be extended to support other quality sources of entropy. Should be extended to support a reasonable fallback.
35 lines
650 B
C
35 lines
650 B
C
/* $OpenLDAP$ */
|
|
/*
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
*/
|
|
|
|
/*
|
|
* lutil_entropy() provides nbyptes of entropy in buf.
|
|
* Quality offerred is suitable for one-time uses, such as "once" keys.
|
|
*/
|
|
int lutil_entropy( char *buf, int nbytes )
|
|
{
|
|
if( nbytes < 0 ) return -1;
|
|
if( nbytes == 0 ) return 0;
|
|
|
|
#ifdef URANDOM_DEVICE
|
|
/* Linux and *BSD offer a urandom device */
|
|
{
|
|
int rc, fd;
|
|
|
|
fd = open( URANDOM_DEVICE, O_RDONLY );
|
|
|
|
if( fd < 0 ) return -1;
|
|
|
|
rc = read( fd, buf, nbytes );
|
|
close(fd);
|
|
|
|
if( rc < nbytes ) return -1;
|
|
|
|
return 0;
|
|
}
|
|
#endif
|
|
return -1;
|
|
}
|