35 const time_t theTime = time( NULL );
37 if( ( theTime == ( time_t ) -1 ) || ( theTime <=
MIN_TIME_VALUE ) )
48 const time_t theTime = time( NULL );
50 if( ( theTime == ( time_t ) -1 ) || ( theTime <=
MIN_TIME_VALUE ) )
78 &msgData, CRYPT_IATTRIBUTE_TIME );
85 CRYPT_IATTRIBUTE_TIME );
90 DEBUG_DIAG((
"Error: No time source available" ));
157 DEBUG_DIAG((
"time_t underflow/overflow has occurred" ));
166 timerInfo->origTimeout = timerInfo->timeRemaining = 0;
171 const time_t currentTime )
179 if( !sanityCheck( timerInfo ) )
181 handleTimeOutOfBounds( timerInfo );
188 if( currentTime < timerInfo->endTime - timerInfo->timeRemaining )
189 needsCorrection =
TRUE;
207 if( currentTime > timerInfo->endTime )
209 const time_t delta = currentTime - timerInfo->endTime;
211 if( ( delta < 0 || delta > ( 30 * 60 ) ) && \
212 timerInfo->origTimeout < delta )
213 needsCorrection =
TRUE;
216 if( !needsCorrection )
221 if( currentTime >= (
MAX_INTLENGTH - timerInfo->timeRemaining ) )
223 DEBUG_DIAG((
"Invalid monoTimer time correction period" ));
225 handleTimeOutOfBounds( timerInfo );
228 timerInfo->endTime = currentTime + timerInfo->timeRemaining;
229 if( timerInfo->endTime < currentTime || \
230 timerInfo->endTime < currentTime +
max( timerInfo->timeRemaining,
231 timerInfo->origTimeout ) )
235 handleTimeOutOfBounds( timerInfo );
256 DEBUG_DIAG((
"Invalid monoTimer time period" ));
258 handleTimeOutOfBounds( timerInfo );
261 timerInfo->endTime = currentTime +
duration;
262 timerInfo->timeRemaining = timerInfo->origTimeout =
duration;
263 initOK = correctMonoTimer( timerInfo, currentTime );
271 IN_INT const int duration )
280 if( !correctMonoTimer( timerInfo, currentTime ) )
285 if( timerInfo->origTimeout >= (
MAX_INTLENGTH - duration ) || \
287 timerInfo->endTime < currentTime )
289 DEBUG_DIAG((
"Invalid monoTimer time period extension" ));
291 handleTimeOutOfBounds( timerInfo );
296 timerInfo->timeRemaining = timerInfo->endTime - currentTime;
299 ( void ) correctMonoTimer( timerInfo, currentTime );
307 time_t timeRemaining;
314 if( timerInfo->timeRemaining <= 0 )
318 if( !correctMonoTimer( timerInfo, currentTime ) )
322 if( timerInfo->endTime < currentTime )
324 DEBUG_DIAG((
"Invalid monoTimer expiry time period" ));
326 handleTimeOutOfBounds( timerInfo );
329 timeRemaining = timerInfo->endTime - currentTime;
330 if( timeRemaining > timerInfo->timeRemaining )
332 handleTimeOutOfBounds( timerInfo );
335 timerInfo->timeRemaining = timeRemaining;
336 return( ( timerInfo->timeRemaining < timeLeft ) ?
TRUE :
FALSE );
342 return( checkMonoTimerExpiryImminent( timerInfo, 0 ) );