summaryrefslogtreecommitdiff
path: root/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
diff options
context:
space:
mode:
authortye1 <tye1@6f19259b-4bc3-4df7-8a09-765794883524>2011-08-16 06:46:52 +0000
committertye1 <tye1@6f19259b-4bc3-4df7-8a09-765794883524>2011-08-16 06:46:52 +0000
commitb7d320f8117ed2fffe001b1a0b7bfcd4f40fafc4 (patch)
treeb4967c39538de2ea2b7849d6353917027c9feb4a /CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
parent2f3f1a64ed373954e29ebd06ece5068259800e11 (diff)
downloadedk2-platforms-b7d320f8117ed2fffe001b1a0b7bfcd4f40fafc4.tar.xz
Add new interfaces to support PKCS7#7 signed data and authenticode signature. Update Cryptest to validate functionality of new interfaces.
Signed-off-by: tye1 Reviewed-by: hhuan13 Reviewed-by: qlong git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12142 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c')
-rw-r--r--CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c65
1 files changed, 64 insertions, 1 deletions
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c b/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
index 20928e1595..805e6b4e20 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
@@ -2,7 +2,7 @@
C Run-Time Libraries (CRT) Time Management Routines Wrapper Implementation
for OpenSSL-based Cryptographic Library (used in DXE & RUNTIME).
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -22,6 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
+#define SECSPERMIN (60)
#define SECSPERHOUR (60 * 60)
#define SECSPERDAY (24 * SECSPERHOUR)
@@ -100,3 +101,65 @@ time_t time (time_t *timer)
return *timer;
}
+
+//
+// Convert a time value from type time_t to struct tm.
+//
+struct tm * gmtime (const time_t *timer)
+{
+ struct tm *GmTime;
+ UINT16 DayNo;
+ UINT16 DayRemainder;
+ time_t Year;
+ time_t YearNo;
+ UINT16 TotalDays;
+ UINT16 MonthNo;
+
+ if (timer == NULL) {
+ return NULL;
+ }
+
+ GmTime = malloc (sizeof (struct tm));
+ if (GmTime == NULL) {
+ return NULL;
+ }
+
+ ZeroMem ((VOID *) GmTime, (UINTN) sizeof (struct tm));
+
+ DayNo = (UINT16) (*timer / SECSPERDAY);
+ DayRemainder = (UINT16) (*timer % SECSPERDAY);
+
+ GmTime->tm_sec = (int) (DayRemainder % SECSPERMIN);
+ GmTime->tm_min = (int) ((DayRemainder % SECSPERHOUR) / SECSPERMIN);
+ GmTime->tm_hour = (int) (DayRemainder / SECSPERHOUR);
+ GmTime->tm_wday = (int) ((DayNo + 4) % 7);
+
+ for (Year = 1970, YearNo = 0; DayNo > 0; Year++) {
+ TotalDays = (UINT16) (IsLeap (Year) ? 366 : 365);
+ if (DayNo >= TotalDays) {
+ DayNo = (UINT16) (DayNo - TotalDays);
+ YearNo++;
+ } else {
+ break;
+ }
+ }
+
+ GmTime->tm_year = (int) (YearNo + (1970 - 1900));
+ GmTime->tm_yday = (int) DayNo;
+
+ for (MonthNo = 12; MonthNo > 1; MonthNo--) {
+ if (DayNo > CumulativeDays[IsLeap(Year)][MonthNo]) {
+ DayNo = (UINT16) (DayNo - (UINT16) (CumulativeDays[IsLeap(Year)][MonthNo]));
+ break;
+ }
+ }
+
+ GmTime->tm_mon = (int) MonthNo;
+ GmTime->tm_mday = (int) DayNo;
+
+ GmTime->tm_isdst = 0;
+ GmTime->tm_gmtoff = 0;
+ GmTime->tm_zone = NULL;
+
+ return GmTime;
+}