/** @file\r
PEM (Privacy Enhanced Mail) Format Handler Wrapper Implementation over OpenSSL.\r
\r
-Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 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
{\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
RSA private key component. Use RsaFree() function to free the\r
resource.\r
\r
- If PemData is NULL, then ASSERT().\r
- If RsaContext is NULL, then ASSERT().\r
+ If PemData is NULL, then return FALSE.\r
+ If RsaContext is NULL, then return FALSE.\r
\r
@retval TRUE RSA Private Key was retrieved successfully.\r
@retval FALSE Invalid PEM key data or incorrect password.\r
BIO *PemBio;\r
\r
//\r
- // ASSERT if PemData is NULL or RsaContext is NULL.\r
+ // Check input parameters.\r
//\r
- ASSERT (PemData != NULL);\r
- ASSERT (RsaContext != NULL);\r
-\r
- if (PemSize > INT_MAX) {\r
+ if (PemData == NULL || RsaContext == NULL || PemSize > INT_MAX) {\r
return FALSE;\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
+ 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
//\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