]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Include/OpenSslSupport.h
CryptoPkg: Replace string wrapper functions with safe string functions
[mirror_edk2.git] / CryptoPkg / Include / OpenSslSupport.h
1 /** @file
2 Root include file to support building OpenSSL Crypto Library.
3
4 Copyright (c) 2010 - 2015, 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 MAX_STRING_SIZE 0x1000
25
26 //
27 // File operations are not required for building Open SSL,
28 // so FILE is mapped to VOID * to pass build
29 //
30 typedef VOID *FILE;
31
32 //
33 // Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h
34 //
35 #if !defined(__CC_ARM) // if va_list is not already defined
36 #define va_list VA_LIST
37 #define va_arg VA_ARG
38 #define va_start VA_START
39 #define va_end VA_END
40 #else // __CC_ARM
41 #define va_start(Marker, Parameter) __va_start(Marker, Parameter)
42 #define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)
43 #define va_end(Marker) ((void)0)
44 #endif
45
46 //
47 // #defines from EFI Application Toolkit required to buiild Open SSL
48 //
49 #define ENOMEM 12 /* Cannot allocate memory */
50 #define EINVAL 22 /* Invalid argument */
51 #define BUFSIZ 1024 /* size of buffer used by setbuf */
52 #define INT_MAX 2147483647 /* max value for an int */
53 #define INT_MIN (-2147483647-1) /* min value for an int */
54 #define LONG_MAX 2147483647L /* max value for a long */
55 #define LONG_MIN (-2147483647-1) /* min value for a long */
56 #define ULONG_MAX 0xffffffff /* max value for an unsigned long */
57 #define LOG_DAEMON (3<<3) /* system daemons */
58 #define LOG_EMERG 0 /* system is unusable */
59 #define LOG_ALERT 1 /* action must be taken immediately */
60 #define LOG_CRIT 2 /* critical conditions */
61 #define LOG_ERR 3 /* error conditions */
62 #define LOG_WARNING 4 /* warning conditions */
63 #define LOG_NOTICE 5 /* normal but significant condition */
64 #define LOG_INFO 6 /* informational */
65 #define LOG_DEBUG 7 /* debug-level messages */
66 #define LOG_PID 0x01 /* log the pid with each message */
67 #define LOG_CONS 0x02 /* log on the console if errors in sending */
68
69 //
70 // Macros from EFI Application Toolkit required to buiild Open SSL
71 //
72 /* The offsetof() macro calculates the offset of a structure member
73 in its structure. Unfortunately this cannot be written down
74 portably, hence it is provided by a Standard C header file.
75 For pre-Standard C compilers, here is a version that usually works
76 (but watch out!): */
77 #define offsetof(type, member) OFFSET_OF (type, member)
78
79 //
80 // Basic types from EFI Application Toolkit required to buiild Open SSL
81 //
82 typedef UINTN size_t;
83 typedef INTN ssize_t;
84 typedef INT64 off_t;
85 typedef UINT16 mode_t;
86 typedef long time_t;
87 typedef unsigned long clock_t;
88 typedef UINT32 uid_t;
89 typedef UINT32 gid_t;
90 typedef UINT32 ino_t;
91 typedef UINT32 dev_t;
92 typedef UINT16 nlink_t;
93 typedef int pid_t;
94 typedef void *DIR;
95 typedef void __sighandler_t (int);
96
97 //
98 // Structures from EFI Application Toolkit required to buiild Open SSL
99 //
100 struct tm {
101 int tm_sec; /* seconds after the minute [0-60] */
102 int tm_min; /* minutes after the hour [0-59] */
103 int tm_hour; /* hours since midnight [0-23] */
104 int tm_mday; /* day of the month [1-31] */
105 int tm_mon; /* months since January [0-11] */
106 int tm_year; /* years since 1900 */
107 int tm_wday; /* days since Sunday [0-6] */
108 int tm_yday; /* days since January 1 [0-365] */
109 int tm_isdst; /* Daylight Savings Time flag */
110 long tm_gmtoff; /* offset from CUT in seconds */
111 char *tm_zone; /* timezone abbreviation */
112 };
113
114 struct timeval {
115 long tv_sec; /* time value, in seconds */
116 long tv_usec; /* time value, in microseconds */
117 } timeval;
118
119 struct dirent {
120 UINT32 d_fileno; /* file number of entry */
121 UINT16 d_reclen; /* length of this record */
122 UINT8 d_type; /* file type, see below */
123 UINT8 d_namlen; /* length of string in d_name */
124 char d_name[255 + 1]; /* name must be no longer than this */
125 };
126
127 struct stat {
128 dev_t st_dev; /* inode's device */
129 ino_t st_ino; /* inode's number */
130 mode_t st_mode; /* inode protection mode */
131 nlink_t st_nlink; /* number of hard links */
132 uid_t st_uid; /* user ID of the file's owner */
133 gid_t st_gid; /* group ID of the file's group */
134 dev_t st_rdev; /* device type */
135 time_t st_atime; /* time of last access */
136 long st_atimensec; /* nsec of last access */
137 time_t st_mtime; /* time of last data modification */
138 long st_mtimensec; /* nsec of last data modification */
139 time_t st_ctime; /* time of last file status change */
140 long st_ctimensec; /* nsec of last file status change */
141 off_t st_size; /* file size, in bytes */
142 INT64 st_blocks; /* blocks allocated for file */
143 UINT32 st_blksize; /* optimal blocksize for I/O */
144 UINT32 st_flags; /* user defined flags for file */
145 UINT32 st_gen; /* file generation number */
146 INT32 st_lspare;
147 INT64 st_qspare[2];
148 };
149
150 //
151 // Externs from EFI Application Toolkit required to buiild Open SSL
152 //
153 extern int errno;
154
155 //
156 // Function prototypes from EFI Application Toolkit required to buiild Open SSL
157 //
158 void *malloc (size_t);
159 void *realloc (void *, size_t);
160 void free (void *);
161 int isdigit (int);
162 int isspace (int);
163 int tolower (int);
164 int isupper (int);
165 int isxdigit (int);
166 int isalnum (int);
167 void *memcpy (void *, const void *, size_t);
168 void *memset (void *, int, size_t);
169 void *memchr (const void *, int, size_t);
170 int memcmp (const void *, const void *, size_t);
171 void *memmove (void *, const void *, size_t);
172 int strcmp (const char *, const char *);
173 int strncmp (const char *, const char *, size_t);
174 char *strcpy (char *, const char *);
175 char *strncpy (char *, const char *, size_t);
176 size_t strlen (const char *);
177 char *strcat (char *, const char *);
178 char *strchr (const char *, int);
179 int strcasecmp (const char *, const char *);
180 int strncasecmp (const char *, const char *, size_t);
181 char *strncpy (char *, const char *, size_t);
182 int strncmp (const char *, const char *, size_t);
183 char *strrchr (const char *, int);
184 unsigned long strtoul (const char *, char **, int);
185 long strtol (const char *, char **, int);
186 int printf (const char *, ...);
187 int sscanf (const char *, const char *, ...);
188 int open (const char *, int, ...);
189 int chmod (const char *, mode_t);
190 int stat (const char *, struct stat *);
191 off_t lseek (int, off_t, int);
192 ssize_t read (int, void *, size_t);
193 ssize_t write (int, const void *, size_t);
194 int close (int);
195 FILE *fopen (const char *, const char *);
196 size_t fread (void *, size_t, size_t, FILE *);
197 size_t fwrite (const void *, size_t, size_t, FILE *);
198 char *fgets (char *, int, FILE *);
199 int fputs (const char *, FILE *);
200 int fprintf (FILE *, const char *, ...);
201 int vfprintf (FILE *, const char *, VA_LIST);
202 int fflush (FILE *);
203 int fclose (FILE *);
204 DIR *opendir (const char *);
205 struct dirent *readdir (DIR *);
206 int closedir (DIR *);
207 void openlog (const char *, int, int);
208 void closelog (void);
209 void syslog (int, const char *, ...);
210 time_t time (time_t *);
211 struct tm *localtime (const time_t *);
212 struct tm *gmtime (const time_t *);
213 struct tm *gmtime_r (const time_t *, struct tm *);
214 uid_t getuid (void);
215 uid_t geteuid (void);
216 gid_t getgid (void);
217 gid_t getegid (void);
218 void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
219 char *getenv (const char *);
220 void exit (int);
221 void abort (void);
222 __sighandler_t *signal (int, __sighandler_t *);
223
224 //
225 // Global variables from EFI Application Toolkit required to buiild Open SSL
226 //
227 extern FILE *stderr;
228 extern FILE *stdin;
229 extern FILE *stdout;
230
231 //
232 // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
233 //
234 #define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count))
235 #define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
236 #define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
237 #define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
238 #define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))
239 #define strcmp AsciiStrCmp
240 #define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
241 #define strcpy(strDest,strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)
242 #define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
243 #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
244 #define strcat(strDest,strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)
245 #define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)
246 #define abort() ASSERT (FALSE)
247 #define assert(expression)
248 #define localtime(timer) NULL
249 #define gmtime_r(timer,result) (result = NULL)
250 #define atoi(nptr) AsciiStrDecimalToUintn(nptr)
251
252 #endif