summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-19 13:33:29 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-19 13:33:29 +0700
commit9a6b3389273cfea7b0272887ec59ce922043f5e0 (patch)
tree85a5d23501a697c590c3a3e8b91d4ececda4d602
parentRefine exception types (diff)
downloadBouncyCastle.NET-ed25519-9a6b3389273cfea7b0272887ec59ce922043f5e0.tar.xz
Refactoring in Math.EC
-rw-r--r--crypto/src/math/ec/ECAlgorithms.cs25
-rw-r--r--crypto/src/math/ec/ECCurve.cs5
2 files changed, 11 insertions, 19 deletions
diff --git a/crypto/src/math/ec/ECAlgorithms.cs b/crypto/src/math/ec/ECAlgorithms.cs
index 15204e4ed..e7a7189b7 100644
--- a/crypto/src/math/ec/ECAlgorithms.cs
+++ b/crypto/src/math/ec/ECAlgorithms.cs
@@ -38,12 +38,12 @@ namespace Org.BouncyCastle.Math.EC
             int count = ps.Length;
             switch (count)
             {
-                case 1:
-                    return ps[0].Multiply(ks[0]);
-                case 2:
-                    return SumOfTwoMultiplies(ps[0], ks[0], ps[1], ks[1]);
-                default:
-                    break;
+            case 1:
+                return ps[0].Multiply(ks[0]);
+            case 2:
+                return SumOfTwoMultiplies(ps[0], ks[0], ps[1], ks[1]);
+            default:
+                break;
             }
 
             ECPoint p = ps[0];
@@ -56,8 +56,7 @@ namespace Org.BouncyCastle.Math.EC
                 imported[i] = ImportPoint(c, ps[i]);
             }
 
-            GlvEndomorphism glvEndomorphism = c.GetEndomorphism() as GlvEndomorphism;
-            if (glvEndomorphism != null)
+            if (c.GetEndomorphism() is GlvEndomorphism glvEndomorphism)
             {
                 return ImplCheckResult(ImplSumOfMultipliesGlv(imported, ks, glvEndomorphism));
             }
@@ -72,18 +71,14 @@ namespace Org.BouncyCastle.Math.EC
 
             // Point multiplication for Koblitz curves (using WTNAF) beats Shamir's trick
             {
-                AbstractF2mCurve f2mCurve = cp as AbstractF2mCurve;
-                if (f2mCurve != null && f2mCurve.IsKoblitz)
-                {
+                if (cp is AbstractF2mCurve f2mCurve && f2mCurve.IsKoblitz)
                     return ImplCheckResult(P.Multiply(a).Add(Q.Multiply(b)));
-                }
             }
 
-            GlvEndomorphism glvEndomorphism = cp.GetEndomorphism() as GlvEndomorphism;
-            if (glvEndomorphism != null)
+            if (cp.GetEndomorphism() is GlvEndomorphism glvEndomorphism)
             {
                 return ImplCheckResult(
-                    ImplSumOfMultipliesGlv(new ECPoint[] { P, Q }, new BigInteger[] { a, b }, glvEndomorphism));
+                    ImplSumOfMultipliesGlv(new ECPoint[]{ P, Q }, new BigInteger[]{ a, b }, glvEndomorphism));
             }
 
             return ImplCheckResult(ImplShamirsTrickWNaf(P, a, Q, b));
diff --git a/crypto/src/math/ec/ECCurve.cs b/crypto/src/math/ec/ECCurve.cs
index b37d62721..73b70f6de 100644
--- a/crypto/src/math/ec/ECCurve.cs
+++ b/crypto/src/math/ec/ECCurve.cs
@@ -130,11 +130,8 @@ namespace Org.BouncyCastle.Math.EC
 
         protected virtual ECMultiplier CreateDefaultMultiplier()
         {
-            GlvEndomorphism glvEndomorphism = m_endomorphism as GlvEndomorphism;
-            if (glvEndomorphism != null)
-            {
+            if (m_endomorphism is GlvEndomorphism glvEndomorphism)
                 return new GlvMultiplier(this, glvEndomorphism);
-            }
 
             return new WNafL2RMultiplier();
         }