internal static ECPoint ImplSumOfMultipliesGlv(ECPoint[] ps, BigInteger[] ks, GlvEndomorphism glvEndomorphism) { BigInteger order = ps[0].Curve.Order; int num = ps.Length; BigInteger[] array = new BigInteger[num << 1]; int i = 0; int num2 = 0; for (; i < num; i++) { BigInteger[] array2 = glvEndomorphism.DecomposeScalar(ks[i].Mod(order)); array[num2++] = array2[0]; array[num2++] = array2[1]; } ECPointMap pointMap = glvEndomorphism.PointMap; if (glvEndomorphism.HasEfficientPointMap) { return(ImplSumOfMultiplies(ps, pointMap, array)); } ECPoint[] array3 = new ECPoint[num << 1]; int j = 0; int num5 = 0; for (; j < num; j++) { ECPoint eCPoint = ps[j]; ECPoint eCPoint2 = pointMap.Map(eCPoint); array3[num5++] = eCPoint; array3[num5++] = eCPoint2; } return(ImplSumOfMultiplies(array3, array)); }
internal static ECPoint ImplSumOfMultipliesGlv(ECPoint[] ps, BigInteger[] ks, GlvEndomorphism glvEndomorphism) { BigInteger n = ps[0].Curve.Order; int len = ps.Length; BigInteger[] abs = new BigInteger[len << 1]; for (int i = 0, j = 0; i < len; ++i) { BigInteger[] ab = glvEndomorphism.DecomposeScalar(ks[i].Mod(n)); abs[j++] = ab[0]; abs[j++] = ab[1]; } ECPointMap pointMap = glvEndomorphism.PointMap; if (glvEndomorphism.HasEfficientPointMap) { return(ECAlgorithms.ImplSumOfMultiplies(ps, pointMap, abs)); } ECPoint[] pqs = new ECPoint[len << 1]; for (int i = 0, j = 0; i < len; ++i) { ECPoint p = ps[i], q = pointMap.Map(p); pqs[j++] = p; pqs[j++] = q; } return(ECAlgorithms.ImplSumOfMultiplies(pqs, abs)); }
internal static ECPoint ImplSumOfMultiplies(ECPoint[] ps, ECPointMap pointMap, BigInteger[] ks) { int num = ps.Length; int num2 = num << 1; bool[] array = new bool[num2]; WNafPreCompInfo[] array2 = new WNafPreCompInfo[num2]; byte[][] array3 = new byte[num2][]; for (int i = 0; i < num; i++) { int num3 = i << 1; int num4 = num3 + 1; BigInteger bigInteger = ks[num3]; array[num3] = (bigInteger.SignValue < 0); bigInteger = bigInteger.Abs(); BigInteger bigInteger2 = ks[num4]; array[num4] = (bigInteger2.SignValue < 0); bigInteger2 = bigInteger2.Abs(); int width = Math.Max(2, Math.Min(16, WNafUtilities.GetWindowSize(Math.Max(bigInteger.BitLength, bigInteger2.BitLength)))); ECPoint p = ps[i]; ECPoint p2 = WNafUtilities.MapPointWithPrecomp(p, width, includeNegated: true, pointMap); array2[num3] = WNafUtilities.GetWNafPreCompInfo(p); array2[num4] = WNafUtilities.GetWNafPreCompInfo(p2); array3[num3] = WNafUtilities.GenerateWindowNaf(width, bigInteger); array3[num4] = WNafUtilities.GenerateWindowNaf(width, bigInteger2); } return(ImplSumOfMultiplies(array, array2, array3)); }
internal static ECPoint ImplSumOfMultiplies(ECEndomorphism endomorphism, ECPoint[] ps, BigInteger[] ks) { int halfCount = ps.Length, fullCount = halfCount << 1; bool[] negs = new bool[fullCount]; WNafPreCompInfo[] infos = new WNafPreCompInfo[fullCount]; byte[][] wnafs = new byte[fullCount][]; ECPointMap pointMap = endomorphism.PointMap; for (int i = 0; i < halfCount; ++i) { int j0 = i << 1, j1 = j0 + 1; BigInteger kj0 = ks[j0]; negs[j0] = kj0.SignValue < 0; kj0 = kj0.Abs(); BigInteger kj1 = ks[j1]; negs[j1] = kj1.SignValue < 0; kj1 = kj1.Abs(); int minWidth = WNafUtilities.GetWindowSize(System.Math.Max(kj0.BitLength, kj1.BitLength), 8); ECPoint P = ps[i]; WNafPreCompInfo infoP = WNafUtilities.Precompute(P, minWidth, true); ECPoint Q = EndoUtilities.MapPoint(endomorphism, P); WNafPreCompInfo infoQ = WNafUtilities.PrecomputeWithPointMap(Q, pointMap, infoP, true); int widthP = System.Math.Min(8, infoP.Width); int widthQ = System.Math.Min(8, infoQ.Width); infos[j0] = infoP; infos[j1] = infoQ; wnafs[j0] = WNafUtilities.GenerateWindowNaf(widthP, kj0); wnafs[j1] = WNafUtilities.GenerateWindowNaf(widthQ, kj1); } return(ImplSumOfMultiplies(negs, infos, wnafs)); }
internal static ECPoint ImplSumOfMultiplies(ECPoint[] ps, ECPointMap pointMap, BigInteger[] ks) { int halfCount = ps.Length, fullCount = halfCount << 1; bool[] negs = new bool[fullCount]; WNafPreCompInfo[] infos = new WNafPreCompInfo[fullCount]; byte[][] wnafs = new byte[fullCount][]; for (int i = 0; i < halfCount; ++i) { int j0 = i << 1, j1 = j0 + 1; BigInteger kj0 = ks[j0]; negs[j0] = kj0.SignValue < 0; kj0 = kj0.Abs(); BigInteger kj1 = ks[j1]; negs[j1] = kj1.SignValue < 0; kj1 = kj1.Abs(); int width = System.Math.Max(2, System.Math.Min(16, WNafUtilities.GetWindowSize(System.Math.Max(kj0.BitLength, kj1.BitLength)))); ECPoint P = ps[i], Q = WNafUtilities.MapPointWithPrecomp(P, width, true, pointMap); infos[j0] = WNafUtilities.GetWNafPreCompInfo(P); infos[j1] = WNafUtilities.GetWNafPreCompInfo(Q); wnafs[j0] = WNafUtilities.GenerateWindowNaf(width, kj0); wnafs[j1] = WNafUtilities.GenerateWindowNaf(width, kj1); } return(ImplSumOfMultiplies(negs, infos, wnafs)); }
internal static ECPoint ImplSumOfMultiplies(ECPoint[] ps, ECPointMap pointMap, BigInteger[] ks) { int length = ps.Length; int num2 = length << 1; bool[] negs = new bool[num2]; WNafPreCompInfo[] infos = new WNafPreCompInfo[num2]; byte[][] wnafs = new byte[num2][]; for (int i = 0; i < length; i++) { int index = i << 1; int num5 = index + 1; BigInteger k = ks[index]; negs[index] = k.SignValue < 0; k = k.Abs(); BigInteger integer2 = ks[num5]; negs[num5] = integer2.SignValue < 0; integer2 = integer2.Abs(); int width = Math.Max(2, Math.Min(0x10, WNafUtilities.GetWindowSize(Math.Max(k.BitLength, integer2.BitLength)))); ECPoint p = ps[i]; ECPoint point2 = WNafUtilities.MapPointWithPrecomp(p, width, true, pointMap); infos[index] = WNafUtilities.GetWNafPreCompInfo(p); infos[num5] = WNafUtilities.GetWNafPreCompInfo(point2); wnafs[index] = WNafUtilities.GenerateWindowNaf(width, k); wnafs[num5] = WNafUtilities.GenerateWindowNaf(width, integer2); } return(ImplSumOfMultiplies(negs, infos, wnafs)); }
internal PrecomputeWithPointMapCallback(ECPoint point, ECPointMap pointMap, WNafPreCompInfo fromWNaf, bool includeNegated) { this.m_point = point; this.m_pointMap = pointMap; this.m_fromWNaf = fromWNaf; this.m_includeNegated = includeNegated; }
public static ECPoint MapPointWithPrecomp(ECPoint p, int width, bool includeNegated, ECPointMap pointMap) { ECCurve c = p.Curve; WNafPreCompInfo wnafPreCompP = Precompute(p, width, includeNegated); ECPoint q = pointMap.Map(p); c.Precompute(q, PRECOMP_NAME, new MapPointCallback(wnafPreCompP, includeNegated, pointMap)); return(q); }
public GlvTypeBEndomorphism(ECCurve curve, GlvTypeBParameters parameters) { /* * NOTE: 'curve' MUST only be used to create a suitable ECFieldElement. Due to the way * ECCurve configuration works, 'curve' will not be the actual instance of ECCurve that the * endomorphism is being used with. */ this.m_parameters = parameters; this.m_pointMap = new ScaleXPointMap(curve.FromBigInteger(parameters.Beta)); }
protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k) { if (!this.curve.Equals(p.Curve)) { throw new InvalidOperationException(); } BigInteger order = p.Curve.Order; BigInteger[] array = this.glvEndomorphism.DecomposeScalar(k.Mod(order)); BigInteger k2 = array[0]; BigInteger l = array[1]; ECPointMap pointMap = this.glvEndomorphism.PointMap; if (this.glvEndomorphism.HasEfficientPointMap) { return(ECAlgorithms.ImplShamirsTrickWNaf(p, k2, pointMap, l)); } return(ECAlgorithms.ImplShamirsTrickWNaf(p, k2, pointMap.Map(p), l)); }
internal static ECPoint ImplShamirsTrickWNaf(ECPoint P, BigInteger k, ECPointMap pointMapQ, BigInteger l) { bool flag = k.SignValue < 0; bool flag2 = l.SignValue < 0; k = k.Abs(); l = l.Abs(); int width = Math.Max(2, Math.Min(0x10, WNafUtilities.GetWindowSize(Math.Max(k.BitLength, l.BitLength)))); ECPoint p = WNafUtilities.MapPointWithPrecomp(P, width, true, pointMapQ); WNafPreCompInfo wNafPreCompInfo = WNafUtilities.GetWNafPreCompInfo(P); WNafPreCompInfo info2 = WNafUtilities.GetWNafPreCompInfo(p); ECPoint[] preCompP = !flag ? wNafPreCompInfo.PreComp : wNafPreCompInfo.PreCompNeg; ECPoint[] preCompQ = !flag2 ? info2.PreComp : info2.PreCompNeg; ECPoint[] preCompNegP = !flag ? wNafPreCompInfo.PreCompNeg : wNafPreCompInfo.PreComp; ECPoint[] preCompNegQ = !flag2 ? info2.PreCompNeg : info2.PreComp; byte[] wnafP = WNafUtilities.GenerateWindowNaf(width, k); byte[] wnafQ = WNafUtilities.GenerateWindowNaf(width, l); return(ImplShamirsTrickWNaf(preCompP, preCompNegP, wnafP, preCompQ, preCompNegQ, wnafQ)); }
protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) if (!curve.Equals(p.Curve)) { throw new InvalidOperationException(); } BigInteger order = p.Curve.Order; BigInteger[] array = glvEndomorphism.DecomposeScalar(k.Mod(order)); BigInteger k2 = array[0]; BigInteger l = array[1]; ECPointMap pointMap = glvEndomorphism.PointMap; if (glvEndomorphism.HasEfficientPointMap) { return(ECAlgorithms.ImplShamirsTrickWNaf(p, k2, pointMap, l)); } return(ECAlgorithms.ImplShamirsTrickWNaf(p, k2, pointMap.Map(p), l)); }
protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k) { if (!curve.Equals(p.Curve)) { throw new InvalidOperationException(); } BigInteger n = p.Curve.Order; BigInteger[] ab = glvEndomorphism.DecomposeScalar(k.Mod(n)); BigInteger a = ab[0], b = ab[1]; ECPointMap pointMap = glvEndomorphism.PointMap; if (glvEndomorphism.HasEfficientPointMap) { return(ECAlgorithms.ImplShamirsTrickWNaf(p, a, pointMap, b)); } return(ECAlgorithms.ImplShamirsTrickWNaf(p, a, pointMap.Map(p), b)); }
public static ECPoint MapPointWithPrecomp(ECPoint p, int width, bool includeNegated, ECPointMap pointMap) { var c = p.Curve; var wnafPreCompP = Precompute(p, width, includeNegated); var q = pointMap.Map(p); var wnafPreCompQ = GetWNafPreCompInfo(c.GetPreCompInfo(q, PRECOMP_NAME)); var twiceP = wnafPreCompP.Twice; if (twiceP != null) { var twiceQ = pointMap.Map(twiceP); wnafPreCompQ.Twice = twiceQ; } var preCompP = wnafPreCompP.PreComp; var preCompQ = new ECPoint[preCompP.Length]; for (var i = 0; i < preCompP.Length; ++i) { preCompQ[i] = pointMap.Map(preCompP[i]); } wnafPreCompQ.PreComp = preCompQ; if (includeNegated) { var preCompNegQ = new ECPoint[preCompQ.Length]; for (var i = 0; i < preCompNegQ.Length; ++i) { preCompNegQ[i] = preCompQ[i].Negate(); } wnafPreCompQ.PreCompNeg = preCompNegQ; } c.SetPreCompInfo(q, PRECOMP_NAME, wnafPreCompQ); return(q); }
internal static ECPoint ImplShamirsTrickWNaf(ECPoint P, BigInteger k, ECPointMap pointMapQ, BigInteger l) { bool negK = k.SignValue < 0, negL = l.SignValue < 0; k = k.Abs(); l = l.Abs(); int width = System.Math.Max(2, System.Math.Min(16, WNafUtilities.GetWindowSize(System.Math.Max(k.BitLength, l.BitLength)))); ECPoint Q = WNafUtilities.MapPointWithPrecomp(P, width, true, pointMapQ); WNafPreCompInfo infoP = WNafUtilities.GetWNafPreCompInfo(P); WNafPreCompInfo infoQ = WNafUtilities.GetWNafPreCompInfo(Q); ECPoint[] preCompP = negK ? infoP.PreCompNeg : infoP.PreComp; ECPoint[] preCompQ = negL ? infoQ.PreCompNeg : infoQ.PreComp; ECPoint[] preCompNegP = negK ? infoP.PreComp : infoP.PreCompNeg; ECPoint[] preCompNegQ = negL ? infoQ.PreComp : infoQ.PreCompNeg; byte[] wnafP = WNafUtilities.GenerateWindowNaf(width, k); byte[] wnafQ = WNafUtilities.GenerateWindowNaf(width, l); return(ImplShamirsTrickWNaf(preCompP, preCompNegP, wnafP, preCompQ, preCompNegQ, wnafQ)); }
internal static ECPoint ImplSumOfMultipliesGlv(ECPoint[] ps, BigInteger[] ks, GlvEndomorphism glvEndomorphism) { BigInteger order = ps[0].Curve.Order; int length = ps.Length; BigInteger[] integerArray = new BigInteger[length << 1]; int index = 0; int num3 = 0; while (index < length) { BigInteger[] integerArray2 = glvEndomorphism.DecomposeScalar(ks[index].Mod(order)); integerArray[num3++] = integerArray2[0]; integerArray[num3++] = integerArray2[1]; index++; } ECPointMap pointMap = glvEndomorphism.PointMap; if (glvEndomorphism.HasEfficientPointMap) { return(ImplSumOfMultiplies(ps, pointMap, integerArray)); } ECPoint[] pointArray = new ECPoint[length << 1]; int num4 = 0; int num5 = 0; while (num4 < length) { ECPoint p = ps[num4]; ECPoint point2 = pointMap.Map(p); pointArray[num5++] = p; pointArray[num5++] = point2; num4++; } return(ImplSumOfMultiplies(pointArray, integerArray)); }
public static ECPoint MapPointWithPrecomp(ECPoint p, int width, bool includeNegated, ECPointMap pointMap) { ECCurve curve = p.Curve; WNafPreCompInfo info = Precompute(p, width, includeNegated); ECPoint point = pointMap.Map(p); WNafPreCompInfo wNafPreCompInfo = GetWNafPreCompInfo(curve.GetPreCompInfo(point, PRECOMP_NAME)); ECPoint twice = info.Twice; if (twice != null) { ECPoint point3 = pointMap.Map(twice); wNafPreCompInfo.Twice = point3; } ECPoint[] preComp = info.PreComp; ECPoint[] pointArray2 = new ECPoint[preComp.Length]; for (int i = 0; i < preComp.Length; i++) { pointArray2[i] = pointMap.Map(preComp[i]); } wNafPreCompInfo.PreComp = pointArray2; if (includeNegated) { ECPoint[] pointArray3 = new ECPoint[pointArray2.Length]; for (int j = 0; j < pointArray3.Length; j++) { pointArray3[j] = pointArray2[j].Negate(); } wNafPreCompInfo.PreCompNeg = pointArray3; } curve.SetPreCompInfo(point, PRECOMP_NAME, wNafPreCompInfo); return(point); }
public GlvTypeBEndomorphism(ECCurve curve, GlvTypeBParameters parameters) { this.m_curve = curve; this.m_parameters = parameters; this.m_pointMap = new ScaleXPointMap(curve.FromBigInteger(parameters.Beta)); }
internal static ECPoint ImplShamirsTrickWNaf(ECPoint P, BigInteger k, ECPointMap pointMapQ, BigInteger l) { bool negK = k.SignValue < 0, negL = l.SignValue < 0; k = k.Abs(); l = l.Abs(); int width = System.Math.Max(2, System.Math.Min(16, WNafUtilities.GetWindowSize(System.Math.Max(k.BitLength, l.BitLength)))); ECPoint Q = WNafUtilities.MapPointWithPrecomp(P, width, true, pointMapQ); WNafPreCompInfo infoP = WNafUtilities.GetWNafPreCompInfo(P); WNafPreCompInfo infoQ = WNafUtilities.GetWNafPreCompInfo(Q); ECPoint[] preCompP = negK ? infoP.PreCompNeg : infoP.PreComp; ECPoint[] preCompQ = negL ? infoQ.PreCompNeg : infoQ.PreComp; ECPoint[] preCompNegP = negK ? infoP.PreComp : infoP.PreCompNeg; ECPoint[] preCompNegQ = negL ? infoQ.PreComp : infoQ.PreCompNeg; byte[] wnafP = WNafUtilities.GenerateWindowNaf(width, k); byte[] wnafQ = WNafUtilities.GenerateWindowNaf(width, l); return ImplShamirsTrickWNaf(preCompP, preCompNegP, wnafP, preCompQ, preCompNegQ, wnafQ); }
internal static ECPoint ImplSumOfMultiplies(ECPoint[] ps, ECPointMap pointMap, BigInteger[] ks) { int halfCount = ps.Length, fullCount = halfCount << 1; bool[] negs = new bool[fullCount]; WNafPreCompInfo[] infos = new WNafPreCompInfo[fullCount]; byte[][] wnafs = new byte[fullCount][]; for (int i = 0; i < halfCount; ++i) { int j0 = i << 1, j1 = j0 + 1; BigInteger kj0 = ks[j0]; negs[j0] = kj0.SignValue < 0; kj0 = kj0.Abs(); BigInteger kj1 = ks[j1]; negs[j1] = kj1.SignValue < 0; kj1 = kj1.Abs(); int width = System.Math.Max(2, System.Math.Min(16, WNafUtilities.GetWindowSize(System.Math.Max(kj0.BitLength, kj1.BitLength)))); ECPoint P = ps[i], Q = WNafUtilities.MapPointWithPrecomp(P, width, true, pointMap); infos[j0] = WNafUtilities.GetWNafPreCompInfo(P); infos[j1] = WNafUtilities.GetWNafPreCompInfo(Q); wnafs[j0] = WNafUtilities.GenerateWindowNaf(width, kj0); wnafs[j1] = WNafUtilities.GenerateWindowNaf(width, kj1); } return ImplSumOfMultiplies(negs, infos, wnafs); }
public static ECPoint MapPointWithPrecomp(ECPoint p, int width, bool includeNegated, ECPointMap pointMap) { ECCurve c = p.Curve; WNafPreCompInfo wnafPreCompP = Precompute(p, width, includeNegated); ECPoint q = pointMap.Map(p); WNafPreCompInfo wnafPreCompQ = GetWNafPreCompInfo(c.GetPreCompInfo(q, PRECOMP_NAME)); ECPoint twiceP = wnafPreCompP.Twice; if (twiceP != null) { ECPoint twiceQ = pointMap.Map(twiceP); wnafPreCompQ.Twice = twiceQ; } ECPoint[] preCompP = wnafPreCompP.PreComp; ECPoint[] preCompQ = new ECPoint[preCompP.Length]; for (int i = 0; i < preCompP.Length; ++i) { preCompQ[i] = pointMap.Map(preCompP[i]); } wnafPreCompQ.PreComp = preCompQ; if (includeNegated) { ECPoint[] preCompNegQ = new ECPoint[preCompQ.Length]; for (int i = 0; i < preCompNegQ.Length; ++i) { preCompNegQ[i] = preCompQ[i].Negate(); } wnafPreCompQ.PreCompNeg = preCompNegQ; } c.SetPreCompInfo(q, PRECOMP_NAME, wnafPreCompQ); return q; }
internal MapPointCallback(WNafPreCompInfo wnafPreCompP, bool includeNegated, ECPointMap pointMap) { this.m_wnafPreCompP = wnafPreCompP; this.m_includeNegated = includeNegated; this.m_pointMap = pointMap; }
public static ECPoint MapPointWithPrecomp(ECPoint p, int width, bool includeNegated, ECPointMap pointMap) { ECCurve curve = p.Curve; WNafPreCompInfo wNafPreCompInfo = WNafUtilities.Precompute(p, width, includeNegated); ECPoint eCPoint = pointMap.Map(p); WNafPreCompInfo wNafPreCompInfo2 = WNafUtilities.GetWNafPreCompInfo(curve.GetPreCompInfo(eCPoint, WNafUtilities.PRECOMP_NAME)); ECPoint twice = wNafPreCompInfo.Twice; if (twice != null) { ECPoint twice2 = pointMap.Map(twice); wNafPreCompInfo2.Twice = twice2; } ECPoint[] preComp = wNafPreCompInfo.PreComp; ECPoint[] array = new ECPoint[preComp.Length]; for (int i = 0; i < preComp.Length; i++) { array[i] = pointMap.Map(preComp[i]); } wNafPreCompInfo2.PreComp = array; if (includeNegated) { ECPoint[] array2 = new ECPoint[array.Length]; for (int j = 0; j < array2.Length; j++) { array2[j] = array[j].Negate(); } wNafPreCompInfo2.PreCompNeg = array2; } curve.SetPreCompInfo(eCPoint, WNafUtilities.PRECOMP_NAME, wNafPreCompInfo2); return(eCPoint); }
public static WNafPreCompInfo PrecomputeWithPointMap(ECPoint p, ECPointMap pointMap, WNafPreCompInfo fromWNaf, bool includeNegated) { return((WNafPreCompInfo)p.Curve.Precompute(p, PRECOMP_NAME, new PrecomputeWithPointMapCallback(p, pointMap, fromWNaf, includeNegated))); }