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