@ -1,4 +1,4 @@
/* $OpenBSD: getentropy_linux.c,v 1.45 2018/03/13 22:53:28 bcook Exp $ */
/* $OpenBSD: getentropy_linux.c,v 1.45.2.1 2018/12/15 15:10:53 bcook Exp $ */
/*
/*
* Copyright ( c ) 2014 Theo de Raadt < deraadt @ openbsd . org >
* Copyright ( c ) 2014 Theo de Raadt < deraadt @ openbsd . org >
@ -73,7 +73,6 @@
int getentropy ( void * buf , size_t len ) ;
int getentropy ( void * buf , size_t len ) ;
static int gotdata ( char * buf , size_t len ) ;
# if defined(SYS_getrandom) && defined(GRND_NONBLOCK)
# if defined(SYS_getrandom) && defined(GRND_NONBLOCK)
static int getentropy_getrandom ( void * buf , size_t len ) ;
static int getentropy_getrandom ( void * buf , size_t len ) ;
# endif
# endif
@ -177,22 +176,6 @@ getentropy(void *buf, size_t len)
return ( ret ) ;
return ( ret ) ;
}
}
/*
* Basic sanity checking ; wish we could do better .
*/
static int
gotdata ( char * buf , size_t len )
{
char any_set = 0 ;
size_t i ;
for ( i = 0 ; i < len ; + + i )
any_set | = buf [ i ] ;
if ( any_set = = 0 )
return ( - 1 ) ;
return ( 0 ) ;
}
# if defined(SYS_getrandom) && defined(GRND_NONBLOCK)
# if defined(SYS_getrandom) && defined(GRND_NONBLOCK)
static int
static int
getentropy_getrandom ( void * buf , size_t len )
getentropy_getrandom ( void * buf , size_t len )
@ -261,10 +244,8 @@ start:
i + = ret ;
i + = ret ;
}
}
close ( fd ) ;
close ( fd ) ;
if ( gotdata ( buf , len ) = = 0 ) {
errno = save_errno ;
return ( 0 ) ; /* satisfied */
}
errno = save_errno ;
return ( 0 ) ; /* satisfied */
nodevrandom :
nodevrandom :
errno = EIO ;
errno = EIO ;
return ( - 1 ) ;
return ( - 1 ) ;
@ -292,10 +273,8 @@ getentropy_sysctl(void *buf, size_t len)
goto sysctlfailed ;
goto sysctlfailed ;
i + = chunk ;
i + = chunk ;
}
}
if ( gotdata ( buf , len ) = = 0 ) {
errno = save_errno ;
return ( 0 ) ; /* satisfied */
}
errno = save_errno ;
return ( 0 ) ; /* satisfied */
sysctlfailed :
sysctlfailed :
errno = EIO ;
errno = EIO ;
return ( - 1 ) ;
return ( - 1 ) ;
@ -541,10 +520,6 @@ getentropy_fallback(void *buf, size_t len)
}
}
explicit_bzero ( & ctx , sizeof ctx ) ;
explicit_bzero ( & ctx , sizeof ctx ) ;
explicit_bzero ( results , sizeof results ) ;
explicit_bzero ( results , sizeof results ) ;
if ( gotdata ( buf , len ) = = 0 ) {
errno = save_errno ;
return ( 0 ) ; /* satisfied */
}
errno = EIO ;
return ( - 1 ) ;
errno = save_errno ;
return ( 0 ) ; /* satisfied */
}
}