From 937aa8662a743eda26c1a54562d132dbeff6f917 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sat, 11 Feb 2023 23:54:37 +0700 Subject: Refactor Wnaf --- crypto/src/math/ec/rfc8032/Wnaf.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crypto/src/math/ec/rfc8032/Wnaf.cs b/crypto/src/math/ec/rfc8032/Wnaf.cs index 1b7d1465d..88319f405 100644 --- a/crypto/src/math/ec/rfc8032/Wnaf.cs +++ b/crypto/src/math/ec/rfc8032/Wnaf.cs @@ -33,25 +33,24 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032 } } - uint sign = 0U; - int j = 0, lead = 32 - width; + int j = 0, lead = 32 - width, sign = 0; for (int i = 0; i < t.Length; ++i, j -= 16) { uint word = t[i]; while (j < 16) { - uint word16 = word >> j; + int word16 = (int)(word >> j); - int skip = Integers.NumberOfTrailingZeros((int)((sign ^ word16) | 0xFFFF0000U)); + int skip = Integers.NumberOfTrailingZeros((sign ^ word16) | 0x00010000); if (skip > 0) { j += skip; continue; } - int digit = ((int)word16 | 1) << lead; - sign = (uint)(digit >> 31); + int digit = (word16 | 1) << lead; + sign = digit >> 31; ws[(i << 4) + j] = (sbyte)(digit >> lead); @@ -59,7 +58,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032 } } - Debug.Assert((int)sign == (int)n[n.Length - 1] >> 31); + Debug.Assert(sign == (int)n[n.Length - 1] >> 31); } } } -- cgit 1.4.1