X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=CryptoPkg%2FLibrary%2FBaseCryptLib%2FHash%2FCryptSha256.c;h=56894aca30d678131290425640366a57ee539aa7;hp=7e6c6c691f87eca030ead2733a44a17588c2f715;hb=6b8ebcb8de52ae5cab543181712e53eeb94340a7;hpb=a8c4464502aabcbda7032daddc772a1bc7386bdf diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha256.c b/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha256.c index 7e6c6c691f..56894aca30 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha256.c +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha256.c @@ -1,7 +1,7 @@ /** @file SHA-256 Digest Wrapper Implementation over OpenSSL. -Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
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 @@ -30,14 +30,14 @@ Sha256GetContextSize ( // // Retrieves OpenSSL SHA-256 Context Size // - return (UINTN)(sizeof (SHA256_CTX)); + return (UINTN) (sizeof (SHA256_CTX)); } /** Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for subsequent use. - If Sha256Context is NULL, then ASSERT(). + If Sha256Context is NULL, then return FALSE. @param[out] Sha256Context Pointer to SHA-256 context being initialized. @@ -52,21 +52,23 @@ Sha256Init ( ) { // - // ASSERT if Sha256Context is NULL + // Check input parameters. // - ASSERT (Sha256Context != NULL); + if (Sha256Context == NULL) { + return FALSE; + } // // OpenSSL SHA-256 Context Initialization // - return (BOOLEAN) (SHA256_Init ((SHA256_CTX *)Sha256Context)); + return (BOOLEAN) (SHA256_Init ((SHA256_CTX *) Sha256Context)); } /** Makes a copy of an existing SHA-256 context. - If Sha256Context is NULL, then ASSERT(). - If NewSha256Context is NULL, then ASSERT(). + If Sha256Context is NULL, then return FALSE. + If NewSha256Context is NULL, then return FALSE. @param[in] Sha256Context Pointer to SHA-256 context being copied. @param[out] NewSha256Context Pointer to new SHA-256 context. @@ -82,6 +84,13 @@ Sha256Duplicate ( OUT VOID *NewSha256Context ) { + // + // Check input parameters. + // + if (Sha256Context == NULL || NewSha256Context == NULL) { + return FALSE; + } + CopyMem (NewSha256Context, Sha256Context, sizeof (SHA256_CTX)); return TRUE; @@ -95,7 +104,7 @@ Sha256Duplicate ( SHA-256 context should be already correctly intialized by Sha256Init(), and should not be finalized by Sha256Final(). Behavior with invalid context is undefined. - If Sha256Context is NULL, then ASSERT(). + If Sha256Context is NULL, then return FALSE. @param[in, out] Sha256Context Pointer to the SHA-256 context. @param[in] Data Pointer to the buffer containing the data to be hashed. @@ -114,21 +123,23 @@ Sha256Update ( ) { // - // ASSERT if Sha256Context is NULL + // Check input parameters. // - ASSERT (Sha256Context != NULL); + if (Sha256Context == NULL) { + return FALSE; + } // - // ASSERT if invalid parameters, in case that only DataLength was checked in OpenSSL + // Check invalid parameters, in case that only DataLength was checked in OpenSSL // - if (Data == NULL) { - ASSERT (DataSize == 0); + if (Data == NULL && DataSize != 0) { + return FALSE; } // // OpenSSL SHA-256 Hash Update // - return (BOOLEAN) (SHA256_Update ((SHA256_CTX *)Sha256Context, Data, DataSize)); + return (BOOLEAN) (SHA256_Update ((SHA256_CTX *) Sha256Context, Data, DataSize)); } /** @@ -140,8 +151,8 @@ Sha256Update ( SHA-256 context should be already correctly intialized by Sha256Init(), and should not be finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined. - If Sha256Context is NULL, then ASSERT(). - If HashValue is NULL, then ASSERT(). + If Sha256Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. @param[in, out] Sha256Context Pointer to the SHA-256 context. @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest @@ -159,13 +170,14 @@ Sha256Final ( ) { // - // ASSERT if Sha256Context is NULL or HashValue is NULL + // Check input parameters. // - ASSERT (Sha256Context != NULL); - ASSERT (HashValue != NULL); + if (Sha256Context == NULL || HashValue == NULL) { + return FALSE; + } // // OpenSSL SHA-256 Hash Finalization // - return (BOOLEAN) (SHA256_Final (HashValue, (SHA256_CTX *)Sha256Context)); + return (BOOLEAN) (SHA256_Final (HashValue, (SHA256_CTX *) Sha256Context)); }