summary refs log tree commit diff
diff options
context:
space:
mode:
authorTriton Circonflexe <triton@kumal.info>2023-07-21 21:18:16 +0200
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-01-28 20:49:15 +0700
commit80222f90aa8e001748a1367c058af3cd2adf1176 (patch)
tree81ee081e8cb6c0cc76629bb41b961f7845ea32e6
parentRefactoring (diff)
downloadBouncyCastle.NET-ed25519-80222f90aa8e001748a1367c058af3cd2adf1176.tar.xz
Fix NullReferenceException in PbeUtilities
Add support for SHA-384 and SHA-512 HMAC algorithms as they already
exist in the field.

Throw a proper SecurityUtilityException when the HMAC algorithm is not
handled.
-rw-r--r--crypto/src/security/PbeUtilities.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crypto/src/security/PbeUtilities.cs b/crypto/src/security/PbeUtilities.cs
index 4121ddd7d..74fda8ce8 100644
--- a/crypto/src/security/PbeUtilities.cs
+++ b/crypto/src/security/PbeUtilities.cs
@@ -131,6 +131,12 @@ namespace Org.BouncyCastle.Security
             Algorithms["PBEWITHHMACSHA256"] = "PBEwithHmacSHA-256";
             Algorithms["PBEWITHHMACSHA-256"] = "PBEwithHmacSHA-256";
             Algorithms[NistObjectIdentifiers.IdSha256.Id] = "PBEwithHmacSHA-256";
+            Algorithms["PBEWITHHMACSHA384"] = "PBEwithHmacSHA-384";
+            Algorithms["PBEWITHHMACSHA-384"] = "PBEwithHmacSHA-384";
+            Algorithms[NistObjectIdentifiers.IdSha384.Id] = "PBEwithHmacSHA-384";
+            Algorithms["PBEWITHHMACSHA512"] = "PBEwithHmacSHA-512";
+            Algorithms["PBEWITHHMACSHA-512"] = "PBEwithHmacSHA-512";
+            Algorithms[NistObjectIdentifiers.IdSha512.Id] = "PBEwithHmacSHA-512";
             Algorithms["PBEWITHHMACRIPEMD128"] = "PBEwithHmacRipeMD128";
             Algorithms[TeleTrusTObjectIdentifiers.RipeMD128.Id] = "PBEwithHmacRipeMD128";
             Algorithms["PBEWITHHMACRIPEMD160"] = "PBEwithHmacRipeMD160";
@@ -169,6 +175,8 @@ namespace Org.BouncyCastle.Security
             AlgorithmType["PBEwithHmacSHA-1"] = Pkcs12;
             AlgorithmType["PBEwithHmacSHA-224"] = Pkcs12;
             AlgorithmType["PBEwithHmacSHA-256"] = Pkcs12;
+            AlgorithmType["PBEwithHmacSHA-384"] = Pkcs12;
+            AlgorithmType["PBEwithHmacSHA-512"] = Pkcs12;
             AlgorithmType["PBEwithHmacRipeMD128"] = Pkcs12;
             AlgorithmType["PBEwithHmacRipeMD160"] = Pkcs12;
             AlgorithmType["PBEwithHmacRipeMD256"] = Pkcs12;
@@ -193,6 +201,8 @@ namespace Org.BouncyCastle.Security
             Oids["PBEwithHmacSHA-1"] = OiwObjectIdentifiers.IdSha1;
             Oids["PBEwithHmacSHA-224"] = NistObjectIdentifiers.IdSha224;
             Oids["PBEwithHmacSHA-256"] = NistObjectIdentifiers.IdSha256;
+            Oids["PBEwithHmacSHA-384"] = NistObjectIdentifiers.IdSha384;
+            Oids["PBEwithHmacSHA-512"] = NistObjectIdentifiers.IdSha512;
             Oids["PBEwithHmacRipeMD128"] = TeleTrusTObjectIdentifiers.RipeMD128;
             Oids["PBEwithHmacRipeMD160"] = TeleTrusTObjectIdentifiers.RipeMD160;
             Oids["PBEwithHmacRipeMD256"] = TeleTrusTObjectIdentifiers.RipeMD256;
@@ -401,7 +411,15 @@ namespace Org.BouncyCastle.Security
             bool			wrongPkcs12Zero,
             Asn1Encodable   pbeParameters)
         {
+            if (algorithm == null)
+            {
+                throw new ArgumentNullException(nameof(algorithm));
+            }
             string mechanism = CollectionUtilities.GetValueOrNull(Algorithms, algorithm);
+            if (mechanism == null)
+            {
+                throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
+            }
 
             byte[] keyBytes = null;
             byte[] salt = null;