summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/PasswordCrypt.h27
-rw-r--r--include/crypt_blowfish.h22
-rw-r--r--include/hexdump.h104
-rw-r--r--include/httpboot.h41
-rw-r--r--include/netboot.h9
-rw-r--r--include/replacements.h50
-rw-r--r--include/tpm.h188
-rw-r--r--include/ucs2.h139
8 files changed, 580 insertions, 0 deletions
diff --git a/include/PasswordCrypt.h b/include/PasswordCrypt.h
new file mode 100644
index 00000000..b726f320
--- /dev/null
+++ b/include/PasswordCrypt.h
@@ -0,0 +1,27 @@
+#ifndef __PASSWORD_CRYPT_H__
+#define __PASSWORD_CRYPT_H__
+
+enum HashMethod {
+ TRADITIONAL_DES = 0,
+ EXTEND_BSDI_DES,
+ MD5_BASED,
+ SHA256_BASED,
+ SHA512_BASED,
+ BLOWFISH_BASED
+};
+
+typedef struct {
+ UINT16 method;
+ UINT64 iter_count;
+ UINT16 salt_size;
+ UINT8 salt[32];
+ UINT8 hash[128];
+} __attribute__ ((packed)) PASSWORD_CRYPT;
+
+#define PASSWORD_CRYPT_SIZE sizeof(PASSWORD_CRYPT)
+
+EFI_STATUS password_crypt (const char *password, UINT32 pw_length,
+ const PASSWORD_CRYPT *pw_hash, UINT8 *hash);
+UINT16 get_hash_size (const UINT16 method);
+
+#endif /* __PASSWORD_CRYPT_H__ */
diff --git a/include/crypt_blowfish.h b/include/crypt_blowfish.h
new file mode 100644
index 00000000..dc3bd567
--- /dev/null
+++ b/include/crypt_blowfish.h
@@ -0,0 +1,22 @@
+/*
+ * Written by Solar Designer <solar at openwall.com> in 2000-2011.
+ * No copyright is claimed, and the software is hereby placed in the public
+ * domain. In case this attempt to disclaim copyright and place the software
+ * in the public domain is deemed null and void, then the software is
+ * Copyright (c) 2000-2011 Solar Designer and it is hereby released to the
+ * general public under the following terms:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted.
+ *
+ * There's ABSOLUTELY NO WARRANTY, express or implied.
+ *
+ * See crypt_blowfish.c for more information.
+ */
+
+#ifndef _CRYPT_BLOWFISH_H
+#define _CRYPT_BLOWFISH_H
+
+char *crypt_blowfish_rn(const char *key, const char *setting,
+ char *output, int size);
+#endif
diff --git a/include/hexdump.h b/include/hexdump.h
new file mode 100644
index 00000000..d5ece4dd
--- /dev/null
+++ b/include/hexdump.h
@@ -0,0 +1,104 @@
+#ifndef STATIC_HEXDUMP_H
+#define STATIC_HEXDUMP_H
+
+static int
+__attribute__((__unused__))
+isprint(char c)
+{
+ if (c < 0x20)
+ return 0;
+ if (c > 0x7e)
+ return 0;
+ return 1;
+}
+
+static UINTN
+__attribute__((__unused__))
+format_hex(UINT8 *data, UINTN size, CHAR16 *buf)
+{
+ UINTN sz = (UINTN)data % 16;
+ CHAR16 hexchars[] = L"0123456789abcdef";
+ int offset = 0;
+ UINTN i;
+ UINTN j;
+
+ for (i = 0; i < sz; i++) {
+ buf[offset++] = L' ';
+ buf[offset++] = L' ';
+ buf[offset++] = L' ';
+ if (i == 7)
+ buf[offset++] = L' ';
+ }
+ for (j = sz; j < 16 && j < size; j++) {
+ UINT8 d = data[j-sz];
+ buf[offset++] = hexchars[(d & 0xf0) >> 4];
+ buf[offset++] = hexchars[(d & 0x0f)];
+ if (j != 15)
+ buf[offset++] = L' ';
+ if (j == 7)
+ buf[offset++] = L' ';
+ }
+ for (i = j; i < 16; i++) {
+ buf[offset++] = L' ';
+ buf[offset++] = L' ';
+ if (i != 15)
+ buf[offset++] = L' ';
+ if (i == 7)
+ buf[offset++] = L' ';
+ }
+ buf[offset] = L'\0';
+ return j - sz;
+}
+
+static void
+__attribute__((__unused__))
+format_text(UINT8 *data, UINTN size, CHAR16 *buf)
+{
+ UINTN sz = (UINTN)data % 16;
+ int offset = 0;
+ UINTN i;
+ UINTN j;
+
+ for (i = 0; i < sz; i++)
+ buf[offset++] = L' ';
+ buf[offset++] = L'|';
+ for (j = sz; j < 16 && j < size; j++) {
+ if (isprint(data[j-sz]))
+ buf[offset++] = data[j-sz];
+ else
+ buf[offset++] = L'.';
+ }
+ buf[offset++] = L'|';
+ for (i = j; i < 16; i++)
+ buf[offset++] = L' ';
+ buf[offset] = L'\0';
+}
+
+static void
+__attribute__((__unused__))
+hexdump(UINT8 *data, UINTN size)
+{
+ UINTN display_offset = (UINTN)data & 0xffffffff;
+ UINTN offset = 0;
+ //Print(L"hexdump: data=0x%016x size=0x%x\n", data, size);
+
+ while (offset < size) {
+ CHAR16 hexbuf[49];
+ CHAR16 txtbuf[19];
+ UINTN sz;
+
+ sz = format_hex(data+offset, size-offset, hexbuf);
+ if (sz == 0)
+ return;
+ uefi_call_wrapper(BS->Stall, 1, 200000);
+
+ format_text(data+offset, size-offset, txtbuf);
+ Print(L"%08x %s %s\n", display_offset, hexbuf, txtbuf);
+ uefi_call_wrapper(BS->Stall, 1, 200000);
+
+ display_offset += sz;
+ offset += sz;
+ }
+}
+
+#endif
diff --git a/include/httpboot.h b/include/httpboot.h
new file mode 100644
index 00000000..2d8d1a1f
--- /dev/null
+++ b/include/httpboot.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 SUSE LINUX GmbH <glin@suse.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Significant portions of this code are derived from Tianocore
+ * (http://tianocore.sf.net) and are Copyright 2009-2012 Intel
+ * Corporation.
+ */
+
+#ifndef _HTTPBOOT_H_
+#define _HTTPBOOT_H_
+
+extern BOOLEAN find_httpboot(EFI_HANDLE device);
+extern EFI_STATUS httpboot_fetch_buffer(EFI_HANDLE image, VOID **buffer,
+ UINT64 *buf_size);
+
+#endif
diff --git a/include/netboot.h b/include/netboot.h
new file mode 100644
index 00000000..6417373b
--- /dev/null
+++ b/include/netboot.h
@@ -0,0 +1,9 @@
+#ifndef _NETBOOT_H_
+#define _NETBOOT_H_
+
+extern BOOLEAN findNetboot(EFI_HANDLE image_handle);
+
+extern EFI_STATUS parseNetbootinfo(EFI_HANDLE image_handle);
+
+extern EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle, VOID **buffer, UINT64 *bufsiz);
+#endif
diff --git a/include/replacements.h b/include/replacements.h
new file mode 100644
index 00000000..e38cded1
--- /dev/null
+++ b/include/replacements.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2013 Red Hat, Inc <pjones@redhat.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef SHIM_REPLACEMENTS_H
+#define SHIM_REPLACEMENTS_H 1
+
+typedef enum {
+ VERIFIED_BY_NOTHING,
+ VERIFIED_BY_CERT,
+ VERIFIED_BY_HASH
+} verification_method_t;
+
+extern verification_method_t verification_method;
+extern int loader_is_participating;
+
+extern void hook_system_services(EFI_SYSTEM_TABLE *local_systab);
+extern void unhook_system_services(void);
+
+extern void hook_exit(EFI_SYSTEM_TABLE *local_systab);
+extern void unhook_exit(void);
+
+extern EFI_STATUS install_shim_protocols(void);
+extern void uninstall_shim_protocols(void);
+
+#endif /* SHIM_REPLACEMENTS_H */
diff --git a/include/tpm.h b/include/tpm.h
new file mode 100644
index 00000000..d11b545b
--- /dev/null
+++ b/include/tpm.h
@@ -0,0 +1,188 @@
+#include <efilib.h>
+
+#define EFI_TPM_GUID {0xf541796d, 0xa62e, 0x4954, {0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd }};
+#define EFI_TPM2_GUID {0x607f766c, 0x7455, 0x42be, {0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f }};
+
+#define TPM_ALG_SHA 0x00000004
+#define EV_IPL 0x0000000d
+
+EFI_STATUS tpm_log_event(EFI_PHYSICAL_ADDRESS buf, UINTN size, UINT8 pcr,
+ const CHAR8 *description);
+EFI_STATUS fallback_should_prefer_reset(void);
+
+EFI_STATUS tpm_log_pe(EFI_PHYSICAL_ADDRESS buf, UINTN size, UINT8 *sha1hash,
+ UINT8 pcr);
+
+EFI_STATUS tpm_measure_variable(CHAR16 *dbname, EFI_GUID guid, UINTN size, void *data);
+
+typedef struct {
+ uint8_t Major;
+ uint8_t Minor;
+ uint8_t RevMajor;
+ uint8_t RevMinor;
+} TCG_VERSION;
+
+typedef struct _TCG_EFI_BOOT_SERVICE_CAPABILITY {
+ uint8_t Size; /// Size of this structure.
+ TCG_VERSION StructureVersion;
+ TCG_VERSION ProtocolSpecVersion;
+ uint8_t HashAlgorithmBitmap; /// Hash algorithms .
+ char TPMPresentFlag; /// 00h = TPM not present.
+ char TPMDeactivatedFlag; /// 01h = TPM currently deactivated.
+} TCG_EFI_BOOT_SERVICE_CAPABILITY;
+
+typedef struct _TCG_PCR_EVENT {
+ uint32_t PCRIndex;
+ uint32_t EventType;
+ uint8_t digest[20];
+ uint32_t EventSize;
+ uint8_t Event[1];
+} TCG_PCR_EVENT;
+
+typedef struct _EFI_IMAGE_LOAD_EVENT {
+ EFI_PHYSICAL_ADDRESS ImageLocationInMemory;
+ UINTN ImageLengthInMemory;
+ UINTN ImageLinkTimeAddress;
+ UINTN LengthOfDevicePath;
+ EFI_DEVICE_PATH DevicePath[1];
+} EFI_IMAGE_LOAD_EVENT;
+
+struct efi_tpm_protocol
+{
+ EFI_STATUS (EFIAPI *status_check) (struct efi_tpm_protocol *this,
+ TCG_EFI_BOOT_SERVICE_CAPABILITY *ProtocolCapability,
+ uint32_t *TCGFeatureFlags,
+ EFI_PHYSICAL_ADDRESS *EventLogLocation,
+ EFI_PHYSICAL_ADDRESS *EventLogLastEntry);
+ EFI_STATUS (EFIAPI *hash_all) (struct efi_tpm_protocol *this,
+ uint8_t *HashData,
+ uint64_t HashLen,
+ uint32_t AlgorithmId,
+ uint64_t *HashedDataLen,
+ uint8_t **HashedDataResult);
+ EFI_STATUS (EFIAPI *log_event) (struct efi_tpm_protocol *this,
+ TCG_PCR_EVENT *TCGLogData,
+ uint32_t *EventNumber,
+ uint32_t Flags);
+ EFI_STATUS (EFIAPI *pass_through_to_tpm) (struct efi_tpm_protocol *this,
+ uint32_t TpmInputParameterBlockSize,
+ uint8_t *TpmInputParameterBlock,
+ uint32_t TpmOutputParameterBlockSize,
+ uint8_t *TpmOutputParameterBlock);
+ EFI_STATUS (EFIAPI *log_extend_event) (struct efi_tpm_protocol *this,
+ EFI_PHYSICAL_ADDRESS HashData,
+ uint64_t HashDataLen,
+ uint32_t AlgorithmId,
+ TCG_PCR_EVENT *TCGLogData,
+ uint32_t *EventNumber,
+ EFI_PHYSICAL_ADDRESS *EventLogLastEntry);
+};
+
+typedef struct efi_tpm_protocol efi_tpm_protocol_t;
+
+typedef uint32_t TREE_EVENT_LOG_BITMAP;
+
+typedef uint32_t EFI_TCG2_EVENT_LOG_BITMAP;
+typedef uint32_t EFI_TCG2_EVENT_LOG_FORMAT;
+typedef uint32_t EFI_TCG2_EVENT_ALGORITHM_BITMAP;
+
+typedef struct tdTREE_VERSION {
+ uint8_t Major;
+ uint8_t Minor;
+} TREE_VERSION;
+
+typedef struct tdEFI_TCG2_VERSION {
+ uint8_t Major;
+ uint8_t Minor;
+} EFI_TCG2_VERSION;
+
+typedef struct tdTREE_BOOT_SERVICE_CAPABILITY {
+ uint8_t Size;
+ TREE_VERSION StructureVersion;
+ TREE_VERSION ProtocolVersion;
+ uint32_t HashAlgorithmBitmap;
+ TREE_EVENT_LOG_BITMAP SupportedEventLogs;
+ BOOLEAN TrEEPresentFlag;
+ uint16_t MaxCommandSize;
+ uint16_t MaxResponseSize;
+ uint32_t ManufacturerID;
+} TREE_BOOT_SERVICE_CAPABILITY;
+
+typedef struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY {
+ uint8_t Size;
+ EFI_TCG2_VERSION StructureVersion;
+ EFI_TCG2_VERSION ProtocolVersion;
+ EFI_TCG2_EVENT_ALGORITHM_BITMAP HashAlgorithmBitmap;
+ EFI_TCG2_EVENT_LOG_BITMAP SupportedEventLogs;
+ BOOLEAN TPMPresentFlag;
+ uint16_t MaxCommandSize;
+ uint16_t MaxResponseSize;
+ uint32_t ManufacturerID;
+ uint32_t NumberOfPcrBanks;
+ EFI_TCG2_EVENT_ALGORITHM_BITMAP ActivePcrBanks;
+} EFI_TCG2_BOOT_SERVICE_CAPABILITY;
+
+typedef uint32_t TCG_PCRINDEX;
+typedef uint32_t TCG_EVENTTYPE;
+
+typedef struct tdEFI_TCG2_EVENT_HEADER {
+ uint32_t HeaderSize;
+ uint16_t HeaderVersion;
+ TCG_PCRINDEX PCRIndex;
+ TCG_EVENTTYPE EventType;
+} __attribute__ ((packed)) EFI_TCG2_EVENT_HEADER;
+
+typedef struct tdEFI_TCG2_EVENT {
+ uint32_t Size;
+ EFI_TCG2_EVENT_HEADER Header;
+ uint8_t Event[1];
+} __attribute__ ((packed)) EFI_TCG2_EVENT;
+
+#define EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 0x00000001
+#define EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002
+
+struct efi_tpm2_protocol
+{
+ EFI_STATUS (EFIAPI *get_capability) (struct efi_tpm2_protocol *this,
+ EFI_TCG2_BOOT_SERVICE_CAPABILITY *ProtocolCapability);
+ EFI_STATUS (EFIAPI *get_event_log) (struct efi_tpm2_protocol *this,
+ EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat,
+ EFI_PHYSICAL_ADDRESS *EventLogLocation,
+ EFI_PHYSICAL_ADDRESS *EventLogLastEntry,
+ BOOLEAN *EventLogTruncated);
+ EFI_STATUS (EFIAPI *hash_log_extend_event) (struct efi_tpm2_protocol *this,
+ uint64_t Flags,
+ EFI_PHYSICAL_ADDRESS DataToHash,
+ uint64_t DataToHashLen,
+ EFI_TCG2_EVENT *EfiTcgEvent);
+ EFI_STATUS (EFIAPI *submit_command) (struct efi_tpm2_protocol *this,
+ uint32_t InputParameterBlockSize,
+ uint8_t *InputParameterBlock,
+ uint32_t OutputParameterBlockSize,
+ uint8_t *OutputParameterBlock);
+ EFI_STATUS (EFIAPI *get_active_pcr_blanks) (struct efi_tpm2_protocol *this,
+ uint32_t *ActivePcrBanks);
+ EFI_STATUS (EFIAPI *set_active_pcr_banks) (struct efi_tpm2_protocol *this,
+ uint32_t ActivePcrBanks);
+ EFI_STATUS (EFIAPI *get_result_of_set_active_pcr_banks) (struct efi_tpm2_protocol *this,
+ uint32_t *OperationPresent,
+ uint32_t *Response);
+};
+
+typedef struct efi_tpm2_protocol efi_tpm2_protocol_t;
+
+typedef UINT32 TCG_EVENTTYPE;
+
+#define EV_EFI_EVENT_BASE ((TCG_EVENTTYPE) 0x80000000)
+#define EV_EFI_VARIABLE_DRIVER_CONFIG (EV_EFI_EVENT_BASE + 1)
+#define EV_EFI_VARIABLE_BOOT (EV_EFI_EVENT_BASE + 2)
+#define EV_EFI_BOOT_SERVICES_APPLICATION (EV_EFI_EVENT_BASE + 3)
+#define EV_EFI_BOOT_SERVICES_DRIVER (EV_EFI_EVENT_BASE + 4)
+#define EV_EFI_RUNTIME_SERVICES_DRIVER (EV_EFI_EVENT_BASE + 5)
+#define EV_EFI_GPT_EVENT (EV_EFI_EVENT_BASE + 6)
+#define EV_EFI_ACTION (EV_EFI_EVENT_BASE + 7)
+#define EV_EFI_PLATFORM_FIRMWARE_BLOB (EV_EFI_EVENT_BASE + 8)
+#define EV_EFI_HANDOFF_TABLES (EV_EFI_EVENT_BASE + 9)
+#define EV_EFI_VARIABLE_AUTHORITY (EV_EFI_EVENT_BASE + 0xE0)
+
+#define PE_COFF_IMAGE 0x0000000000000010
diff --git a/include/ucs2.h b/include/ucs2.h
new file mode 100644
index 00000000..806774c7
--- /dev/null
+++ b/include/ucs2.h
@@ -0,0 +1,139 @@
+/*
+ * shim - trivial UEFI first-stage bootloader
+ *
+ * Copyright 2013 Red Hat, Inc <pjones@redhat.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Significant portions of this code are derived from Tianocore
+ * (http://tianocore.sf.net) and are Copyright 2009-2012 Intel
+ * Corporation.
+ */
+
+#ifndef SHIM_UCS2_H
+#define SHIM_UCS2_H
+
+#include <stdbool.h>
+
+static inline INTN
+__attribute__((unused))
+StrCaseCmp(CHAR16 *s0, CHAR16 *s1)
+{
+ CHAR16 c0, c1;
+ while (1) {
+ if (*s0 == L'\0' || *s1 == L'\0')
+ return *s1 - *s0;
+ c0 = (*s0 >= L'a' && *s0 <= L'z') ? *s0 - 32 : *s0;
+ c1 = (*s1 >= L'a' && *s1 <= L'z') ? *s1 - 32 : *s1;
+ if (c0 != c1)
+ return c1 - c0;
+ s0++;
+ s1++;
+ }
+ return 0;
+}
+
+static inline INTN
+__attribute__((unused))
+StrnCaseCmp(CHAR16 *s0, CHAR16 *s1, int n)
+{
+ CHAR16 c0, c1;
+ int x = 0;
+ while (n > x++) {
+ if (*s0 == L'\0' || *s1 == L'\0')
+ return *s1 - *s0;
+ c0 = (*s0 >= L'a' && *s0 <= L'z') ? *s0 - 32 : *s0;
+ c1 = (*s1 >= L'a' && *s1 <= L'z') ? *s1 - 32 : *s1;
+ if (c0 != c1)
+ return c1 - c0;
+ s0++;
+ s1++;
+ }
+ return 0;
+}
+
+static inline UINTN
+__attribute__((unused))
+StrCSpn(const CHAR16 *s, const CHAR16 *reject)
+{
+ UINTN ret;
+
+ for (ret = 0; s[ret] != L'\0'; ret++) {
+ int i;
+ for (i = 0; reject[i] != L'\0'; i++) {
+ if (reject[i] == s[ret])
+ return ret;
+ }
+ }
+ return ret;
+}
+
+/*
+ * Test if an entire buffer is nothing but NUL characters. This
+ * implementation "gracefully" ignores the difference between the
+ * UTF-8/ASCII 1-byte NUL and the UCS-2 2-byte NUL.
+ */
+static inline bool
+__attribute__((__unused__))
+is_all_nuls(UINT8 *data, UINTN data_size)
+{
+ UINTN i;
+
+ for (i = 0; i < data_size; i++) {
+ if (data[i] != 0)
+ return false;
+ }
+ return true;
+}
+
+static inline UINTN
+__attribute__((__unused__))
+count_ucs2_strings(UINT8 *data, UINTN data_size)
+{
+ UINTN pos = 0;
+ UINTN last_nul_pos = 0;
+ UINTN num_nuls = 0;
+ UINTN i;
+
+ if (data_size % 2 != 0)
+ return 0;
+
+ for (i = pos; i < data_size; i++) {
+ if (i % 2 != 0) {
+ if (data[i] != 0)
+ return 0;
+ } else if (data[i] == 0) {
+ last_nul_pos = i;
+ num_nuls++;
+ }
+ pos = i;
+ }
+ if (num_nuls > 0 && last_nul_pos != pos - 1)
+ return 0;
+ return num_nuls;
+}
+
+#endif /* SHIM_UCS2_H */