summary refs log tree commit diff
path: root/crypto/src/x509
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-07-28 20:13:02 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-07-28 20:13:02 +0700
commita375c08770711d4265a1606baae162c185ef916f (patch)
tree4ddb6a00add42ab5249d6a37caacd2db29dcb7cd /crypto/src/x509
parentRefactoring around digest calculation (diff)
downloadBouncyCastle.NET-ed25519-a375c08770711d4265a1606baae162c185ef916f.tar.xz
Refactoring around digest calculation
Diffstat (limited to 'crypto/src/x509')
-rw-r--r--crypto/src/x509/X509Utilities.cs16
-rw-r--r--crypto/src/x509/store/X509CertStoreSelector.cs11
2 files changed, 16 insertions, 11 deletions
diff --git a/crypto/src/x509/X509Utilities.cs b/crypto/src/x509/X509Utilities.cs
index 5051b1b4e..e7dfeb2c5 100644
--- a/crypto/src/x509/X509Utilities.cs
+++ b/crypto/src/x509/X509Utilities.cs
@@ -129,14 +129,22 @@ namespace Org.BouncyCastle.X509
 			m_exParams.Add("SHA512WITHRSAANDMGF1", CreatePssParams(sha512AlgId, 64));
 		}
 
-		internal static byte[] CalculateDigest(DerObjectIdentifier oid, Asn1Encodable asn1Encodable)
+		internal static byte[] CalculateDigest(AlgorithmIdentifier digestAlgorithm, Asn1Encodable asn1Encodable)
 		{
-            var digest = DigestUtilities.GetDigest(oid);
+            var digest = DigestUtilities.GetDigest(digestAlgorithm.Algorithm);
             var digestCalculator = new DefaultDigestCalculator(digest);
             var digestResult = CalculateResult(digestCalculator, asn1Encodable);
 			return digestResult.Collect();
         }
 
+        internal static byte[] CalculateDigest(IDigestFactory digestFactory,
+            Asn1Encodable asn1Encodable)
+        {
+            var digestCalculator = digestFactory.CreateCalculator();
+            var digestResult = CalculateResult(digestCalculator, asn1Encodable);
+            return digestResult.Collect();
+        }
+
         internal static TResult CalculateResult<TResult>(IStreamCalculator<TResult> streamCalculator,
             Asn1Encodable asn1Encodable)
         {
@@ -220,11 +228,11 @@ namespace Org.BouncyCastle.X509
             return GenerateBitString(signatureFactory.CreateCalculator(), asn1Encodable);
         }
 
-        internal static bool VerifyMac(IMacFactory macFactory, Asn1Encodable asn1Encodable, DerBitString protection)
+        internal static bool VerifyMac(IMacFactory macFactory, Asn1Encodable asn1Encodable, DerBitString expected)
         {
             var result = CalculateResult(macFactory.CreateCalculator(), asn1Encodable);
 
-            return Arrays.FixedTimeEquals(result.Collect(), protection.GetBytes());
+            return Arrays.FixedTimeEquals(result.Collect(), expected.GetOctets());
         }
 
         internal static bool VerifySignature(IVerifierFactory verifierFactory, Asn1Encodable asn1Encodable,
diff --git a/crypto/src/x509/store/X509CertStoreSelector.cs b/crypto/src/x509/store/X509CertStoreSelector.cs
index ca15b9efa..c60c8b24b 100644
--- a/crypto/src/x509/store/X509CertStoreSelector.cs
+++ b/crypto/src/x509/store/X509CertStoreSelector.cs
@@ -276,11 +276,13 @@ namespace Org.BouncyCastle.X509.Store
 			if (!MatchExtension(subjectKeyIdentifier, c, X509Extensions.SubjectKeyIdentifier))
 				return false;
 
-			if (subjectPublicKey != null && !subjectPublicKey.Equals(GetSubjectPublicKey(c)))
+			SubjectPublicKeyInfo subjectPublicKeyInfo = c.CertificateStructure.SubjectPublicKeyInfo;
+
+            if (subjectPublicKey != null && !subjectPublicKey.Equals(subjectPublicKeyInfo))
 				return false;
 
 			if (subjectPublicKeyAlgID != null
-				&& !subjectPublicKeyAlgID.Equals(GetSubjectPublicKey(c).Algorithm))
+				&& !subjectPublicKeyAlgID.Equals(subjectPublicKeyInfo.Algorithm))
 				return false;
 
 			return true;
@@ -306,11 +308,6 @@ namespace Org.BouncyCastle.X509.Store
 			return s == null ? null : new HashSet<T>(s);
 		}
 
-		private static SubjectPublicKeyInfo GetSubjectPublicKey(X509Certificate c)
-		{
-			return c.CertificateStructure.SubjectPublicKeyInfo;
-		}
-
 		private static bool MatchExtension(byte[] b, X509Certificate c, DerObjectIdentifier	oid)
 		{
 			if (b == null)