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