]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix some typo and coding style issues in BaseCryptLib instances.
authortye1 <tye1@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 27 Jul 2012 07:49:42 +0000 (07:49 +0000)
committertye1 <tye1@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 27 Jul 2012 07:49:42 +0000 (07:49 +0000)
Signed-off by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Fu, Siyuan <Siyuan.fu@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13564 6f19259b-4bc3-4df7-8a09-765794883524

20 files changed:
CryptoPkg/Include/Library/BaseCryptLib.h
CryptoPkg/Library/BaseCryptLib/Cipher/CryptAes.c
CryptoPkg/Library/BaseCryptLib/Cipher/CryptArc4.c
CryptoPkg/Library/BaseCryptLib/Cipher/CryptTdes.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptMd5.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptSha1.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptSha256.c
CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5.c
CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha1.c
CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c
CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7.c [deleted file]
CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Sign.c
CryptoPkg/Library/BaseCryptLib/Pk/CryptRsa.c [deleted file]
CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaBasic.c
CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c
CryptoPkg/Library/BaseCryptLib/SysCall/BaseMemAllocation.c
CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/BaseCryptLibRuntimeCryptProtocol.inf

index decca54eac5c54b6a619fbcaaa10061e05bdef51..d996410201c2ddd35bb33b3c0ab27ad93e015c54 100644 (file)
@@ -778,7 +778,7 @@ TdesGetContextSize (
   Initializes user-supplied memory as TDES context for subsequent use.\r
 \r
   This function initializes user-supplied memory pointed by TdesContext as TDES context.\r
-  In addtion, it sets up all TDES key materials for subsequent encryption and decryption\r
+  In addition, it sets up all TDES key materials for subsequent encryption and decryption\r
   operations.\r
   There are 3 key options as follows:\r
   KeyLength = 64,  Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)\r
@@ -974,7 +974,7 @@ AesGetContextSize (
   Initializes user-supplied memory as AES context for subsequent use.\r
 \r
   This function initializes user-supplied memory pointed by AesContext as AES context.\r
-  In addtion, it sets up all AES key materials for subsequent encryption and decryption\r
+  In addition, it sets up all AES key materials for subsequent encryption and decryption\r
   operations.\r
   There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r
 \r
@@ -1167,7 +1167,7 @@ Arc4GetContextSize (
   Initializes user-supplied memory as ARC4 context for subsequent use.\r
 \r
   This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.\r
-  In addtion, it sets up all ARC4 key materials for subsequent encryption and decryption\r
+  In addition, it sets up all ARC4 key materials for subsequent encryption and decryption\r
   operations.\r
 \r
   If Arc4Context is NULL, then return FALSE.\r
index 45e4a4392efa18a26916a4a51c73f49b709111fb..c8dbb797fa7aeb30523dec90cad2c59c02222e4d 100644 (file)
@@ -38,7 +38,7 @@ AesGetContextSize (
   Initializes user-supplied memory as AES context for subsequent use.\r
 \r
   This function initializes user-supplied memory pointed by AesContext as AES context.\r
-  In addtion, it sets up all AES key materials for subsequent encryption and decryption\r
+  In addition, it sets up all AES key materials for subsequent encryption and decryption\r
   operations.\r
   There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r
 \r
index 69214181373ec6ee7b1df948da28c2bbfbbff672..0e5331c20d0824590092e22b6dcdc4268c783f74 100644 (file)
@@ -32,14 +32,14 @@ Arc4GetContextSize (
   // for backup copy. When Arc4Reset() is called, we can use the backup copy to restore\r
   // the working copy to the initial state.\r
   //\r
-  return (UINTN) (2 * sizeof(RC4_KEY));\r
+  return (UINTN) (2 * sizeof (RC4_KEY));\r
 }\r
 \r
 /**\r
   Initializes user-supplied memory as ARC4 context for subsequent use.\r
 \r
   This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.\r
-  In addtion, it sets up all ARC4 key materials for subsequent encryption and decryption\r
+  In addition, it sets up all ARC4 key materials for subsequent encryption and decryption\r
   operations.\r
 \r
   If Arc4Context is NULL, then return FALSE.\r
@@ -75,7 +75,7 @@ Arc4Init (
 \r
   RC4_set_key (Rc4Key, (UINT32) KeySize, Key);\r
 \r
-  CopyMem (Rc4Key +  1, Rc4Key, sizeof(RC4_KEY));\r
+  CopyMem (Rc4Key +  1, Rc4Key, sizeof (RC4_KEY));\r
 \r
   return TRUE;\r
 }\r
@@ -205,7 +205,7 @@ Arc4Reset (
   \r
   Rc4Key = (RC4_KEY *) Arc4Context;\r
 \r
-  CopyMem (Rc4Key, Rc4Key + 1, sizeof(RC4_KEY));\r
+  CopyMem (Rc4Key, Rc4Key + 1, sizeof (RC4_KEY));\r
 \r
   return TRUE;\r
 }\r
index 8213718b42642f89ec75451d5daa0278533561e5..f3a1eb7293de8da7c88a5abf16463ad6e46f7d29 100644 (file)
@@ -37,7 +37,7 @@ TdesGetContextSize (
   Initializes user-supplied memory as TDES context for subsequent use.\r
 \r
   This function initializes user-supplied memory pointed by TdesContext as TDES context.\r
-  In addtion, it sets up all TDES key materials for subsequent encryption and decryption\r
+  In addition, it sets up all TDES key materials for subsequent encryption and decryption\r
   operations.\r
   There are 3 key options as follows:\r
   KeyLength = 64,  Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)\r
@@ -76,9 +76,9 @@ TdesInit (
   KeySchedule = (DES_key_schedule *) TdesContext;\r
 \r
   //\r
-  // \r
+  // If input Key is a weak key, return error.\r
   //\r
-  if (DES_is_weak_key ((const_DES_cblock *) Key)) {\r
+  if (DES_is_weak_key ((const_DES_cblock *) Key) == 1) {\r
     return FALSE;\r
   }\r
 \r
@@ -90,7 +90,7 @@ TdesInit (
     return TRUE;\r
   }\r
 \r
-  if (DES_is_weak_key ((const_DES_cblock *) Key + 8)) {\r
+  if (DES_is_weak_key ((const_DES_cblock *) Key + 8) == 1) {\r
     return FALSE;\r
   }\r
 \r
@@ -101,7 +101,7 @@ TdesInit (
     return TRUE;\r
   }\r
 \r
-  if (DES_is_weak_key ((const_DES_cblock *) Key + 16)) {\r
+  if (DES_is_weak_key ((const_DES_cblock *) Key + 16) == 1) {\r
     return FALSE;\r
   }\r
 \r
index 31fc4dcea9d900d7ab6dade3aac8365b9f90e1b5..633d34379032b5c9ad9537e6d709bf2e4813bb66 100644 (file)
@@ -30,7 +30,7 @@ Md4GetContextSize (
   //\r
   // Retrieves the OpenSSL MD4 Context Size\r
   //\r
-  return (UINTN)(sizeof (MD4_CTX));\r
+  return (UINTN) (sizeof (MD4_CTX));\r
 }\r
 \r
 /**\r
@@ -61,7 +61,7 @@ Md4Init (
   //\r
   // OpenSSL MD4 Context Initialization\r
   //\r
-  return (BOOLEAN) (MD4_Init ((MD4_CTX *)Md4Context));\r
+  return (BOOLEAN) (MD4_Init ((MD4_CTX *) Md4Context));\r
 }\r
 \r
 /**\r
@@ -139,7 +139,7 @@ Md4Update (
   //\r
   // OpenSSL MD4 Hash Update\r
   //\r
-  return (BOOLEAN) (MD4_Update ((MD4_CTX *)Md4Context, Data, DataSize));\r
+  return (BOOLEAN) (MD4_Update ((MD4_CTX *) Md4Context, Data, DataSize));\r
 }\r
 \r
 /**\r
@@ -179,5 +179,5 @@ Md4Final (
   //\r
   // OpenSSL MD4 Hash Finalization\r
   //\r
-  return (BOOLEAN) (MD4_Final (HashValue, (MD4_CTX *)Md4Context));\r
+  return (BOOLEAN) (MD4_Final (HashValue, (MD4_CTX *) Md4Context));\r
 }\r
index 1d852c74951682313bfed192230a1a1c5a1ab130..dcf76913cce861bfb19856416ee953b2e797fbbe 100644 (file)
@@ -31,7 +31,7 @@ Md5GetContextSize (
   //\r
   // Retrieves the OpenSSL MD5 Context Size\r
   //\r
-  return (UINTN)(sizeof (MD5_CTX));\r
+  return (UINTN) (sizeof (MD5_CTX));\r
 }\r
 \r
 \r
@@ -63,7 +63,7 @@ Md5Init (
   //\r
   // OpenSSL MD5 Context Initialization\r
   //\r
-  return (BOOLEAN) (MD5_Init ((MD5_CTX *)Md5Context));\r
+  return (BOOLEAN) (MD5_Init ((MD5_CTX *) Md5Context));\r
 }\r
 \r
 /**\r
@@ -141,7 +141,7 @@ Md5Update (
   //\r
   // OpenSSL MD5 Hash Update\r
   //\r
-  return (BOOLEAN) (MD5_Update ((MD5_CTX *)Md5Context, Data, DataSize));\r
+  return (BOOLEAN) (MD5_Update ((MD5_CTX *) Md5Context, Data, DataSize));\r
 }\r
 \r
 /**\r
@@ -181,5 +181,5 @@ Md5Final (
   //\r
   // OpenSSL MD5 Hash Finalization\r
   //\r
-  return (BOOLEAN) (MD5_Final (HashValue, (MD5_CTX *)Md5Context));\r
+  return (BOOLEAN) (MD5_Final (HashValue, (MD5_CTX *) Md5Context));\r
 }\r
index 633028b64e46d097151f613e6884a0ad8531be1c..78c29c1b18558b6a856ebc597de400e4bdcfe327 100644 (file)
@@ -31,7 +31,7 @@ Sha1GetContextSize (
   //\r
   // Retrieves OpenSSL SHA Context Size\r
   //\r
-  return (UINTN)(sizeof (SHA_CTX));\r
+  return (UINTN) (sizeof (SHA_CTX));\r
 }\r
 \r
 /**\r
@@ -62,7 +62,7 @@ Sha1Init (
   //\r
   // OpenSSL SHA-1 Context Initialization\r
   //\r
-  return (BOOLEAN) (SHA1_Init ((SHA_CTX *)Sha1Context));\r
+  return (BOOLEAN) (SHA1_Init ((SHA_CTX *) Sha1Context));\r
 }\r
 \r
 /**\r
@@ -140,7 +140,7 @@ Sha1Update (
   //\r
   // OpenSSL SHA-1 Hash Update\r
   //\r
-  return (BOOLEAN) (SHA1_Update ((SHA_CTX *)Sha1Context, Data, DataSize));\r
+  return (BOOLEAN) (SHA1_Update ((SHA_CTX *) Sha1Context, Data, DataSize));\r
 }\r
 \r
 /**\r
@@ -180,5 +180,5 @@ Sha1Final (
   //\r
   // OpenSSL SHA-1 Hash Finalization\r
   //\r
-  return (BOOLEAN) (SHA1_Final (HashValue, (SHA_CTX *)Sha1Context));\r
+  return (BOOLEAN) (SHA1_Final (HashValue, (SHA_CTX *) Sha1Context));\r
 }\r
index ca0cb1aa8ced7f71ccbcf594e622006d69f8dc8a..56894aca30d678131290425640366a57ee539aa7 100644 (file)
@@ -30,7 +30,7 @@ Sha256GetContextSize (
   //\r
   // Retrieves OpenSSL SHA-256 Context Size\r
   //\r
-  return (UINTN)(sizeof (SHA256_CTX));\r
+  return (UINTN) (sizeof (SHA256_CTX));\r
 }\r
 \r
 /**\r
@@ -61,7 +61,7 @@ Sha256Init (
   //\r
   // OpenSSL SHA-256 Context Initialization\r
   //\r
-  return (BOOLEAN) (SHA256_Init ((SHA256_CTX *)Sha256Context));\r
+  return (BOOLEAN) (SHA256_Init ((SHA256_CTX *) Sha256Context));\r
 }\r
 \r
 /**\r
@@ -139,7 +139,7 @@ Sha256Update (
   //\r
   // OpenSSL SHA-256 Hash Update\r
   //\r
-  return (BOOLEAN) (SHA256_Update ((SHA256_CTX *)Sha256Context, Data, DataSize));\r
+  return (BOOLEAN) (SHA256_Update ((SHA256_CTX *) Sha256Context, Data, DataSize));\r
 }\r
 \r
 /**\r
@@ -179,5 +179,5 @@ Sha256Final (
   //\r
   // OpenSSL SHA-256 Hash Finalization\r
   //\r
-  return (BOOLEAN) (SHA256_Final (HashValue, (SHA256_CTX *)Sha256Context));\r
+  return (BOOLEAN) (SHA256_Final (HashValue, (SHA256_CTX *) Sha256Context));\r
 }\r
index 0cdab7ac11e5a45b7a070e5ddbee7253a87b50a7..45f7d4977e1bf8c148666f35b2bfd6b7121ee789 100644 (file)
@@ -30,7 +30,7 @@ HmacMd5GetContextSize (
   //\r
   // Retrieves the OpenSSL HMAC-MD5 Context Size\r
   //\r
-  return (UINTN)(sizeof (HMAC_CTX));\r
+  return (UINTN) (sizeof (HMAC_CTX));\r
 }\r
 \r
 /**\r
index 58da2f3aecd5eb95cdd7817860d16a979d5e224e..b183ae562e9390e5c1c1447e9cdfdb49e7ef7cbd 100644 (file)
@@ -30,7 +30,7 @@ HmacSha1GetContextSize (
   //\r
   // Retrieves the OpenSSL HMAC-SHA1 Context Size\r
   //\r
-  return (UINTN)(sizeof (HMAC_CTX));\r
+  return (UINTN) (sizeof (HMAC_CTX));\r
 }\r
 \r
 /**\r
index 2c3a97b2c0f91539d5e3113e96cf9b0fd65ce4d2..319ad59eccfe761f420fd9e75060de1617169ec5 100644 (file)
@@ -36,7 +36,7 @@ PasswordCallback (
 {\r
   INTN  KeyLength;\r
 \r
-  ZeroMem ((VOID *)Buf, (UINTN)Size);\r
+  ZeroMem ((VOID *) Buf, (UINTN) Size);\r
   if (Key != NULL) {\r
     //\r
     // Duplicate key phrase directly.\r
@@ -93,16 +93,16 @@ RsaGetPrivateKeyFromPem (
   // Add possible block-cipher descriptor for PEM data decryption.\r
   // NOTE: Only support most popular ciphers (3DES, AES) for the encrypted PEM.\r
   //\r
-  EVP_add_cipher (EVP_des_ede3_cbc());\r
-  EVP_add_cipher (EVP_aes_128_cbc());\r
-  EVP_add_cipher (EVP_aes_192_cbc());\r
-  EVP_add_cipher (EVP_aes_256_cbc());\r
+  EVP_add_cipher (EVP_des_ede3_cbc ());\r
+  EVP_add_cipher (EVP_aes_128_cbc ());\r
+  EVP_add_cipher (EVP_aes_192_cbc ());\r
+  EVP_add_cipher (EVP_aes_256_cbc ());\r
 \r
   //\r
   // Read encrypted PEM Data.\r
   //\r
   PemBio = BIO_new (BIO_s_mem ());\r
-  BIO_write (PemBio, PemData, (int)PemSize);\r
+  BIO_write (PemBio, PemData, (int) PemSize);\r
   if (PemBio == NULL) {\r
     goto _Exit;\r
   }\r
@@ -110,7 +110,7 @@ RsaGetPrivateKeyFromPem (
   //\r
   // Retrieve RSA Private Key from encrypted PEM data.\r
   //\r
-  *RsaContext = PEM_read_bio_RSAPrivateKey (PemBio, NULL, (pem_password_cb *)&PasswordCallback, (void *)Password);\r
+  *RsaContext = PEM_read_bio_RSAPrivateKey (PemBio, NULL, (pem_password_cb *) &PasswordCallback, (void *) Password);\r
   if (*RsaContext != NULL) {\r
     Status = TRUE;\r
   }\r
index 20f13469b30f407367557e01e4f1fac16cbf967e..30792d27ca08f6b30eceff3d185448f8d468825f 100644 (file)
@@ -32,7 +32,7 @@ DhNew (
   //\r
   // Allocates & Initializes DH Context by OpenSSL DH_new()\r
   //\r
-  return (VOID *)DH_new ();\r
+  return (VOID *) DH_new ();\r
 }\r
 \r
 /**\r
@@ -52,7 +52,7 @@ DhFree (
   //\r
   // Free OpenSSL DH Context\r
   //\r
-  DH_free ((DH *)DhContext);\r
+  DH_free ((DH *) DhContext);\r
 }\r
 \r
 /**\r
diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7.c
deleted file mode 100644 (file)
index 218e7ac..0000000
+++ /dev/null
@@ -1,753 +0,0 @@
-/** @file\r
-  PKCS#7 SignedData Verification Wrapper Implementation over OpenSSL.\r
-\r
-  Caution: This module requires additional review when modified.\r
-  This library will have external input - signature (e.g. UEFI Authenticated\r
-  Variable). It may by input in SMM mode.\r
-  This external input must be validated carefully to avoid security issue like\r
-  buffer overflow, integer overflow.\r
-\r
-  WrapPkcs7Data(), Pkcs7GetSigners(), Pkcs7Verify() will get UEFI Authenticated\r
-  Variable and will do basic check for data structure.\r
-\r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "InternalCryptLib.h"\r
-\r
-#include <openssl/objects.h>\r
-#include <openssl/x509.h>\r
-#include <openssl/pkcs7.h>\r
-\r
-UINT8 mOidValue[9] = { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02 };\r
-\r
-/**\r
-  Verification callback function to override any existing callbacks in OpenSSL\r
-  for intermediate certificate supports.\r
-\r
-  @param[in]  Status   Original status before calling this callback.\r
-  @param[in]  Context  X509 store context.\r
-\r
-  @retval     1        Current X509 certificate is verified successfully.\r
-  @retval     0        Verification failed.\r
-\r
-**/\r
-int\r
-X509VerifyCb (\r
-  IN int            Status,\r
-  IN X509_STORE_CTX *Context\r
-  )\r
-{\r
-  X509_OBJECT  *Obj;\r
-  INTN         Error;\r
-  INTN         Index;\r
-  INTN         Count;\r
-\r
-  Obj   = NULL;\r
-  Error = (INTN) X509_STORE_CTX_get_error (Context);\r
-\r
-  //\r
-  // X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT and X509_V_ERR_UNABLE_TO_GET_ISSUER_\r
-  // CERT_LOCALLY mean a X509 certificate is not self signed and its issuer\r
-  // can not be found in X509_verify_cert of X509_vfy.c.\r
-  // In order to support intermediate certificate node, we override the\r
-  // errors if the certification is obtained from X509 store, i.e. it is\r
-  // a trusted ceritifcate node that is enrolled by user.\r
-  // Besides,X509_V_ERR_CERT_UNTRUSTED and X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE\r
-  // are also ignored to enable such feature.\r
-  //\r
-  if ((Error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT) ||\r
-      (Error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)) {\r
-    Obj = (X509_OBJECT *) malloc (sizeof (X509_OBJECT));\r
-    if (Obj == NULL) {\r
-      return 0;\r
-    }\r
-\r
-    Obj->type      = X509_LU_X509;\r
-    Obj->data.x509 = Context->current_cert;\r
-\r
-    CRYPTO_w_lock (CRYPTO_LOCK_X509_STORE);\r
-\r
-    if (X509_OBJECT_retrieve_match (Context->ctx->objs, Obj)) {\r
-      Status = 1;\r
-    } else {\r
-      //\r
-      // If any certificate in the chain is enrolled as trusted certificate,\r
-      // pass the certificate verification.\r
-      //\r
-      if (Error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY) {\r
-        Count = (INTN) sk_X509_num (Context->chain);\r
-        for (Index = 0; Index < Count; Index++) {\r
-          Obj->data.x509 = sk_X509_value (Context->chain, (int) Index);\r
-          if (X509_OBJECT_retrieve_match (Context->ctx->objs, Obj)) {\r
-            Status = 1;\r
-            break;\r
-          }\r
-        }\r
-      }\r
-    }\r
-\r
-    CRYPTO_w_unlock (CRYPTO_LOCK_X509_STORE);\r
-  }\r
-\r
-  if ((Error == X509_V_ERR_CERT_UNTRUSTED) ||\r
-      (Error == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE)) {\r
-    Status = 1;\r
-  }\r
-\r
-  if (Obj != NULL) {\r
-    OPENSSL_free (Obj);\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
-  Syntax Standard, version 1.5". This interface is only intended to be used for\r
-  application to perform PKCS#7 functionality validation.\r
-\r
-  @param[in]  PrivateKey       Pointer to the PEM-formatted private key data for\r
-                               data signing.\r
-  @param[in]  PrivateKeySize   Size of the PEM private key data in bytes.\r
-  @param[in]  KeyPassword      NULL-terminated passphrase used for encrypted PEM\r
-                               key data.\r
-  @param[in]  InData           Pointer to the content to be signed.\r
-  @param[in]  InDataSize       Size of InData in bytes.\r
-  @param[in]  SignCert         Pointer to signer's DER-encoded certificate to sign with.\r
-  @param[in]  OtherCerts       Pointer to an optional additional set of certificates to\r
-                               include in the PKCS#7 signedData (e.g. any intermediate\r
-                               CAs in the chain).\r
-  @param[out] SignedData       Pointer to output PKCS#7 signedData.\r
-  @param[out] SignedDataSize   Size of SignedData in bytes.\r
-\r
-  @retval     TRUE             PKCS#7 data signing succeeded.\r
-  @retval     FALSE            PKCS#7 data signing failed.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-Pkcs7Sign (\r
-  IN   CONST UINT8  *PrivateKey,\r
-  IN   UINTN        PrivateKeySize,\r
-  IN   CONST UINT8  *KeyPassword,\r
-  IN   UINT8        *InData,\r
-  IN   UINTN        InDataSize,\r
-  IN   UINT8        *SignCert,\r
-  IN   UINT8        *OtherCerts      OPTIONAL,\r
-  OUT  UINT8        **SignedData,\r
-  OUT  UINTN        *SignedDataSize\r
-  )\r
-{\r
-  BOOLEAN   Status;\r
-  EVP_PKEY  *Key;\r
-  BIO       *DataBio;\r
-  PKCS7     *Pkcs7;\r
-  UINT8     *RsaContext;\r
-  UINT8     *P7Data;\r
-  UINTN     P7DataSize;\r
-  UINT8     *Tmp;\r
-\r
-  //\r
-  // Check input parameters.\r
-  //\r
-  if (PrivateKey == NULL || KeyPassword == NULL || InData == NULL ||\r
-    SignCert == NULL || SignedData == NULL || SignedDataSize == NULL || InDataSize > INT_MAX) {\r
-    return FALSE;\r
-  }\r
-\r
-  RsaContext = NULL;\r
-  Key        = NULL;\r
-  Pkcs7      = NULL;\r
-  DataBio    = NULL;\r
-  Status     = FALSE;\r
-\r
-  //\r
-  // Retrieve RSA private key from PEM data.\r
-  //\r
-  Status = RsaGetPrivateKeyFromPem (\r
-             PrivateKey,\r
-             PrivateKeySize,\r
-             (CONST CHAR8 *) KeyPassword,\r
-             (VOID **) &RsaContext\r
-             );\r
-  if (!Status) {\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // Register & Initialize necessary digest algorithms and PRNG for PKCS#7 Handling\r
-  //\r
-  EVP_add_digest (EVP_md5());\r
-  EVP_add_digest (EVP_sha1());\r
-  EVP_add_digest (EVP_sha256());\r
-  RandomSeed (NULL, 0);\r
-\r
-  //\r
-  // Construct OpenSSL EVP_PKEY for private key.\r
-  //\r
-  Key = EVP_PKEY_new ();\r
-  if (Key == NULL) {\r
-    Status = FALSE;\r
-    goto _Exit;\r
-  }\r
-  Key->save_type = EVP_PKEY_RSA;\r
-  Key->type      = EVP_PKEY_type (EVP_PKEY_RSA);\r
-  Key->pkey.rsa  = (RSA *) RsaContext;\r
-\r
-  //\r
-  // Convert the data to be signed to BIO format. \r
-  //\r
-  DataBio = BIO_new (BIO_s_mem ());\r
-  BIO_write (DataBio, InData, (int) InDataSize);\r
-\r
-  //\r
-  // Create the PKCS#7 signedData structure.\r
-  //\r
-  Pkcs7 = PKCS7_sign (\r
-            (X509 *) SignCert,\r
-            Key,\r
-            (STACK_OF(X509) *) OtherCerts,\r
-            DataBio,\r
-            PKCS7_BINARY | PKCS7_NOATTR | PKCS7_DETACHED\r
-            );\r
-  if (Pkcs7 == NULL) {\r
-    Status = FALSE;\r
-    goto _Exit;\r
-  }\r
-\r
-  //\r
-  // Convert PKCS#7 signedData structure into DER-encoded buffer.\r
-  //\r
-  P7DataSize = i2d_PKCS7 (Pkcs7, NULL);\r
-  if (P7DataSize <= 19) {\r
-    Status = FALSE;\r
-    goto _Exit;\r
-  }\r
-\r
-  P7Data     = malloc (P7DataSize);\r
-  if (P7Data == NULL) {\r
-    Status = FALSE;\r
-    goto _Exit;\r
-  }\r
-\r
-  Tmp        = P7Data;\r
-  P7DataSize = i2d_PKCS7 (Pkcs7, (unsigned char **) &Tmp);\r
-\r
-  //\r
-  // Strip ContentInfo to content only for signeddata. The data be trimmed off\r
-  // is totally 19 bytes.\r
-  //\r
-  *SignedDataSize = P7DataSize - 19;\r
-  *SignedData     = malloc (*SignedDataSize);\r
-  if (*SignedData == NULL) {\r
-    Status = FALSE;\r
-    OPENSSL_free (P7Data);\r
-    goto _Exit;\r
-  }\r
-\r
-  CopyMem (*SignedData, P7Data + 19, *SignedDataSize);\r
-  \r
-  OPENSSL_free (P7Data);\r
-\r
-  Status = TRUE;\r
-\r
-_Exit:\r
-  //\r
-  // Release Resources\r
-  //\r
-  if (RsaContext != NULL) {\r
-    RsaFree (RsaContext);\r
-    if (Key != NULL) {\r
-      Key->pkey.rsa = NULL;\r
-    }\r
-  }\r
-\r
-  if (Key != NULL) {\r
-    EVP_PKEY_free (Key);\r
-  }\r
-\r
-  if (DataBio != NULL) {\r
-    BIO_free (DataBio);\r
-  }\r
-\r
-  if (Pkcs7 != NULL) {\r
-    PKCS7_free (Pkcs7);\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Check input P7Data is a wrapped ContentInfo structure or not. If not construct\r
-  a new structure to wrap P7Data.\r
-\r
-  Caution: This function may receive untrusted input.\r
-  UEFI Authenticated Variable is external input, so this function will do basic\r
-  check for PKCS#7 data structure.\r
-\r
-  @param[in]  P7Data       Pointer to the PKCS#7 message to verify.\r
-  @param[in]  P7Length     Length of the PKCS#7 message in bytes.\r
-  @param[out] WrapFlag     If TRUE P7Data is a ContentInfo structure, otherwise\r
-                           return FALSE.\r
-  @param[out] WrapData     If return status of this function is TRUE: \r
-                           1) when WrapFlag is TRUE, pointer to P7Data.\r
-                           2) when WrapFlag is FALSE, pointer to a new ContentInfo\r
-                           structure. It's caller's responsibility to free this\r
-                           buffer.\r
-  @param[out] WrapDataSize Length of ContentInfo structure in bytes.\r
-\r
-  @retval     TRUE         The operation is finished successfully.\r
-  @retval     FALSE        The operation is failed due to lack of resources.\r
-\r
-**/\r
-BOOLEAN\r
-WrapPkcs7Data (\r
-  IN  CONST UINT8  *P7Data,\r
-  IN  UINTN        P7Length,\r
-  OUT BOOLEAN      *WrapFlag,\r
-  OUT UINT8        **WrapData,\r
-  OUT UINTN        *WrapDataSize\r
-  )\r
-{\r
-  BOOLEAN          Wrapped;\r
-  UINT8            *SignedData;\r
-\r
-  //\r
-  // Check whether input P7Data is a wrapped ContentInfo structure or not.\r
-  //\r
-  Wrapped = FALSE;\r
-  if ((P7Data[4] == 0x06) && (P7Data[5] == 0x09)) {\r
-    if (CompareMem (P7Data + 6, mOidValue, sizeof (mOidValue)) == 0) {\r
-      if ((P7Data[15] == 0xA0) && (P7Data[16] == 0x82)) {\r
-        Wrapped = TRUE;\r
-      }\r
-    }\r
-  }\r
-\r
-  if (Wrapped) {\r
-    *WrapData     = (UINT8 *) P7Data;\r
-    *WrapDataSize = P7Length;\r
-  } else {\r
-    //\r
-    // Wrap PKCS#7 signeddata to a ContentInfo structure - add a header in 19 bytes.\r
-    //\r
-    *WrapDataSize = P7Length + 19;\r
-    *WrapData     = malloc (*WrapDataSize);\r
-    if (*WrapData == NULL) {\r
-      *WrapFlag = Wrapped;\r
-      return FALSE;\r
-    }\r
-\r
-    SignedData = *WrapData;\r
-\r
-    //\r
-    // Part1: 0x30, 0x82.\r
-    //\r
-    SignedData[0] = 0x30;\r
-    SignedData[1] = 0x82;\r
-\r
-    //\r
-    // Part2: Length1 = P7Length + 19 - 4, in big endian.\r
-    //\r
-    SignedData[2] = (UINT8) (((UINT16) (*WrapDataSize - 4)) >> 8);\r
-    SignedData[3] = (UINT8) (((UINT16) (*WrapDataSize - 4)) & 0xff);\r
-\r
-    //\r
-    // Part3: 0x06, 0x09.\r
-    //\r
-    SignedData[4] = 0x06;\r
-    SignedData[5] = 0x09;\r
-\r
-    //\r
-    // Part4: OID value -- 0x2A 0x86 0x48 0x86 0xF7 0x0D 0x01 0x07 0x02.\r
-    //\r
-    CopyMem (SignedData + 6, mOidValue, sizeof (mOidValue));\r
-\r
-    //\r
-    // Part5: 0xA0, 0x82.\r
-    //\r
-    SignedData[15] = 0xA0;\r
-    SignedData[16] = 0x82;\r
-\r
-    //\r
-    // Part6: Length2 = P7Length, in big endian.\r
-    //\r
-    SignedData[17] = (UINT8) (((UINT16) P7Length) >> 8);\r
-    SignedData[18] = (UINT8) (((UINT16) P7Length) & 0xff);\r
-\r
-    //\r
-    // Part7: P7Data.\r
-    //\r
-    CopyMem (SignedData + 19, P7Data, P7Length);\r
-  }\r
-\r
-  *WrapFlag = Wrapped;\r
-  return TRUE;\r
-}\r
-\r
-/**\r
-  Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r
-  Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
-  in a ContentInfo structure.\r
-\r
-  If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r
-  return FALSE. If P7Length overflow, then return FAlSE.\r
-\r
-  Caution: This function may receive untrusted input.\r
-  UEFI Authenticated Variable is external input, so this function will do basic\r
-  check for PKCS#7 data structure.\r
-\r
-  @param[in]  P7Data       Pointer to the PKCS#7 message to verify.\r
-  @param[in]  P7Length     Length of the PKCS#7 message in bytes.\r
-  @param[out] CertStack    Pointer to Signer's certificates retrieved from P7Data.\r
-                           It's caller's responsiblity to free the buffer.\r
-  @param[out] StackLength  Length of signer's certificates in bytes.\r
-  @param[out] TrustedCert  Pointer to a trusted certificate from Signer's certificates.\r
-                           It's caller's responsiblity to free the buffer.\r
-  @param[out] CertLength   Length of the trusted certificate in bytes.\r
-\r
-  @retval  TRUE            The operation is finished successfully.\r
-  @retval  FALSE           Error occurs during the operation.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-Pkcs7GetSigners (\r
-  IN  CONST UINT8  *P7Data,\r
-  IN  UINTN        P7Length,\r
-  OUT UINT8        **CertStack,\r
-  OUT UINTN        *StackLength,\r
-  OUT UINT8        **TrustedCert,\r
-  OUT UINTN        *CertLength\r
-  )\r
-{\r
-  PKCS7            *Pkcs7;\r
-  BOOLEAN          Status;\r
-  UINT8            *SignedData;\r
-  UINT8            *Temp;\r
-  UINTN            SignedDataSize;\r
-  BOOLEAN          Wrapped;\r
-  STACK_OF(X509)   *Stack;\r
-  UINT8            Index;\r
-  UINT8            *CertBuf;\r
-  UINT8            *OldBuf;\r
-  UINTN            BufferSize;\r
-  UINTN            OldSize;\r
-  UINT8            *SingleCert;\r
-  UINTN            SingleCertSize;\r
-\r
-  if ((P7Data == NULL) || (CertStack == NULL) || (StackLength == NULL) ||\r
-      (TrustedCert == NULL) || (CertLength == NULL) || (P7Length > INT_MAX)) {\r
-    return FALSE;\r
-  }\r
-  \r
-  Status = WrapPkcs7Data (P7Data, P7Length, &Wrapped, &SignedData, &SignedDataSize);\r
-  if (!Status) {\r
-    return Status;\r
-  }\r
-\r
-  Status     = FALSE;\r
-  Pkcs7      = NULL;\r
-  Stack      = NULL;\r
-  CertBuf    = NULL;\r
-  OldBuf     = NULL;\r
-  SingleCert = NULL;\r
-\r
-  //\r
-  // Retrieve PKCS#7 Data (DER encoding)\r
-  //\r
-  if (SignedDataSize > INT_MAX) {\r
-    goto _Exit;\r
-  }\r
-\r
-  Temp = SignedData;\r
-  Pkcs7 = d2i_PKCS7 (NULL, (const unsigned char **) &Temp, (int) SignedDataSize);\r
-  if (Pkcs7 == NULL) {\r
-    goto _Exit;\r
-  }\r
-\r
-  //\r
-  // Check if it's PKCS#7 Signed Data (for Authenticode Scenario)\r
-  //\r
-  if (!PKCS7_type_is_signed (Pkcs7)) {\r
-    goto _Exit;\r
-  }\r
-\r
-  Stack = PKCS7_get0_signers(Pkcs7, NULL, PKCS7_BINARY);\r
-  if (Stack == NULL) {\r
-    goto _Exit;\r
-  }\r
-\r
-  //\r
-  // Convert CertStack to buffer in following format:\r
-  // UINT8  CertNumber;\r
-  // UINT32 Cert1Length;\r
-  // UINT8  Cert1[];\r
-  // UINT32 Cert2Length;\r
-  // UINT8  Cert2[];\r
-  // ...\r
-  // UINT32 CertnLength;\r
-  // UINT8  Certn[];\r
-  //\r
-  BufferSize = sizeof (UINT8);\r
-  OldSize    = BufferSize;\r
-  \r
-  for (Index = 0; ; Index++) {\r
-    Status = X509PopCertificate (Stack, &SingleCert, &SingleCertSize);\r
-    if (!Status) {\r
-      break;\r
-    }\r
-\r
-    OldSize    = BufferSize;\r
-    OldBuf     = CertBuf;\r
-    BufferSize = OldSize + SingleCertSize + sizeof (UINT32);\r
-    CertBuf    = malloc (BufferSize);\r
-\r
-    if (CertBuf == NULL) {\r
-      goto _Exit;\r
-    }\r
-\r
-    if (OldBuf != NULL) {\r
-      CopyMem (CertBuf, OldBuf, OldSize);\r
-      free (OldBuf);\r
-      OldBuf = NULL;\r
-    }\r
-\r
-    WriteUnaligned32 ((UINT32 *) (CertBuf + OldSize), (UINT32) SingleCertSize);\r
-    CopyMem (CertBuf + OldSize + sizeof (UINT32), SingleCert, SingleCertSize);\r
-\r
-    free (SingleCert);\r
-    SingleCert = NULL;\r
-  }\r
-\r
-  if (CertBuf != NULL) {\r
-    //\r
-    // Update CertNumber.\r
-    //\r
-    CertBuf[0] = Index;\r
-\r
-    *CertLength = BufferSize - OldSize - sizeof (UINT32);\r
-    *TrustedCert = malloc (*CertLength);\r
-    if (*TrustedCert == NULL) {\r
-      goto _Exit;\r
-    }\r
-\r
-    CopyMem (*TrustedCert, CertBuf + OldSize + sizeof (UINT32), *CertLength);\r
-    *CertStack   = CertBuf;\r
-    *StackLength = BufferSize;\r
-    Status = TRUE;\r
-  } \r
-\r
-_Exit:\r
-  //\r
-  // Release Resources\r
-  //\r
-  if (!Wrapped) {\r
-    free (SignedData);\r
-  }\r
-\r
-  if (Pkcs7 != NULL) {\r
-    PKCS7_free (Pkcs7);\r
-  }\r
-\r
-  if (Stack != NULL) {\r
-    sk_X509_pop_free(Stack, X509_free);\r
-  }\r
-\r
-  if (SingleCert !=  NULL) {\r
-    free (SingleCert);\r
-  }\r
-\r
-  if (!Status && (CertBuf != NULL)) {\r
-    free (CertBuf);\r
-    *CertStack = NULL;\r
-  }\r
-\r
-  if (OldBuf != NULL) {\r
-    free (OldBuf);\r
-  }\r
-  \r
-  return Status;\r
-}\r
-\r
-/**\r
-  Wrap function to use free() to free allocated memory for certificates.\r
-\r
-  @param[in]  Certs        Pointer to the certificates to be freed.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-Pkcs7FreeSigners (\r
-  IN  UINT8        *Certs\r
-  )\r
-{\r
-  if (Certs == NULL) {\r
-    return;\r
-  }\r
-\r
-  free (Certs);\r
-}\r
-\r
-/**\r
-  Verifies the validility of a PKCS#7 signed data as described in "PKCS #7:\r
-  Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
-  in a ContentInfo structure.\r
-\r
-  If P7Data, TrustedCert or InData is NULL, then return FALSE.\r
-  If P7Length, CertLength or DataLength overflow, then return FAlSE.\r
-\r
-  Caution: This function may receive untrusted input.\r
-  UEFI Authenticated Variable is external input, so this function will do basic\r
-  check for PKCS#7 data structure.\r
-\r
-  @param[in]  P7Data       Pointer to the PKCS#7 message to verify.\r
-  @param[in]  P7Length     Length of the PKCS#7 message in bytes.\r
-  @param[in]  TrustedCert  Pointer to a trusted/root certificate encoded in DER, which\r
-                           is used for certificate chain verification.\r
-  @param[in]  CertLength   Length of the trusted certificate in bytes.\r
-  @param[in]  InData       Pointer to the content to be verified.\r
-  @param[in]  DataLength   Length of InData in bytes.\r
-\r
-  @retval  TRUE  The specified PKCS#7 signed data is valid.\r
-  @retval  FALSE Invalid PKCS#7 signed data.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-Pkcs7Verify (\r
-  IN  CONST UINT8  *P7Data,\r
-  IN  UINTN        P7Length,\r
-  IN  CONST UINT8  *TrustedCert,\r
-  IN  UINTN        CertLength,\r
-  IN  CONST UINT8  *InData,\r
-  IN  UINTN        DataLength\r
-  )\r
-{\r
-  PKCS7       *Pkcs7;\r
-  BIO         *CertBio;\r
-  BIO         *DataBio;\r
-  BOOLEAN     Status;\r
-  X509        *Cert;\r
-  X509_STORE  *CertStore;\r
-  UINT8       *SignedData;\r
-  UINT8       *Temp;\r
-  UINTN       SignedDataSize;\r
-  BOOLEAN     Wrapped;\r
-\r
-  //\r
-  // Check input parameters.\r
-  //\r
-  if (P7Data == NULL || TrustedCert == NULL || InData == NULL || \r
-    P7Length > INT_MAX || CertLength > INT_MAX || DataLength > INT_MAX) {\r
-    return FALSE;\r
-  }\r
-  \r
-  Pkcs7     = NULL;\r
-  CertBio   = NULL;\r
-  DataBio   = NULL;\r
-  Cert      = NULL;\r
-  CertStore = NULL;\r
-\r
-  //\r
-  // Register & Initialize necessary digest algorithms for PKCS#7 Handling\r
-  //\r
-  EVP_add_digest (EVP_md5());\r
-  EVP_add_digest (EVP_sha1());\r
-  EVP_add_digest_alias (SN_sha1WithRSAEncryption, SN_sha1WithRSA);\r
-  EVP_add_digest (EVP_sha256());\r
-\r
-  Status = WrapPkcs7Data (P7Data, P7Length, &Wrapped, &SignedData, &SignedDataSize);\r
-  if (!Status) {\r
-    return Status;\r
-  }\r
-\r
-  Status = FALSE;\r
-  \r
-  //\r
-  // Retrieve PKCS#7 Data (DER encoding)\r
-  //\r
-  if (SignedDataSize > INT_MAX) {\r
-    goto _Exit;\r
-  }\r
-\r
-  Temp = SignedData;\r
-  Pkcs7 = d2i_PKCS7 (NULL, (const unsigned char **) &Temp, (int) SignedDataSize);\r
-  if (Pkcs7 == NULL) {\r
-    goto _Exit;\r
-  }\r
-\r
-  //\r
-  // Check if it's PKCS#7 Signed Data (for Authenticode Scenario)\r
-  //\r
-  if (!PKCS7_type_is_signed (Pkcs7)) {\r
-    goto _Exit;\r
-  }\r
-\r
-  //\r
-  // Read DER-encoded root certificate and Construct X509 Certificate\r
-  //\r
-  CertBio = BIO_new (BIO_s_mem ());\r
-  BIO_write (CertBio, TrustedCert, (int)CertLength);\r
-  if (CertBio == NULL) {\r
-    goto _Exit;\r
-  }\r
-  Cert = d2i_X509_bio (CertBio, NULL);\r
-  if (Cert == NULL) {\r
-    goto _Exit;\r
-  }\r
-\r
-  //\r
-  // Setup X509 Store for trusted certificate\r
-  //\r
-  CertStore = X509_STORE_new ();\r
-  if (CertStore == NULL) {\r
-    goto _Exit;\r
-  }\r
-  if (!(X509_STORE_add_cert (CertStore, Cert))) {\r
-    goto _Exit;\r
-  }\r
-\r
-  //\r
-  // Register customized X509 verification callback function to support\r
-  // trusted intermediate certificate anchor.\r
-  //\r
-  CertStore->verify_cb = X509VerifyCb;\r
-\r
-  //\r
-  // For generic PKCS#7 handling, InData may be NULL if the content is present\r
-  // in PKCS#7 structure. So ignore NULL checking here.\r
-  //\r
-  DataBio = BIO_new (BIO_s_mem ());\r
-  BIO_write (DataBio, InData, (int)DataLength);\r
-\r
-  //\r
-  // Verifies the PKCS#7 signedData structure\r
-  //\r
-  Status = (BOOLEAN) PKCS7_verify (Pkcs7, NULL, CertStore, DataBio, NULL, PKCS7_BINARY);\r
-\r
-_Exit:\r
-  //\r
-  // Release Resources\r
-  //\r
-  BIO_free (DataBio);\r
-  BIO_free (CertBio);\r
-  X509_free (Cert);\r
-  X509_STORE_free (CertStore);\r
-  PKCS7_free (Pkcs7);\r
-\r
-  if (!Wrapped) {\r
-    OPENSSL_free (SignedData);\r
-  }\r
-\r
-  return Status;\r
-}\r
index b275ab851ed192e1fc08c2f5cf1d19ef0a9cde6a..11472ebf3b27669186765d4038294352258216dd 100644 (file)
@@ -194,4 +194,3 @@ _Exit:
 \r
   return Status;\r
 }\r
-\r
diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptRsa.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptRsa.c
deleted file mode 100644 (file)
index 0483353..0000000
+++ /dev/null
@@ -1,722 +0,0 @@
-/** @file\r
-  RSA Asymmetric Cipher Wrapper Implementation over OpenSSL.\r
-\r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "InternalCryptLib.h"\r
-\r
-#include <openssl/rsa.h>\r
-#include <openssl/err.h>\r
-\r
-//\r
-// ASN.1 value for Hash Algorithm ID with the Distringuished Encoding Rules (DER)\r
-// Refer to Section 9.2 of PKCS#1 v2.1\r
-//                           \r
-CONST UINT8  Asn1IdMd5[] = {\r
-  0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,\r
-  0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10\r
-  };\r
-\r
-CONST UINT8  Asn1IdSha1[] = {\r
-  0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e,\r
-  0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14\r
-  };\r
-\r
-CONST UINT8  Asn1IdSha256[] = {\r
-  0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,\r
-  0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,\r
-  0x00, 0x04, 0x20\r
-  };\r
-\r
-\r
-/**\r
-  Allocates and initializes one RSA context for subsequent use.\r
-\r
-  @return  Pointer to the RSA context that has been initialized.\r
-           If the allocations fails, RsaNew() returns NULL.\r
-\r
-**/\r
-VOID *\r
-EFIAPI\r
-RsaNew (\r
-  VOID\r
-  )\r
-{\r
-  //\r
-  // Allocates & Initializes RSA Context by OpenSSL RSA_new()\r
-  //\r
-  return (VOID *)RSA_new ();\r
-}\r
-\r
-/**\r
-  Release the specified RSA context.\r
-\r
-  If RsaContext is NULL, then return FALSE.\r
-\r
-  @param[in]  RsaContext  Pointer to the RSA context to be released.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-RsaFree (\r
-  IN  VOID  *RsaContext\r
-  )\r
-{\r
-  //\r
-  // Free OpenSSL RSA Context\r
-  //\r
-  RSA_free ((RSA *)RsaContext);\r
-}\r
-\r
-/**\r
-  Sets the tag-designated key component into the established RSA context.\r
-\r
-  This function sets the tag-designated RSA key component into the established\r
-  RSA context from the user-specified non-negative integer (octet string format\r
-  represented in RSA PKCS#1).\r
-  If BigNumber is NULL, then the specified key componenet in RSA context is cleared.\r
-\r
-  If RsaContext is NULL, then return FALSE.\r
-\r
-  @param[in, out]  RsaContext  Pointer to RSA context being set.\r
-  @param[in]       KeyTag      Tag of RSA key component being set.\r
-  @param[in]       BigNumber   Pointer to octet integer buffer.\r
-                               If NULL, then the specified key componenet in RSA\r
-                               context is cleared.\r
-  @param[in]       BnSize      Size of big number buffer in bytes.\r
-                               If BigNumber is NULL, then it is ignored.\r
-\r
-  @retval  TRUE   RSA key component was set successfully.\r
-  @retval  FALSE  Invalid RSA key component tag.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RsaSetKey (\r
-  IN OUT  VOID         *RsaContext,\r
-  IN      RSA_KEY_TAG  KeyTag,\r
-  IN      CONST UINT8  *BigNumber,\r
-  IN      UINTN        BnSize\r
-  )\r
-{\r
-  RSA  *RsaKey;\r
-\r
-  //\r
-  // Check input parameters.\r
-  //\r
-  if (RsaContext == NULL) {\r
-    return FALSE;\r
-  }\r
-\r
-  RsaKey = (RSA *)RsaContext;\r
-  //\r
-  // Set RSA Key Components by converting octet string to OpenSSL BN representation.\r
-  // NOTE: For RSA public key (used in signature verification), only public components\r
-  //       (N, e) are needed.\r
-  //\r
-  switch (KeyTag) {\r
-\r
-  //\r
-  // RSA Public Modulus (N)\r
-  //\r
-  case RsaKeyN:\r
-    if (RsaKey->n != NULL) {\r
-      BN_free (RsaKey->n);\r
-    }\r
-    RsaKey->n = NULL;\r
-    if (BigNumber == NULL) {\r
-      break;\r
-    }\r
-    RsaKey->n = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->n);\r
-    break;\r
-\r
-  //\r
-  // RSA Public Exponent (e)\r
-  //\r
-  case RsaKeyE:\r
-    if (RsaKey->e != NULL) {\r
-      BN_free (RsaKey->e);\r
-    }\r
-    RsaKey->e = NULL;\r
-    if (BigNumber == NULL) {\r
-      break;\r
-    }\r
-    RsaKey->e = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->e);\r
-    break;\r
-\r
-  //\r
-  // RSA Private Exponent (d)\r
-  //\r
-  case RsaKeyD:\r
-    if (RsaKey->d != NULL) {\r
-      BN_free (RsaKey->d);\r
-    }\r
-    RsaKey->d = NULL;\r
-    if (BigNumber == NULL) {\r
-      break;\r
-    }\r
-    RsaKey->d = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->d);\r
-    break;\r
-\r
-  //\r
-  // RSA Secret Prime Factor of Modulus (p)\r
-  //\r
-  case RsaKeyP:\r
-    if (RsaKey->p != NULL) {\r
-      BN_free (RsaKey->p);\r
-    }\r
-    RsaKey->p = NULL;\r
-    if (BigNumber == NULL) {\r
-      break;\r
-    }\r
-    RsaKey->p = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->p);\r
-    break;\r
-\r
-  //\r
-  // RSA Secret Prime Factor of Modules (q)\r
-  //\r
-  case RsaKeyQ:\r
-    if (RsaKey->q != NULL) {\r
-      BN_free (RsaKey->q);\r
-    }\r
-    RsaKey->q = NULL;\r
-    if (BigNumber == NULL) {\r
-      break;\r
-    }\r
-    RsaKey->q = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->q);\r
-    break;\r
-\r
-  //\r
-  // p's CRT Exponent (== d mod (p - 1))\r
-  //\r
-  case RsaKeyDp:\r
-    if (RsaKey->dmp1 != NULL) {\r
-      BN_free (RsaKey->dmp1);\r
-    }\r
-    RsaKey->dmp1 = NULL;\r
-    if (BigNumber == NULL) {\r
-      break;\r
-    }\r
-    RsaKey->dmp1 = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->dmp1);\r
-    break;\r
-\r
-  //\r
-  // q's CRT Exponent (== d mod (q - 1))\r
-  //\r
-  case RsaKeyDq:\r
-    if (RsaKey->dmq1 != NULL) {\r
-      BN_free (RsaKey->dmq1);\r
-    }\r
-    RsaKey->dmq1 = NULL;\r
-    if (BigNumber == NULL) {\r
-      break;\r
-    }\r
-    RsaKey->dmq1 = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->dmq1);\r
-    break;\r
-\r
-  //\r
-  // The CRT Coefficient (== 1/q mod p)\r
-  //\r
-  case RsaKeyQInv:\r
-    if (RsaKey->iqmp != NULL) {\r
-      BN_free (RsaKey->iqmp);\r
-    }\r
-    RsaKey->iqmp = NULL;\r
-    if (BigNumber == NULL) {\r
-      break;\r
-    }\r
-    RsaKey->iqmp = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->iqmp);\r
-    break;\r
-\r
-  default:\r
-    return FALSE;\r
-  }\r
-\r
-  return TRUE;\r
-}\r
-\r
-/**\r
-  Gets the tag-designated RSA key component from the established RSA context.\r
-\r
-  This function retrieves the tag-designated RSA key component from the\r
-  established RSA context as a non-negative integer (octet string format\r
-  represented in RSA PKCS#1).\r
-  If specified key component has not been set or has been cleared, then returned\r
-  BnSize is set to 0.\r
-  If the BigNumber buffer is too small to hold the contents of the key, FALSE\r
-  is returned and BnSize is set to the required buffer size to obtain the key.\r
-\r
-  If RsaContext is NULL, then return FALSE.\r
-  If BnSize is NULL, then return FALSE.\r
-  If BnSize is large enough but BigNumber is NULL, then return FALSE.\r
-\r
-  @param[in, out]  RsaContext  Pointer to RSA context being set.\r
-  @param[in]       KeyTag      Tag of RSA key component being set.\r
-  @param[out]      BigNumber   Pointer to octet integer buffer.\r
-  @param[in, out]  BnSize      On input, the size of big number buffer in bytes.\r
-                               On output, the size of data returned in big number buffer in bytes.\r
-\r
-  @retval  TRUE   RSA key component was retrieved successfully.\r
-  @retval  FALSE  Invalid RSA key component tag.\r
-  @retval  FALSE  BnSize is too small.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RsaGetKey (\r
-  IN OUT  VOID         *RsaContext,\r
-  IN      RSA_KEY_TAG  KeyTag,\r
-  OUT     UINT8        *BigNumber,\r
-  IN OUT  UINTN        *BnSize\r
-  )\r
-{\r
-  RSA    *RsaKey;\r
-  BIGNUM *BnKey;\r
-  UINTN  Size;\r
-\r
-  //\r
-  // Check input parameters.\r
-  //\r
-  if (RsaContext == NULL || BnSize == NULL) {\r
-    return FALSE;\r
-  }\r
-\r
-  RsaKey  = (RSA *) RsaContext;\r
-  Size    = *BnSize;\r
-  *BnSize = 0;\r
-\r
-  switch (KeyTag) {\r
-\r
-  //\r
-  // RSA Public Modulus (N)\r
-  //\r
-  case RsaKeyN:\r
-    if (RsaKey->n == NULL) {\r
-      return TRUE;\r
-    }\r
-    BnKey = RsaKey->n;\r
-    break;\r
-\r
-  //\r
-  // RSA Public Exponent (e)\r
-  //\r
-  case RsaKeyE:\r
-    if (RsaKey->e == NULL) {\r
-      return TRUE;\r
-    }\r
-    BnKey = RsaKey->e;\r
-    break;\r
-\r
-  //\r
-  // RSA Private Exponent (d)\r
-  //\r
-  case RsaKeyD:\r
-    if (RsaKey->d == NULL) {\r
-      return TRUE;\r
-    }\r
-    BnKey = RsaKey->d;\r
-    break;\r
-\r
-  //\r
-  // RSA Secret Prime Factor of Modulus (p)\r
-  //\r
-  case RsaKeyP:\r
-    if (RsaKey->p == NULL) {\r
-      return TRUE;\r
-    }\r
-    BnKey = RsaKey->p;\r
-    break;\r
-\r
-  //\r
-  // RSA Secret Prime Factor of Modules (q)\r
-  //\r
-  case RsaKeyQ:\r
-    if (RsaKey->q == NULL) {\r
-      return TRUE;\r
-    }\r
-    BnKey = RsaKey->q;\r
-    break;\r
-\r
-  //\r
-  // p's CRT Exponent (== d mod (p - 1))\r
-  //\r
-  case RsaKeyDp:\r
-    if (RsaKey->dmp1 == NULL) {\r
-      return TRUE;\r
-    }\r
-    BnKey = RsaKey->dmp1;\r
-    break;\r
-\r
-  //\r
-  // q's CRT Exponent (== d mod (q - 1))\r
-  //\r
-  case RsaKeyDq:\r
-    if (RsaKey->dmq1 == NULL) {\r
-      return TRUE;\r
-    }\r
-    BnKey = RsaKey->dmq1;\r
-    break;\r
-\r
-  //\r
-  // The CRT Coefficient (== 1/q mod p)\r
-  //\r
-  case RsaKeyQInv:\r
-    if (RsaKey->iqmp == NULL) {\r
-      return TRUE;\r
-    }\r
-    BnKey = RsaKey->iqmp;\r
-    break;\r
-\r
-  default:\r
-    return FALSE;\r
-  }\r
-\r
-  *BnSize = Size;\r
-  Size    = BN_num_bytes (BnKey);\r
-\r
-  if (*BnSize < Size) {\r
-    *BnSize = Size;\r
-    return FALSE;\r
-  }\r
-\r
-  if (BigNumber == NULL) {\r
-    return FALSE;\r
-  }\r
-  *BnSize = BN_bn2bin (BnKey, BigNumber) ;\r
-  \r
-  return TRUE;\r
-}\r
-\r
-/**\r
-  Generates RSA key components.\r
-\r
-  This function generates RSA key components. It takes RSA public exponent E and\r
-  length in bits of RSA modulus N as input, and generates all key components.\r
-  If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r
-\r
-  Before this function can be invoked, pseudorandom number generator must be correctly\r
-  initialized by RandomSeed().\r
-\r
-  If RsaContext is NULL, then return FALSE.\r
-\r
-  @param[in, out]  RsaContext           Pointer to RSA context being set.\r
-  @param[in]       ModulusLength        Length of RSA modulus N in bits.\r
-  @param[in]       PublicExponent       Pointer to RSA public exponent.\r
-  @param[in]       PublicExponentSize   Size of RSA public exponent buffer in bytes. \r
-\r
-  @retval  TRUE   RSA key component was generated successfully.\r
-  @retval  FALSE  Invalid RSA key component tag.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RsaGenerateKey (\r
-  IN OUT  VOID         *RsaContext,\r
-  IN      UINTN        ModulusLength,\r
-  IN      CONST UINT8  *PublicExponent,\r
-  IN      UINTN        PublicExponentSize\r
-  )\r
-{\r
-  BIGNUM   *KeyE;\r
-  BOOLEAN  RetVal;\r
-\r
-  //\r
-  // Check input parameters.\r
-  //\r
-  if (RsaContext == NULL) {\r
-    return FALSE;\r
-  }\r
-  \r
-  KeyE = BN_new ();\r
-  if (PublicExponent == NULL) {\r
-    BN_set_word (KeyE, 0x10001);\r
-  } else {\r
-    BN_bin2bn (PublicExponent, (UINT32) PublicExponentSize, KeyE);\r
-  }\r
-\r
-  RetVal = FALSE;\r
-  if (RSA_generate_key_ex ((RSA *) RsaContext, (UINT32) ModulusLength, KeyE, NULL) == 1) {\r
-   RetVal = TRUE;\r
-  }\r
-\r
-  BN_free (KeyE);\r
-  return RetVal;\r
-}\r
-\r
-/**\r
-  Validates key components of RSA context.\r
-\r
-  This function validates key compoents of RSA context in following aspects:\r
-  - Whether p is a prime\r
-  - Whether q is a prime\r
-  - Whether n = p * q\r
-  - Whether d*e = 1  mod lcm(p-1,q-1)\r
-\r
-  If RsaContext is NULL, then return FALSE.\r
-\r
-  @param[in]  RsaContext  Pointer to RSA context to check.\r
-\r
-  @retval  TRUE   RSA key components are valid.\r
-  @retval  FALSE  RSA key components are not valid.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RsaCheckKey (\r
-  IN  VOID  *RsaContext\r
-  )\r
-{\r
-  UINTN  Reason;\r
-\r
-  //\r
-  // Check input parameters.\r
-  //\r
-  if (RsaContext == NULL) {\r
-    return FALSE;\r
-  }\r
-  \r
-  if  (RSA_check_key ((RSA *) RsaContext) != 1) {\r
-    Reason = ERR_GET_REASON (ERR_peek_last_error ());\r
-    if (Reason == RSA_R_P_NOT_PRIME ||\r
-        Reason == RSA_R_Q_NOT_PRIME ||\r
-        Reason == RSA_R_N_DOES_NOT_EQUAL_P_Q ||\r
-        Reason == RSA_R_D_E_NOT_CONGRUENT_TO_1) {\r
-      return FALSE;\r
-    }\r
-  }\r
-\r
-  return TRUE;\r
-}\r
-\r
-/**\r
-  Performs the PKCS1-v1_5 encoding methods defined in RSA PKCS #1.\r
-\r
-  @param  Message      Message buffer to be encoded.\r
-  @param  MessageSize  Size of message buffer in bytes.\r
-  @param  DigestInfo   Pointer to buffer of digest info for output.\r
-\r
-  @return  Size of DigestInfo in bytes.\r
-\r
-**/  \r
-UINTN\r
-DigestInfoEncoding (\r
-  IN   CONST UINT8  *Message,\r
-  IN   UINTN        MessageSize,\r
-  OUT  UINT8        *DigestInfo\r
-  )\r
-{\r
-  CONST UINT8  *HashDer;\r
-  UINTN        DerSize;\r
-\r
-  //\r
-  // Check input parameters.\r
-  //\r
-  if (Message == NULL || DigestInfo == NULL) {\r
-    return FALSE;\r
-  }\r
-\r
-  //\r
-  // The original message length is used to determine the hash algorithm since\r
-  // message is digest value hashed by the specified algorithm.\r
-  //\r
-  switch (MessageSize) {\r
-  case MD5_DIGEST_SIZE:\r
-    HashDer = Asn1IdMd5;\r
-    DerSize = sizeof (Asn1IdMd5);\r
-    break;\r
-  \r
-  case SHA1_DIGEST_SIZE:\r
-    HashDer = Asn1IdSha1;\r
-    DerSize = sizeof (Asn1IdSha1);\r
-    break;\r
-   \r
-  case SHA256_DIGEST_SIZE:\r
-    HashDer = Asn1IdSha256;\r
-    DerSize = sizeof (Asn1IdSha256);\r
-    break;\r
-  \r
-  default:\r
-    return FALSE;\r
-  }\r
-\r
-  CopyMem (DigestInfo, HashDer, DerSize);\r
-  CopyMem (DigestInfo + DerSize, Message, MessageSize);\r
-\r
-  return (DerSize + MessageSize);\r
-}\r
-\r
-/**\r
-  Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r
-\r
-  This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r
-  RSA PKCS#1.\r
-  If the Signature buffer is too small to hold the contents of signature, FALSE\r
-  is returned and SigSize is set to the required buffer size to obtain the signature.\r
-\r
-  If RsaContext is NULL, then return FALSE.\r
-  If MessageHash is NULL, then return FALSE.\r
-  If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r
-  If SigSize is large enough but Signature is NULL, then return FALSE.\r
-\r
-  @param[in]       RsaContext   Pointer to RSA context for signature generation.\r
-  @param[in]       MessageHash  Pointer to octet message hash to be signed.\r
-  @param[in]       HashSize     Size of the message hash in bytes.\r
-  @param[out]      Signature    Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
-  @param[in, out]  SigSize      On input, the size of Signature buffer in bytes.\r
-                                On output, the size of data returned in Signature buffer in bytes.\r
-\r
-  @retval  TRUE   Signature successfully generated in PKCS1-v1_5.\r
-  @retval  FALSE  Signature generation failed.\r
-  @retval  FALSE  SigSize is too small.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RsaPkcs1Sign (\r
-  IN      VOID         *RsaContext,\r
-  IN      CONST UINT8  *MessageHash,\r
-  IN      UINTN        HashSize,\r
-  OUT     UINT8        *Signature,\r
-  IN OUT  UINTN        *SigSize\r
-  )\r
-{\r
-  RSA      *Rsa;\r
-  UINTN    Size;\r
-  INTN     ReturnVal;\r
-\r
-  //\r
-  // Check input parameters.\r
-  //\r
-  if (RsaContext == NULL || MessageHash == NULL ||\r
-    (HashSize != MD5_DIGEST_SIZE && HashSize != SHA1_DIGEST_SIZE && HashSize != SHA256_DIGEST_SIZE)) {\r
-    return FALSE;\r
-  }\r
-\r
-  Rsa = (RSA *) RsaContext;\r
-  Size = BN_num_bytes (Rsa->n);\r
-\r
-  if (*SigSize < Size) {\r
-    *SigSize = Size;\r
-    return FALSE;\r
-  }\r
-\r
-  if (Signature == NULL) {\r
-    return FALSE;\r
-  }\r
-\r
-  Size = DigestInfoEncoding (MessageHash, HashSize, Signature);\r
-\r
-  ReturnVal = RSA_private_encrypt (\r
-                (UINT32) Size,\r
-                Signature,\r
-                Signature,\r
-                Rsa,\r
-                RSA_PKCS1_PADDING\r
-                );\r
-\r
-  if (ReturnVal < (INTN) Size) {\r
-    return FALSE;\r
-  }\r
-\r
-  *SigSize = (UINTN)ReturnVal;\r
-  return TRUE;\r
-}\r
-\r
-/**\r
-  Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r
-  RSA PKCS#1.\r
-\r
-  If RsaContext is NULL, then return FALSE.\r
-  If MessageHash is NULL, then return FALSE.\r
-  If Signature is NULL, then return FALSE.\r
-  If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r
-\r
-  @param[in]  RsaContext   Pointer to RSA context for signature verification.\r
-  @param[in]  MessageHash  Pointer to octet message hash to be checked.\r
-  @param[in]  HashSize     Size of the message hash in bytes.\r
-  @param[in]  Signature    Pointer to RSA PKCS1-v1_5 signature to be verified.\r
-  @param[in]  SigSize      Size of signature in bytes.\r
-\r
-  @retval  TRUE   Valid signature encoded in PKCS1-v1_5.\r
-  @retval  FALSE  Invalid signature or invalid RSA context.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RsaPkcs1Verify (\r
-  IN  VOID         *RsaContext,\r
-  IN  CONST UINT8  *MessageHash,\r
-  IN  UINTN        HashSize,\r
-  IN  UINT8        *Signature,\r
-  IN  UINTN        SigSize\r
-  )\r
-{\r
-  INTN     Length;\r
-\r
-  //\r
-  // Check input parameters.\r
-  //\r
-  if (RsaContext == NULL || MessageHash == NULL || Signature == NULL) {\r
-    return FALSE;\r
-  }\r
-\r
-  \r
-  //\r
-  // Check for unsupported hash size:\r
-  //    Only MD5, SHA-1 or SHA-256 digest size is supported\r
-  //\r
-  if (HashSize != MD5_DIGEST_SIZE && HashSize != SHA1_DIGEST_SIZE && HashSize != SHA256_DIGEST_SIZE) {\r
-    return FALSE;\r
-  }\r
-  \r
-  //\r
-  // RSA PKCS#1 Signature Decoding using OpenSSL RSA Decryption with Public Key\r
-  //\r
-  Length = RSA_public_decrypt (\r
-             (UINT32) SigSize,\r
-             Signature,\r
-             Signature,\r
-             RsaContext,\r
-             RSA_PKCS1_PADDING\r
-             );\r
-\r
-  //\r
-  // Invalid RSA Key or PKCS#1 Padding Checking Failed (if Length < 0)\r
-  // NOTE: Length should be the addition of HashSize and some DER value.\r
-  //       Ignore more strict length checking here.\r
-  //\r
-  if (Length < (INTN) HashSize) {\r
-    return FALSE;\r
-  }\r
-\r
-  //\r
-  // Validate the MessageHash and Decoded Signature\r
-  // NOTE: The decoded Signature should be the DER encoding of the DigestInfo value\r
-  //       DigestInfo ::= SEQUENCE {\r
-  //           digestAlgorithm AlgorithmIdentifier\r
-  //           digest OCTET STRING\r
-  //       }\r
-  //       Then Memory Comparing should skip the DER value of the underlying SEQUENCE\r
-  //       type and AlgorithmIdentifier.\r
-  //\r
-  if (CompareMem (MessageHash, Signature + Length - HashSize, HashSize) == 0) {\r
-    //\r
-    // Valid RSA PKCS#1 Signature\r
-    //\r
-    return TRUE;\r
-  } else {\r
-    //\r
-    // Failed to verification\r
-    //\r
-    return FALSE;\r
-  }\r
-}\r
index 6bf95deb589c95ac7e01844d11bef7a8efceb7c0..d828cb4b3f309b9899482fc819eba6ca1aa74305 100644 (file)
@@ -40,7 +40,7 @@ RsaNew (
   //\r
   // Allocates & Initializes RSA Context by OpenSSL RSA_new()\r
   //\r
-  return (VOID *)RSA_new ();\r
+  return (VOID *) RSA_new ();\r
 }\r
 \r
 /**\r
@@ -58,7 +58,7 @@ RsaFree (
   //\r
   // Free OpenSSL RSA Context\r
   //\r
-  RSA_free ((RSA *)RsaContext);\r
+  RSA_free ((RSA *) RsaContext);\r
 }\r
 \r
 /**\r
@@ -101,7 +101,7 @@ RsaSetKey (
     return FALSE;\r
   }\r
 \r
-  RsaKey = (RSA *)RsaContext;\r
+  RsaKey = (RSA *) RsaContext;\r
   //\r
   // Set RSA Key Components by converting octet string to OpenSSL BN representation.\r
   // NOTE: For RSA public key (used in signature verification), only public components\r
index a0c5a2a78efc3748863a4a1a8e383a54fc26cddd..f90600473a0db474166522f974d86d951a081b77 100644 (file)
@@ -367,7 +367,7 @@ X509GetSubjectName (
   }\r
   *SubjectSize = (UINTN) X509Name->bytes->length;\r
   if (CertSubject != NULL) {\r
-    CopyMem (CertSubject, (UINT8 *)X509Name->bytes->data, *SubjectSize);\r
+    CopyMem (CertSubject, (UINT8 *) X509Name->bytes->data, *SubjectSize);\r
     Status = TRUE;\r
   }\r
 \r
index 68bc25aba65c571df23530559c9988f831a66946..544f07215b8f1b5dbdd89a1a233b822cf3634aae 100644 (file)
@@ -2,7 +2,7 @@
   Base Memory Allocation Routines Wrapper for Crypto library over OpenSSL\r
   during PEI & DXE phases.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -22,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 /* Allocates memory blocks */\r
 void *malloc (size_t size)\r
 {\r
-  return AllocatePool ((UINTN)size);\r
+  return AllocatePool ((UINTN) size);\r
 }\r
 \r
 /* Reallocate memory blocks */\r
@@ -32,7 +32,7 @@ void *realloc (void *ptr, size_t size)
   // BUG: hardcode OldSize == size! We have no any knowledge about\r
   // memory size of original pointer ptr.\r
   //\r
-  return ReallocatePool ((UINTN)size, (UINTN)size, ptr);\r
+  return ReallocatePool ((UINTN) size, (UINTN) size, ptr);\r
 }\r
 \r
 /* De-allocates or frees a memory block */\r
index 0761e46e15f3df1c34f4c47d1a4c18e179742ad6..79bb0678e376121a56cf43186609d7a20a55b602 100644 (file)
@@ -2,7 +2,7 @@
   Light-weight Memory Management Routines for OpenSSL-based Crypto\r
   Library at Runtime Phase.\r
 \r
-Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -385,7 +385,7 @@ RuntimeCryptLibConstructor (
 /* Allocates memory blocks */\r
 void *malloc (size_t size)\r
 {\r
-  return RuntimeAllocateMem ((UINTN)size);\r
+  return RuntimeAllocateMem ((UINTN) size);\r
 }\r
 \r
 /* Reallocate memory blocks */\r
index 8ef2d4182aa58f4e23021bd9152fdbeb59d58f32..2fb9074755f395eef3c8022255d74466f7ee7794 100644 (file)
@@ -37,7 +37,7 @@
 \r
 [Sources]\r
   RuntimeDxeIpfCryptLib.c\r
-\r
+  InternalCryptLib.h\r
   Hash/CryptMd4Null.c\r
   Hash/CryptMd5Null.c\r
   Hash/CryptSha1Null.c\r