From 1ad2f2670440e3d5ca9f78a36992d7ffe54e56da Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Tue, 31 Oct 2017 20:29:18 -0400 Subject: [PATCH] tpm2: Create real random numbers to get different keys Do not use rand() for creating random numbers since this only creates pseudo random numbers and the keys always end up being the same since it wasn't seeded, either. Signed-off-by: Stefan Berger --- src/tpm2/Entropy.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tpm2/Entropy.c b/src/tpm2/Entropy.c index 3dc54be..4590836 100644 --- a/src/tpm2/Entropy.c +++ b/src/tpm2/Entropy.c @@ -3,7 +3,7 @@ /* */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: Entropy.c 809 2016-11-16 18:31:54Z kgoldman $ */ +/* $Id: Entropy.c 1091 2017-10-31 20:31:59Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -55,7 +55,7 @@ /* arising in any way out of use or reliance upon this specification or any */ /* information herein. */ /* */ -/* (c) Copyright IBM Corp. and others, 2016 */ +/* (c) Copyright IBM Corp. and others, 2016, 2017 */ /* */ /********************************************************************************/ @@ -64,6 +64,9 @@ #define _CRT_RAND_S #include #include + +#include + #include "PlatformData.h" #include "Platform_fp.h" /* C.4.2. Local values */ @@ -98,7 +101,9 @@ _plat__GetEntropy( } // Only provide entropy 32 bits at a time to test the ability // of the caller to deal with partial results. - rndNum = rand(); + /* rndNum = rand(); kgold rand() is not random */ + RAND_bytes((unsigned char *)&rndNum, sizeof(uint32_t)); /* kgold */ + if(firstValue) firstValue = 0; else -- 2.39.5