public EncriptionResult EncryptEncodedNumber(ECCPoint encodedNumber, ECCPoint openKey) { var seancePrivateKey = GeneratePrivateKey(GeneratorPoint.PointDimention); var left = ECCPoint.Multiply(seancePrivateKey, GeneratorPoint); //tip for decryption var right = encodedNumber + ECCPoint.Multiply(seancePrivateKey, openKey); //encrypted point return(new EncriptionResult(left, right)); }
public ECCKey GenerateKey() { var key = new ECCKey(); key.PrivateKey = GeneratePrivateKey(GeneratorPoint.PointDimention); key.OpenKey = ECCPoint.Multiply(key.PrivateKey, GeneratorPoint); key.P = GeneratorPoint.Curve.FieldModule; key.G = GeneratorPoint; return(key); }
public ECCPoint CreatePoint() { Random random = new Random(); var bytes = new byte[64]; random.NextBytes(bytes); var privateKey = new mpz_t(bytes, 0) % GeneratorPoint.PointDimention; if (privateKey < 0) { privateKey = privateKey * -1; } return(ECCPoint.Multiply(privateKey, GeneratorPoint)); }
public static ECCPoint Double(ECCPoint point) { var pointX = new mpz_t(point.X); var pointY = new mpz_t(point.Y); var module = new mpz_t(point.Curve.FieldModule); var curveAkof = new mpz_t(point.Curve.A); if (point == O) { return(O); } var dy = 3 * pointX * pointX + curveAkof; var dx = 2 * pointY; if (dx < 0) { dx += module; } if (dy < 0) { dy += module; } var dxInverse = dx.InvertMod(module);// BigInteger.ModPow(dx, curve.FieldModule - 2, curve.FieldModule); var m = (dy * dxInverse) % module; var resultX = (m * m - pointX - pointX) % module; var resultY = (m * (pointX - resultX) - pointY) % module; if (resultX < 0) { resultX += module; } if (resultY < 0) { resultY += module; } return(point.Curve.GetPoint(resultX, resultY)); }
public static ECCPoint Multiply(mpz_t x, ECCPoint p) { ECCPoint temp = p; x = x - 1; while (x != 0) { if ((x % 2) != 0) { if ((temp.X == p.X) || (temp.Y == p.Y)) { temp = Double(temp); } else { temp = temp + p; } x = x - 1; } x = x / 2; p = Double(p); } return(temp); }
public EncriptionResult(ECCPoint left, ECCPoint right) { Left = left; Right = right; }