public static void GetB32(byte[] r, int index, Fe a) { r[index] = (byte)(a.N[9] >> 14 & (uint)byte.MaxValue); r[index + 1] = (byte)(a.N[9] >> 6 & (uint)byte.MaxValue); r[index + 2] = (byte)(((int)a.N[9] & 63) << 2 | (int)(a.N[8] >> 24) & 3); r[index + 3] = (byte)(a.N[8] >> 16 & (uint)byte.MaxValue); r[index + 4] = (byte)(a.N[8] >> 8 & (uint)byte.MaxValue); r[index + 5] = (byte)(a.N[8] & (uint)byte.MaxValue); r[index + 6] = (byte)(a.N[7] >> 18 & (uint)byte.MaxValue); r[index + 7] = (byte)(a.N[7] >> 10 & (uint)byte.MaxValue); r[index + 8] = (byte)(a.N[7] >> 2 & (uint)byte.MaxValue); r[index + 9] = (byte)(((int)a.N[7] & 3) << 6 | (int)(a.N[6] >> 20) & 63); r[index + 10] = (byte)(a.N[6] >> 12 & (uint)byte.MaxValue); r[index + 11] = (byte)(a.N[6] >> 4 & (uint)byte.MaxValue); r[index + 12] = (byte)(((int)a.N[6] & 15) << 4 | (int)(a.N[5] >> 22) & 15); r[index + 13] = (byte)(a.N[5] >> 14 & (uint)byte.MaxValue); r[index + 14] = (byte)(a.N[5] >> 6 & (uint)byte.MaxValue); r[index + 15] = (byte)(((int)a.N[5] & 63) << 2 | (int)(a.N[4] >> 24) & 3); r[index + 16] = (byte)(a.N[4] >> 16 & (uint)byte.MaxValue); r[index + 17] = (byte)(a.N[4] >> 8 & (uint)byte.MaxValue); r[index + 18] = (byte)(a.N[4] & (uint)byte.MaxValue); r[index + 19] = (byte)(a.N[3] >> 18 & (uint)byte.MaxValue); r[index + 20] = (byte)(a.N[3] >> 10 & (uint)byte.MaxValue); r[index + 21] = (byte)(a.N[3] >> 2 & (uint)byte.MaxValue); r[index + 22] = (byte)(((int)a.N[3] & 3) << 6 | (int)(a.N[2] >> 20) & 63); r[index + 23] = (byte)(a.N[2] >> 12 & (uint)byte.MaxValue); r[index + 24] = (byte)(a.N[2] >> 4 & (uint)byte.MaxValue); r[index + 25] = (byte)(((int)a.N[2] & 15) << 4 | (int)(a.N[1] >> 22) & 15); r[index + 26] = (byte)(a.N[1] >> 14 & (uint)byte.MaxValue); r[index + 27] = (byte)(a.N[1] >> 6 & (uint)byte.MaxValue); r[index + 28] = (byte)(((int)a.N[1] & 63) << 2 | (int)(a.N[0] >> 24) & 3); r[index + 29] = (byte)(a.N[0] >> 16 & (uint)byte.MaxValue); r[index + 30] = (byte)(a.N[0] >> 8 & (uint)byte.MaxValue); r[index + 31] = (byte)(a.N[0] & (uint)byte.MaxValue); }
public static void Clear(Fe a) { for (int index = 0; index < 10; ++index) { a.N[index] = 0U; } }
public static void GetB32(byte[] r, Fe a) { r[0] = (byte)(a.N[9] >> 14 & (uint)byte.MaxValue); r[1] = (byte)(a.N[9] >> 6 & (uint)byte.MaxValue); r[2] = (byte)(((int)a.N[9] & 63) << 2 | (int)(a.N[8] >> 24) & 3); r[3] = (byte)(a.N[8] >> 16 & (uint)byte.MaxValue); r[4] = (byte)(a.N[8] >> 8 & (uint)byte.MaxValue); r[5] = (byte)(a.N[8] & (uint)byte.MaxValue); r[6] = (byte)(a.N[7] >> 18 & (uint)byte.MaxValue); r[7] = (byte)(a.N[7] >> 10 & (uint)byte.MaxValue); r[8] = (byte)(a.N[7] >> 2 & (uint)byte.MaxValue); r[9] = (byte)(((int)a.N[7] & 3) << 6 | (int)(a.N[6] >> 20) & 63); r[10] = (byte)(a.N[6] >> 12 & (uint)byte.MaxValue); r[11] = (byte)(a.N[6] >> 4 & (uint)byte.MaxValue); r[12] = (byte)(((int)a.N[6] & 15) << 4 | (int)(a.N[5] >> 22) & 15); r[13] = (byte)(a.N[5] >> 14 & (uint)byte.MaxValue); r[14] = (byte)(a.N[5] >> 6 & (uint)byte.MaxValue); r[15] = (byte)(((int)a.N[5] & 63) << 2 | (int)(a.N[4] >> 24) & 3); r[16] = (byte)(a.N[4] >> 16 & (uint)byte.MaxValue); r[17] = (byte)(a.N[4] >> 8 & (uint)byte.MaxValue); r[18] = (byte)(a.N[4] & (uint)byte.MaxValue); r[19] = (byte)(a.N[3] >> 18 & (uint)byte.MaxValue); r[20] = (byte)(a.N[3] >> 10 & (uint)byte.MaxValue); r[21] = (byte)(a.N[3] >> 2 & (uint)byte.MaxValue); r[22] = (byte)(((int)a.N[3] & 3) << 6 | (int)(a.N[2] >> 20) & 63); r[23] = (byte)(a.N[2] >> 12 & (uint)byte.MaxValue); r[24] = (byte)(a.N[2] >> 4 & (uint)byte.MaxValue); r[25] = (byte)(((int)a.N[2] & 15) << 4 | (int)(a.N[1] >> 22) & 15); r[26] = (byte)(a.N[1] >> 14 & (uint)byte.MaxValue); r[27] = (byte)(a.N[1] >> 6 & (uint)byte.MaxValue); r[28] = (byte)(((int)a.N[1] & 63) << 2 | (int)(a.N[0] >> 24) & 3); r[29] = (byte)(a.N[0] >> 16 & (uint)byte.MaxValue); r[30] = (byte)(a.N[0] >> 8 & (uint)byte.MaxValue); r[31] = (byte)(a.N[0] & (uint)byte.MaxValue); }
public static void InvAllVar(Fe[] r, Fe[] a, int len) { if (len < 1) { return; } for (int index = 0; index < len; ++index) { r[index] = a[index].Clone(); } int index1 = 0; while (++index1 < len) { Field.Mul(r[index1], r[index1 - 1], a[index1]); } Fe fe = new Fe(); int index2; Field.InvVar(fe, r[index2 = index1 - 1]); while (index2 > 0) { int index3 = index2--; Field.Mul(r[index3], r[index2], fe); Field.Mul(fe, fe, a[index3]); } r[0] = fe.Clone(); }
public void runAI() { whenIStartIA = Environment.TickCount; usedneurons = 0; JSIAMind mind = GetMindOf(type); try { do { if (!CanPlay()) { break; } myNeuron = new AINeuron(); usedneurons++; try { mind.Play(this); } catch (FightException Fe) { throw Fe; } catch (FighterException fe) { throw fe; } catch (Exception e) { Logger.Error(e); } finally { if (myNeuron != null) { myNeuron.Dispose(); myNeuron = null; } } Wait(10); } while (CanPlay()); } catch (FightException Fe) { Fe.finalAction(); } catch (FighterException fe) { fe.finalAction(); } finally { whenIStartIA = 0; usedneurons = 0; mind = null; } }
/// <summary> /// Same as Equal, but may be variable time. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static bool EqualVar(Fe a, Fe b) { Fe na = new Fe(); Negate(na, a, 1); Add(na, b); return(NormalizesToZeroVar(na)); }
public static bool EqualVar(Fe a, Fe b) { Fe r = new Fe(); Field.Negate(r, a, 1U); Field.Add(r, b); return(Field.NormalizesToZeroVar(r)); }
public static bool NormalizesToZeroVar(Fe r) { uint num1 = r.N[0]; uint num2 = r.N[9]; uint num3 = num2 >> 22; uint num4 = num1 + num3 * 977U; uint num5 = num4 & 67108863U; uint num6 = num5 ^ 976U; if (num5 > 0U & num6 != 67108863U) { return(false); } uint num7 = r.N[1]; uint num8 = r.N[2]; uint num9 = r.N[3]; uint num10 = r.N[4]; uint num11 = r.N[5]; uint num12 = r.N[6]; uint num13 = r.N[7]; uint num14 = r.N[8]; uint num15 = num2 & 4194303U; uint num16 = num7 + (num3 << 6) + (num4 >> 26); uint num17 = num8 + (num16 >> 26); uint num18 = num16 & 67108863U; uint num19 = num5 | num18; uint num20 = num6 & (num18 ^ 64U); uint num21 = num9 + (num17 >> 26); uint num22 = num17 & 67108863U; uint num23 = num19 | num22; uint num24 = num20 & num22; uint num25 = num10 + (num21 >> 26); uint num26 = num21 & 67108863U; uint num27 = num23 | num26; uint num28 = num24 & num26; uint num29 = num11 + (num25 >> 26); uint num30 = num25 & 67108863U; uint num31 = num27 | num30; uint num32 = num28 & num30; uint num33 = num12 + (num29 >> 26); uint num34 = num29 & 67108863U; uint num35 = num31 | num34; uint num36 = num32 & num34; uint num37 = num13 + (num33 >> 26); uint num38 = num33 & 67108863U; uint num39 = num35 | num38; uint num40 = num36 & num38; uint num41 = num14 + (num37 >> 26); uint num42 = num37 & 67108863U; uint num43 = num39 | num42; uint num44 = num40 & num42; uint num45 = num15 + (num41 >> 26); uint num46 = num41 & 67108863U; uint num47 = num43 | num46; uint num48 = num44 & num46; return((num47 | num45) == 0U | (num48 & (num45 ^ 62914560U)) == 67108863U); }
public static void ToStorage(FeStorage r, Fe a) { r.N[0] = a.N[0] | a.N[1] << 26; r.N[1] = a.N[1] >> 6 | a.N[2] << 20; r.N[2] = a.N[2] >> 12 | a.N[3] << 14; r.N[3] = a.N[3] >> 18 | a.N[4] << 8; r.N[4] = (uint)((int)(a.N[4] >> 24) | (int)a.N[5] << 2 | (int)a.N[6] << 28); r.N[5] = a.N[6] >> 4 | a.N[7] << 22; r.N[6] = a.N[7] >> 10 | a.N[8] << 16; r.N[7] = a.N[8] >> 16 | a.N[9] << 10; }
public static void Negate(Fe r, Fe a, uint m) { r.N[0] = (uint)(134215774 * ((int)m + 1)) - a.N[0]; r.N[1] = (uint)(134217598 * ((int)m + 1)) - a.N[1]; r.N[2] = (uint)(134217726 * ((int)m + 1)) - a.N[2]; r.N[3] = (uint)(134217726 * ((int)m + 1)) - a.N[3]; r.N[4] = (uint)(134217726 * ((int)m + 1)) - a.N[4]; r.N[5] = (uint)(134217726 * ((int)m + 1)) - a.N[5]; r.N[6] = (uint)(134217726 * ((int)m + 1)) - a.N[6]; r.N[7] = (uint)(134217726 * ((int)m + 1)) - a.N[7]; r.N[8] = (uint)(134217726 * ((int)m + 1)) - a.N[8]; r.N[9] = (uint)(8388606 * ((int)m + 1)) - a.N[9]; }
public static void MulInt(Fe r, uint a) { r.N[0] *= a; r.N[1] *= a; r.N[2] *= a; r.N[3] *= a; r.N[4] *= a; r.N[5] *= a; r.N[6] *= a; r.N[7] *= a; r.N[8] *= a; r.N[9] *= a; }
public static void Add(Fe r, Fe a) { r.N[0] += a.N[0]; r.N[1] += a.N[1]; r.N[2] += a.N[2]; r.N[3] += a.N[3]; r.N[4] += a.N[4]; r.N[5] += a.N[5]; r.N[6] += a.N[6]; r.N[7] += a.N[7]; r.N[8] += a.N[8]; r.N[9] += a.N[9]; }
public static void FromStorage(Fe r, FeStorage a) { r.N[0] = a.N[0] & 67108863U; r.N[1] = a.N[0] >> 26 | (uint)((int)a.N[1] << 6 & 67108863); r.N[2] = a.N[1] >> 20 | (uint)((int)a.N[2] << 12 & 67108863); r.N[3] = a.N[2] >> 14 | (uint)((int)a.N[3] << 18 & 67108863); r.N[4] = a.N[3] >> 8 | (uint)((int)a.N[4] << 24 & 67108863); r.N[5] = a.N[4] >> 2 & 67108863U; r.N[6] = a.N[4] >> 28 | (uint)((int)a.N[5] << 4 & 67108863); r.N[7] = a.N[5] >> 22 | (uint)((int)a.N[6] << 10 & 67108863); r.N[8] = a.N[6] >> 16 | (uint)((int)a.N[7] << 16 & 67108863); r.N[9] = a.N[7] >> 10; }
public static bool SetB32(Fe r, byte[] a) { r.N[0] = (uint)((int)a[31] | (int)a[30] << 8 | (int)a[29] << 16 | ((int)a[28] & 3) << 24); r.N[1] = (uint)((int)a[28] >> 2 & 63 | (int)a[27] << 6 | (int)a[26] << 14 | ((int)a[25] & 15) << 22); r.N[2] = (uint)((int)a[25] >> 4 & 15 | (int)a[24] << 4 | (int)a[23] << 12 | ((int)a[22] & 63) << 20); r.N[3] = (uint)((int)a[22] >> 6 & 3 | (int)a[21] << 2 | (int)a[20] << 10 | (int)a[19] << 18); r.N[4] = (uint)((int)a[18] | (int)a[17] << 8 | (int)a[16] << 16 | ((int)a[15] & 3) << 24); r.N[5] = (uint)((int)a[15] >> 2 & 63 | (int)a[14] << 6 | (int)a[13] << 14 | ((int)a[12] & 15) << 22); r.N[6] = (uint)((int)a[12] >> 4 & 15 | (int)a[11] << 4 | (int)a[10] << 12 | ((int)a[9] & 63) << 20); r.N[7] = (uint)((int)a[9] >> 6 & 3 | (int)a[8] << 2 | (int)a[7] << 10 | (int)a[6] << 18); r.N[8] = (uint)((int)a[5] | (int)a[4] << 8 | (int)a[3] << 16 | ((int)a[2] & 3) << 24); r.N[9] = (uint)((int)a[2] >> 2 & 63 | (int)a[1] << 6 | (int)a[0] << 14); return(r.N[9] != 4194303U || ((int)r.N[8] & (int)r.N[7] & (int)r.N[6] & (int)r.N[5] & (int)r.N[4] & (int)r.N[3] & (int)r.N[2]) != 67108863 || r.N[1] + 64U + (r.N[0] + 977U >> 26) <= 67108863U); }
public static bool SetB32(Fe r, byte[] a, int index) { r.N[0] = (uint)((int)a[index + 31] | (int)a[index + 30] << 8 | (int)a[index + 29] << 16 | ((int)a[index + 28] & 3) << 24); r.N[1] = (uint)((int)a[index + 28] >> 2 & 63 | (int)a[index + 27] << 6 | (int)a[index + 26] << 14 | ((int)a[index + 25] & 15) << 22); r.N[2] = (uint)((int)a[index + 25] >> 4 & 15 | (int)a[index + 24] << 4 | (int)a[index + 23] << 12 | ((int)a[index + 22] & 63) << 20); r.N[3] = (uint)((int)a[index + 22] >> 6 & 3 | (int)a[index + 21] << 2 | (int)a[index + 20] << 10 | (int)a[index + 19] << 18); r.N[4] = (uint)((int)a[index + 18] | (int)a[index + 17] << 8 | (int)a[index + 16] << 16 | ((int)a[index + 15] & 3) << 24); r.N[5] = (uint)((int)a[index + 15] >> 2 & 63 | (int)a[index + 14] << 6 | (int)a[index + 13] << 14 | ((int)a[index + 12] & 15) << 22); r.N[6] = (uint)((int)a[index + 12] >> 4 & 15 | (int)a[index + 11] << 4 | (int)a[index + 10] << 12 | ((int)a[index + 9] & 63) << 20); r.N[7] = (uint)((int)a[index + 9] >> 6 & 3 | (int)a[index + 8] << 2 | (int)a[index + 7] << 10 | (int)a[index + 6] << 18); r.N[8] = (uint)((int)a[index + 5] | (int)a[index + 4] << 8 | (int)a[index + 3] << 16 | ((int)a[index + 2] & 3) << 24); r.N[9] = (uint)((int)a[index + 2] >> 2 & 63 | (int)a[index + 1] << 6 | (int)a[index] << 14); return(r.N[9] != 4194303U || ((int)r.N[8] & (int)r.N[7] & (int)r.N[6] & (int)r.N[5] & (int)r.N[4] & (int)r.N[3] & (int)r.N[2]) != 67108863 || r.N[1] + 64U + (r.N[0] + 977U >> 26) <= 67108863U); }
public static void Cmov(Fe r, Fe a, uint flag) { uint num1 = flag + uint.MaxValue; uint num2 = ~num1; r.N[0] = (uint)((int)r.N[0] & (int)num1 | (int)a.N[0] & (int)num2); r.N[1] = (uint)((int)r.N[1] & (int)num1 | (int)a.N[1] & (int)num2); r.N[2] = (uint)((int)r.N[2] & (int)num1 | (int)a.N[2] & (int)num2); r.N[3] = (uint)((int)r.N[3] & (int)num1 | (int)a.N[3] & (int)num2); r.N[4] = (uint)((int)r.N[4] & (int)num1 | (int)a.N[4] & (int)num2); r.N[5] = (uint)((int)r.N[5] & (int)num1 | (int)a.N[5] & (int)num2); r.N[6] = (uint)((int)r.N[6] & (int)num1 | (int)a.N[6] & (int)num2); r.N[7] = (uint)((int)r.N[7] & (int)num1 | (int)a.N[7] & (int)num2); r.N[8] = (uint)((int)r.N[8] & (int)num1 | (int)a.N[8] & (int)num2); r.N[9] = (uint)((int)r.N[9] & (int)num1 | (int)a.N[9] & (int)num2); }
public static void NormalizeWeak(Fe r) { uint num1 = r.N[0]; uint num2 = r.N[1]; uint num3 = r.N[2]; uint num4 = r.N[3]; uint num5 = r.N[4]; uint num6 = r.N[5]; uint num7 = r.N[6]; uint num8 = r.N[7]; uint num9 = r.N[8]; uint num10 = r.N[9]; uint num11 = num10 >> 22; uint num12 = num10 & 4194303U; uint num13 = num1 + num11 * 977U; uint num14 = num2 + (num11 << 6) + (num13 >> 26); uint num15 = num13 & 67108863U; uint num16 = num3 + (num14 >> 26); uint num17 = num14 & 67108863U; uint num18 = num4 + (num16 >> 26); uint num19 = num16 & 67108863U; uint num20 = num5 + (num18 >> 26); uint num21 = num18 & 67108863U; uint num22 = num6 + (num20 >> 26); uint num23 = num20 & 67108863U; uint num24 = num7 + (num22 >> 26); uint num25 = num22 & 67108863U; uint num26 = num8 + (num24 >> 26); uint num27 = num24 & 67108863U; uint num28 = num9 + (num26 >> 26); uint num29 = num26 & 67108863U; uint num30 = num12 + (num28 >> 26); uint num31 = num28 & 67108863U; r.N[0] = num15; r.N[1] = num17; r.N[2] = num19; r.N[3] = num21; r.N[4] = num23; r.N[5] = num25; r.N[6] = num27; r.N[7] = num29; r.N[8] = num31; r.N[9] = num30; }
private void TimeDomainInit(int samplesPerSecond) { hangover = 0; NLMS_LEN = FilterLength; x = new float[NLMS_LEN + NLMS_EXT]; // tap delayed loudspeaker signal xf = new float[NLMS_LEN + NLMS_EXT]; // pre-whitening tap delayed signal h = new float[NLMS_LEN]; // tap weights j = NLMS_EXT; delta = 0.0f; Ambient = NoiseFloor; dfast = dslow = M75dB_PCM; xfast = xslow = M80dB_PCM; gain = 1.0f; Fx.Init(2000.0f / samplesPerSecond); Fe.Init(2000.0f / samplesPerSecond); aes_y2 = M0dB; }
public override int GetHashCode() { int hash = 1; if (Fe != 0L) { hash ^= Fe.GetHashCode(); } if (Ctp != 0L) { hash ^= Ctp.GetHashCode(); } if (Channel != 0L) { hash ^= Channel.GetHashCode(); } hash ^= gate_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public GeJ(Fe xVal, Fe yVal, Fe zVal) { this.X = xVal ?? new Fe(); this.Y = yVal ?? new Fe(); this.Z = zVal ?? new Fe(); }
public ActionResult UpdateFee(Fe obj) { try { DB49Entities k = new DB49Entities(); List <Student> students = k.Students.ToList(); ViewBag.StudentList = new SelectList(students, "StudentID", "Name"); List <Scholarshipss> scholarships = k.Scholarshipsses.ToList(); ViewBag.ScholarshipList = new SelectList(scholarships, "ScholarshipID", "Scholarship"); List <Lookup> lookups = k.Lookups.ToList(); ViewBag.LookupList = new SelectList(lookups, "LookupID", "Name"); Student s = new Student(); Scholarshipss t = new Scholarshipss(); Lookup p = new Lookup(); Fe d = new Fe(); d.StudentID = obj.StudentID; d.ScholarshipID = obj.ScholarshipID; d.LookupID = obj.LookupID; d.LookupID = obj.LookupID; d.NewFee = obj.NewFee; k.Fes.Add(d); k.SaveChanges(); var m = k.Fes.Where(n => n.StudentID == obj.StudentID).ToList(); foreach (var item in m) { // var k = db.Students.Select(new Student { EmailId = l.Email }).ToList(); if (item != null) { Session["FeeID"] = d.FeeID.ToString(); Session["ScholarshipID"] = d.ScholarshipID.ToString(); Session["LookupID"] = d.LookupID.ToString(); Session["NewFee"] = d.NewFee.ToString(); Session["StudentID"] = d.StudentID.ToString(); return(RedirectToAction("UpFeeChallan", "Student")); // message = " Course Registered Successfully.\\nRegisteredCourse Id:" + r.RegisteredCourseID.ToString(); //ViewBag.Message = message; } } } catch (DbEntityValidationException e) { Console.WriteLine(e.ToString()); } return(View(obj)); }
public static bool IsOdd(Fe a) { return((a.N[0] & 1U) > 0U); }
/** Checks whether a field element is a quadratic residue. */ // static int secp256k1_fe_is_quad_var(const secp256k1_fe* a) // { //# ifndef USE_NUM_NONE // unsigned char b[32]; // secp256k1_num n; // secp256k1_num m; // /* secp256k1 field prime, value p defined in "Standards for Efficient Cryptography" (SEC2) 2.7.1. */ // static const unsigned char prime[32] = { // 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, // 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, // 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, // 0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F // }; // secp256k1_fe c = *a; // NormalizeVar(c); // GetB32(b, c); // secp256k1_num_set_bin(n, b, 32); // secp256k1_num_set_bin(m, prime, 32); // return secp256k1_num_jacobi(n, m) >= 0; //#else // secp256k1_fe r; // return Sqrt(r, a); //#endif //} /// <summary> /// Sets a field element to be the (modular) inverse of another. Requires the input's magnitude to be at most 8. The output magnitude is 1 (but not guaranteed to be normalized). /// </summary> /// <param name="r"></param> /// <param name="a"></param> /// <returns></returns> public static void Inv(Fe r, Fe a) { Fe x2, x3, x6, x9, x11, x22, x44, x88, x176, x220, x223, t1; int j; /** The binary representation of (p - 2) has 5 blocks of 1s, with lengths in * { 1, 2, 22, 223 }. Use an addition chain to calculate 2^n - 1 for each block: * [1], [2], 3, 6, 9, 11, [22], 44, 88, 176, 220, [223] */ x2 = new Fe(); Sqr(x2, a); Mul(x2, x2, a); x3 = new Fe(); Sqr(x3, x2); Mul(x3, x3, a); x6 = x3.Clone(); for (j = 0; j < 3; j++) { Sqr(x6, x6); } Mul(x6, x6, x3); x9 = x6.Clone(); for (j = 0; j < 3; j++) { Sqr(x9, x9); } Mul(x9, x9, x3); x11 = x9.Clone(); for (j = 0; j < 2; j++) { Sqr(x11, x11); } Mul(x11, x11, x2); x22 = x11.Clone(); for (j = 0; j < 11; j++) { Sqr(x22, x22); } Mul(x22, x22, x11); x44 = x22.Clone(); for (j = 0; j < 22; j++) { Sqr(x44, x44); } Mul(x44, x44, x22); x88 = x44.Clone(); for (j = 0; j < 44; j++) { Sqr(x88, x88); } Mul(x88, x88, x44); x176 = x88.Clone(); for (j = 0; j < 88; j++) { Sqr(x176, x176); } Mul(x176, x176, x88); x220 = x176.Clone(); for (j = 0; j < 44; j++) { Sqr(x220, x220); } Mul(x220, x220, x44); x223 = x220.Clone(); for (j = 0; j < 3; j++) { Sqr(x223, x223); } Mul(x223, x223, x3); /* The final result is then assembled using a sliding window over the blocks. */ t1 = x223.Clone(); for (j = 0; j < 23; j++) { Sqr(t1, t1); } Mul(t1, t1, x22); for (j = 0; j < 5; j++) { Sqr(t1, t1); } Mul(t1, t1, a); for (j = 0; j < 3; j++) { Sqr(t1, t1); } Mul(t1, t1, x2); for (j = 0; j < 2; j++) { Sqr(t1, t1); } Mul(r, a, t1); }
public Ge() { this.X = new Fe(); this.Y = new Fe(); }
public Ge(uint[] xarr, uint[] yarr) { this.X = new Fe(xarr); this.Y = new Fe(yarr); }
public static void Mul(Fe r, Fe a, Fe b) { Field.MulInner(r.N, a.N, b.N); }
/// <summary> /// Potentially faster version of Inv, without constant-time guarantee. /// </summary> /// <param name="r"></param> /// <param name="a"></param> /// <returns></returns> public static void InvVar(Fe r, Fe a) { #if USE_FIELD_INV_BUILTIN Inv(r, a); #elif USE_FIELD_INV_NUM secp256k1_num n, m;
public static void Sqr(Fe r, Fe a) { Field.SqrInner(r.N, a.N); }
/** Compare two field elements. Requires both inputs to be normalized */ //static int secp256k1_fe_cmp_var(const secp256k1_fe* a, const secp256k1_fe* b); /** Set a field element equal to 32-byte big endian value. If successful, the resulting field element is normalized. */ //static int SetB32(secp256k1_fe* r, const unsigned char* a); /** Convert a field element to a 32-byte big endian value. Requires the input to be normalized */ //static void GetB32(unsigned char* r, const secp256k1_fe* a); /** Set a field element equal to the additive inverse of another. Takes a maximum magnitude of the input * as an argument. The magnitude of the output is one higher. */ //static void Negate(secp256k1_fe* r, const secp256k1_fe* a, int m); /** Multiplies the passed field element with a small integer constant. Multiplies the magnitude by that * small integer. */ //static void MulInt(secp256k1_fe* r, int a); /** Adds a field element to another. The result has the sum of the inputs' magnitudes as magnitude. */ //static void Add(secp256k1_fe* r, const secp256k1_fe* a); /** Sets a field element to be the product of two others. Requires the inputs' magnitudes to be at most 8. * The output magnitude is 1 (but not guaranteed to be normalized). */ //static void Mul(secp256k1_fe* r, const secp256k1_fe* a, const secp256k1_fe* SECP256K1_RESTRICT b); /** Sets a field element to be the square of another. Requires the input's magnitude to be at most 8. * The output magnitude is 1 (but not guaranteed to be normalized). */ //static void Sqr(secp256k1_fe* r, const secp256k1_fe* a); /// <summary> /// If a has a square root, it is computed in r and 1 is returned. If a does not have a square root, the root of its negation is computed and 0 is returned. The input's magnitude can be at most 8. The output magnitude is 1 (but not guaranteed to be normalized). The result in r will always be a square itself. /// </summary> /// <param name="r"></param> /// <param name="a"></param> /// <returns></returns> public static bool Sqrt(Fe r, Fe a) { /** Given that p is congruent to 3 mod 4, we can compute the square root of * a mod p as the (p+1)/4'th power of a. * * As (p+1)/4 is an even number, it will have the same result for a and for * (-a). Only one of these two numbers actually has a square root however, * so we test at the end by squaring and comparing to the input. * Also because (p+1)/4 is an even number, the computed square root is * itself always a square (a ** ((p+1)/4) is the square of a ** ((p+1)/8)). */ Fe x2, x3, x6, x9, x11, x22, x44, x88, x176, x220, x223, t1; int j; /** The binary representation of (p + 1)/4 has 3 blocks of 1s, with lengths in * { 2, 22, 223 }. Use an addition chain to calculate 2^n - 1 for each block: * 1, [2], 3, 6, 9, 11, [22], 44, 88, 176, 220, [223] */ x2 = new Fe(); Sqr(x2, a); Mul(x2, x2, a); x3 = new Fe(); Sqr(x3, x2); Mul(x3, x3, a); x6 = x3.Clone(); for (j = 0; j < 3; j++) { Sqr(x6, x6); } Mul(x6, x6, x3); x9 = x6.Clone(); for (j = 0; j < 3; j++) { Sqr(x9, x9); } Mul(x9, x9, x3); x11 = x9.Clone(); for (j = 0; j < 2; j++) { Sqr(x11, x11); } Mul(x11, x11, x2); x22 = x11.Clone(); for (j = 0; j < 11; j++) { Sqr(x22, x22); } Mul(x22, x22, x11); x44 = x22.Clone(); for (j = 0; j < 22; j++) { Sqr(x44, x44); } Mul(x44, x44, x22); x88 = x44.Clone(); for (j = 0; j < 44; j++) { Sqr(x88, x88); } Mul(x88, x88, x44); x176 = x88.Clone(); for (j = 0; j < 88; j++) { Sqr(x176, x176); } Mul(x176, x176, x88); x220 = x176.Clone(); for (j = 0; j < 44; j++) { Sqr(x220, x220); } Mul(x220, x220, x44); x223 = x220.Clone(); for (j = 0; j < 3; j++) { Sqr(x223, x223); } Mul(x223, x223, x3); /* The final result is then assembled using a sliding window over the blocks. */ t1 = x223.Clone(); for (j = 0; j < 23; j++) { Sqr(t1, t1); } Mul(t1, t1, x22); for (j = 0; j < 6; j++) { Sqr(t1, t1); } Mul(t1, t1, x2); Sqr(t1, t1); Sqr(r, t1); /* Check that a square root was actually calculated */ Sqr(t1, r); return(Equal(t1, a)); }
public static void Cmov(Fe r, Fe a, bool flag) { Field.Cmov(r, a, flag ? 1U : 0U); }