Allow disabling DRBG with KCAPI. Add KCAPI /dev/hwrng support.

This commit is contained in:
David Garske
2022-03-17 14:42:23 -07:00
parent 5fe6f1c875
commit 1b0e5f4806
3 changed files with 34 additions and 4 deletions

View File

@ -3888,8 +3888,8 @@ if test "x$ENABLED_HASHDRBG" = "xyes"
then
AM_CFLAGS="$AM_CFLAGS -DHAVE_HASHDRBG"
else
# turn on Hash DRBG if FIPS is on
if test "x$ENABLED_FIPS" = "xyes"
# turn on Hash DRBG if FIPS is on (don't force on for KCAPI)
if test "x$ENABLED_FIPS" = "xyes" && test "x$ENABLED_KCAPI" = "xno"
then
AM_CFLAGS="$AM_CFLAGS -DHAVE_HASHDRBG"
ENABLED_HASHDRBG=yes

View File

@ -2786,8 +2786,33 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
return 0;
}
#endif
/* End wc_GenerateSeed */
#if defined(CUSTOM_RAND_GENERATE_BLOCK) && defined(WOLFSSL_KCAPI)
#include <fcntl.h>
int wc_hwrng_generate_block(byte *output, word32 sz)
{
int fd;
int len;
int ret = 0;
fd = open("/dev/hwrng", O_RDONLY);
if (fd == -1)
return OPEN_RAN_E;
while(sz)
{
len = (int)read(fd, output, sz);
if (len == -1)
{
ret = READ_RAN_E;
break;
}
sz -= len;
output += len;
}
close(fd);
return ret;
}
#endif
#endif /* WC_NO_RNG */
#endif /* HAVE_FIPS */

View File

@ -99,6 +99,11 @@
* #define CUSTOM_RAND_GENERATE_BLOCK myRngFunc
* extern int myRngFunc(byte* output, word32 sz);
*/
#if defined(CUSTOM_RAND_GENERATE_BLOCK) && defined(WOLFSSL_KCAPI)
#undef CUSTOM_RAND_GENERATE_BLOCK
#define CUSTOM_RAND_GENERATE_BLOCK wc_hwrng_generate_block
WOLFSSL_LOCAL int wc_hwrng_generate_block(byte *output, word32 sz);
#endif
#elif defined(HAVE_HASHDRBG)
#ifdef NO_SHA256
#error "Hash DRBG requires SHA-256."