]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Include/OpenSslSupport.h
CryptoPkg: Fix OpenSSL BN wordsize and OPENSSL_SYS_UEFI handling
[mirror_edk2.git] / CryptoPkg / Include / OpenSslSupport.h
index 33eda7dd50e1457c58bf8fb0be59b897a276e485..64bef42d0595c33f281834d6f9489116cc9c68d1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Root include file to support building OpenSSL Crypto Library.\r
 \r
-Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -21,6 +21,33 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/DebugLib.h>\r
 \r
+#define MAX_STRING_SIZE  0x1000\r
+\r
+//\r
+// OpenSSL relies on explicit configuration for word size in crypto/bn,\r
+// but we want it to be automatically inferred from the target. So we\r
+// bypass what's in <openssl/opensslconf.h> for OPENSSL_SYS_UEFI, and\r
+// define our own here.\r
+//\r
+#ifdef CONFIG_HEADER_BN_H\r
+#error CONFIG_HEADER_BN_H already defined\r
+#endif\r
+\r
+#define CONFIG_HEADER_BN_H\r
+\r
+#if defined(MDE_CPU_X64) || defined(MDE_CPU_AARCH64) || defined(MDE_CPU_IA64)\r
+//\r
+// With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs\r
+// SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is\r
+// 64-bit. Since using 'long long' works fine on GCC too, just do that.\r
+//\r
+#define SIXTY_FOUR_BIT\r
+#elif defined(MDE_CPU_IA32) || defined(MDE_CPU_ARM) || defined(MDE_CPU_EBC)\r
+#define THIRTY_TWO_BIT\r
+#else\r
+#error Unknown target architecture\r
+#endif\r
+\r
 //\r
 // File operations are not required for building Open SSL, \r
 // so FILE is mapped to VOID * to pass build\r
@@ -72,7 +99,7 @@ typedef VOID  *FILE;
    portably, hence it is provided by a Standard C header file.\r
    For pre-Standard C compilers, here is a version that usually works\r
    (but watch out!): */\r
-#define offsetof(type, member) ( (int) & ((type*)0) -> member )\r
+#define offsetof(type, member) OFFSET_OF (type, member)\r
 \r
 //\r
 // Basic types from EFI Application Toolkit required to buiild Open SSL\r
@@ -109,6 +136,11 @@ struct tm {
   char  *tm_zone;   /* timezone abbreviation */\r
 };\r
 \r
+struct timeval {\r
+  long tv_sec;      /* time value, in seconds */\r
+  long tv_usec;     /* time value, in microseconds */\r
+} timeval;\r
+\r
 struct dirent {\r
   UINT32  d_fileno;         /* file number of entry */\r
   UINT16  d_reclen;         /* length of this record */\r
@@ -231,14 +263,15 @@ extern FILE  *stdout;
 #define memmove(dest,source,count)        CopyMem(dest,source,(UINTN)(count))\r
 #define strcmp                            AsciiStrCmp\r
 #define strncmp(string1,string2,count)    (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))\r
-#define strcpy(strDest,strSource)         AsciiStrCpy(strDest,strSource)\r
-#define strncpy(strDest,strSource,count)  AsciiStrnCpy(strDest,strSource,(UINTN)count)\r
-#define strlen(str)                       (size_t)(AsciiStrLen(str))\r
-#define strcat(strDest,strSource)         AsciiStrCat(strDest,strSource)\r
+#define strcpy(strDest,strSource)         AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)\r
+#define strncpy(strDest,strSource,count)  AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)\r
+#define strlen(str)                       (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))\r
+#define strcat(strDest,strSource)         AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)\r
 #define strchr(str,ch)                    ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)\r
 #define abort()                           ASSERT (FALSE)\r
 #define assert(expression)\r
 #define localtime(timer)                  NULL\r
 #define gmtime_r(timer,result)            (result = NULL)\r
+#define atoi(nptr)                        AsciiStrDecimalToUintn(nptr)\r
 \r
 #endif\r