]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c
Fix several issues in BaseCryptLib:
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Pem / CryptPem.c
index 2c3a97b2c0f91539d5e3113e96cf9b0fd65ce4d2..078a960d5848e7084ec7516329da7e1da0508c1b 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
@@ -86,23 +86,30 @@ RsaGetPrivateKeyFromPem (
     return FALSE;\r
   }\r
 \r
-  Status = FALSE;\r
-  PemBio = NULL;\r
-\r
   //\r
   // 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
+  if (EVP_add_cipher (EVP_des_ede3_cbc ()) == 0) {\r
+    return FALSE;\r
+  }\r
+  if (EVP_add_cipher (EVP_aes_128_cbc ()) == 0) {\r
+    return FALSE;\r
+  }\r
+  if (EVP_add_cipher (EVP_aes_192_cbc ()) == 0) {\r
+    return FALSE;\r
+  }\r
+  if (EVP_add_cipher (EVP_aes_256_cbc ()) == 0) {\r
+    return FALSE;\r
+  }\r
+\r
+  Status = FALSE;\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 +117,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