From c3649a2def02c41d837ae1f79dda729ccb91e677 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Sun, 25 Nov 2012 14:36:20 +0000 Subject: Imported Upstream version 0.3.9 --- src/tspi/tspi_random.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/tspi/tspi_random.c (limited to 'src/tspi/tspi_random.c') diff --git a/src/tspi/tspi_random.c b/src/tspi/tspi_random.c new file mode 100644 index 0000000..9fe8c27 --- /dev/null +++ b/src/tspi/tspi_random.c @@ -0,0 +1,74 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include +#include +#include +#include + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "obj.h" + + +TSS_RESULT +Tspi_TPM_GetRandom(TSS_HTPM hTPM, /* in */ + UINT32 ulRandomDataLength, /* in */ + BYTE ** prgbRandomData) /* out */ +{ + TSS_HCONTEXT tspContext; + TSS_RESULT result; + + if (prgbRandomData == NULL || ulRandomDataLength > 4096) + return TSPERR(TSS_E_BAD_PARAMETER); + + if ((result = obj_tpm_get_tsp_context(hTPM, &tspContext))) + return result; + + if (ulRandomDataLength == 0) + return TSS_SUCCESS; + + if ((result = TCS_API(tspContext)->GetRandom(tspContext, ulRandomDataLength, + prgbRandomData))) + return result; + + if ((result = __tspi_add_mem_entry(tspContext, *prgbRandomData))) { + free(*prgbRandomData); + *prgbRandomData = NULL; + return result; + } + + return TSS_SUCCESS; +} + +TSS_RESULT +Tspi_TPM_StirRandom(TSS_HTPM hTPM, /* in */ + UINT32 ulEntropyDataLength, /* in */ + BYTE * rgbEntropyData) /* in */ +{ + TSS_RESULT result; + TSS_HCONTEXT tspContext; + + if (ulEntropyDataLength > 0 && rgbEntropyData == NULL) + return TSPERR(TSS_E_BAD_PARAMETER); + + if ((result = obj_tpm_get_tsp_context(hTPM, &tspContext))) + return result; + + if ((result = TCS_API(tspContext)->StirRandom(tspContext, ulEntropyDataLength, + rgbEntropyData))) + return result; + + return TSS_SUCCESS; +} -- cgit v1.2.3