summaryrefslogtreecommitdiffstats
path: root/CryptoPkg/Library/BaseCryptLib/SysCall
diff options
context:
space:
mode:
Diffstat (limited to 'CryptoPkg/Library/BaseCryptLib/SysCall')
-rw-r--r--CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c26
-rw-r--r--CryptoPkg/Library/BaseCryptLib/SysCall/ConstantTimeClock.c11
-rw-r--r--CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c237
-rw-r--r--CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c101
-rw-r--r--CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c56
-rw-r--r--CryptoPkg/Library/BaseCryptLib/SysCall/UnitTestHostCrtWrapper.c67
-rw-r--r--CryptoPkg/Library/BaseCryptLib/SysCall/inet_pton.c369
7 files changed, 552 insertions, 315 deletions
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c b/CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c
index d14644d135..b7bed15c18 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c
@@ -13,21 +13,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Extra header to record the memory buffer size from malloc routine.
//
-#define CRYPTMEM_HEAD_SIGNATURE SIGNATURE_32('c','m','h','d')
+#define CRYPTMEM_HEAD_SIGNATURE SIGNATURE_32('c','m','h','d')
typedef struct {
UINT32 Signature;
UINT32 Reserved;
UINTN Size;
} CRYPTMEM_HEAD;
-#define CRYPTMEM_OVERHEAD sizeof(CRYPTMEM_HEAD)
+#define CRYPTMEM_OVERHEAD sizeof(CRYPTMEM_HEAD)
//
// -- Memory-Allocation Routines --
//
/* Allocates memory blocks */
-void *malloc (size_t size)
+void *
+malloc (
+ size_t size
+ )
{
CRYPTMEM_HEAD *PoolHdr;
UINTN NewSize;
@@ -38,7 +41,7 @@ void *malloc (size_t size)
//
NewSize = (UINTN)(size) + CRYPTMEM_OVERHEAD;
- Data = AllocatePool (NewSize);
+ Data = AllocatePool (NewSize);
if (Data != NULL) {
PoolHdr = (CRYPTMEM_HEAD *)Data;
//
@@ -57,7 +60,11 @@ void *malloc (size_t size)
}
/* Reallocate memory blocks */
-void *realloc (void *ptr, size_t size)
+void *
+realloc (
+ void *ptr,
+ size_t size
+ )
{
CRYPTMEM_HEAD *OldPoolHdr;
CRYPTMEM_HEAD *NewPoolHdr;
@@ -66,9 +73,9 @@ void *realloc (void *ptr, size_t size)
VOID *Data;
NewSize = (UINTN)size + CRYPTMEM_OVERHEAD;
- Data = AllocatePool (NewSize);
+ Data = AllocatePool (NewSize);
if (Data != NULL) {
- NewPoolHdr = (CRYPTMEM_HEAD *)Data;
+ NewPoolHdr = (CRYPTMEM_HEAD *)Data;
NewPoolHdr->Signature = CRYPTMEM_HEAD_SIGNATURE;
NewPoolHdr->Size = size;
if (ptr != NULL) {
@@ -96,7 +103,10 @@ void *realloc (void *ptr, size_t size)
}
/* De-allocates or frees a memory block */
-void free (void *ptr)
+void
+free (
+ void *ptr
+ )
{
CRYPTMEM_HEAD *PoolHdr;
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/ConstantTimeClock.c b/CryptoPkg/Library/BaseCryptLib/SysCall/ConstantTimeClock.c
index 18b04f2afd..2956b92d08 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/ConstantTimeClock.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/ConstantTimeClock.c
@@ -23,15 +23,22 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// -- Time Management Routines --
//
-time_t time (time_t *timer)
+time_t
+time (
+ time_t *timer
+ )
{
if (timer != NULL) {
*timer = 0;
}
+
return 0;
}
-struct tm * gmtime (const time_t *timer)
+struct tm *
+gmtime (
+ const time_t *timer
+ )
{
return NULL;
}
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c b/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
index 42235ab96a..bac477da07 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
@@ -9,7 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <CrtLibSupport.h>
-int errno = 0;
+int errno = 0;
FILE *stderr = NULL;
FILE *stdin = NULL;
@@ -35,15 +35,15 @@ QuickSortWorker (
IN VOID *Buffer
)
{
- VOID *Pivot;
- UINTN LoopCount;
- UINTN NextSwapLocation;
+ VOID *Pivot;
+ UINTN LoopCount;
+ UINTN NextSwapLocation;
- ASSERT(BufferToSort != NULL);
- ASSERT(CompareFunction != NULL);
- ASSERT(Buffer != NULL);
+ ASSERT (BufferToSort != NULL);
+ ASSERT (CompareFunction != NULL);
+ ASSERT (Buffer != NULL);
- if (Count < 2 || ElementSize < 1) {
+ if ((Count < 2) || (ElementSize < 1)) {
return;
}
@@ -58,8 +58,7 @@ QuickSortWorker (
// Now get the pivot such that all on "left" are below it
// and everything "right" are above it
//
- for (LoopCount = 0; LoopCount < Count - 1; LoopCount++)
- {
+ for (LoopCount = 0; LoopCount < Count - 1; LoopCount++) {
//
// If the element is less than the pivot
//
@@ -77,6 +76,7 @@ QuickSortWorker (
NextSwapLocation++;
}
}
+
//
// Swap pivot to its final position (NextSwapLocation)
//
@@ -107,28 +107,37 @@ QuickSortWorker (
return;
}
-//---------------------------------------------------------
+// ---------------------------------------------------------
// Standard C Run-time Library Interface Wrapper
-//---------------------------------------------------------
+// ---------------------------------------------------------
//
// -- String Manipulation Routines --
//
-char *strchr(const char *str, int ch)
+char *
+strchr (
+ const char *str,
+ int ch
+ )
{
return ScanMem8 (str, AsciiStrSize (str), (UINT8)ch);
}
/* Scan a string for the last occurrence of a character */
-char *strrchr (const char *str, int c)
+char *
+strrchr (
+ const char *str,
+ int c
+ )
{
- char * save;
+ char *save;
for (save = NULL; ; ++str) {
if (*str == c) {
save = (char *)str;
}
+
if (*str == 0) {
return (save);
}
@@ -136,19 +145,25 @@ char *strrchr (const char *str, int c)
}
/* Compare first n bytes of string s1 with string s2, ignoring case */
-int strncasecmp (const char *s1, const char *s2, size_t n)
+int
+strncasecmp (
+ const char *s1,
+ const char *s2,
+ size_t n
+ )
{
- int Val;
+ int Val;
- ASSERT(s1 != NULL);
- ASSERT(s2 != NULL);
+ ASSERT (s1 != NULL);
+ ASSERT (s2 != NULL);
if (n != 0) {
do {
- Val = tolower(*s1) - tolower(*s2);
+ Val = tolower (*s1) - tolower (*s2);
if (Val != 0) {
return Val;
}
+
++s1;
++s2;
if (*s1 == '\0') {
@@ -156,11 +171,17 @@ int strncasecmp (const char *s1, const char *s2, size_t n)
}
} while (--n != 0);
}
+
return 0;
}
/* Read formatted data from a string */
-int sscanf (const char *buffer, const char *format, ...)
+int
+sscanf (
+ const char *buffer,
+ const char *format,
+ ...
+ )
{
//
// Null sscanf() function implementation to satisfy the linker, since
@@ -170,14 +191,21 @@ int sscanf (const char *buffer, const char *format, ...)
}
/* Maps errnum to an error-message string */
-char * strerror (int errnum)
+char *
+strerror (
+ int errnum
+ )
{
return NULL;
}
/* Computes the length of the maximum initial segment of the string pointed to by s1
which consists entirely of characters from the string pointed to by s2. */
-size_t strspn (const char *s1 , const char *s2)
+size_t
+strspn (
+ const char *s1,
+ const char *s2
+ )
{
UINT8 Map[32];
UINT32 Index;
@@ -207,11 +235,15 @@ size_t strspn (const char *s1 , const char *s2)
/* Computes the length of the maximum initial segment of the string pointed to by s1
which consists entirely of characters not from the string pointed to by s2. */
-size_t strcspn (const char *s1, const char *s2)
+size_t
+strcspn (
+ const char *s1,
+ const char *s2
+ )
{
- UINT8 Map[32];
- UINT32 Index;
- size_t Count;
+ UINT8 Map[32];
+ UINT32 Index;
+ size_t Count;
for (Index = 0; Index < 32; Index++) {
Map[Index] = 0;
@@ -224,9 +256,9 @@ size_t strcspn (const char *s1, const char *s2)
Map[0] |= 1;
- Count = 0;
+ Count = 0;
while (!(Map[*s1 >> 3] & (1 << (*s1 & 7)))) {
- Count ++;
+ Count++;
s1++;
}
@@ -238,7 +270,10 @@ size_t strcspn (const char *s1, const char *s2)
//
/* Determines if a particular character is a decimal-digit character */
-int isdigit (int c)
+int
+isdigit (
+ int c
+ )
{
//
// <digit> ::= [0-9]
@@ -247,7 +282,10 @@ int isdigit (int c)
}
/* Determine if an integer represents character that is a hex digit */
-int isxdigit (int c)
+int
+isxdigit (
+ int c
+ )
{
//
// <hexdigit> ::= [0-9] | [a-f] | [A-F]
@@ -258,7 +296,10 @@ int isxdigit (int c)
}
/* Determines if a particular character represents a space character */
-int isspace (int c)
+int
+isspace (
+ int c
+ )
{
//
// <space> ::= [ ]
@@ -267,7 +308,10 @@ int isspace (int c)
}
/* Determine if a particular character is an alphanumeric character */
-int isalnum (int c)
+int
+isalnum (
+ int c
+ )
{
//
// <alnum> ::= [0-9] | [a-z] | [A-Z]
@@ -278,7 +322,10 @@ int isalnum (int c)
}
/* Determines if a particular character is in upper case */
-int isupper (int c)
+int
+isupper (
+ int c
+ )
{
//
// <uppercase letter> := [A-Z]
@@ -291,7 +338,12 @@ int isupper (int c)
//
/* Convert strings to a long-integer value */
-long strtol (const char *nptr, char **endptr, int base)
+long
+strtol (
+ const char *nptr,
+ char **endptr,
+ int base
+ )
{
//
// Null strtol() function implementation to satisfy the linker, since there is
@@ -301,7 +353,12 @@ long strtol (const char *nptr, char **endptr, int base)
}
/* Convert strings to an unsigned long-integer value */
-unsigned long strtoul (const char *nptr, char **endptr, int base)
+unsigned long
+strtoul (
+ const char *nptr,
+ char **endptr,
+ int base
+ )
{
//
// Null strtoul() function implementation to satisfy the linker, since there is
@@ -311,11 +368,15 @@ unsigned long strtoul (const char *nptr, char **endptr, int base)
}
/* Convert character to lowercase */
-int tolower (int c)
+int
+tolower (
+ int c
+ )
{
if (('A' <= (c)) && ((c) <= 'Z')) {
return (c - ('A' - 'a'));
}
+
return (c);
}
@@ -324,7 +385,13 @@ int tolower (int c)
//
/* Performs a quick sort */
-void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, const void *))
+void
+qsort (
+ void *base,
+ size_t num,
+ size_t width,
+ int ( *compare )(const void *, const void *)
+ )
{
VOID *Buffer;
@@ -351,7 +418,10 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
//
/* Get a value from the current environment */
-char *getenv (const char *varname)
+char *
+getenv (
+ const char *varname
+ )
{
//
// Null getenv() function implementation to satisfy the linker, since there is
@@ -361,7 +431,10 @@ char *getenv (const char *varname)
}
/* Get a value from the current environment */
-char *secure_getenv (const char *varname)
+char *
+secure_getenv (
+ const char *varname
+ )
{
//
// Null secure_getenv() function implementation to satisfy the linker, since
@@ -378,7 +451,13 @@ char *secure_getenv (const char *varname)
//
/* Write data to a stream */
-size_t fwrite (const void *buffer, size_t size, size_t count, FILE *stream)
+size_t
+fwrite (
+ const void *buffer,
+ size_t size,
+ size_t count,
+ FILE *stream
+ )
{
return 0;
}
@@ -387,12 +466,23 @@ size_t fwrite (const void *buffer, size_t size, size_t count, FILE *stream)
// -- Dummy OpenSSL Support Routines --
//
-int BIO_printf (void *bio, const char *format, ...)
+int
+BIO_printf (
+ void *bio,
+ const char *format,
+ ...
+ )
{
return 0;
}
-int BIO_snprintf(char *buf, size_t n, const char *format, ...)
+int
+BIO_snprintf (
+ char *buf,
+ size_t n,
+ const char *format,
+ ...
+ )
{
return 0;
}
@@ -403,7 +493,7 @@ typedef
VOID
(EFIAPI *NoReturnFuncPtr)(
VOID
- ) __attribute__((__noreturn__));
+ ) __attribute__ ((__noreturn__));
STATIC
VOID
@@ -414,60 +504,95 @@ NopFunction (
{
}
-void abort (void)
+void
+abort (
+ void
+ )
{
- NoReturnFuncPtr NoReturnFunc;
+ NoReturnFuncPtr NoReturnFunc;
- NoReturnFunc = (NoReturnFuncPtr) NopFunction;
+ NoReturnFunc = (NoReturnFuncPtr)NopFunction;
NoReturnFunc ();
}
#else
-void abort (void)
+void
+abort (
+ void
+ )
{
// Do nothing
}
#endif
-int fclose (FILE *f)
+int
+fclose (
+ FILE *f
+ )
{
return 0;
}
-FILE *fopen (const char *c, const char *m)
+FILE *
+fopen (
+ const char *c,
+ const char *m
+ )
{
return NULL;
}
-size_t fread (void *b, size_t c, size_t i, FILE *f)
+size_t
+fread (
+ void *b,
+ size_t c,
+ size_t i,
+ FILE *f
+ )
{
return 0;
}
-uid_t getuid (void)
+uid_t
+getuid (
+ void
+ )
{
return 0;
}
-uid_t geteuid (void)
+uid_t
+geteuid (
+ void
+ )
{
return 0;
}
-gid_t getgid (void)
+gid_t
+getgid (
+ void
+ )
{
return 0;
}
-gid_t getegid (void)
+gid_t
+getegid (
+ void
+ )
{
return 0;
}
-int printf (char const *fmt, ...)
+int
+printf (
+ char const *fmt,
+ ...
+ )
{
return 0;
}
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
index 3e12a0500a..0d2ca604ea 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
@@ -13,42 +13,42 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/MemoryAllocationLib.h>
#include <Guid/EventGroup.h>
-//----------------------------------------------------------------
+// ----------------------------------------------------------------
// Initial version. Needs further optimizations.
-//----------------------------------------------------------------
+// ----------------------------------------------------------------
//
// Definitions for Runtime Memory Operations
//
-#define RT_PAGE_SIZE 0x200
-#define RT_PAGE_MASK 0x1FF
-#define RT_PAGE_SHIFT 9
+#define RT_PAGE_SIZE 0x200
+#define RT_PAGE_MASK 0x1FF
+#define RT_PAGE_SHIFT 9
-#define RT_SIZE_TO_PAGES(a) (((a) >> RT_PAGE_SHIFT) + (((a) & RT_PAGE_MASK) ? 1 : 0))
-#define RT_PAGES_TO_SIZE(a) ((a) << RT_PAGE_SHIFT)
+#define RT_SIZE_TO_PAGES(a) (((a) >> RT_PAGE_SHIFT) + (((a) & RT_PAGE_MASK) ? 1 : 0))
+#define RT_PAGES_TO_SIZE(a) ((a) << RT_PAGE_SHIFT)
//
// Page Flag Definitions
//
-#define RT_PAGE_FREE 0x00000000
-#define RT_PAGE_USED 0x00000001
+#define RT_PAGE_FREE 0x00000000
+#define RT_PAGE_USED 0x00000001
-#define MIN_REQUIRED_BLOCKS 600
+#define MIN_REQUIRED_BLOCKS 600
//
// Memory Page Table
//
typedef struct {
- UINTN StartPageOffset; // Offset of the starting page allocated.
+ UINTN StartPageOffset; // Offset of the starting page allocated.
// Only available for USED pages.
- UINT32 PageFlag; // Page Attributes.
+ UINT32 PageFlag; // Page Attributes.
} RT_MEMORY_PAGE_ENTRY;
typedef struct {
- UINTN PageCount;
- UINTN LastEmptyPageOffset;
- UINT8 *DataAreaBase; // Pointer to data Area.
- RT_MEMORY_PAGE_ENTRY Pages[1]; // Page Table Entries.
+ UINTN PageCount;
+ UINTN LastEmptyPageOffset;
+ UINT8 *DataAreaBase; // Pointer to data Area.
+ RT_MEMORY_PAGE_ENTRY Pages[1]; // Page Table Entries.
} RT_MEMORY_PAGE_TABLE;
//
@@ -59,8 +59,7 @@ RT_MEMORY_PAGE_TABLE *mRTPageTable = NULL;
//
// Event for Runtime Address Conversion.
//
-STATIC EFI_EVENT mVirtualAddressChangeEvent;
-
+STATIC EFI_EVENT mVirtualAddressChangeEvent;
/**
Initializes pre-allocated memory pointed by ScratchBuffer for subsequent
@@ -114,7 +113,6 @@ InitializeScratchMemory (
return EFI_SUCCESS;
}
-
/**
Look-up Free memory Region for object allocation.
@@ -182,6 +180,7 @@ LookupFreeMemRegion (
//
return (UINTN)(-1);
}
+
for (Index = 0; Index < (StartPageIndex - ReqPages); ) {
//
// Check Consecutive ReqPages Pages.
@@ -203,7 +202,8 @@ LookupFreeMemRegion (
// Failed! Skip current adjacent Used pages
//
while ((SubIndex < (StartPageIndex - ReqPages)) &&
- ((mRTPageTable->Pages[SubIndex + Index].PageFlag & RT_PAGE_USED) != 0)) {
+ ((mRTPageTable->Pages[SubIndex + Index].PageFlag & RT_PAGE_USED) != 0))
+ {
SubIndex++;
}
@@ -216,7 +216,6 @@ LookupFreeMemRegion (
return (UINTN)(-1);
}
-
/**
Allocates a buffer at runtime phase.
@@ -274,7 +273,6 @@ RuntimeAllocateMem (
return AllocPtr;
}
-
/**
Frees a buffer that was previously allocated at runtime phase.
@@ -290,19 +288,20 @@ RuntimeFreeMem (
UINTN StartPageIndex;
StartOffset = (UINTN)Buffer - (UINTN)mRTPageTable->DataAreaBase;
- StartPageIndex = RT_SIZE_TO_PAGES (mRTPageTable->Pages[RT_SIZE_TO_PAGES(StartOffset)].StartPageOffset);
+ StartPageIndex = RT_SIZE_TO_PAGES (mRTPageTable->Pages[RT_SIZE_TO_PAGES (StartOffset)].StartPageOffset);
while (StartPageIndex < mRTPageTable->PageCount) {
if (((mRTPageTable->Pages[StartPageIndex].PageFlag & RT_PAGE_USED) != 0) &&
- (mRTPageTable->Pages[StartPageIndex].StartPageOffset == StartOffset)) {
- //
- // Free this page
- //
- mRTPageTable->Pages[StartPageIndex].PageFlag &= ~RT_PAGE_USED;
- mRTPageTable->Pages[StartPageIndex].PageFlag |= RT_PAGE_FREE;
- mRTPageTable->Pages[StartPageIndex].StartPageOffset = 0;
-
- StartPageIndex++;
+ (mRTPageTable->Pages[StartPageIndex].StartPageOffset == StartOffset))
+ {
+ //
+ // Free this page
+ //
+ mRTPageTable->Pages[StartPageIndex].PageFlag &= ~RT_PAGE_USED;
+ mRTPageTable->Pages[StartPageIndex].PageFlag |= RT_PAGE_FREE;
+ mRTPageTable->Pages[StartPageIndex].StartPageOffset = 0;
+
+ StartPageIndex++;
} else {
break;
}
@@ -311,7 +310,6 @@ RuntimeFreeMem (
return;
}
-
/**
Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
@@ -325,18 +323,17 @@ RuntimeFreeMem (
VOID
EFIAPI
RuntimeCryptLibAddressChangeEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
//
// Converts a pointer for runtime memory management to a new virtual address.
//
- EfiConvertPointer (0x0, (VOID **) &mRTPageTable->DataAreaBase);
- EfiConvertPointer (0x0, (VOID **) &mRTPageTable);
+ EfiConvertPointer (0x0, (VOID **)&mRTPageTable->DataAreaBase);
+ EfiConvertPointer (0x0, (VOID **)&mRTPageTable);
}
-
/**
Constructor routine for runtime crypt library instance.
@@ -384,19 +381,25 @@ RuntimeCryptLibConstructor (
return Status;
}
-
//
// -- Memory-Allocation Routines Wrapper for UEFI-OpenSSL Library --
//
/* Allocates memory blocks */
-void *malloc (size_t size)
+void *
+malloc (
+ size_t size
+ )
{
- return RuntimeAllocateMem ((UINTN) size);
+ return RuntimeAllocateMem ((UINTN)size);
}
/* Reallocate memory blocks */
-void *realloc (void *ptr, size_t size)
+void *
+realloc (
+ void *ptr,
+ size_t size
+ )
{
VOID *NewPtr;
UINTN StartOffset;
@@ -415,9 +418,10 @@ void *realloc (void *ptr, size_t size)
PageCount = 0;
while (StartPageIndex < mRTPageTable->PageCount) {
if (((mRTPageTable->Pages[StartPageIndex].PageFlag & RT_PAGE_USED) != 0) &&
- (mRTPageTable->Pages[StartPageIndex].StartPageOffset == StartOffset)) {
- StartPageIndex++;
- PageCount++;
+ (mRTPageTable->Pages[StartPageIndex].StartPageOffset == StartOffset))
+ {
+ StartPageIndex++;
+ PageCount++;
} else {
break;
}
@@ -430,7 +434,7 @@ void *realloc (void *ptr, size_t size)
return ptr;
}
- NewPtr = RuntimeAllocateMem ((UINTN) size);
+ NewPtr = RuntimeAllocateMem ((UINTN)size);
if (NewPtr == NULL) {
return NULL;
}
@@ -443,7 +447,10 @@ void *realloc (void *ptr, size_t size)
}
/* Deallocates or frees a memory block */
-void free (void *ptr)
+void
+free (
+ void *ptr
+ )
{
//
// In Standard C, free() handles a null pointer argument transparently. This
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c b/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
index 027e5a942e..7d28446d4b 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
@@ -15,17 +15,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// -- Time Management Routines --
//
-#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
-#define SECSPERMIN (60)
-#define SECSPERHOUR (60 * 60)
-#define SECSPERDAY (24 * SECSPERHOUR)
+#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
+#define SECSPERMIN (60)
+#define SECSPERHOUR (60 * 60)
+#define SECSPERDAY (24 * SECSPERHOUR)
//
// The arrays give the cumulative number of days up to the first of the
// month number used as the index (1 -> 12) for regular and leap years.
// The value at index 13 is for the whole year.
//
-UINTN CumulativeDays[2][14] = {
+UINTN CumulativeDays[2][14] = {
{
0,
0,
@@ -61,10 +61,13 @@ UINTN CumulativeDays[2][14] = {
};
/* Get the system time as seconds elapsed since midnight, January 1, 1970. */
-//INTN time(
+// INTN time(
// INTN *timer
// )
-time_t time (time_t *timer)
+time_t
+time (
+ time_t *timer
+ )
{
EFI_STATUS Status;
EFI_TIME Time;
@@ -84,7 +87,7 @@ time_t time (time_t *timer)
// UTime should now be set to 00:00:00 on Jan 1 of the current year.
//
for (Year = 1970, CalTime = 0; Year != Time.Year; Year++) {
- CalTime = CalTime + (time_t)(CumulativeDays[IsLeap(Year)][13] * SECSPERDAY);
+ CalTime = CalTime + (time_t)(CumulativeDays[IsLeap (Year)][13] * SECSPERDAY);
}
//
@@ -92,7 +95,7 @@ time_t time (time_t *timer)
//
CalTime = CalTime +
(time_t)((Time.TimeZone != EFI_UNSPECIFIED_TIMEZONE) ? (Time.TimeZone * 60) : 0) +
- (time_t)(CumulativeDays[IsLeap(Time.Year)][Time.Month] * SECSPERDAY) +
+ (time_t)(CumulativeDays[IsLeap (Time.Year)][Time.Month] * SECSPERDAY) +
(time_t)(((Time.Day > 0) ? Time.Day - 1 : 0) * SECSPERDAY) +
(time_t)(Time.Hour * SECSPERHOUR) +
(time_t)(Time.Minute * 60) +
@@ -108,7 +111,10 @@ time_t time (time_t *timer)
//
// Convert a time value from type time_t to struct tm.
//
-struct tm * gmtime (const time_t *timer)
+struct tm *
+gmtime (
+ const time_t *timer
+ )
{
struct tm *GmTime;
UINT16 DayNo;
@@ -127,38 +133,38 @@ struct tm * gmtime (const time_t *timer)
return NULL;
}
- ZeroMem ((VOID *) GmTime, (UINTN) sizeof (struct tm));
+ ZeroMem ((VOID *)GmTime, (UINTN)sizeof (struct tm));
- DayNo = (UINT16) (*timer / SECSPERDAY);
- DayRemainder = (UINT16) (*timer % SECSPERDAY);
+ 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);
+ 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);
+ TotalDays = (UINT16)(IsLeap (Year) ? 366 : 365);
if (DayNo >= TotalDays) {
- DayNo = (UINT16) (DayNo - TotalDays);
+ DayNo = (UINT16)(DayNo - TotalDays);
YearNo++;
} else {
break;
}
}
- GmTime->tm_year = (int) (YearNo + (1970 - 1900));
- GmTime->tm_yday = (int) DayNo;
+ 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]));
+ if (DayNo >= CumulativeDays[IsLeap (Year)][MonthNo]) {
+ DayNo = (UINT16)(DayNo - (UINT16)(CumulativeDays[IsLeap (Year)][MonthNo]));
break;
}
}
- GmTime->tm_mon = (int) MonthNo - 1;
- GmTime->tm_mday = (int) DayNo + 1;
+ GmTime->tm_mon = (int)MonthNo - 1;
+ GmTime->tm_mday = (int)DayNo + 1;
GmTime->tm_isdst = 0;
GmTime->tm_gmtoff = 0;
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/UnitTestHostCrtWrapper.c b/CryptoPkg/Library/BaseCryptLib/SysCall/UnitTestHostCrtWrapper.c
index a9c288e8f2..066d53e4fa 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/UnitTestHostCrtWrapper.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/UnitTestHostCrtWrapper.c
@@ -14,28 +14,38 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/DebugLib.h>
/* Convert character to lowercase */
-int tolower (int c)
+int
+tolower (
+ int c
+ )
{
if (('A' <= (c)) && ((c) <= 'Z')) {
return (c - ('A' - 'a'));
}
+
return (c);
}
/* Compare first n bytes of string s1 with string s2, ignoring case */
-int strncasecmp (const char *s1, const char *s2, size_t n)
+int
+strncasecmp (
+ const char *s1,
+ const char *s2,
+ size_t n
+ )
{
- int Val;
+ int Val;
- ASSERT(s1 != NULL);
- ASSERT(s2 != NULL);
+ ASSERT (s1 != NULL);
+ ASSERT (s2 != NULL);
if (n != 0) {
do {
- Val = tolower(*s1) - tolower(*s2);
+ Val = tolower (*s1) - tolower (*s2);
if (Val != 0) {
return Val;
}
+
++s1;
++s2;
if (*s1 == '\0') {
@@ -43,11 +53,17 @@ int strncasecmp (const char *s1, const char *s2, size_t n)
}
} while (--n != 0);
}
+
return 0;
}
/* Read formatted data from a string */
-int sscanf (const char *buffer, const char *format, ...)
+int
+sscanf (
+ const char *buffer,
+ const char *format,
+ ...
+ )
{
//
// Null sscanf() function implementation to satisfy the linker, since
@@ -60,34 +76,57 @@ int sscanf (const char *buffer, const char *format, ...)
// -- Dummy OpenSSL Support Routines --
//
-int BIO_printf (void *bio, const char *format, ...)
+int
+BIO_printf (
+ void *bio,
+ const char *format,
+ ...
+ )
{
return 0;
}
-int BIO_snprintf(char *buf, size_t n, const char *format, ...)
+int
+BIO_snprintf (
+ char *buf,
+ size_t n,
+ const char *format,
+ ...
+ )
{
return 0;
}
-uid_t getuid (void)
+uid_t
+getuid (
+ void
+ )
{
return 0;
}
-uid_t geteuid (void)
+uid_t
+geteuid (
+ void
+ )
{
return 0;
}
-gid_t getgid (void)
+gid_t
+getgid (
+ void
+ )
{
return 0;
}
-gid_t getegid (void)
+gid_t
+getegid (
+ void
+ )
{
return 0;
}
-int errno = 0;
+int errno = 0;
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/inet_pton.c b/CryptoPkg/Library/BaseCryptLib/SysCall/inet_pton.c
index 32e1ab8690..c61f34e734 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/inet_pton.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/inet_pton.c
@@ -18,28 +18,28 @@
* Portions copyright (c) 1999, 2000
* Intel Corporation.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
- *
+ *
* This product includes software developed by Intel Corporation and
* its contributors.
- *
+ *
* 4. Neither the name of Intel Corporation or its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -51,11 +51,11 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
- *
+ *
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$Id: inet_pton.c,v 1.1.1.1 2003/11/19 01:51:30 kyu3 Exp $";
+#if defined (LIBC_SCCS) && !defined (lint)
+static char rcsid[] = "$Id: inet_pton.c,v 1.1.1.1 2003/11/19 01:51:30 kyu3 Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -72,186 +72,229 @@ static char rcsid[] = "$Id: inet_pton.c,v 1.1.1.1 2003/11/19 01:51:30 kyu3 Exp $
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
-static int inet_pton4 (const char *src, u_char *dst);
-static int inet_pton6 (const char *src, u_char *dst);
+static int
+inet_pton4 (
+ const char *src,
+ u_char *dst
+ );
+
+static int
+inet_pton6 (
+ const char *src,
+ u_char *dst
+ );
/* int
* inet_pton(af, src, dst)
- * convert from presentation format (which usually means ASCII printable)
- * to network format (which is usually some kind of binary format).
+ * convert from presentation format (which usually means ASCII printable)
+ * to network format (which is usually some kind of binary format).
* return:
- * 1 if the address was valid for the specified address family
- * 0 if the address wasn't valid (`dst' is untouched in this case)
- * -1 if some other error occurred (`dst' is untouched in this case, too)
+ * 1 if the address was valid for the specified address family
+ * 0 if the address wasn't valid (`dst' is untouched in this case)
+ * -1 if some other error occurred (`dst' is untouched in this case, too)
* author:
- * Paul Vixie, 1996.
+ * Paul Vixie, 1996.
*/
int
-inet_pton(
- int af,
- const char *src,
- void *dst
- )
+inet_pton (
+ int af,
+ const char *src,
+ void *dst
+ )
{
- switch (af) {
- case AF_INET:
- return (inet_pton4(src, dst));
- case AF_INET6:
- return (inet_pton6(src, dst));
- default:
- errno = EAFNOSUPPORT;
- return (-1);
- }
- /* NOTREACHED */
+ switch (af) {
+ case AF_INET:
+ return (inet_pton4 (src, dst));
+ case AF_INET6:
+ return (inet_pton6 (src, dst));
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+
+ /* NOTREACHED */
}
/* int
* inet_pton4(src, dst)
- * like inet_aton() but without all the hexadecimal and shorthand.
+ * like inet_aton() but without all the hexadecimal and shorthand.
* return:
- * 1 if `src' is a valid dotted quad, else 0.
+ * 1 if `src' is a valid dotted quad, else 0.
* notice:
- * does not touch `dst' unless it's returning 1.
+ * does not touch `dst' unless it's returning 1.
* author:
- * Paul Vixie, 1996.
+ * Paul Vixie, 1996.
*/
static int
-inet_pton4(
- const char *src,
- u_char *dst
- )
+inet_pton4 (
+ const char *src,
+ u_char *dst
+ )
{
- static const char digits[] = "0123456789";
- int saw_digit, octets, ch;
- u_char tmp[NS_INADDRSZ], *tp;
-
- saw_digit = 0;
- octets = 0;
- *(tp = tmp) = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- if ((pch = strchr(digits, ch)) != NULL) {
- u_int new = *tp * 10 + (u_int)(pch - digits);
-
- if (new > 255)
- return (0);
- *tp = (u_char)new;
- if (! saw_digit) {
- if (++octets > 4)
- return (0);
- saw_digit = 1;
- }
- } else if (ch == '.' && saw_digit) {
- if (octets == 4)
- return (0);
- *++tp = 0;
- saw_digit = 0;
- } else
- return (0);
- }
- if (octets < 4)
- return (0);
-
- memcpy(dst, tmp, NS_INADDRSZ);
- return (1);
+ static const char digits[] = "0123456789";
+ int saw_digit, octets, ch;
+ u_char tmp[NS_INADDRSZ], *tp;
+
+ saw_digit = 0;
+ octets = 0;
+ *(tp = tmp) = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr (digits, ch)) != NULL) {
+ u_int new = *tp * 10 + (u_int)(pch - digits);
+
+ if (new > 255) {
+ return (0);
+ }
+
+ *tp = (u_char)new;
+ if (!saw_digit) {
+ if (++octets > 4) {
+ return (0);
+ }
+
+ saw_digit = 1;
+ }
+ } else if ((ch == '.') && saw_digit) {
+ if (octets == 4) {
+ return (0);
+ }
+
+ *++tp = 0;
+ saw_digit = 0;
+ } else {
+ return (0);
+ }
+ }
+
+ if (octets < 4) {
+ return (0);
+ }
+
+ memcpy (dst, tmp, NS_INADDRSZ);
+ return (1);
}
/* int
* inet_pton6(src, dst)
- * convert presentation level address to network order binary form.
+ * convert presentation level address to network order binary form.
* return:
- * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
+ * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
* notice:
- * (1) does not touch `dst' unless it's returning 1.
- * (2) :: in a full address is silently ignored.
+ * (1) does not touch `dst' unless it's returning 1.
+ * (2) :: in a full address is silently ignored.
* credit:
- * inspired by Mark Andrews.
+ * inspired by Mark Andrews.
* author:
- * Paul Vixie, 1996.
+ * Paul Vixie, 1996.
*/
static int
-inet_pton6(
- const char *src,
- u_char *dst
- )
+inet_pton6 (
+ const char *src,
+ u_char *dst
+ )
{
- static const char xdigits_l[] = "0123456789abcdef",
- xdigits_u[] = "0123456789ABCDEF";
- u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
- const char *xdigits, *curtok;
- int ch, saw_xdigit;
- u_int val;
-
- memset((tp = tmp), '\0', NS_IN6ADDRSZ);
- endp = tp + NS_IN6ADDRSZ;
- colonp = NULL;
- /* Leading :: requires some special handling. */
- if (*src == ':')
- if (*++src != ':')
- return (0);
- curtok = src;
- saw_xdigit = 0;
- val = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
- pch = strchr((xdigits = xdigits_u), ch);
- if (pch != NULL) {
- val <<= 4;
- val |= (pch - xdigits);
- if (val > 0xffff)
- return (0);
- saw_xdigit = 1;
- continue;
- }
- if (ch == ':') {
- curtok = src;
- if (!saw_xdigit) {
- if (colonp)
- return (0);
- colonp = tp;
- continue;
- }
- if (tp + NS_INT16SZ > endp)
- return (0);
- *tp++ = (u_char) (val >> 8) & 0xff;
- *tp++ = (u_char) val & 0xff;
- saw_xdigit = 0;
- val = 0;
- continue;
- }
- if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
- inet_pton4(curtok, tp) > 0) {
- tp += NS_INADDRSZ;
- saw_xdigit = 0;
- break; /* '\0' was seen by inet_pton4(). */
- }
- return (0);
- }
- if (saw_xdigit) {
- if (tp + NS_INT16SZ > endp)
- return (0);
- *tp++ = (u_char) (val >> 8) & 0xff;
- *tp++ = (u_char) val & 0xff;
- }
- if (colonp != NULL) {
- /*
- * Since some memmove()'s erroneously fail to handle
- * overlapping regions, we'll do the shift by hand.
- */
- const int n = (int)(tp - colonp);
- int i;
-
- for (i = 1; i <= n; i++) {
- endp[- i] = colonp[n - i];
- colonp[n - i] = 0;
- }
- tp = endp;
- }
- if (tp != endp)
- return (0);
- memcpy(dst, tmp, NS_IN6ADDRSZ);
- return (1);
+ static const char xdigits_l[] = "0123456789abcdef",
+ xdigits_u[] = "0123456789ABCDEF";
+ u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
+ const char *xdigits, *curtok;
+ int ch, saw_xdigit;
+ u_int val;
+
+ memset ((tp = tmp), '\0', NS_IN6ADDRSZ);
+ endp = tp + NS_IN6ADDRSZ;
+ colonp = NULL;
+ /* Leading :: requires some special handling. */
+ if (*src == ':') {
+ if (*++src != ':') {
+ return (0);
+ }
+ }
+
+ curtok = src;
+ saw_xdigit = 0;
+ val = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr ((xdigits = xdigits_l), ch)) == NULL) {
+ pch = strchr ((xdigits = xdigits_u), ch);
+ }
+
+ if (pch != NULL) {
+ val <<= 4;
+ val |= (pch - xdigits);
+ if (val > 0xffff) {
+ return (0);
+ }
+
+ saw_xdigit = 1;
+ continue;
+ }
+
+ if (ch == ':') {
+ curtok = src;
+ if (!saw_xdigit) {
+ if (colonp) {
+ return (0);
+ }
+
+ colonp = tp;
+ continue;
+ }
+
+ if (tp + NS_INT16SZ > endp) {
+ return (0);
+ }
+
+ *tp++ = (u_char)(val >> 8) & 0xff;
+ *tp++ = (u_char)val & 0xff;
+ saw_xdigit = 0;
+ val = 0;
+ continue;
+ }
+
+ if ((ch == '.') && ((tp + NS_INADDRSZ) <= endp) &&
+ (inet_pton4 (curtok, tp) > 0))
+ {
+ tp += NS_INADDRSZ;
+ saw_xdigit = 0;
+ break; /* '\0' was seen by inet_pton4(). */
+ }
+
+ return (0);
+ }
+
+ if (saw_xdigit) {
+ if (tp + NS_INT16SZ > endp) {
+ return (0);
+ }
+
+ *tp++ = (u_char)(val >> 8) & 0xff;
+ *tp++ = (u_char)val & 0xff;
+ }
+
+ if (colonp != NULL) {
+ /*
+ * Since some memmove()'s erroneously fail to handle
+ * overlapping regions, we'll do the shift by hand.
+ */
+ const int n = (int)(tp - colonp);
+ int i;
+
+ for (i = 1; i <= n; i++) {
+ endp[-i] = colonp[n - i];
+ colonp[n - i] = 0;
+ }
+
+ tp = endp;
+ }
+
+ if (tp != endp) {
+ return (0);
+ }
+
+ memcpy (dst, tmp, NS_IN6ADDRSZ);
+ return (1);
}