From d4a07a9a76b92e32e32463fbb908a2c531360163 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 30 Jan 2014 15:13:55 +0700 Subject: Add SquareN to perform repeated modular squaring --- crypto/src/math/ec/custom/sec/SecP256K1Field.cs | 15 +++++++++++++++ crypto/src/math/ec/custom/sec/SecP256R1Field.cs | 15 +++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'crypto/src') diff --git a/crypto/src/math/ec/custom/sec/SecP256K1Field.cs b/crypto/src/math/ec/custom/sec/SecP256K1Field.cs index ec2c36e9f..527360cf6 100644 --- a/crypto/src/math/ec/custom/sec/SecP256K1Field.cs +++ b/crypto/src/math/ec/custom/sec/SecP256K1Field.cs @@ -112,6 +112,21 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec Reduce(tt, z); } + public static void SquareN(uint[] x, int n, uint[] z) + { + Debug.Assert(n > 0); + + uint[] tt = Nat256.CreateExt(); + Nat256.Square(x, tt); + Reduce(tt, z); + + while (--n > 0) + { + Nat256.Square(z, tt); + Reduce(tt, z); + } + } + public static void Subtract(uint[] x, uint[] y, uint[] z) { int c = Nat256.Sub(x, y, z); diff --git a/crypto/src/math/ec/custom/sec/SecP256R1Field.cs b/crypto/src/math/ec/custom/sec/SecP256R1Field.cs index baea02dd0..cb9874bfd 100644 --- a/crypto/src/math/ec/custom/sec/SecP256R1Field.cs +++ b/crypto/src/math/ec/custom/sec/SecP256R1Field.cs @@ -145,6 +145,21 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec Reduce(tt, z); } + public static void SquareN(uint[] x, int n, uint[] z) + { + Debug.Assert(n > 0); + + uint[] tt = Nat256.CreateExt(); + Nat256.Square(x, tt); + Reduce(tt, z); + + while (--n > 0) + { + Nat256.Square(z, tt); + Reduce(tt, z); + } + } + public static void Subtract(uint[] x, uint[] y, uint[] z) { int c = Nat256.Sub(x, y, z); -- cgit 1.4.1