]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaBasic.c
Fix several issues in BaseCryptLib:
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Pk / CryptRsaBasic.c
index 6bf95deb589c95ac7e01844d11bef7a8efceb7c0..76754b4a72f0a2800fe88ae637c63893821b7e19 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
@@ -97,11 +97,11 @@ RsaSetKey (
   //\r
   // Check input parameters.\r
   //\r
-  if (RsaContext == NULL) {\r
+  if (RsaContext == NULL || BnSize > INT_MAX) {\r
     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
@@ -121,6 +121,10 @@ RsaSetKey (
       break;\r
     }\r
     RsaKey->n = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->n);\r
+    if (RsaKey->n == NULL) {\r
+      return FALSE;\r
+    }\r
+\r
     break;\r
 \r
   //\r
@@ -135,6 +139,10 @@ RsaSetKey (
       break;\r
     }\r
     RsaKey->e = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->e);\r
+    if (RsaKey->e == NULL) {\r
+      return FALSE;\r
+    }\r
+\r
     break;\r
 \r
   //\r
@@ -149,6 +157,10 @@ RsaSetKey (
       break;\r
     }\r
     RsaKey->d = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->d);\r
+    if (RsaKey->d == NULL) {\r
+      return FALSE;\r
+    }\r
+\r
     break;\r
 \r
   //\r
@@ -163,6 +175,10 @@ RsaSetKey (
       break;\r
     }\r
     RsaKey->p = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->p);\r
+    if (RsaKey->p == NULL) {\r
+      return FALSE;\r
+    }\r
+\r
     break;\r
 \r
   //\r
@@ -177,6 +193,10 @@ RsaSetKey (
       break;\r
     }\r
     RsaKey->q = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->q);\r
+    if (RsaKey->q == NULL) {\r
+      return FALSE;\r
+    }\r
+\r
     break;\r
 \r
   //\r
@@ -191,6 +211,10 @@ RsaSetKey (
       break;\r
     }\r
     RsaKey->dmp1 = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->dmp1);\r
+    if (RsaKey->dmp1 == NULL) {\r
+      return FALSE;\r
+    }\r
+\r
     break;\r
 \r
   //\r
@@ -205,6 +229,10 @@ RsaSetKey (
       break;\r
     }\r
     RsaKey->dmq1 = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->dmq1);\r
+    if (RsaKey->dmq1 == NULL) {\r
+      return FALSE;\r
+    }\r
+\r
     break;\r
 \r
   //\r
@@ -219,6 +247,10 @@ RsaSetKey (
       break;\r
     }\r
     RsaKey->iqmp = BN_bin2bn (BigNumber, (UINT32) BnSize, RsaKey->iqmp);\r
+    if (RsaKey->iqmp == NULL) {\r
+      return FALSE;\r
+    }\r
+\r
     break;\r
 \r
   default:\r
@@ -262,7 +294,7 @@ RsaPkcs1Verify (
   //\r
   // Check input parameters.\r
   //\r
-  if (RsaContext == NULL || MessageHash == NULL || Signature == NULL) {\r
+  if (RsaContext == NULL || MessageHash == NULL || Signature == NULL || SigSize > INT_MAX) {\r
     return FALSE;\r
   }\r
 \r