mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.
`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.
Does not include updates to OpenSSL generated header files checked
into the repo. Those in `CryptoPkg\Library\OpensslLib\OpensslGen\`.
Compared to macro-based include guards, `#pragma once`:
- Eliminates the risk of macro name collisions or copy/paste errors
where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
(e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
file entirely, rather than re-reading it to find the matching
`#endif` ("multiple-include optimization").
- Note that some compilers may already optimize traditional include
guards, by recognzining the idiomatic pattern.
This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.
However, this is considered acceptable given:
1. edk2 already defines a subset of supported compilers in
BaseTools/Conf/tools_def.template, all of which have supported
`#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
include guard naming and potential macro collisions.
Approximate compiler support dates:
- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
(http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
169 lines
4.1 KiB
C
169 lines
4.1 KiB
C
/** @file
|
|
Application for Cryptographic Primitives Validation.
|
|
|
|
Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
**/
|
|
|
|
#pragma once
|
|
|
|
#include <PiPei.h>
|
|
#include <Uefi.h>
|
|
#include <Library/UefiLib.h>
|
|
#include <Library/DebugLib.h>
|
|
#include <Library/UnitTestLib.h>
|
|
#include <Library/PrintLib.h>
|
|
#include <Library/BaseCryptLib.h>
|
|
#include <Library/BaseLib.h>
|
|
#include <Library/BaseMemoryLib.h>
|
|
#include <Library/MemoryAllocationLib.h>
|
|
// #include <UnitTestTypes.h>
|
|
#include <Library/UnitTestLib.h>
|
|
// #include <Library/UnitTestAssertLib.h>
|
|
|
|
#define UNIT_TEST_NAME "BaseCryptLib Unit Test"
|
|
#define UNIT_TEST_VERSION "1.0"
|
|
|
|
typedef struct {
|
|
CHAR8 *Description;
|
|
CHAR8 *ClassName;
|
|
UNIT_TEST_FUNCTION Func;
|
|
UNIT_TEST_PREREQUISITE PreReq;
|
|
UNIT_TEST_CLEANUP CleanUp;
|
|
UNIT_TEST_CONTEXT Context;
|
|
} TEST_DESC;
|
|
|
|
typedef struct {
|
|
CHAR8 *Title;
|
|
CHAR8 *Package;
|
|
UNIT_TEST_SUITE_SETUP Sup;
|
|
UNIT_TEST_SUITE_TEARDOWN Tdn;
|
|
UINTN *TestNum;
|
|
TEST_DESC *TestDesc;
|
|
} SUITE_DESC;
|
|
|
|
extern UINTN mPkcs7EkuTestNum;
|
|
extern TEST_DESC mPkcs7EkuTest[];
|
|
|
|
extern UINTN mHashTestNum;
|
|
extern TEST_DESC mHashTest[];
|
|
|
|
extern UINTN mHmacTestNum;
|
|
extern TEST_DESC mHmacTest[];
|
|
|
|
extern UINTN mBlockCipherTestNum;
|
|
extern TEST_DESC mBlockCipherTest[];
|
|
|
|
extern UINTN mRsaTestNum;
|
|
extern TEST_DESC mRsaTest[];
|
|
|
|
extern UINTN mRsaCertTestNum;
|
|
extern TEST_DESC mRsaCertTest[];
|
|
|
|
extern UINTN mPkcs7TestNum;
|
|
extern TEST_DESC mPkcs7Test[];
|
|
|
|
extern UINTN mPkcs5TestNum;
|
|
extern TEST_DESC mPkcs5Test[];
|
|
|
|
extern UINTN mAuthenticodeTestNum;
|
|
extern TEST_DESC mAuthenticodeTest[];
|
|
|
|
extern UINTN mImageTimestampTestNum;
|
|
extern TEST_DESC mImageTimestampTest[];
|
|
|
|
extern UINTN mDhTestNum;
|
|
extern TEST_DESC mDhTest[];
|
|
|
|
extern UINTN mPrngTestNum;
|
|
extern TEST_DESC mPrngTest[];
|
|
|
|
extern UINTN mOaepTestNum;
|
|
extern TEST_DESC mOaepTest[];
|
|
|
|
extern UINTN mRsaPssTestNum;
|
|
extern TEST_DESC mRsaPssTest[];
|
|
|
|
extern UINTN mHkdfTestNum;
|
|
extern TEST_DESC mHkdfTest[];
|
|
|
|
extern UINTN mAeadAesGcmTestNum;
|
|
extern TEST_DESC mAeadAesGcmTest[];
|
|
|
|
extern UINTN mBnTestNum;
|
|
extern TEST_DESC mBnTest[];
|
|
|
|
extern UINTN mEcTestNum;
|
|
extern TEST_DESC mEcTest[];
|
|
|
|
extern UINTN mX509TestNum;
|
|
extern TEST_DESC mX509Test[];
|
|
|
|
extern UINTN mPkcs7ContentTestNum;
|
|
extern TEST_DESC mPkcs7ContentTest[];
|
|
|
|
//
|
|
// Test Case only for MbedTls.
|
|
//
|
|
extern UINTN mPkcs7EkuTestMbedTlsNum;
|
|
extern TEST_DESC mPkcs7EkuTestMbedTls[];
|
|
|
|
extern UINTN mRsaTestMbedTlsNum;
|
|
extern TEST_DESC mRsaTestMbedTls[];
|
|
|
|
extern UINTN mPkcs7TestMbedTlsNum;
|
|
extern TEST_DESC mPkcs7TestMbedTls[];
|
|
|
|
extern UINTN mOaepTestMbedTlsNum;
|
|
extern TEST_DESC mOaepTestMbedTls[];
|
|
|
|
extern UINTN mPkcs7ContentTestMbedTlsNum;
|
|
extern TEST_DESC mPkcs7ContentTestMbedTls[];
|
|
|
|
/** Creates a framework you can use */
|
|
EFI_STATUS
|
|
EFIAPI
|
|
CreateUnitTest (
|
|
IN CHAR8 *UnitTestName,
|
|
IN CHAR8 *UnitTestVersion,
|
|
IN OUT UNIT_TEST_FRAMEWORK_HANDLE *Framework
|
|
);
|
|
|
|
/**
|
|
Validate UEFI-OpenSSL DH Interfaces.
|
|
|
|
@retval EFI_SUCCESS Validation succeeded.
|
|
@retval EFI_ABORTED Validation failed.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
ValidateCryptDh (
|
|
VOID
|
|
);
|
|
|
|
/**
|
|
Validate UEFI-OpenSSL pseudorandom number generator interfaces.
|
|
|
|
@retval EFI_SUCCESS Validation succeeded.
|
|
@retval EFI_ABORTED Validation failed.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
ValidateCryptPrng (
|
|
VOID
|
|
);
|
|
|
|
/**
|
|
Initialize the unit test framework, suite, and unit tests for the
|
|
sample unit tests and run the unit tests.
|
|
|
|
@retval EFI_SUCCESS All test cases were dispatched.
|
|
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to
|
|
initialize the unit tests.
|
|
**/
|
|
EFI_STATUS
|
|
EFIAPI
|
|
UefiTestMain (
|
|
VOID
|
|
);
|