summary refs log tree commit diff
path: root/crypto/test/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-05-04 20:25:34 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-05-04 20:25:34 +0700
commitd2e7b80ec7d7955cebb9ad6bc62ca339bff6d018 (patch)
tree4ef8ea5769f16a0343cc3a3b7009ecf9b46f8652 /crypto/test/src
parentProvide getter for native certificate instance (diff)
downloadBouncyCastle.NET-ed25519-d2e7b80ec7d7955cebb9ad6bc62ca339bff6d018.tar.xz
TLS PSS raw signatures
Diffstat (limited to 'crypto/test/src')
-rw-r--r--crypto/test/src/tls/crypto/test/BcTlsCryptoTest.cs46
1 files changed, 18 insertions, 28 deletions
diff --git a/crypto/test/src/tls/crypto/test/BcTlsCryptoTest.cs b/crypto/test/src/tls/crypto/test/BcTlsCryptoTest.cs
index ddbe4c6b8..e0bd39f64 100644
--- a/crypto/test/src/tls/crypto/test/BcTlsCryptoTest.cs
+++ b/crypto/test/src/tls/crypto/test/BcTlsCryptoTest.cs
@@ -585,6 +585,20 @@ namespace Org.BouncyCastle.Tls.Crypto.Tests
             return Utilities.Encoders.Hex.Decode(s.Replace(" ", ""));
         }
 
+        private byte[] ImplPrehash(int signatureScheme, byte[] message)
+        {
+            int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(signatureScheme);
+            TlsHash tlsHash = m_crypto.CreateHash(cryptoHashAlgorithm);
+            tlsHash.Update(message, 0, message.Length);
+            return tlsHash.CalculateHash();
+        }
+
+        private byte[] ImplPrehash(SignatureAndHashAlgorithm signatureAndHashAlgorithm, byte[] message)
+        {
+            int signatureScheme = SignatureScheme.From(signatureAndHashAlgorithm);
+            return ImplPrehash(signatureScheme, message);
+        }
+
         private void ImplTestAgreement(TlsAgreement aA, TlsAgreement aB)
         {
             byte[] pA = aA.GenerateEphemeral();
@@ -682,8 +696,6 @@ namespace Org.BouncyCastle.Tls.Crypto.Tests
         private void ImplTestSignature12(TlsCredentialedSigner credentialedSigner,
             SignatureAndHashAlgorithm signatureAndHashAlgorithm)
         {
-            short hashAlgorithm = signatureAndHashAlgorithm.Hash;
-
             byte[] message = m_crypto.CreateNonceGenerator(TlsUtilities.EmptyBytes).GenerateNonce(100);
 
             byte[] signature;
@@ -696,14 +708,7 @@ namespace Org.BouncyCastle.Tls.Crypto.Tests
             }
             else
             {
-                // Currently 1.2 relies on these being handled by stream signers 
-                Assert.IsTrue(HashAlgorithm.Intrinsic != hashAlgorithm);
-
-                int cryptoHashAlgorithm = TlsCryptoUtilities.GetHash(hashAlgorithm);
-
-                TlsHash tlsHash = m_crypto.CreateHash(cryptoHashAlgorithm);
-                tlsHash.Update(message, 0, message.Length);
-                byte[] hash = tlsHash.CalculateHash();
+                byte[] hash = ImplPrehash(signatureAndHashAlgorithm, message);
                 signature = credentialedSigner.GenerateRawSignature(hash);
             }
 
@@ -722,14 +727,7 @@ namespace Org.BouncyCastle.Tls.Crypto.Tests
             }
             else
             {
-                // Currently 1.2 relies on these being handled by stream verifiers 
-                Assert.IsTrue(HashAlgorithm.Intrinsic != hashAlgorithm);
-
-                int cryptoHashAlgorithm = TlsCryptoUtilities.GetHash(hashAlgorithm);
-
-                TlsHash tlsHash = m_crypto.CreateHash(cryptoHashAlgorithm);
-                tlsHash.Update(message, 0, message.Length);
-                byte[] hash = tlsHash.CalculateHash();
+                byte[] hash = ImplPrehash(signatureAndHashAlgorithm, message);
                 verified = tlsVerifier.VerifyRawSignature(digitallySigned, hash);
             }
 
@@ -750,11 +748,7 @@ namespace Org.BouncyCastle.Tls.Crypto.Tests
             }
             else
             {
-                int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(signatureScheme);
-
-                TlsHash tlsHash = m_crypto.CreateHash(cryptoHashAlgorithm);
-                tlsHash.Update(message, 0, message.Length);
-                byte[] hash = tlsHash.CalculateHash();
+                byte[] hash = ImplPrehash(signatureScheme, message);
                 signature = credentialedSigner.GenerateRawSignature(hash);
             }
 
@@ -774,11 +768,7 @@ namespace Org.BouncyCastle.Tls.Crypto.Tests
             }
             else
             {
-                int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(signatureScheme);
-
-                TlsHash tlsHash = m_crypto.CreateHash(cryptoHashAlgorithm);
-                tlsHash.Update(message, 0, message.Length);
-                byte[] hash = tlsHash.CalculateHash();
+                byte[] hash = ImplPrehash(signatureScheme, message);
                 verified = tlsVerifier.VerifyRawSignature(digitallySigned, hash);
             }