diff options
Diffstat (limited to 'crypto/src/math/ec/custom/gm/SM2P256V1Curve.cs')
-rw-r--r-- | crypto/src/math/ec/custom/gm/SM2P256V1Curve.cs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/crypto/src/math/ec/custom/gm/SM2P256V1Curve.cs b/crypto/src/math/ec/custom/gm/SM2P256V1Curve.cs index 2c5d8f3a3..86c8efaf7 100644 --- a/crypto/src/math/ec/custom/gm/SM2P256V1Curve.cs +++ b/crypto/src/math/ec/custom/gm/SM2P256V1Curve.cs @@ -13,6 +13,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.GM private const int SM2P256V1_DEFAULT_COORDS = COORD_JACOBIAN; private const int SM2P256V1_FE_INTS = 8; + private static readonly ECFieldElement[] SM2P256V1_AFFINE_ZS = new ECFieldElement[] { new SM2P256V1FieldElement(BigInteger.One) }; protected readonly SM2P256V1Point m_infinity; @@ -93,7 +94,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.GM } private class SM2P256V1LookupTable - : ECLookupTable + : AbstractECLookupTable { private readonly SM2P256V1Curve m_outer; private readonly uint[] m_table; @@ -106,12 +107,12 @@ namespace Org.BouncyCastle.Math.EC.Custom.GM 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) { uint[] x = Nat256.Create(), y = Nat256.Create(); int pos = 0; @@ -129,7 +130,26 @@ namespace Org.BouncyCastle.Math.EC.Custom.GM pos += (SM2P256V1_FE_INTS * 2); } - return m_outer.CreateRawPoint(new SM2P256V1FieldElement(x), new SM2P256V1FieldElement(y), false); + return CreatePoint(x, y); + } + + public override ECPoint LookupVar(int index) + { + uint[] x = Nat256.Create(), y = Nat256.Create(); + int pos = index * SM2P256V1_FE_INTS * 2; + + for (int j = 0; j < SM2P256V1_FE_INTS; ++j) + { + x[j] = m_table[pos + j]; + y[j] = m_table[pos + SM2P256V1_FE_INTS + j]; + } + + return CreatePoint(x, y); + } + + private ECPoint CreatePoint(uint[] x, uint[] y) + { + return m_outer.CreateRawPoint(new SM2P256V1FieldElement(x), new SM2P256V1FieldElement(y), SM2P256V1_AFFINE_ZS, false); } } } |