Debian Codegraph @

Cryptlib/Include/OpenSslSupport.h

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