-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OvmfPkg: Add C runtime apis referenced by Boringssl
BoringSSL is a fork of OpenSSL that is designed to meet Google's needs. As documented at https://boringssl.googlesource.com/boringssl, Boringssl manages Google's patches to openssl and is used in almost all of Google products that rely on OpenSSL. A fork of EDK2 forms the basis for the Uefi code in GCP compute and Google would like to use Boringssl to work with it. As part of that effort, there are many C runtime apis that get referenced and are currently not implemented in EDK2. This change adds those apis to edk2. In particular, this change adds the following : - Stubs for file functions added to CrtWrapper.c. These have been implemented to return -1 rather than 0 since there is no file system support. This will ensure that any calls into these apis will return failure. - Implementation of (strdup : string duplication function) - Implementations of the following apis in CrtUtils.c, which are referenced and used by the Boringssl code : bsearch : binary search getentropy : return entropy of requested length Signed-off-by: Leena Soman <[email protected]>
- Loading branch information
1 parent
c624788
commit bccd226
Showing
6 changed files
with
96 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** @file | ||
C Run-Time Libraries (CRT) Utility apis for BoringSSL-based | ||
Cryptographic Library. | ||
Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR> | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <CrtLibSupport.h> | ||
#include <Uefi/UefiBaseType.h> | ||
#include <Library/RngLib.h> | ||
#include <Library/SafeIntLib.h> | ||
|
||
/* Performs a binary search */ | ||
void * | ||
bsearch ( | ||
const void *key, | ||
const void *base, | ||
size_t nmemb, | ||
size_t size, | ||
int ( *compar )(const void *, const void *) | ||
) | ||
{ | ||
void *Mid; | ||
int Sign; | ||
RETURN_STATUS Status = RETURN_INVALID_PARAMETER; | ||
size_t Result; | ||
|
||
if (!key || !base || !nmemb || !size) { | ||
return NULL; | ||
} | ||
|
||
Status = SafeUintnMult ((UINTN)size, (UINTN)(nmemb/2), (UINTN *)&Result); | ||
|
||
if ((Status == RETURN_BUFFER_TOO_SMALL) || | ||
(Status == RETURN_INVALID_PARAMETER)) | ||
{ | ||
return NULL; | ||
} | ||
|
||
while (nmemb > 0) { | ||
Mid = (char *)base + size * (nmemb/2); | ||
Sign = compar (key, Mid); | ||
if (Sign < 0) { | ||
nmemb /= 2; | ||
} else if (Sign > 0) { | ||
base = (char *)Mid + size; | ||
nmemb -= nmemb/2 + 1; | ||
} else { | ||
return Mid; | ||
} | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
/* Returns entropy of requested length in provided buffer */ | ||
int | ||
getentropy ( | ||
void *buffer, | ||
size_t length | ||
) | ||
{ | ||
UINT8 *EntropyBuffer = (UINT8 *)buffer; | ||
UINTN Index; | ||
UINT64 RandNum; | ||
UINTN CopyLength; | ||
|
||
if (length > GETENTROPY_MAX) { | ||
errno = EIO; | ||
return -1; | ||
} | ||
|
||
if (EntropyBuffer == NULL) { | ||
errno = EFAULT; | ||
return -1; | ||
} | ||
|
||
for (Index = 0; Index < length; Index += sizeof (UINT64)) { | ||
if (!GetRandomNumber64 (&RandNum)) { | ||
errno = ENOSYS; | ||
return -1; | ||
} | ||
|
||
CopyLength = | ||
(length - Index >= sizeof (UINT64)) ? sizeof (UINT64) : (length - Index); | ||
CopyMem (EntropyBuffer + Index, &RandNum, CopyLength); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters