diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-08-09 17:08:48 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-08-09 17:08:48 +0700 |
commit | ac5ab976832d3d6e107502acd318f9fe3b12e547 (patch) | |
tree | d594b09d80bd74705d23e011a43f8fc8fda87904 /crypto/src/math/ec/custom/sec/SecT571R1Curve.cs | |
parent | ASN.1 updates from bc-java (diff) | |
download | BouncyCastle.NET-ed25519-ac5ab976832d3d6e107502acd318f9fe3b12e547.tar.xz |
Add non-constant-time variant to ECLookupTable
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecT571R1Curve.cs')
-rw-r--r-- | crypto/src/math/ec/custom/sec/SecT571R1Curve.cs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecT571R1Curve.cs b/crypto/src/math/ec/custom/sec/SecT571R1Curve.cs index 7ebf90856..840c29638 100644 --- a/crypto/src/math/ec/custom/sec/SecT571R1Curve.cs +++ b/crypto/src/math/ec/custom/sec/SecT571R1Curve.cs @@ -10,6 +10,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { private const int SECT571R1_DEFAULT_COORDS = COORD_LAMBDA_PROJECTIVE; private const int SECT571R1_FE_LONGS = 9; + private static readonly ECFieldElement[] SECT571R1_AFFINE_ZS = new ECFieldElement[] { new SecT571FieldElement(BigInteger.One) }; protected readonly SecT571R1Point m_infinity; @@ -118,7 +119,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec } private class SecT571R1LookupTable - : ECLookupTable + : AbstractECLookupTable { private readonly SecT571R1Curve m_outer; private readonly ulong[] m_table; @@ -131,12 +132,12 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec this.m_size = size; } - public virtual int Size + public override int Size { get { return m_size; } } - public virtual ECPoint Lookup(int index) + public override ECPoint Lookup(int index) { ulong[] x = Nat576.Create64(), y = Nat576.Create64(); int pos = 0; @@ -154,7 +155,26 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec pos += (SECT571R1_FE_LONGS * 2); } - return m_outer.CreateRawPoint(new SecT571FieldElement(x), new SecT571FieldElement(y), false); + return CreatePoint(x, y); + } + + public override ECPoint LookupVar(int index) + { + ulong[] x = Nat576.Create64(), y = Nat576.Create64(); + int pos = index * SECT571R1_FE_LONGS * 2; + + for (int j = 0; j < SECT571R1_FE_LONGS; ++j) + { + x[j] = m_table[pos + j]; + y[j] = m_table[pos + SECT571R1_FE_LONGS + j]; + } + + return CreatePoint(x, y); + } + + private ECPoint CreatePoint(ulong[] x, ulong[] y) + { + return m_outer.CreateRawPoint(new SecT571FieldElement(x), new SecT571FieldElement(y), SECT571R1_AFFINE_ZS, false); } } } |