]>
Commit | Line | Data |
---|---|---|
97f98500 HT |
1 | /** @file\r |
2 | Root include file to support building OpenSSL Crypto Library.\r | |
3 | \r | |
1463ce18 | 4 | Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r |
97f98500 HT |
5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #ifndef __OPEN_SSL_SUPPORT_H__\r | |
16 | #define __OPEN_SSL_SUPPORT_H__\r | |
17 | \r | |
18 | #include <Base.h>\r | |
19 | #include <Library/BaseLib.h>\r | |
20 | #include <Library/BaseMemoryLib.h>\r | |
21 | #include <Library/MemoryAllocationLib.h>\r | |
22 | #include <Library/DebugLib.h>\r | |
23 | \r | |
5c4a3795 QL |
24 | #define MAX_STRING_SIZE 0x1000\r |
25 | \r | |
3b21958b DW |
26 | //\r |
27 | // OpenSSL relies on explicit configuration for word size in crypto/bn,\r | |
28 | // but we want it to be automatically inferred from the target. So we\r | |
29 | // bypass what's in <openssl/opensslconf.h> for OPENSSL_SYS_UEFI, and\r | |
30 | // define our own here.\r | |
31 | //\r | |
32 | #ifdef CONFIG_HEADER_BN_H\r | |
33 | #error CONFIG_HEADER_BN_H already defined\r | |
34 | #endif\r | |
35 | \r | |
36 | #define CONFIG_HEADER_BN_H\r | |
37 | \r | |
38 | #if defined(MDE_CPU_X64) || defined(MDE_CPU_AARCH64) || defined(MDE_CPU_IA64)\r | |
39 | //\r | |
40 | // With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs\r | |
41 | // SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is\r | |
42 | // 64-bit. Since using 'long long' works fine on GCC too, just do that.\r | |
43 | //\r | |
44 | #define SIXTY_FOUR_BIT\r | |
45 | #elif defined(MDE_CPU_IA32) || defined(MDE_CPU_ARM) || defined(MDE_CPU_EBC)\r | |
46 | #define THIRTY_TWO_BIT\r | |
47 | #else\r | |
48 | #error Unknown target architecture\r | |
49 | #endif\r | |
50 | \r | |
97f98500 HT |
51 | //\r |
52 | // File operations are not required for building Open SSL, \r | |
53 | // so FILE is mapped to VOID * to pass build\r | |
54 | //\r | |
55 | typedef VOID *FILE;\r | |
56 | \r | |
57 | //\r | |
58 | // Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h\r | |
59 | //\r | |
8e01b449 | 60 | #if !defined(__CC_ARM) // if va_list is not already defined\r |
97f98500 HT |
61 | #define va_list VA_LIST\r |
62 | #define va_arg VA_ARG\r | |
63 | #define va_start VA_START\r | |
64 | #define va_end VA_END\r | |
8e01b449 | 65 | #else // __CC_ARM\r |
66 | #define va_start(Marker, Parameter) __va_start(Marker, Parameter)\r | |
67 | #define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)\r | |
68 | #define va_end(Marker) ((void)0)\r | |
69 | #endif\r | |
70 | \r | |
97f98500 HT |
71 | //\r |
72 | // #defines from EFI Application Toolkit required to buiild Open SSL\r | |
73 | //\r | |
74 | #define ENOMEM 12 /* Cannot allocate memory */\r | |
75 | #define EINVAL 22 /* Invalid argument */\r | |
76 | #define BUFSIZ 1024 /* size of buffer used by setbuf */\r | |
77 | #define INT_MAX 2147483647 /* max value for an int */\r | |
78 | #define INT_MIN (-2147483647-1) /* min value for an int */\r | |
79 | #define LONG_MAX 2147483647L /* max value for a long */\r | |
80 | #define LONG_MIN (-2147483647-1) /* min value for a long */\r | |
81 | #define ULONG_MAX 0xffffffff /* max value for an unsigned long */\r | |
82 | #define LOG_DAEMON (3<<3) /* system daemons */\r | |
83 | #define LOG_EMERG 0 /* system is unusable */\r | |
84 | #define LOG_ALERT 1 /* action must be taken immediately */\r | |
85 | #define LOG_CRIT 2 /* critical conditions */\r | |
86 | #define LOG_ERR 3 /* error conditions */\r | |
87 | #define LOG_WARNING 4 /* warning conditions */\r | |
88 | #define LOG_NOTICE 5 /* normal but significant condition */\r | |
89 | #define LOG_INFO 6 /* informational */\r | |
90 | #define LOG_DEBUG 7 /* debug-level messages */\r | |
91 | #define LOG_PID 0x01 /* log the pid with each message */\r | |
92 | #define LOG_CONS 0x02 /* log on the console if errors in sending */\r | |
93 | \r | |
94 | //\r | |
95 | // Macros from EFI Application Toolkit required to buiild Open SSL\r | |
96 | //\r | |
97 | /* The offsetof() macro calculates the offset of a structure member\r | |
98 | in its structure. Unfortunately this cannot be written down\r | |
99 | portably, hence it is provided by a Standard C header file.\r | |
100 | For pre-Standard C compilers, here is a version that usually works\r | |
101 | (but watch out!): */\r | |
afc18ead | 102 | #define offsetof(type, member) OFFSET_OF (type, member)\r |
97f98500 HT |
103 | \r |
104 | //\r | |
105 | // Basic types from EFI Application Toolkit required to buiild Open SSL\r | |
106 | //\r | |
107 | typedef UINTN size_t;\r | |
108 | typedef INTN ssize_t;\r | |
109 | typedef INT64 off_t;\r | |
110 | typedef UINT16 mode_t;\r | |
111 | typedef long time_t;\r | |
112 | typedef unsigned long clock_t;\r | |
113 | typedef UINT32 uid_t;\r | |
114 | typedef UINT32 gid_t;\r | |
115 | typedef UINT32 ino_t;\r | |
116 | typedef UINT32 dev_t;\r | |
117 | typedef UINT16 nlink_t;\r | |
118 | typedef int pid_t;\r | |
119 | typedef void *DIR;\r | |
120 | typedef void __sighandler_t (int);\r | |
121 | \r | |
122 | //\r | |
123 | // Structures from EFI Application Toolkit required to buiild Open SSL\r | |
124 | //\r | |
125 | struct tm {\r | |
126 | int tm_sec; /* seconds after the minute [0-60] */\r | |
127 | int tm_min; /* minutes after the hour [0-59] */\r | |
128 | int tm_hour; /* hours since midnight [0-23] */\r | |
129 | int tm_mday; /* day of the month [1-31] */\r | |
130 | int tm_mon; /* months since January [0-11] */\r | |
131 | int tm_year; /* years since 1900 */\r | |
132 | int tm_wday; /* days since Sunday [0-6] */\r | |
133 | int tm_yday; /* days since January 1 [0-365] */\r | |
134 | int tm_isdst; /* Daylight Savings Time flag */\r | |
135 | long tm_gmtoff; /* offset from CUT in seconds */\r | |
136 | char *tm_zone; /* timezone abbreviation */\r | |
137 | };\r | |
138 | \r | |
1463ce18 QL |
139 | struct timeval {\r |
140 | long tv_sec; /* time value, in seconds */\r | |
141 | long tv_usec; /* time value, in microseconds */\r | |
142 | } timeval;\r | |
143 | \r | |
97f98500 HT |
144 | struct dirent {\r |
145 | UINT32 d_fileno; /* file number of entry */\r | |
146 | UINT16 d_reclen; /* length of this record */\r | |
147 | UINT8 d_type; /* file type, see below */\r | |
148 | UINT8 d_namlen; /* length of string in d_name */\r | |
149 | char d_name[255 + 1]; /* name must be no longer than this */\r | |
150 | };\r | |
151 | \r | |
152 | struct stat {\r | |
153 | dev_t st_dev; /* inode's device */\r | |
154 | ino_t st_ino; /* inode's number */\r | |
155 | mode_t st_mode; /* inode protection mode */\r | |
156 | nlink_t st_nlink; /* number of hard links */\r | |
157 | uid_t st_uid; /* user ID of the file's owner */\r | |
158 | gid_t st_gid; /* group ID of the file's group */\r | |
159 | dev_t st_rdev; /* device type */\r | |
160 | time_t st_atime; /* time of last access */\r | |
161 | long st_atimensec; /* nsec of last access */\r | |
162 | time_t st_mtime; /* time of last data modification */\r | |
163 | long st_mtimensec; /* nsec of last data modification */\r | |
164 | time_t st_ctime; /* time of last file status change */\r | |
165 | long st_ctimensec; /* nsec of last file status change */\r | |
166 | off_t st_size; /* file size, in bytes */\r | |
167 | INT64 st_blocks; /* blocks allocated for file */\r | |
168 | UINT32 st_blksize; /* optimal blocksize for I/O */\r | |
169 | UINT32 st_flags; /* user defined flags for file */\r | |
170 | UINT32 st_gen; /* file generation number */\r | |
171 | INT32 st_lspare;\r | |
172 | INT64 st_qspare[2];\r | |
173 | };\r | |
174 | \r | |
175 | //\r | |
176 | // Externs from EFI Application Toolkit required to buiild Open SSL\r | |
177 | //\r | |
178 | extern int errno;\r | |
179 | \r | |
180 | //\r | |
181 | // Function prototypes from EFI Application Toolkit required to buiild Open SSL\r | |
182 | //\r | |
183 | void *malloc (size_t);\r | |
184 | void *realloc (void *, size_t);\r | |
185 | void free (void *);\r | |
186 | int isdigit (int);\r | |
187 | int isspace (int);\r | |
188 | int tolower (int);\r | |
189 | int isupper (int);\r | |
190 | int isxdigit (int);\r | |
191 | int isalnum (int);\r | |
192 | void *memcpy (void *, const void *, size_t);\r | |
193 | void *memset (void *, int, size_t);\r | |
194 | void *memchr (const void *, int, size_t);\r | |
195 | int memcmp (const void *, const void *, size_t);\r | |
196 | void *memmove (void *, const void *, size_t);\r | |
197 | int strcmp (const char *, const char *);\r | |
198 | int strncmp (const char *, const char *, size_t);\r | |
199 | char *strcpy (char *, const char *);\r | |
200 | char *strncpy (char *, const char *, size_t);\r | |
201 | size_t strlen (const char *);\r | |
202 | char *strcat (char *, const char *);\r | |
203 | char *strchr (const char *, int);\r | |
204 | int strcasecmp (const char *, const char *);\r | |
205 | int strncasecmp (const char *, const char *, size_t);\r | |
206 | char *strncpy (char *, const char *, size_t);\r | |
207 | int strncmp (const char *, const char *, size_t);\r | |
208 | char *strrchr (const char *, int);\r | |
209 | unsigned long strtoul (const char *, char **, int);\r | |
210 | long strtol (const char *, char **, int);\r | |
211 | int printf (const char *, ...);\r | |
212 | int sscanf (const char *, const char *, ...);\r | |
213 | int open (const char *, int, ...);\r | |
214 | int chmod (const char *, mode_t);\r | |
215 | int stat (const char *, struct stat *);\r | |
216 | off_t lseek (int, off_t, int);\r | |
217 | ssize_t read (int, void *, size_t);\r | |
218 | ssize_t write (int, const void *, size_t);\r | |
219 | int close (int);\r | |
220 | FILE *fopen (const char *, const char *);\r | |
221 | size_t fread (void *, size_t, size_t, FILE *);\r | |
222 | size_t fwrite (const void *, size_t, size_t, FILE *);\r | |
223 | char *fgets (char *, int, FILE *);\r | |
224 | int fputs (const char *, FILE *);\r | |
225 | int fprintf (FILE *, const char *, ...);\r | |
226 | int vfprintf (FILE *, const char *, VA_LIST);\r | |
227 | int fflush (FILE *);\r | |
228 | int fclose (FILE *);\r | |
229 | DIR *opendir (const char *);\r | |
230 | struct dirent *readdir (DIR *);\r | |
231 | int closedir (DIR *);\r | |
232 | void openlog (const char *, int, int);\r | |
233 | void closelog (void);\r | |
234 | void syslog (int, const char *, ...);\r | |
235 | time_t time (time_t *);\r | |
236 | struct tm *localtime (const time_t *);\r | |
237 | struct tm *gmtime (const time_t *);\r | |
238 | struct tm *gmtime_r (const time_t *, struct tm *);\r | |
239 | uid_t getuid (void);\r | |
240 | uid_t geteuid (void);\r | |
241 | gid_t getgid (void);\r | |
242 | gid_t getegid (void);\r | |
243 | void qsort (void *, size_t, size_t, int (*)(const void *, const void *));\r | |
244 | char *getenv (const char *);\r | |
245 | void exit (int);\r | |
246 | void abort (void);\r | |
247 | __sighandler_t *signal (int, __sighandler_t *);\r | |
248 | \r | |
249 | //\r | |
250 | // Global variables from EFI Application Toolkit required to buiild Open SSL\r | |
251 | //\r | |
c61fb9c8 | 252 | extern FILE *stderr;\r |
253 | extern FILE *stdin;\r | |
254 | extern FILE *stdout;\r | |
97f98500 HT |
255 | \r |
256 | //\r | |
257 | // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions\r | |
258 | //\r | |
259 | #define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count))\r | |
260 | #define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))\r | |
261 | #define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)\r | |
262 | #define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))\r | |
4a567c96 | 263 | #define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))\r |
97f98500 HT |
264 | #define strcmp AsciiStrCmp\r |
265 | #define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))\r | |
5c4a3795 QL |
266 | #define strcpy(strDest,strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)\r |
267 | #define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)\r | |
268 | #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))\r | |
269 | #define strcat(strDest,strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)\r | |
97f98500 HT |
270 | #define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)\r |
271 | #define abort() ASSERT (FALSE)\r | |
272 | #define assert(expression)\r | |
273 | #define localtime(timer) NULL\r | |
97f98500 | 274 | #define gmtime_r(timer,result) (result = NULL)\r |
1463ce18 | 275 | #define atoi(nptr) AsciiStrDecimalToUintn(nptr)\r |
97f98500 HT |
276 | \r |
277 | #endif\r |