diff --git a/src/tpm2/Clock.c b/src/tpm2/Clock.c index f8d86921..37f64533 100644 --- a/src/tpm2/Clock.c +++ b/src/tpm2/Clock.c @@ -95,6 +95,18 @@ ClockGetTime( return time; } +/* ClockAdjustPostResume -- adjust time parameters post resume */ +#include "Tpm.h" +void +ClockAdjustPostResume(UINT64 backthen) +{ + UINT64 now = ClockGetTime(CLOCK_REALTIME); + INT64 timediff = now - backthen; + + g_time += timediff; + s_realTimePrevious += timediff; + s_tpmTime += timediff; +} /* C.3.3. Simulator Functions */ /* C.3.3.1. Introduction */ diff --git a/src/tpm2/NVMarshal.c b/src/tpm2/NVMarshal.c index 68065b87..f077f2ba 100644 --- a/src/tpm2/NVMarshal.c +++ b/src/tpm2/NVMarshal.c @@ -2985,6 +2985,7 @@ VolatileState_Unmarshal(BYTE **buffer, INT32 *size) NV_HEADER hdr; BOOL needs_block; UINT16 array_size = 0; + UINT64 backthen; if (rc == TPM_RC_SUCCESS) { rc = NV_HEADER_Unmarshal(&hdr, buffer, size, @@ -3363,16 +3364,7 @@ skip_hardware_clock: rc = UINT32_Unmarshal(&s_adjustRate, buffer, size); } if (rc == TPM_RC_SUCCESS) { - UINT64 backthen, now; - INT64 timediff; - rc = UINT64_Unmarshal(&backthen, buffer, size); - now = ClockGetTime(CLOCK_REALTIME); - - timediff = now - backthen; - g_time += timediff; - s_realTimePrevious += timediff; - s_tpmTime += timediff; } /* version 2 starts having indicator for next versions that we can skip; @@ -3402,6 +3394,9 @@ skip_future_versions: } } + if (rc == TPM_RC_SUCCESS) { + ClockAdjustPostResume(backthen); + } return rc; } diff --git a/src/tpm2/Platform_fp.h b/src/tpm2/Platform_fp.h index 2f4c21f7..19152f1f 100644 --- a/src/tpm2/Platform_fp.h +++ b/src/tpm2/Platform_fp.h @@ -377,8 +377,9 @@ _plat__GetUnique( unsigned char *b // output buffer ); -/* libtpms: ClockGetTime() needs to be public */ +/* libtpms: */ #include +void ClockAdjustPostResume(UINT64 backthen); uint64_t ClockGetTime(clockid_t clk_id); #endif // _PLATFORM_FP_H_