From 9a6b3389273cfea7b0272887ec59ce922043f5e0 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sat, 19 Nov 2022 13:33:29 +0700 Subject: Refactoring in Math.EC --- crypto/src/math/ec/ECAlgorithms.cs | 25 ++++++++++--------------- crypto/src/math/ec/ECCurve.cs | 5 +---- 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(); } -- cgit 1.4.1