Commit | Line | Data |
---|---|---|
97f98500 HT |
1 | /** @file\r |
2 | C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based\r | |
3 | Cryptographic Library.\r | |
4 | \r | |
c61fb9c8 | 5 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r |
97f98500 HT |
6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include <OpenSslSupport.h>\r | |
17 | \r | |
8e01b449 | 18 | int errno = 0;\r |
19 | \r | |
c61fb9c8 | 20 | FILE *stderr = NULL;\r |
21 | FILE *stdin = NULL;\r | |
22 | FILE *stdout = NULL;\r | |
23 | \r | |
97f98500 HT |
24 | typedef\r |
25 | INTN\r | |
26 | (*SORT_COMPARE)(\r | |
27 | IN VOID *Buffer1,\r | |
28 | IN VOID *Buffer2\r | |
29 | );\r | |
30 | \r | |
31 | //\r | |
32 | // Duplicated from EDKII BaseSortLib for qsort() wrapper\r | |
33 | //\r | |
34 | STATIC\r | |
35 | VOID\r | |
36 | QuickSortWorker (\r | |
37 | IN OUT VOID *BufferToSort,\r | |
38 | IN CONST UINTN Count,\r | |
39 | IN CONST UINTN ElementSize,\r | |
40 | IN SORT_COMPARE CompareFunction,\r | |
41 | IN VOID *Buffer\r | |
42 | )\r | |
43 | {\r | |
44 | VOID *Pivot;\r | |
45 | UINTN LoopCount;\r | |
46 | UINTN NextSwapLocation;\r | |
47 | \r | |
48 | ASSERT(BufferToSort != NULL);\r | |
49 | ASSERT(CompareFunction != NULL);\r | |
50 | ASSERT(Buffer != NULL);\r | |
51 | \r | |
52 | if (Count < 2 || ElementSize < 1) {\r | |
53 | return;\r | |
54 | }\r | |
55 | \r | |
56 | NextSwapLocation = 0;\r | |
57 | \r | |
58 | //\r | |
59 | // Pick a pivot (we choose last element)\r | |
60 | //\r | |
61 | Pivot = ((UINT8 *)BufferToSort + ((Count - 1) * ElementSize));\r | |
62 | \r | |
63 | //\r | |
64 | // Now get the pivot such that all on "left" are below it\r | |
65 | // and everything "right" are above it\r | |
66 | //\r | |
67 | for (LoopCount = 0; LoopCount < Count - 1; LoopCount++)\r | |
68 | {\r | |
69 | //\r | |
70 | // If the element is less than the pivot\r | |
71 | //\r | |
72 | if (CompareFunction ((VOID *)((UINT8 *)BufferToSort + ((LoopCount) * ElementSize)), Pivot) <= 0) {\r | |
73 | //\r | |
74 | // Swap\r | |
75 | //\r | |
76 | CopyMem (Buffer, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);\r | |
77 | CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), (UINT8 *)BufferToSort + ((LoopCount) * ElementSize), ElementSize);\r | |
78 | CopyMem ((UINT8 *)BufferToSort + ((LoopCount) * ElementSize), Buffer, ElementSize);\r | |
79 | \r | |
80 | //\r | |
81 | // Increment NextSwapLocation\r | |
82 | //\r | |
83 | NextSwapLocation++;\r | |
84 | }\r | |
85 | }\r | |
86 | //\r | |
87 | // Swap pivot to it's final position (NextSwapLocaiton)\r | |
88 | //\r | |
89 | CopyMem (Buffer, Pivot, ElementSize);\r | |
90 | CopyMem (Pivot, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);\r | |
91 | CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), Buffer, ElementSize);\r | |
92 | \r | |
93 | //\r | |
94 | // Now recurse on 2 paritial lists. Neither of these will have the 'pivot' element.\r | |
95 | // IE list is sorted left half, pivot element, sorted right half...\r | |
96 | //\r | |
97 | QuickSortWorker (\r | |
98 | BufferToSort,\r | |
99 | NextSwapLocation,\r | |
100 | ElementSize,\r | |
101 | CompareFunction,\r | |
102 | Buffer\r | |
103 | );\r | |
104 | \r | |
105 | QuickSortWorker (\r | |
106 | (UINT8 *)BufferToSort + (NextSwapLocation + 1) * ElementSize,\r | |
107 | Count - NextSwapLocation - 1,\r | |
108 | ElementSize,\r | |
109 | CompareFunction,\r | |
110 | Buffer\r | |
111 | );\r | |
112 | \r | |
113 | return;\r | |
114 | }\r | |
115 | \r | |
116 | //---------------------------------------------------------\r | |
117 | // Standard C Run-time Library Interface Wrapper\r | |
118 | //---------------------------------------------------------\r | |
119 | \r | |
120 | //\r | |
121 | // -- String Manipulation Routines --\r | |
122 | //\r | |
123 | \r | |
124 | /* Scan a string for the last occurrence of a character */\r | |
125 | char *strrchr (const char *str, int c)\r | |
126 | {\r | |
127 | char * save;\r | |
128 | \r | |
129 | for (save = NULL; ; ++str) {\r | |
130 | if (*str == c) {\r | |
131 | save = (char *)str;\r | |
132 | }\r | |
133 | if (*str == 0) {\r | |
134 | return (save);\r | |
135 | }\r | |
136 | }\r | |
137 | }\r | |
138 | \r | |
139 | /* Read formatted data from a string */\r | |
140 | int sscanf (const char *buffer, const char *format, ...)\r | |
141 | {\r | |
142 | //\r | |
143 | // Null sscanf() function implementation to satisfy the linker, since\r | |
144 | // no direct functionality logic dependency in present UEFI cases.\r | |
145 | //\r | |
146 | return 0;\r | |
147 | }\r | |
148 | \r | |
149 | //\r | |
150 | // -- Character Classification Routines --\r | |
151 | //\r | |
152 | \r | |
153 | /* Determines if a particular character is a decimal-digit character */\r | |
154 | int isdigit (int c)\r | |
155 | {\r | |
156 | //\r | |
157 | // <digit> ::= [0-9]\r | |
158 | //\r | |
159 | return (('0' <= (c)) && ((c) <= '9'));\r | |
160 | }\r | |
161 | \r | |
162 | /* Determine if an integer represents character that is a hex digit */\r | |
163 | int isxdigit (int c)\r | |
164 | {\r | |
165 | //\r | |
166 | // <hexdigit> ::= [0-9] | [a-f] | [A-F]\r | |
167 | //\r | |
168 | return ((('0' <= (c)) && ((c) <= '9')) ||\r | |
169 | (('a' <= (c)) && ((c) <= 'f')) ||\r | |
170 | (('A' <= (c)) && ((c) <= 'F')));\r | |
171 | }\r | |
172 | \r | |
173 | /* Determines if a particular character represents a space character */\r | |
174 | int isspace (int c)\r | |
175 | {\r | |
176 | //\r | |
177 | // <space> ::= [ ]\r | |
178 | //\r | |
179 | return ((c) == ' ');\r | |
180 | }\r | |
181 | \r | |
182 | /* Determine if a particular character is an alphanumeric character */\r | |
183 | int isalnum (int c)\r | |
184 | {\r | |
185 | //\r | |
186 | // <alnum> ::= [0-9] | [a-z] | [A-Z]\r | |
187 | //\r | |
188 | return ((('0' <= (c)) && ((c) <= '9')) ||\r | |
189 | (('a' <= (c)) && ((c) <= 'z')) ||\r | |
190 | (('A' <= (c)) && ((c) <= 'Z')));\r | |
191 | }\r | |
192 | \r | |
193 | /* Determines if a particular character is in upper case */\r | |
194 | int isupper (int c)\r | |
195 | {\r | |
196 | //\r | |
197 | // <uppercase letter> := [A-Z]\r | |
198 | //\r | |
199 | return (('A' <= (c)) && ((c) <= 'Z'));\r | |
200 | }\r | |
201 | \r | |
202 | //\r | |
203 | // -- Data Conversion Routines --\r | |
204 | //\r | |
205 | \r | |
206 | /* Convert strings to a long-integer value */\r | |
207 | long strtol (const char *nptr, char **endptr, int base)\r | |
208 | {\r | |
209 | //\r | |
210 | // Null strtol() function implementation to satisfy the linker, since there is\r | |
211 | // no direct functionality logic dependency in present UEFI cases.\r | |
212 | //\r | |
213 | return 0;\r | |
214 | }\r | |
215 | \r | |
216 | /* Convert strings to an unsigned long-integer value */\r | |
217 | unsigned long strtoul (const char *nptr, char **endptr, int base)\r | |
218 | {\r | |
219 | //\r | |
220 | // Null strtoul() function implementation to satisfy the linker, since there is\r | |
221 | // no direct functionality logic dependency in present UEFI cases.\r | |
222 | //\r | |
223 | return 0;\r | |
224 | }\r | |
225 | \r | |
226 | /* Convert character to lowercase */\r | |
227 | int tolower (int c)\r | |
228 | {\r | |
229 | if (('A' <= (c)) && ((c) <= 'Z')) {\r | |
230 | return (c - ('A' - 'a'));\r | |
231 | }\r | |
232 | return (c);\r | |
233 | }\r | |
234 | \r | |
235 | //\r | |
236 | // -- Searching and Sorting Routines --\r | |
237 | //\r | |
238 | \r | |
239 | /* Performs a quick sort */\r | |
240 | void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, const void *))\r | |
241 | {\r | |
242 | VOID *Buffer;\r | |
243 | \r | |
244 | ASSERT (base != NULL);\r | |
245 | ASSERT (compare != NULL);\r | |
246 | \r | |
247 | Buffer = AllocatePool (width);\r | |
248 | ASSERT (Buffer != NULL);\r | |
249 | \r | |
250 | //\r | |
251 | // Re-use PerformQuickSort() function Implementation in EDKII BaseSortLib.\r | |
252 | //\r | |
253 | QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);\r | |
254 | \r | |
255 | FreePool (Buffer);\r | |
256 | return;\r | |
257 | }\r | |
258 | \r | |
259 | //\r | |
260 | // -- Process and Environment Control Routines --\r | |
261 | //\r | |
262 | \r | |
263 | /* Get a value from the current environment */\r | |
264 | char *getenv (const char *varname)\r | |
265 | {\r | |
266 | //\r | |
267 | // Null getenv() function implementation to satisfy the linker, since there is\r | |
268 | // no direct functionality logic dependency in present UEFI cases.\r | |
269 | //\r | |
270 | return NULL;\r | |
271 | }\r | |
272 | \r | |
273 | //\r | |
274 | // -- Stream I/O Routines --\r | |
275 | //\r | |
276 | \r | |
277 | /* Write formatted output using a pointer to a list of arguments */\r | |
278 | int vfprintf (FILE *stream, const char *format, VA_LIST arg)\r | |
279 | {\r | |
280 | return 0;\r | |
281 | }\r | |
282 | \r | |
283 | /* Write data to a stream */\r | |
284 | size_t fwrite (const void *buffer, size_t size, size_t count, FILE *stream)\r | |
285 | {\r | |
286 | return 0;\r | |
287 | }\r | |
f754e613 | 288 | \r |
289 | //\r | |
290 | // -- Dummy OpenSSL Support Routines --\r | |
291 | //\r | |
292 | \r | |
293 | int BIO_printf (void *bio, const char *format, ...)\r | |
294 | {\r | |
295 | return 0;\r | |
296 | }\r | |
297 | \r | |
298 | int BIO_snprintf(char *buf, size_t n, const char *format, ...)\r | |
299 | {\r | |
300 | return 0;\r | |
301 | }\r | |
4a567c96 | 302 | \r |
303 | void *UI_OpenSSL(void)\r | |
304 | {\r | |
305 | return NULL;\r | |
306 | }\r | |
8e01b449 | 307 | \r |
308 | int X509_load_cert_file (VOID *ctx, const char *file, int type)\r | |
309 | {\r | |
310 | return 0;\r | |
311 | }\r | |
312 | \r | |
313 | int X509_load_crl_file (VOID *ctx, const char *file, int type)\r | |
314 | {\r | |
315 | return 0;\r | |
316 | }\r | |
317 | \r | |
318 | int chmod (const char *c, mode_t m)\r | |
319 | {\r | |
320 | return -1;\r | |
321 | }\r | |
322 | \r | |
323 | int close (int f)\r | |
324 | {\r | |
325 | return -1;\r | |
326 | }\r | |
327 | \r | |
328 | void closelog (void)\r | |
329 | {\r | |
330 | \r | |
331 | }\r | |
332 | \r | |
f114914b | 333 | #ifdef __GNUC__\r |
334 | \r | |
335 | typedef\r | |
336 | VOID\r | |
337 | (EFIAPI *NoReturnFuncPtr)(\r | |
338 | VOID\r | |
339 | ) __attribute__((__noreturn__));\r | |
340 | \r | |
341 | \r | |
342 | STATIC\r | |
343 | VOID\r | |
344 | EFIAPI\r | |
345 | NopFunction (\r | |
346 | VOID\r | |
347 | )\r | |
348 | {\r | |
349 | }\r | |
350 | \r | |
351 | \r | |
8e01b449 | 352 | void exit (int e)\r |
353 | {\r | |
f114914b | 354 | NoReturnFuncPtr NoReturnFunc;\r |
355 | \r | |
356 | NoReturnFunc = (NoReturnFuncPtr) NopFunction;\r | |
8e01b449 | 357 | \r |
f114914b | 358 | NoReturnFunc ();\r |
8e01b449 | 359 | }\r |
360 | \r | |
f114914b | 361 | #else\r |
362 | \r | |
363 | void exit (int e)\r | |
364 | {\r | |
365 | }\r | |
366 | \r | |
367 | #endif\r | |
368 | \r | |
8e01b449 | 369 | int fclose (FILE *f)\r |
370 | {\r | |
371 | return 0;\r | |
372 | }\r | |
373 | \r | |
374 | FILE *fopen (const char *c, const char *m)\r | |
375 | {\r | |
376 | return NULL;\r | |
377 | }\r | |
378 | \r | |
379 | size_t fread (void *b, size_t c, size_t i, FILE *f)\r | |
380 | {\r | |
381 | return 0;\r | |
382 | }\r | |
383 | \r | |
384 | int fprintf (FILE *f, const char *s, ...)\r | |
385 | {\r | |
386 | return 0;\r | |
387 | }\r | |
388 | \r | |
389 | uid_t getuid (void)\r | |
390 | {\r | |
391 | return 0;\r | |
392 | }\r | |
393 | \r | |
394 | uid_t geteuid (void)\r | |
395 | {\r | |
396 | return 0;\r | |
397 | }\r | |
398 | \r | |
399 | gid_t getgid (void)\r | |
400 | {\r | |
401 | return 0;\r | |
402 | }\r | |
403 | \r | |
404 | gid_t getegid (void)\r | |
405 | {\r | |
406 | return 0;\r | |
407 | }\r | |
408 | \r | |
409 | off_t lseek (int a, off_t o, int d)\r | |
410 | {\r | |
411 | return 0;\r | |
412 | }\r | |
413 | \r | |
414 | void openlog (const char *c, int a, int b)\r | |
415 | {\r | |
416 | \r | |
417 | }\r | |
418 | \r | |
419 | ssize_t read (int f, void *b, size_t c)\r | |
420 | {\r | |
421 | return 0;\r | |
422 | }\r | |
423 | \r | |
424 | int stat (const char *c, struct stat *s)\r | |
425 | {\r | |
426 | return -1;\r | |
427 | }\r | |
428 | \r | |
429 | int strcasecmp (const char *c, const char *s)\r | |
430 | {\r | |
431 | return 0;\r | |
432 | }\r | |
433 | \r | |
434 | int strncasecmp (const char *c, const char *s, size_t l)\r | |
435 | {\r | |
436 | return 0;\r | |
437 | }\r | |
438 | \r | |
439 | void syslog (int a, const char *c, ...)\r | |
440 | {\r | |
441 | \r | |
442 | }\r | |
443 | \r | |
444 | ssize_t write (int f, const void *b, size_t l)\r | |
445 | {\r | |
446 | return 0;\r | |
447 | }\r |