protected virtual ECFieldElement CalculateJacobianModifiedW(ECFieldElement Z, ECFieldElement ZSquared) { ECFieldElement a = this.Curve.A; if (a.IsZero || Z.IsOne) { return(a); } if (ZSquared == null) { ZSquared = Z.Square(); } ECFieldElement eCFieldElement = ZSquared.Square(); ECFieldElement eCFieldElement2 = a.Negate(); if (eCFieldElement2.BitLength < a.BitLength) { eCFieldElement = eCFieldElement.Multiply(eCFieldElement2).Negate(); } else { eCFieldElement = eCFieldElement.Multiply(a); } return(eCFieldElement); }
protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) { ECFieldElement b = this.FromBigInteger(X1); ECFieldElement y = b.Square().Add(this.A).Multiply(b).Add(this.B).Sqrt(); if (y == null) { throw new ArgumentException("Invalid point compression"); } if (y.TestBitZero() != (yTilde == 1)) { y = y.Negate(); } return(this.CreateRawPoint(b, y, true)); }
protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) { ECFieldElement eCFieldElement = this.FromBigInteger(X1); ECFieldElement eCFieldElement2 = eCFieldElement.Square().Add(this.A).Multiply(eCFieldElement).Add(this.B); ECFieldElement eCFieldElement3 = eCFieldElement2.Sqrt(); if (eCFieldElement3 == null) { throw new ArgumentException("Invalid point compression"); } if (eCFieldElement3.TestBitZero() != (yTilde == 1)) { eCFieldElement3 = eCFieldElement3.Negate(); } return(this.CreateRawPoint(eCFieldElement, eCFieldElement3, true)); }
protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) ECFieldElement eCFieldElement = FromBigInteger(X1); ECFieldElement eCFieldElement2 = eCFieldElement.Square().Add(A).Multiply(eCFieldElement) .Add(B); ECFieldElement eCFieldElement3 = eCFieldElement2.Sqrt(); if (eCFieldElement3 == null) { throw new ArgumentException("Invalid point compression"); } if (eCFieldElement3.TestBitZero() != (yTilde == 1)) { eCFieldElement3 = eCFieldElement3.Negate(); } return(CreateRawPoint(eCFieldElement, eCFieldElement3, withCompression: true)); }
protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) { ECFieldElement x = FromBigInteger(X1); ECFieldElement rhs = x.Square().Add(A).Multiply(x).Add(B); ECFieldElement y = rhs.Sqrt(); /* * If y is not a square, then we haven't got a point on the curve */ if (y == null) { throw new ArgumentException("Invalid point compression"); } if (y.TestBitZero() != (yTilde == 1)) { // Use the other root y = y.Negate(); } return(CreateRawPoint(x, y, true)); }
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 beta = alpha.Sqrt(); // // if we can't find a sqrt we haven't got a point on the // curve - run! // if (beta == null) { throw new ArithmeticException("Invalid point compression"); } if (beta.TestBitZero() != (yTilde == 1)) { // Use the other root beta = beta.Negate(); } return(new FpPoint(this, x, beta, true)); }
public override ECPoint Twice() { //IL_0386: Unknown result type (might be due to invalid IL or missing references) if (base.IsInfinity) { return(this); } ECCurve curve = Curve; ECFieldElement rawYCoord = base.RawYCoord; if (rawYCoord.IsZero) { return(curve.Infinity); } int coordinateSystem = curve.CoordinateSystem; ECFieldElement rawXCoord = base.RawXCoord; switch (coordinateSystem) { case 0: { ECFieldElement x3 = rawXCoord.Square(); ECFieldElement eCFieldElement10 = Three(x3).Add(Curve.A).Divide(Two(rawYCoord)); ECFieldElement eCFieldElement11 = eCFieldElement10.Square().Subtract(Two(rawXCoord)); ECFieldElement y2 = eCFieldElement10.Multiply(rawXCoord.Subtract(eCFieldElement11)).Subtract(rawYCoord); return(new FpPoint(Curve, eCFieldElement11, y2, base.IsCompressed)); } case 1: { ECFieldElement eCFieldElement12 = base.RawZCoords[0]; bool isOne2 = eCFieldElement12.IsOne; ECFieldElement eCFieldElement13 = curve.A; if (!eCFieldElement13.IsZero && !isOne2) { eCFieldElement13 = eCFieldElement13.Multiply(eCFieldElement12.Square()); } eCFieldElement13 = eCFieldElement13.Add(Three(rawXCoord.Square())); ECFieldElement eCFieldElement14 = (isOne2 ? rawYCoord : rawYCoord.Multiply(eCFieldElement12)); ECFieldElement eCFieldElement15 = (isOne2 ? rawYCoord.Square() : eCFieldElement14.Multiply(rawYCoord)); ECFieldElement x4 = rawXCoord.Multiply(eCFieldElement15); ECFieldElement eCFieldElement16 = Four(x4); ECFieldElement eCFieldElement17 = eCFieldElement13.Square().Subtract(Two(eCFieldElement16)); ECFieldElement eCFieldElement18 = Two(eCFieldElement14); ECFieldElement x5 = eCFieldElement17.Multiply(eCFieldElement18); ECFieldElement eCFieldElement19 = Two(eCFieldElement15); ECFieldElement y3 = eCFieldElement16.Subtract(eCFieldElement17).Multiply(eCFieldElement13).Subtract(Two(eCFieldElement19.Square())); ECFieldElement x6 = (isOne2 ? Two(eCFieldElement19) : eCFieldElement18.Square()); ECFieldElement eCFieldElement20 = Two(x6).Multiply(eCFieldElement14); return(new FpPoint(curve, x5, y3, new ECFieldElement[1] { eCFieldElement20 }, base.IsCompressed)); } case 2: { ECFieldElement eCFieldElement = base.RawZCoords[0]; bool isOne = eCFieldElement.IsOne; ECFieldElement eCFieldElement2 = rawYCoord.Square(); ECFieldElement x = eCFieldElement2.Square(); ECFieldElement a = curve.A; ECFieldElement eCFieldElement3 = a.Negate(); ECFieldElement eCFieldElement4; ECFieldElement eCFieldElement5; if (eCFieldElement3.ToBigInteger().Equals(BigInteger.ValueOf(3L))) { ECFieldElement b = (isOne ? eCFieldElement : eCFieldElement.Square()); eCFieldElement4 = Three(rawXCoord.Add(b).Multiply(rawXCoord.Subtract(b))); eCFieldElement5 = Four(eCFieldElement2.Multiply(rawXCoord)); } else { ECFieldElement x2 = rawXCoord.Square(); eCFieldElement4 = Three(x2); if (isOne) { eCFieldElement4 = eCFieldElement4.Add(a); } else if (!a.IsZero) { ECFieldElement eCFieldElement6 = (isOne ? eCFieldElement : eCFieldElement.Square()); ECFieldElement eCFieldElement7 = eCFieldElement6.Square(); eCFieldElement4 = ((eCFieldElement3.BitLength >= a.BitLength) ? eCFieldElement4.Add(eCFieldElement7.Multiply(a)) : eCFieldElement4.Subtract(eCFieldElement7.Multiply(eCFieldElement3))); } eCFieldElement5 = Four(rawXCoord.Multiply(eCFieldElement2)); } ECFieldElement eCFieldElement8 = eCFieldElement4.Square().Subtract(Two(eCFieldElement5)); ECFieldElement y = eCFieldElement5.Subtract(eCFieldElement8).Multiply(eCFieldElement4).Subtract(Eight(x)); ECFieldElement eCFieldElement9 = Two(rawYCoord); if (!isOne) { eCFieldElement9 = eCFieldElement9.Multiply(eCFieldElement); } return(new FpPoint(curve, eCFieldElement8, y, new ECFieldElement[1] { eCFieldElement9 }, base.IsCompressed)); } case 4: return(TwiceJacobianModified(calculateW: true)); default: throw new InvalidOperationException("unsupported coordinate system"); } }
public override ECPoint Twice() { ECFieldElement element20; bool isOne; ECFieldElement element22; ECFieldElement element25; ECFieldElement element26; if (base.IsInfinity) { return(this); } ECCurve curve = this.Curve; ECFieldElement rawYCoord = base.RawYCoord; if (rawYCoord.IsZero) { return(curve.Infinity); } int coordinateSystem = curve.CoordinateSystem; ECFieldElement rawXCoord = base.RawXCoord; switch (coordinateSystem) { case 0: { ECFieldElement x = rawXCoord.Square(); ECFieldElement element4 = this.Three(x).Add(this.Curve.A).Divide(this.Two(rawYCoord)); ECFieldElement element5 = element4.Square().Subtract(this.Two(rawXCoord)); return(new FpPoint(this.Curve, element5, element4.Multiply(rawXCoord.Subtract(element5)).Subtract(rawYCoord), base.IsCompressed)); } case 1: { ECFieldElement element7 = base.RawZCoords[0]; bool isOne = element7.IsOne; ECFieldElement a = curve.A; if (!a.IsZero && !isOne) { a = a.Multiply(element7.Square()); } a = a.Add(this.Three(rawXCoord.Square())); ECFieldElement x = !isOne?rawYCoord.Multiply(element7) : rawYCoord; ECFieldElement element10 = !isOne?x.Multiply(rawYCoord) : rawYCoord.Square(); ECFieldElement element11 = rawXCoord.Multiply(element10); ECFieldElement element12 = this.Four(element11); ECFieldElement element13 = a.Square().Subtract(this.Two(element12)); ECFieldElement element14 = this.Two(x); ECFieldElement element15 = element13.Multiply(element14); ECFieldElement element16 = this.Two(element10); ECFieldElement element17 = element12.Subtract(element13).Multiply(a).Subtract(this.Two(element16.Square())); ECFieldElement element18 = !isOne?element14.Square() : this.Two(element16); ECFieldElement element19 = this.Two(element18).Multiply(x); return(new FpPoint(curve, element15, element17, new ECFieldElement[] { element19 }, base.IsCompressed)); } case 2: { element20 = base.RawZCoords[0]; isOne = element20.IsOne; ECFieldElement element21 = rawYCoord.Square(); element22 = element21.Square(); ECFieldElement a = curve.A; ECFieldElement element24 = a.Negate(); if (!element24.ToBigInteger().Equals(BigInteger.ValueOf(3L))) { ECFieldElement x = rawXCoord.Square(); element25 = this.Three(x); if (isOne) { element25 = element25.Add(a); } else if (!a.IsZero) { ECFieldElement element30 = (!isOne ? element20.Square() : element20).Square(); if (element24.BitLength < a.BitLength) { element25 = element25.Subtract(element30.Multiply(element24)); } else { element25 = element25.Add(element30.Multiply(a)); } } element26 = this.Four(rawXCoord.Multiply(element21)); break; } ECFieldElement element27 = !isOne?element20.Square() : element20; element25 = this.Three(rawXCoord.Add(element27).Multiply(rawXCoord.Subtract(element27))); element26 = this.Four(element21.Multiply(rawXCoord)); break; } case 4: return(this.TwiceJacobianModified(true)); default: throw new InvalidOperationException("unsupported coordinate system"); } ECFieldElement b = element25.Square().Subtract(this.Two(element26)); ECFieldElement y = element26.Subtract(b).Multiply(element25).Subtract(this.Eight(element22)); ECFieldElement element33 = this.Two(rawYCoord); if (!isOne) { element33 = element33.Multiply(element20); } return(new FpPoint(curve, b, y, new ECFieldElement[] { element33 }, base.IsCompressed)); }
public override ECPoint Twice() { if (base.IsInfinity) { return(this); } ECCurve curve = this.Curve; ECFieldElement rawYCoord = base.RawYCoord; if (rawYCoord.IsZero) { return(curve.Infinity); } int coordinateSystem = curve.CoordinateSystem; ECFieldElement rawXCoord = base.RawXCoord; switch (coordinateSystem) { case 0: { ECFieldElement x = rawXCoord.Square(); ECFieldElement eCFieldElement = this.Three(x).Add(this.Curve.A).Divide(this.Two(rawYCoord)); ECFieldElement eCFieldElement2 = eCFieldElement.Square().Subtract(this.Two(rawXCoord)); ECFieldElement y = eCFieldElement.Multiply(rawXCoord.Subtract(eCFieldElement2)).Subtract(rawYCoord); return(new FpPoint(this.Curve, eCFieldElement2, y, base.IsCompressed)); } case 1: { ECFieldElement eCFieldElement3 = base.RawZCoords[0]; bool isOne = eCFieldElement3.IsOne; ECFieldElement eCFieldElement4 = curve.A; if (!eCFieldElement4.IsZero && !isOne) { eCFieldElement4 = eCFieldElement4.Multiply(eCFieldElement3.Square()); } eCFieldElement4 = eCFieldElement4.Add(this.Three(rawXCoord.Square())); ECFieldElement eCFieldElement5 = isOne ? rawYCoord : rawYCoord.Multiply(eCFieldElement3); ECFieldElement eCFieldElement6 = isOne ? rawYCoord.Square() : eCFieldElement5.Multiply(rawYCoord); ECFieldElement x2 = rawXCoord.Multiply(eCFieldElement6); ECFieldElement eCFieldElement7 = this.Four(x2); ECFieldElement eCFieldElement8 = eCFieldElement4.Square().Subtract(this.Two(eCFieldElement7)); ECFieldElement eCFieldElement9 = this.Two(eCFieldElement5); ECFieldElement x3 = eCFieldElement8.Multiply(eCFieldElement9); ECFieldElement eCFieldElement10 = this.Two(eCFieldElement6); ECFieldElement y2 = eCFieldElement7.Subtract(eCFieldElement8).Multiply(eCFieldElement4).Subtract(this.Two(eCFieldElement10.Square())); ECFieldElement x4 = isOne ? this.Two(eCFieldElement10) : eCFieldElement9.Square(); ECFieldElement eCFieldElement11 = this.Two(x4).Multiply(eCFieldElement5); return(new FpPoint(curve, x3, y2, new ECFieldElement[] { eCFieldElement11 }, base.IsCompressed)); } case 2: { ECFieldElement eCFieldElement12 = base.RawZCoords[0]; bool isOne2 = eCFieldElement12.IsOne; ECFieldElement eCFieldElement13 = rawYCoord.Square(); ECFieldElement x5 = eCFieldElement13.Square(); ECFieldElement a = curve.A; ECFieldElement eCFieldElement14 = a.Negate(); ECFieldElement eCFieldElement15; ECFieldElement eCFieldElement16; if (eCFieldElement14.ToBigInteger().Equals(BigInteger.ValueOf(3L))) { ECFieldElement b = isOne2 ? eCFieldElement12 : eCFieldElement12.Square(); eCFieldElement15 = this.Three(rawXCoord.Add(b).Multiply(rawXCoord.Subtract(b))); eCFieldElement16 = this.Four(eCFieldElement13.Multiply(rawXCoord)); } else { ECFieldElement x6 = rawXCoord.Square(); eCFieldElement15 = this.Three(x6); if (isOne2) { eCFieldElement15 = eCFieldElement15.Add(a); } else if (!a.IsZero) { ECFieldElement eCFieldElement17 = isOne2 ? eCFieldElement12 : eCFieldElement12.Square(); ECFieldElement eCFieldElement18 = eCFieldElement17.Square(); if (eCFieldElement14.BitLength < a.BitLength) { eCFieldElement15 = eCFieldElement15.Subtract(eCFieldElement18.Multiply(eCFieldElement14)); } else { eCFieldElement15 = eCFieldElement15.Add(eCFieldElement18.Multiply(a)); } } eCFieldElement16 = this.Four(rawXCoord.Multiply(eCFieldElement13)); } ECFieldElement eCFieldElement19 = eCFieldElement15.Square().Subtract(this.Two(eCFieldElement16)); ECFieldElement y3 = eCFieldElement16.Subtract(eCFieldElement19).Multiply(eCFieldElement15).Subtract(this.Eight(x5)); ECFieldElement eCFieldElement20 = this.Two(rawYCoord); if (!isOne2) { eCFieldElement20 = eCFieldElement20.Multiply(eCFieldElement12); } return(new FpPoint(curve, eCFieldElement19, y3, new ECFieldElement[] { eCFieldElement20 }, base.IsCompressed)); } case 4: return(this.TwiceJacobianModified(true)); } throw new InvalidOperationException("unsupported coordinate system"); }