public void InitialiseCurve() { BigInt p = new BigInt("bffffffffffffffffffffffffffcffff3", 16); Fp field = new Fp(p); curve = new EllipticCurve(field, BigInt.ZERO, BigInt.ONE); }
public void TestMultiply() { double One16th = Math.Pow(2, -4); double One256th = Math.Pow(2, -8); double One1024th = Math.Pow(2, -10); double t = 4; t += 3 * One16th; t += 2 * One256th; t += One1024th; Fp a = new Fp(t); a.ReportDigitsBin(); double t2 = 2; t2 += 2 * One16th; t2 += One256th; t2 += One1024th; Fp b = new Fp(t2); b.ReportDigitsBin(); Fp p = Fp.Mul(a, b); }
public static Fp One() { var fp = new Fp(); fp.SetInt(1); return(fp); }
static void TestETH_mapToG1() { var tbl = new[] { new { msg = "asdf", dst = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_", x = "bc73d15443009a8ff2ddce864136d892274dd8365c60d0d2d44cc543387348e366a8f1e1401427e37743c29ed2c939a", y = "101e26428a1b78c05458cb1cc37d2d87876ad3437096d2827f376702d4451667fe1fa82e82795495d33d466133ed1862", }, }; G1 P = new G1(); Fp x = new Fp(); Fp y = new Fp(); foreach (var v in tbl) { P.HashAndMapTo(v.msg); x.SetStr(v.x, 16); y.SetStr(v.y, 16); Normalize(ref P, P); Console.WriteLine("x={0}", P.x.GetStr(16)); Console.WriteLine("y={0}", P.y.GetStr(16)); assert("P.x", P.x.Equals(x)); assert("P.y", P.y.Equals(y)); } }
public static Fp One() { var x = new Fp(); x.SetInt(1); return(x); }
static void TestETH_mapToG1() { var tbl = new[] { new { msg = "asdf", x = "a72df17570d0eb81260042edbea415ad49bdb94a1bc1ce9d1bf147d0d48268170764bb513a3b994d662e1faba137106", y = "122b77eca1ed58795b7cd456576362f4f7bd7a572a29334b4817898a42414d31e9c0267f2dc481a4daf8bcf4a460322", }, }; G1 P = new G1(); Fp x = new Fp(); Fp y = new Fp(); foreach (var v in tbl) { P.HashAndMapTo(v.msg); x.SetStr(v.x, 16); y.SetStr(v.y, 16); Normalize(ref P, P); Console.WriteLine("x={0}", P.x.GetStr(16)); Console.WriteLine("y={0}", P.y.GetStr(16)); assert("P.x", P.x.Equals(x)); assert("P.y", P.y.Equals(y)); } }
public void TestMultiplyER() { double t = 1.000123456; Fp a = new Fp(t); a.ReportDigitsBin(); double t2 = 1.00278654; Fp b = new Fp(t2); b.ReportDigitsBin(); for (int i = 0; i < 100; i++) { Fp p = Fp.Mul(a, b); a = new Fp(p); a.ReportDigitsBin(); t = t * t2; } double t3 = t * t2; Fp c = new Fp(t3); c.ReportDigitsBin(); }
public void All_constructors_are_fine() { Fp a = new Fp(new BigInteger(2)); Fp b = new Fp(new byte[] { 2 }); Assert.AreEqual(a, (Fp)2); Assert.AreEqual(b, (Fp)2); }
public void setUp() { // fp = new ECPointTest.Fp(); Fp.CreatePoints(); // f2m = new ECPointTest.F2m(); F2m.CreatePoints(); }
public async Task <ActionResult> DeleteConfirmed(int id) { Fp fp = await db.Fps.FindAsync(id); db.Fps.Remove(fp); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public void SquareRootTest() { BigInt e = BigInt.ValueOf(5); BigInt pT = BigInt.ValueOf(11); BigInt aT = BigInt.ValueOf(3); Fp fT = new Fp(pT); Assert.AreEqual(e, fT.SquareRoot(aT)); }
public void Implicit_operators_seem_fine() { Fp a = 1; Fp b = 1U; Fp c = 1L; Fp d = 1UL; Fp e = new BigInteger(1); Assert.True(a == b && a == c && a == d && a == e); }
public void InitializeField() { BigInt p = new BigInt("bffffffffffffffffffffffffffcffff3", 16); field = new Fp(p); a = new BigInt("489a03c58dcf7fcfc97e99ffef0bb4634", 16); b = new BigInt("510c6972d795ec0c2b081b81de767f808", 16); c = new BigInt("417b9d98f934b571bffaed8d2968f6d67", 16); d = new BigInt("6bdafdf", 16); }
public async Task <ActionResult> Edit([Bind(Include = "fpid,nome")] Fp fp) { if (ModelState.IsValid) { db.Entry(fp).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(fp)); }
public override int GetHashCode() { int hash = 1; if (Id.Length != 0) { hash ^= Id.GetHashCode(); } if (Team != 0) { hash ^= Team.GetHashCode(); } if (Name.Length != 0) { hash ^= Name.GetHashCode(); } if (ImageUrl.Length != 0) { hash ^= ImageUrl.GetHashCode(); } if (Fp != 0) { hash ^= Fp.GetHashCode(); } if (Stamina != 0) { hash ^= Stamina.GetHashCode(); } if (MaxStamina != 0) { hash ^= MaxStamina.GetHashCode(); } if (FortType != 0) { hash ^= FortType.GetHashCode(); } if (Latitude != 0L) { hash ^= Latitude.GetHashCode(); } if (Longitude != 0L) { hash ^= Longitude.GetHashCode(); } if (Description.Length != 0) { hash ^= Description.GetHashCode(); } if (Modifier != 0D) { hash ^= Modifier.GetHashCode(); } return(hash); }
public BFUserPrivateKey(SerializedPrivateKey key) { this.key = new Point(new BigInt(key.KeyX), new BigInt(key.KeyY)); Fp field = new Fp(new BigInt(key.CurveField)); EllipticCurve curve = new EllipticCurve(field, new BigInt(key.CurveA), new BigInt(key.CurveB)); Pairing e = new TatePairing(curve, new BigInt(key.PairingGroupOrder), new BigInt(key.PairingCofactor)); Point p = new Point(new BigInt(key.PX), new BigInt(key.PY)); Point pPub = new Point(new BigInt(key.PPubX), new BigInt(key.PPubY)); this.param = new BFMasterPublicKey(e, p, pPub); }
public void InitializePoints() { BigInt xA = new BigInt("79e7128ff9ea31d83fcad7522eeaf8ef5dcddf2026dd8b61f31cb42c99f0b53e36f6879ea556d459f551b7ac87827b64a172cc3f5170acba502d3d4334ce6ae0", 16); BigInt yA = new BigInt("2dfab43956cfa22ab888f29f3f0de15117476e7ebe56ec0f56344cb848dc60b0d27960ec82fb217d6bc17e873f265139fb6d88080ce15d642f0b6c88f6eb5b93", 16); BigInt xB = new BigInt("488af43b1f7896f448eb9b2b0d8d08609fae80378331a2f46eff498ff74587c9faee194750fa83dab39c249af427ee35eca11c85ae040c251b0c3e2d42867a6c", 16); BigInt yB = new BigInt("2fc1857562f9d8a35157eadecfd990157f8a064038d7d7c9d721c57202de9d8f1456295983f0cb61332084f3df37e9d6d24aba24e563df2a82b6a851038dbf2e", 16); BigInt p = new BigInt("7401141187874108427630978940572992096905023977763437457544729409920516808700177140037470732982461341936680397619662697052215095603718060674210397061385939", 10); field = new Fp(p); a = new Complex(field, xA, yA); b = new Complex(field, xB, yB); }
public async Task <ActionResult> Create([Bind(Include = "fpid,nome")] Fp fp) { if (ModelState.IsValid) { db.Fps.Add(fp); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(fp)); }
public override int GetHashCode() { int hash = 1; if (FortId.Length != 0) { hash ^= FortId.GetHashCode(); } if (TeamColor != 0) { hash ^= TeamColor.GetHashCode(); } if (pokemonData_ != null) { hash ^= PokemonData.GetHashCode(); } if (Name.Length != 0) { hash ^= Name.GetHashCode(); } hash ^= imageUrls_.GetHashCode(); if (Fp != 0) { hash ^= Fp.GetHashCode(); } if (Stamina != 0) { hash ^= Stamina.GetHashCode(); } if (MaxStamina != 0) { hash ^= MaxStamina.GetHashCode(); } if (Type != 0) { hash ^= Type.GetHashCode(); } if (Latitude != 0D) { hash ^= Latitude.GetHashCode(); } if (Longitude != 0D) { hash ^= Longitude.GetHashCode(); } if (Description.Length != 0) { hash ^= Description.GetHashCode(); } hash ^= modifiers_.GetHashCode(); return(hash); }
// D.1.4 91 /** * return a sqrt root - the routine verifies that the calculation * returns the right value - if none exists it returns null. */ public override ECFieldElement sqrt() { // p mod 4 == 3 if (p.testBit(1)) { // z = g^(u+1) + p, p = 4u + 3 ECFieldElement z = new Fp(p, x.modPow(p.shiftRight(2).add(ECConstants.ONE), p)); return(z.square().Equals(this) ? z : null); } throw new Exception("not done yet"); }
public void Implicit_operators_reuse_zero() { Fp a = 0; Fp b = 0U; Fp c = 0L; Fp d = 0UL; Fp e = new BigInteger(0); Assert.True(ReferenceEquals(a, Fp.Zero), a.GetType().Name); Assert.True(ReferenceEquals(b, Fp.Zero), a.GetType().Name); Assert.True(ReferenceEquals(c, Fp.Zero), a.GetType().Name); Assert.True(ReferenceEquals(d, Fp.Zero), a.GetType().Name); Assert.True(ReferenceEquals(e, Fp.Zero), a.GetType().Name); }
public void Implicit_operators_reuse_one() { Fp a = 1; Fp b = 1U; Fp c = 1L; Fp d = 1UL; Fp e = new BigInteger(1); Assert.True(ReferenceEquals(a, Fp.One), a.GetType().Name); Assert.True(ReferenceEquals(b, Fp.One), a.GetType().Name); Assert.True(ReferenceEquals(c, Fp.One), a.GetType().Name); Assert.True(ReferenceEquals(d, Fp.One), a.GetType().Name); Assert.True(ReferenceEquals(e, Fp.One), a.GetType().Name); }
// GET: Fps/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Fp fp = await db.Fps.FindAsync(id); if (fp == null) { return(HttpNotFound()); } return(View(fp)); }
public void Works_modulo() { Fp result = (Fp)1 - (Parameters.P - 1); Assert.AreEqual((Fp)2, result, "sub"); result = (Fp)1 + (Parameters.P - 1); Assert.AreEqual((Fp)0, result, "add"); result = ((Fp)Parameters.P - 1).Double(); Assert.AreEqual((Fp)BigInteger.Parse("21888242871839275222246405745257275088696311157297823662689037894645226208581"), result, "double"); result = ((Fp)Parameters.P - 1).Negate(); Assert.AreEqual((Fp)1, result, "double"); }
static void TestFp() { Console.WriteLine("TestFp"); Fp x = new Fp(); assert("x.isZero", x.IsZero()); x.Clear(); assert("0", x.GetStr(10) == "0"); assert("0.IzZero", x.IsZero()); assert("!0.IzOne", !x.IsOne()); x.SetInt(1); assert("1", x.GetStr(10) == "1"); assert("!1.IzZero", !x.IsZero()); assert("1.IzOne", x.IsOne()); x.SetInt(3); assert("3", x.GetStr(10) == "3"); assert("!3.IzZero", !x.IsZero()); assert("!3.IzOne", !x.IsOne()); x.SetInt(-5); x = -x; assert("5", x.GetStr(10) == "5"); x.SetInt(4); x = x * x; assert("16", x.GetStr(10) == "16"); assert("10", x.GetStr(16) == "10"); Fp y; y = x; assert("x == y", x.Equals(y)); x.SetInt(123); assert("123", x.GetStr(10) == "123"); assert("7b", x.GetStr(16) == "7b"); assert("y != x", !x.Equals(y)); Console.WriteLine("exception test"); try { x.SetStr("1234567891234x", 10); Console.WriteLine("x = {0}", x); } catch (Exception e) { Console.WriteLine("OK ; expected exception: {0}", e); } x.SetStr("1234567891234", 10); assert("1234567891234", x.GetStr(10) == "1234567891234"); { byte[] buf = x.Serialize(); y.Deserialize(buf); assert("x == y", x.Equals(y)); } }
public static TatePairing nssTate() { BigInt p = new BigInt("8D5006492B424C09D2FEBE717EE382A57EBE3A352FC383E1AC79F21DDB43706CFB192333A7E9CF644636332E83D90A1E56EFBAE8715AA07883483F8267E80ED3", 16); Field field = new Fp(p); //order =2^159+2^17+1 BigInt orderOfGroup = new BigInt("8000000000000000000000000000000000020001", 16); //BigInt orderOfE= new BigInt("11711338024714009669995700965425239711927177698599625717955894184681899877662611539569996945969293708404400344208273812850399351303651875378098503534075638"); //co-factor BigInt cof = new BigInt("11AA00C9256849813A5FD7CE2FDC7054AFD7809E7F7FD948C4B9C1C1E76FFEFF4ECAB83C950112DECB41D6EDA", 16); FieldElement a4 = field.Negate(BigInt.ValueOf(3)); FieldElement a6 = new BigInt("609993837367998001C95B87A6BA872135E26906DB4C192D6E038486177A3EDF6C50B9BB20DF881F2BD05842F598F3E037B362DBF89F0A62E5871D41D951BF8E", 16); EllipticCurve ec = new EllipticCurve(field, field.GetZero(), field.GetZero(), field.GetZero(), a4, a6); return(new TatePairing(ec, orderOfGroup, cof)); }
public static TatePairing ssTate() { BigInt p = new BigInt("8BA2A5229BD9C57CFC8ACEC76DFDBF3E3E1952C6B3193ECF5C571FB502FC5DF410F9267E9F2A605BB0F76F52A79E8043BF4AF0EF2E9FA78B0F1E2CDFC4E8549B", 16); Field field = new Fp(p); BigInt orderOfGroup = new BigInt("8000000000000000000000000000000000020001", 16); BigInt cof = new BigInt("117454A4537B38AF9F9159D8EDBFB7E7C7C2E48760E930A461D5F451F9D9210DC70095F4B241FF57F1BB0549C", 16); //curve //y^2=x^3+x FieldElement a = field.GetOne(); FieldElement b = field.GetZero(); EllipticCurve ec = new EllipticCurve(field, a, b); return(new TatePairing(ec, orderOfGroup, cof)); }
public static TatePairing ssTate2() { BigInt p = new BigInt("8780710799663312522437781984754049815806883199414208211028653399266475630880222957078625179422662221423155858769582317459277713367317481324925129998224791", 10); Field field = new Fp(p); BigInt orderOfGroup = new BigInt("730750818665451621361119245571504901405976559617", 10); BigInt cof = new BigInt("12016012264891146079388821366740534204802954401251311822919615131047207289359704531102844802183906537786776", 10); //curve //y^2=x^3+x FieldElement a4 = field.GetOne(); FieldElement a6 = field.GetZero(); EllipticCurve ec = new EllipticCurve(field, field.GetZero(), field.GetZero(), field.GetZero(), a4, a6); return(new TatePairing(ec, orderOfGroup, cof)); }
public void TestCreateFp() { double One256th = 0.00390625; double One1024th = Math.Pow(2, -10); double t = 12; t += One256th; t += One1024th; Fp a = new Fp(t); a.ReportDigitsBin(); double tc = a.GetDouble(); DComponents dtc = new DComponents(tc); Debug.WriteLine($"The recombined value is {dtc.ToBase2String(false)}, (Decimal: {tc})."); }
public void ComputeTest() { BigInt p = new BigInt("bffffffffffffffffffffffffffcffff3", 16); BigInt q = new BigInt("fffffffffffffffffffffffffffbffff", 16); BigInt cofactor = p.Add(BigInt.ONE); Fp field = new Fp(p); EllipticCurve curve = new EllipticCurve(field, BigInt.ZERO, BigInt.ONE); Pairing pairing = new TatePairing(curve, q, cofactor); BigInt xA = new BigInt("489a03c58dcf7fcfc97e99ffef0bb4634", 16); BigInt yA = new BigInt("510c6972d795ec0c2b081b81de767f808", 16); BigInt xB = new BigInt("40e98b9382e0b1fa6747dcb1655f54f75", 16); BigInt yB = new BigInt("b497a6a02e7611511d0db2ff133b32a3f", 16); Point a = new Point(xA, yA); Point b = new Point(xB, yB); FieldElement result = pairing.Compute(a, b); BigInt xE = new BigInt("18901869995136711856104482098716151434", 10); BigInt yE = new BigInt("3528981068833319305513374283552333670736", 10); FieldElement expected = new Complex(field, xE, yE); Assert.AreEqual(expected, result); }