1. Add new API supports for PEM & X509 key retrieving & verification;
2. Add new MD4 hash supports; 3. Add corresponding test case in Cryptest utility; 4. Fix MACRO definition issue in OpensslLib.inf and parameter checking issues in some wrapper implementations. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11214 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
177
CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4.c
Normal file
177
CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4.c
Normal file
@@ -0,0 +1,177 @@
|
||||
/** @file
|
||||
MD4 Digest Wrapper Implementation over OpenSSL.
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <openssl/md4.h>
|
||||
|
||||
/**
|
||||
Retrieves the size, in bytes, of the context buffer required for MD4 hash operations.
|
||||
|
||||
@return The size, in bytes, of the context buffer required for MD4 hash operations.
|
||||
|
||||
**/
|
||||
UINTN
|
||||
EFIAPI
|
||||
Md4GetContextSize (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
//
|
||||
// Retrieves the OpenSSL MD4 Context Size
|
||||
//
|
||||
return (UINTN)(sizeof (MD4_CTX));
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes user-supplied memory pointed by Md4Context as MD4 hash context for
|
||||
subsequent use.
|
||||
|
||||
If Md4Context is NULL, then ASSERT().
|
||||
|
||||
@param[out] Md4Context Pointer to MD4 context being initialized.
|
||||
|
||||
@retval TRUE MD4 context initialization succeeded.
|
||||
@retval FALSE MD4 context initialization failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Md4Init (
|
||||
OUT VOID *Md4Context
|
||||
)
|
||||
{
|
||||
//
|
||||
// ASSERT if Md4Context is NULL.
|
||||
//
|
||||
ASSERT (Md4Context != NULL);
|
||||
|
||||
//
|
||||
// OpenSSL MD4 Context Initialization
|
||||
//
|
||||
return (BOOLEAN) (MD4_Init ((MD4_CTX *)Md4Context));
|
||||
}
|
||||
|
||||
/**
|
||||
Makes a copy of an existing MD4 context.
|
||||
|
||||
If Md4Context is NULL, then ASSERT().
|
||||
If NewMd4Context is NULL, then ASSERT().
|
||||
|
||||
@param[in] Md4Context Pointer to MD4 context being copied.
|
||||
@param[out] NewMd4Context Pointer to new MD4 context.
|
||||
|
||||
@retval TRUE MD4 context copy succeeded.
|
||||
@retval FALSE MD4 context copy failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Md4Duplicate (
|
||||
IN CONST VOID *Md4Context,
|
||||
OUT VOID *NewMd4Context
|
||||
)
|
||||
{
|
||||
//
|
||||
// ASSERT if Md4Context or NewMd4Context is NULL.
|
||||
//
|
||||
ASSERT (Md4Context != NULL);
|
||||
ASSERT (NewMd4Context != NULL);
|
||||
|
||||
CopyMem (NewMd4Context, Md4Context, sizeof (MD4_CTX));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Digests the input data and updates MD4 context.
|
||||
|
||||
This function performs MD4 digest on a data buffer of the specified size.
|
||||
It can be called multiple times to compute the digest of long or discontinuous data streams.
|
||||
MD4 context should be already correctly intialized by Md4Init(), and should not be finalized
|
||||
by Md4Final(). Behavior with invalid context is undefined.
|
||||
|
||||
If Md4Context is NULL, then ASSERT().
|
||||
|
||||
@param[in, out] Md4Context Pointer to the MD4 context.
|
||||
@param[in] Data Pointer to the buffer containing the data to be hashed.
|
||||
@param[in] DataSize Size of Data buffer in bytes.
|
||||
|
||||
@retval TRUE MD4 data digest succeeded.
|
||||
@retval FALSE MD4 data digest failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Md4Update (
|
||||
IN OUT VOID *Md4Context,
|
||||
IN CONST VOID *Data,
|
||||
IN UINTN DataSize
|
||||
)
|
||||
{
|
||||
//
|
||||
// ASSERT if Md4Context is NULL
|
||||
//
|
||||
ASSERT (Md4Context != NULL);
|
||||
|
||||
//
|
||||
// ASSERT if invalid parameters, in case that only DataLength was checked in OpenSSL
|
||||
//
|
||||
if (Data == NULL) {
|
||||
ASSERT (DataSize == 0);
|
||||
}
|
||||
|
||||
//
|
||||
// OpenSSL MD4 Hash Update
|
||||
//
|
||||
return (BOOLEAN) (MD4_Update ((MD4_CTX *)Md4Context, Data, DataSize));
|
||||
}
|
||||
|
||||
/**
|
||||
Completes computation of the MD4 digest value.
|
||||
|
||||
This function completes MD4 hash computation and retrieves the digest value into
|
||||
the specified memory. After this function has been called, the MD4 context cannot
|
||||
be used again.
|
||||
MD4 context should be already correctly intialized by Md4Init(), and should not be
|
||||
finalized by Md4Final(). Behavior with invalid MD4 context is undefined.
|
||||
|
||||
If Md4Context is NULL, then ASSERT().
|
||||
If HashValue is NULL, then ASSERT().
|
||||
|
||||
@param[in, out] Md4Context Pointer to the MD4 context.
|
||||
@param[out] HashValue Pointer to a buffer that receives the MD4 digest
|
||||
value (16 bytes).
|
||||
|
||||
@retval TRUE MD4 digest computation succeeded.
|
||||
@retval FALSE MD4 digest computation failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Md4Final (
|
||||
IN OUT VOID *Md4Context,
|
||||
OUT UINT8 *HashValue
|
||||
)
|
||||
{
|
||||
//
|
||||
// ASSERT if Md4Context is NULL or HashValue is NULL
|
||||
//
|
||||
ASSERT (Md4Context != NULL);
|
||||
ASSERT (HashValue != NULL);
|
||||
|
||||
//
|
||||
// OpenSSL MD4 Hash Finalization
|
||||
//
|
||||
return (BOOLEAN) (MD4_Final (HashValue, (MD4_CTX *)Md4Context));
|
||||
}
|
@@ -84,6 +84,12 @@ Md5Duplicate (
|
||||
OUT VOID *NewMd5Context
|
||||
)
|
||||
{
|
||||
//
|
||||
// ASSERT if Md5Context or NewMd5Context is NULL.
|
||||
//
|
||||
ASSERT (Md5Context != NULL);
|
||||
ASSERT (NewMd5Context != NULL);
|
||||
|
||||
CopyMem (NewMd5Context, Md5Context, sizeof (MD5_CTX));
|
||||
|
||||
return TRUE;
|
||||
|
@@ -83,6 +83,12 @@ Sha1Duplicate (
|
||||
OUT VOID *NewSha1Context
|
||||
)
|
||||
{
|
||||
//
|
||||
// ASSERT if Sha1Context or NewSha1Context is NULL.
|
||||
//
|
||||
ASSERT (Sha1Context != NULL);
|
||||
ASSERT (NewSha1Context != NULL);
|
||||
|
||||
CopyMem (NewSha1Context, Sha1Context, sizeof (SHA_CTX));
|
||||
|
||||
return TRUE;
|
||||
|
@@ -82,6 +82,12 @@ Sha256Duplicate (
|
||||
OUT VOID *NewSha256Context
|
||||
)
|
||||
{
|
||||
//
|
||||
// ASSERT if Sha256Context or NewSha256Context is NULL.
|
||||
//
|
||||
ASSERT (Sha256Context != NULL);
|
||||
ASSERT (NewSha256Context != NULL);
|
||||
|
||||
CopyMem (NewSha256Context, Sha256Context, sizeof (SHA256_CTX));
|
||||
|
||||
return TRUE;
|
||||
|
Reference in New Issue
Block a user