summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-04-27 22:59:26 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-04-27 22:59:26 +0700
commitb3684bb62499d52cdea3c0cad82f001462a22b50 (patch)
tree46cec26c805f1732a919995d77f61436af6b8b66
parentSparkle: Fix GetUpdateOutputSize(0) behaviour (diff)
downloadBouncyCastle.NET-ed25519-b3684bb62499d52cdea3c0cad82f001462a22b50.tar.xz
Refactoring in SparkleEngine
-rw-r--r--crypto/src/crypto/engines/SparkleEngine.cs38
1 files changed, 3 insertions, 35 deletions
diff --git a/crypto/src/crypto/engines/SparkleEngine.cs b/crypto/src/crypto/engines/SparkleEngine.cs
index 053ca3bb5..cd6586623 100644
--- a/crypto/src/crypto/engines/SparkleEngine.cs
+++ b/crypto/src/crypto/engines/SparkleEngine.cs
@@ -145,7 +145,6 @@ namespace Org.BouncyCastle.Crypto.Engines
             _M2 = (((2u ^ (1u << CAP_BRANS))) << 24);
             _M3 = (((3u ^ (1u << CAP_BRANS))) << 24);
             state = new uint[STATE_WORDS];
-            tag = new byte[TAG_BYTES];
             k = new uint[KEY_WORDS];
             npub = new uint[RATE_WORDS];
 
@@ -221,8 +220,7 @@ namespace Org.BouncyCastle.Crypto.Engines
 
             m_state = forEncryption ? State.EncInit : State.DecInit;
 
-            // TODO true might be better?
-            Reset(false);
+            Reset();
         }
 
         public void ProcessAadByte(byte input)
@@ -520,8 +518,6 @@ namespace Org.BouncyCastle.Crypto.Engines
             if (forEncryption)
             {
                 resultLength = m_bufPos + TAG_BYTES;
-                Check.OutputLength(outBytes, outOff, resultLength, "output buffer too short");
-
             }
             else
             {
@@ -531,10 +527,10 @@ namespace Org.BouncyCastle.Crypto.Engines
                 m_bufPos -= TAG_BYTES;
 
                 resultLength = m_bufPos;
-                Check.OutputLength(outBytes, outOff, resultLength, "output buffer too short");
-
             }
 
+            Check.OutputLength(outBytes, outOff, resultLength, "output buffer too short");
+
             if (encrypted || m_bufPos > 0)
             {
                 // Encryption of Last Block
@@ -733,34 +729,6 @@ namespace Org.BouncyCastle.Crypto.Engines
             m_state = nextState;
         }
 
-        private void FinishData(State nextState)
-        {
-            // TODO
-            //switch (asconParameters)
-            //{
-            //case AsconParameters.ascon128:
-            //    x1 ^= K1;
-            //    x2 ^= K2;
-            //    break;
-            //case AsconParameters.ascon128a:
-            //    x2 ^= K1;
-            //    x3 ^= K2;
-            //    break;
-            //case AsconParameters.ascon80pq:
-            //    x1 ^= (K0 << 32 | K1 >> 32);
-            //    x2 ^= (K1 << 32 | K2 >> 32);
-            //    x3 ^=  K2 << 32;
-            //    break;
-            //default:
-            //    throw new InvalidOperationException();
-            //}
-            //P(12);
-            //x3 ^= K1;
-            //x4 ^= K2;
-
-            m_state = nextState;
-        }
-
 #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
         private void ProcessBufferAad(ReadOnlySpan<byte> buffer)
         {