summary refs log tree commit diff
path: root/crypto/src/math
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-31 14:05:29 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-31 14:05:29 +0700
commit4609a835b2c5029885c51ba071c37ad54476b21e (patch)
treed77735c554a1d608a2d07d84ce1f9ef666c1589d /crypto/src/math
parentUnroll MulWordAddExt (diff)
downloadBouncyCastle.NET-ed25519-4609a835b2c5029885c51ba071c37ad54476b21e.tar.xz
Refactoring
Diffstat (limited to 'crypto/src/math')
-rw-r--r--crypto/src/math/ec/custom/sec/SecP256K1Curve.cs4
-rw-r--r--crypto/src/math/ec/custom/sec/SecP256K1Field.cs7
-rw-r--r--crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs1
-rw-r--r--crypto/src/math/ec/custom/sec/SecP256R1Curve.cs4
-rw-r--r--crypto/src/math/ec/custom/sec/SecP256R1FieldElement.cs2
5 files changed, 8 insertions, 10 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecP256K1Curve.cs b/crypto/src/math/ec/custom/sec/SecP256K1Curve.cs
index 95139a014..a938a67d7 100644
--- a/crypto/src/math/ec/custom/sec/SecP256K1Curve.cs
+++ b/crypto/src/math/ec/custom/sec/SecP256K1Curve.cs
@@ -23,7 +23,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             this.m_a = FromBigInteger(BigInteger.Zero);
             this.m_b = FromBigInteger(BigInteger.ValueOf(7));
             this.m_order = new BigInteger(1, Hex.Decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"));
-            this.m_cofactor = BigInteger.ValueOf(1);
+            this.m_cofactor = BigInteger.One;
             this.m_coord = SECP256K1_DEFAULT_COORDS;
         }
 
@@ -71,7 +71,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
         protected override ECPoint DecompressPoint(int yTilde, BigInteger X1)
         {
             ECFieldElement x = FromBigInteger(X1);
-            ECFieldElement alpha = x.Square().Add(m_a).Multiply(x).Add(m_b);
+            ECFieldElement alpha = x.Square().Multiply(x).Add(B);
             ECFieldElement beta = alpha.Sqrt();
 
             //
diff --git a/crypto/src/math/ec/custom/sec/SecP256K1Field.cs b/crypto/src/math/ec/custom/sec/SecP256K1Field.cs
index 527360cf6..6fe575b38 100644
--- a/crypto/src/math/ec/custom/sec/SecP256K1Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecP256K1Field.cs
@@ -13,7 +13,8 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             0x00000000, 0x00000000, 0x00000000, 0xFFFFF85E, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
             0xFFFFFFFF, 0xFFFFFFFF };
         private const uint PExt15 = 0xFFFFFFFF;
-        private static readonly ulong PInv = 0x00000001000003D1UL;
+        private const ulong PInv = 0x00000001000003D1UL;
+        private const uint PInvLow = 0x3D1;
 
         public static void Add(uint[] x, uint[] y, uint[] z)
         {
@@ -88,11 +89,11 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
         public static void Reduce(uint[] tt, uint[] z)
         {
             long extra = -(long)tt[8];
-            extra += (long)Nat256.MulWordAddExt((uint)PInv, tt, 8, tt, 0);
+            extra += (long)Nat256.MulWordAddExt(PInvLow, tt, 8, tt, 0);
             extra += (long)Nat256.AddToExt(tt, 8, tt, 1) << 32;
             extra += (long)tt[8];
 
-            ulong c = Nat256.MulWordDwordAdd((uint)PInv, (ulong)extra, tt, 0);
+            ulong c = Nat256.MulWordDwordAdd(PInvLow, (ulong)extra, tt, 0);
             c += Nat256.AddDWord((ulong)extra, tt, 1);
 
             Debug.Assert(c == 0 || c == 1);
diff --git a/crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs b/crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs
index d9d965a42..2c3499caa 100644
--- a/crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs
+++ b/crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs
@@ -119,7 +119,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return new SecP256K1FieldElement(z);
         }
 
-        // D.1.4 91
         /**
          * return a sqrt root - the routine verifies that the calculation returns the right value - if
          * none exists it returns null.
diff --git a/crypto/src/math/ec/custom/sec/SecP256R1Curve.cs b/crypto/src/math/ec/custom/sec/SecP256R1Curve.cs
index c0620574c..9525c0207 100644
--- a/crypto/src/math/ec/custom/sec/SecP256R1Curve.cs
+++ b/crypto/src/math/ec/custom/sec/SecP256R1Curve.cs
@@ -25,7 +25,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             this.m_b = FromBigInteger(new BigInteger(1,
                 Hex.Decode("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B")));
             this.m_order = new BigInteger(1, Hex.Decode("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551"));
-            this.m_cofactor = BigInteger.ValueOf(1);
+            this.m_cofactor = BigInteger.One;
             this.m_coord = SecP256R1_DEFAULT_COORDS;
         }
 
@@ -73,7 +73,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
         protected override ECPoint DecompressPoint(int yTilde, BigInteger X1)
         {
             ECFieldElement x = FromBigInteger(X1);
-            ECFieldElement alpha = x.Square().Add(m_a).Multiply(x).Add(m_b);
+            ECFieldElement alpha = x.Square().Add(A).Multiply(x).Add(B);
             ECFieldElement beta = alpha.Sqrt();
 
             //
diff --git a/crypto/src/math/ec/custom/sec/SecP256R1FieldElement.cs b/crypto/src/math/ec/custom/sec/SecP256R1FieldElement.cs
index 650f12aaf..b47133676 100644
--- a/crypto/src/math/ec/custom/sec/SecP256R1FieldElement.cs
+++ b/crypto/src/math/ec/custom/sec/SecP256R1FieldElement.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Diagnostics;
 
 using Org.BouncyCastle.Utilities;
 
@@ -119,7 +118,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return new SecP256R1FieldElement(z);
         }
 
-        // D.1.4 91
         /**
          * return a sqrt root - the routine verifies that the calculation returns the right value - if
          * none exists it returns null.