public SecP521R1FieldElement() { this.x = Nat.Create(17); }
public static void AddExt(uint[] xx, uint[] yy, uint[] zz) { if ((Nat.Add(14, xx, yy, zz) != 0 || (zz[13] == uint.MaxValue && Nat.Gte(14, zz, PExt))) && Nat.AddTo(PExtInv.Length, PExtInv, zz) != 0) { Nat.IncAt(14, zz, PExtInv.Length); } }
static void Run(string[] args) { var arguments = new Arguments(args); var engineDirArg = arguments.GetValue("Engine.EngineDir", null); if (!string.IsNullOrEmpty(engineDirArg)) { Platform.OverrideEngineDir(engineDirArg); } var supportDirArg = arguments.GetValue("Engine.SupportDir", null); if (!string.IsNullOrEmpty(supportDirArg)) { Platform.OverrideSupportDir(supportDirArg); } Log.AddChannel("debug", "dedicated-debug.log", true); Log.AddChannel("perf", "dedicated-perf.log", true); Log.AddChannel("server", "dedicated-server.log", true); Log.AddChannel("nat", "dedicated-nat.log", true); Log.AddChannel("geoip", "dedicated-geoip.log", true); // Special case handling of Game.Mod argument: if it matches a real filesystem path // then we use this to override the mod search path, and replace it with the mod id var modID = arguments.GetValue("Game.Mod", null); var explicitModPaths = Array.Empty <string>(); if (modID != null && (File.Exists(modID) || Directory.Exists(modID))) { explicitModPaths = new[] { modID }; modID = Path.GetFileNameWithoutExtension(modID); } if (modID == null) { throw new InvalidOperationException("Game.Mod argument missing or mod could not be found."); } // HACK: The engine code assumes that Game.Settings is set. // This isn't nearly as bad as ModData, but is still not very nice. Game.InitializeSettings(arguments); var settings = Game.Settings.Server; Nat.Initialize(); var envModSearchPaths = Environment.GetEnvironmentVariable("MOD_SEARCH_PATHS"); var modSearchPaths = !string.IsNullOrWhiteSpace(envModSearchPaths) ? FieldLoader.GetValue <string[]>("MOD_SEARCH_PATHS", envModSearchPaths) : new[] { Path.Combine(Platform.EngineDir, "mods") }; var mods = new InstalledMods(modSearchPaths, explicitModPaths); Console.WriteLine("[{0}] Starting dedicated server for mod: {1}", DateTime.Now.ToString(settings.TimestampFormat), modID); while (true) { // HACK: The engine code *still* assumes that Game.ModData is set var modData = Game.ModData = new ModData(mods[modID], mods); modData.MapCache.LoadMaps(); settings.Map = modData.MapCache.ChooseInitialMap(settings.Map, new MersenneTwister()); var endpoints = new List <IPEndPoint> { new IPEndPoint(IPAddress.IPv6Any, settings.ListenPort), new IPEndPoint(IPAddress.Any, settings.ListenPort) }; var server = new Server(endpoints, settings, modData, ServerType.Dedicated); GC.Collect(); while (true) { Thread.Sleep(1000); if (server.State == ServerState.GameStarted && server.Conns.Count < 1) { Console.WriteLine("[{0}] No one is playing, shutting down...", DateTime.Now.ToString(settings.TimestampFormat)); server.Shutdown(); break; } } modData.Dispose(); Console.WriteLine("[{0}] Starting a new server instance...", DateTime.Now.ToString(settings.TimestampFormat)); } }
public static void Reduce(uint[] xx, uint[] z) { long xx10 = xx[10], xx11 = xx[11], xx12 = xx[12], xx13 = xx[13]; const long n = 1; long t0 = (long)xx[7] + xx11 - n; long t1 = (long)xx[8] + xx12; long t2 = (long)xx[9] + xx13; long cc = 0; cc += (long)xx[0] - t0; long z0 = (uint)cc; cc >>= 32; cc += (long)xx[1] - t1; z[1] = (uint)cc; cc >>= 32; cc += (long)xx[2] - t2; z[2] = (uint)cc; cc >>= 32; cc += (long)xx[3] + t0 - xx10; long z3 = (uint)cc; cc >>= 32; cc += (long)xx[4] + t1 - xx11; z[4] = (uint)cc; cc >>= 32; cc += (long)xx[5] + t2 - xx12; z[5] = (uint)cc; cc >>= 32; cc += (long)xx[6] + xx10 - xx13; z[6] = (uint)cc; cc >>= 32; cc += n; Debug.Assert(cc >= 0); z3 += cc; z0 -= cc; z[0] = (uint)z0; cc = z0 >> 32; if (cc != 0) { cc += (long)z[1]; z[1] = (uint)cc; cc >>= 32; cc += (long)z[2]; z[2] = (uint)cc; z3 += cc >> 32; } z[3] = (uint)z3; cc = z3 >> 32; Debug.Assert(cc == 0 || cc == 1); if ((cc != 0 && Nat.IncAt(7, z, 4) != 0) || (z[6] == P6 && Nat224.Gte(z, P))) { AddPInvTo(z); } }
public static void MultiplyAddToExt(uint[] x, uint[] y, uint[] zz) { if ((Nat192.MulAddTo(x, y, zz) != 0u || (zz[11] == 4294967295u && Nat.Gte(12, zz, SecP192R1Field.PExt))) && Nat.AddTo(SecP192R1Field.PExtInv.Length, SecP192R1Field.PExtInv, zz) != 0u) { Nat.IncAt(12, zz, SecP192R1Field.PExtInv.Length); } }
public override ECFieldElement Subtract(ECFieldElement b) { uint[] z = Nat.Create(17); SecP521R1Field.Subtract(x, ((SecP521R1FieldElement)b).x, z); return(new SecP521R1FieldElement(z)); }
public override ECFieldElement Negate() { uint[] z = Nat.Create(17); SecP521R1Field.Negate(x, z); return(new SecP521R1FieldElement(z)); }
public static void Reduce(uint[] xx, uint[] z) { ulong xx06 = xx[6], xx07 = xx[7], xx08 = xx[8]; ulong xx09 = xx[9], xx10 = xx[10], xx11 = xx[11]; ulong t0 = xx06 + xx10; ulong t1 = xx07 + xx11; ulong cc = 0; cc += (ulong)xx[0] + t0; uint z0 = (uint)cc; cc >>= 32; cc += (ulong)xx[1] + t1; z[1] = (uint)cc; cc >>= 32; t0 += xx08; t1 += xx09; cc += (ulong)xx[2] + t0; ulong z2 = (uint)cc; cc >>= 32; cc += (ulong)xx[3] + t1; z[3] = (uint)cc; cc >>= 32; t0 -= xx06; t1 -= xx07; cc += (ulong)xx[4] + t0; z[4] = (uint)cc; cc >>= 32; cc += (ulong)xx[5] + t1; z[5] = (uint)cc; cc >>= 32; z2 += cc; cc += z0; z[0] = (uint)cc; cc >>= 32; if (cc != 0) { cc += z[1]; z[1] = (uint)cc; z2 += cc >> 32; } z[2] = (uint)z2; cc = z2 >> 32; Debug.Assert(cc == 0 || cc == 1); if ((cc != 0 && Nat.IncAt(6, z, 3) != 0) || (z[5] == P5 && Nat192.Gte(z, P))) { AddPInvTo(z); } }
public override ECPoint Add(ECPoint b) { if (this.IsInfinity) { return(b); } if (b.IsInfinity) { return(this); } if (this == b) { return(Twice()); } ECCurve curve = this.Curve; SecP384R1FieldElement X1 = (SecP384R1FieldElement)this.RawXCoord, Y1 = (SecP384R1FieldElement)this.RawYCoord; SecP384R1FieldElement X2 = (SecP384R1FieldElement)b.RawXCoord, Y2 = (SecP384R1FieldElement)b.RawYCoord; SecP384R1FieldElement Z1 = (SecP384R1FieldElement)this.RawZCoords[0]; SecP384R1FieldElement Z2 = (SecP384R1FieldElement)b.RawZCoords[0]; uint c; uint[] tt1 = Nat.Create(24); uint[] tt2 = Nat.Create(24); uint[] t3 = Nat.Create(12); uint[] t4 = Nat.Create(12); bool Z1IsOne = Z1.IsOne; uint[] U2, S2; if (Z1IsOne) { U2 = X2.x; S2 = Y2.x; } else { S2 = t3; SecP384R1Field.Square(Z1.x, S2); U2 = tt2; SecP384R1Field.Multiply(S2, X2.x, U2); SecP384R1Field.Multiply(S2, Z1.x, S2); SecP384R1Field.Multiply(S2, Y2.x, S2); } bool Z2IsOne = Z2.IsOne; uint[] U1, S1; if (Z2IsOne) { U1 = X1.x; S1 = Y1.x; } else { S1 = t4; SecP384R1Field.Square(Z2.x, S1); U1 = tt1; SecP384R1Field.Multiply(S1, X1.x, U1); SecP384R1Field.Multiply(S1, Z2.x, S1); SecP384R1Field.Multiply(S1, Y1.x, S1); } uint[] H = Nat.Create(12); SecP384R1Field.Subtract(U1, U2, H); uint[] R = Nat.Create(12); SecP384R1Field.Subtract(S1, S2, R); // Check if b == this or b == -this if (Nat.IsZero(12, H)) { if (Nat.IsZero(12, R)) { // this == b, i.e. this must be doubled return(this.Twice()); } // this == -b, i.e. the result is the point at infinity return(curve.Infinity); } uint[] HSquared = t3; SecP384R1Field.Square(H, HSquared); uint[] G = Nat.Create(12); SecP384R1Field.Multiply(HSquared, H, G); uint[] V = t3; SecP384R1Field.Multiply(HSquared, U1, V); SecP384R1Field.Negate(G, G); Nat384.Mul(S1, G, tt1); c = Nat.AddBothTo(12, V, V, G); SecP384R1Field.Reduce32(c, G); SecP384R1FieldElement X3 = new SecP384R1FieldElement(t4); SecP384R1Field.Square(R, X3.x); SecP384R1Field.Subtract(X3.x, G, X3.x); SecP384R1FieldElement Y3 = new SecP384R1FieldElement(G); SecP384R1Field.Subtract(V, X3.x, Y3.x); Nat384.Mul(Y3.x, R, tt2); SecP384R1Field.AddExt(tt1, tt2, tt1); SecP384R1Field.Reduce(tt1, Y3.x); SecP384R1FieldElement Z3 = new SecP384R1FieldElement(H); if (!Z1IsOne) { SecP384R1Field.Multiply(Z3.x, Z1.x, Z3.x); } if (!Z2IsOne) { SecP384R1Field.Multiply(Z3.x, Z2.x, Z3.x); } ECFieldElement[] zs = new ECFieldElement[] { Z3 }; return(new SecP384R1Point(curve, X3, Y3, zs, IsCompressed)); }
public override ECPoint Twice() { if (base.IsInfinity) { return(this); } ECCurve curve = Curve; SecP256R1FieldElement secP256R1FieldElement = (SecP256R1FieldElement)base.RawYCoord; if (secP256R1FieldElement.IsZero) { return(curve.Infinity); } SecP256R1FieldElement secP256R1FieldElement2 = (SecP256R1FieldElement)base.RawXCoord; SecP256R1FieldElement secP256R1FieldElement3 = (SecP256R1FieldElement)base.RawZCoords[0]; uint[] array = Nat256.Create(); uint[] array2 = Nat256.Create(); uint[] array3 = Nat256.Create(); SecP256R1Field.Square(secP256R1FieldElement.x, array3); uint[] array4 = Nat256.Create(); SecP256R1Field.Square(array3, array4); bool isOne = secP256R1FieldElement3.IsOne; uint[] array5 = secP256R1FieldElement3.x; if (!isOne) { array5 = array2; SecP256R1Field.Square(secP256R1FieldElement3.x, array5); } SecP256R1Field.Subtract(secP256R1FieldElement2.x, array5, array); uint[] array6 = array2; SecP256R1Field.Add(secP256R1FieldElement2.x, array5, array6); SecP256R1Field.Multiply(array6, array, array6); uint x = Nat256.AddBothTo(array6, array6, array6); SecP256R1Field.Reduce32(x, array6); uint[] array7 = array3; SecP256R1Field.Multiply(array3, secP256R1FieldElement2.x, array7); x = Nat.ShiftUpBits(8, array7, 2, 0u); SecP256R1Field.Reduce32(x, array7); x = Nat.ShiftUpBits(8, array4, 3, 0u, array); SecP256R1Field.Reduce32(x, array); SecP256R1FieldElement secP256R1FieldElement4 = new SecP256R1FieldElement(array4); SecP256R1Field.Square(array6, secP256R1FieldElement4.x); SecP256R1Field.Subtract(secP256R1FieldElement4.x, array7, secP256R1FieldElement4.x); SecP256R1Field.Subtract(secP256R1FieldElement4.x, array7, secP256R1FieldElement4.x); SecP256R1FieldElement secP256R1FieldElement5 = new SecP256R1FieldElement(array7); SecP256R1Field.Subtract(array7, secP256R1FieldElement4.x, secP256R1FieldElement5.x); SecP256R1Field.Multiply(secP256R1FieldElement5.x, array6, secP256R1FieldElement5.x); SecP256R1Field.Subtract(secP256R1FieldElement5.x, array, secP256R1FieldElement5.x); SecP256R1FieldElement secP256R1FieldElement6 = new SecP256R1FieldElement(array6); SecP256R1Field.Twice(secP256R1FieldElement.x, secP256R1FieldElement6.x); if (!isOne) { SecP256R1Field.Multiply(secP256R1FieldElement6.x, secP256R1FieldElement3.x, secP256R1FieldElement6.x); } return(new SecP256R1Point(curve, secP256R1FieldElement4, secP256R1FieldElement5, new ECFieldElement[1] { secP256R1FieldElement6 }, base.IsCompressed)); }
static void Initialize(Arguments args) { var engineDirArg = args.GetValue("Engine.EngineDir", null); if (!string.IsNullOrEmpty(engineDirArg)) { Platform.OverrideEngineDir(engineDirArg); } var supportDirArg = args.GetValue("Engine.SupportDir", null); if (!string.IsNullOrEmpty(supportDirArg)) { Platform.OverrideSupportDir(supportDirArg); } Console.WriteLine("Platform is {0}", Platform.CurrentPlatform); // Load the engine version as early as possible so it can be written to exception logs try { EngineVersion = File.ReadAllText(Path.Combine(Platform.EngineDir, "VERSION")).Trim(); } catch { } if (string.IsNullOrEmpty(EngineVersion)) { EngineVersion = "Unknown"; } Console.WriteLine("Engine version is {0}", EngineVersion); Console.WriteLine("Runtime: {0}", Platform.RuntimeVersion); // Special case handling of Game.Mod argument: if it matches a real filesystem path // then we use this to override the mod search path, and replace it with the mod id var modID = args.GetValue("Game.Mod", null); var explicitModPaths = new string[0]; if (modID != null && (File.Exists(modID) || Directory.Exists(modID))) { explicitModPaths = new[] { modID }; modID = Path.GetFileNameWithoutExtension(modID); } InitializeSettings(args); Log.AddChannel("perf", "perf.log"); Log.AddChannel("debug", "debug.log"); Log.AddChannel("server", "server.log", true); Log.AddChannel("sound", "sound.log"); Log.AddChannel("graphics", "graphics.log"); Log.AddChannel("geoip", "geoip.log"); Log.AddChannel("nat", "nat.log"); Log.AddChannel("client", "client.log"); var platforms = new[] { Settings.Game.Platform, "Default", null }; foreach (var p in platforms) { if (p == null) { throw new InvalidOperationException("Failed to initialize platform-integration library. Check graphics.log for details."); } Settings.Game.Platform = p; try { var rendererPath = Path.Combine(Platform.BinDir, "OpenRA.Platforms." + p + ".dll"); #if !MONO var loader = new AssemblyLoader(rendererPath); var platformType = loader.LoadDefaultAssembly().GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t)); #else var assembly = Assembly.LoadFile(rendererPath); var platformType = assembly.GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t)); #endif if (platformType == null) { throw new InvalidOperationException("Platform dll must include exactly one IPlatform implementation."); } var platform = (IPlatform)platformType.GetConstructor(Type.EmptyTypes).Invoke(null); Renderer = new Renderer(platform, Settings.Graphics); Sound = new Sound(platform, Settings.Sound); break; } catch (Exception e) { Log.Write("graphics", "{0}", e); Console.WriteLine("Renderer initialization failed. Check graphics.log for details."); Renderer?.Dispose(); Sound?.Dispose(); } } Nat.Initialize(); var modSearchArg = args.GetValue("Engine.ModSearchPaths", null); var modSearchPaths = modSearchArg != null? FieldLoader.GetValue <string[]>("Engine.ModsPath", modSearchArg) : new[] { Path.Combine(Platform.EngineDir, "mods") }; Mods = new InstalledMods(modSearchPaths, explicitModPaths); Console.WriteLine("Internal mods:"); foreach (var mod in Mods) { Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version); } modLaunchWrapper = args.GetValue("Engine.LaunchWrapper", null); ExternalMods = new ExternalMods(); if (modID != null && Mods.TryGetValue(modID, out _)) { var launchPath = args.GetValue("Engine.LaunchPath", null); var launchArgs = new List <string>(); // Sanitize input from platform-specific launchers // Process.Start requires paths to not be quoted, even if they contain spaces if (launchPath != null && launchPath.First() == '"' && launchPath.Last() == '"') { launchPath = launchPath.Substring(1, launchPath.Length - 2); } if (launchPath == null) { // When launching the assembly directly we must propagate the Engine.EngineDir argument if defined // Platform-specific launchers are expected to manage this internally. launchPath = Assembly.GetEntryAssembly().Location; if (!string.IsNullOrEmpty(engineDirArg)) { launchArgs.Add("Engine.EngineDir=\"" + engineDirArg + "\""); } } ExternalMods.Register(Mods[modID], launchPath, launchArgs, ModRegistration.User); if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out var activeMod)) { ExternalMods.ClearInvalidRegistrations(activeMod, ModRegistration.User); } } Console.WriteLine("External mods:"); foreach (var mod in ExternalMods) { Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); } InitializeMod(modID, args); Ui.InitializeTranslation(); }
public override ECPoint Twice() { if (this.IsInfinity) { return(this); } ECCurve curve = this.Curve; SecP521R1FieldElement Y1 = (SecP521R1FieldElement)this.RawYCoord; if (Y1.IsZero) { return(curve.Infinity); } SecP521R1FieldElement X1 = (SecP521R1FieldElement)this.RawXCoord, Z1 = (SecP521R1FieldElement)this.RawZCoords[0]; uint[] t1 = Nat.Create(17); uint[] t2 = Nat.Create(17); uint[] Y1Squared = Nat.Create(17); SecP521R1Field.Square(Y1.x, Y1Squared); uint[] T = Nat.Create(17); SecP521R1Field.Square(Y1Squared, T); bool Z1IsOne = Z1.IsOne; uint[] Z1Squared = Z1.x; if (!Z1IsOne) { Z1Squared = t2; SecP521R1Field.Square(Z1.x, Z1Squared); } SecP521R1Field.Subtract(X1.x, Z1Squared, t1); uint[] M = t2; SecP521R1Field.Add(X1.x, Z1Squared, M); SecP521R1Field.Multiply(M, t1, M); SecP521R1Field.Twice(M, t1); SecP521R1Field.Add(M, t1, M); uint[] S = Y1Squared; SecP521R1Field.Multiply(Y1Squared, X1.x, S); Nat.ShiftUpBits(17, S, 2, 0); SecP521R1Field.Reduce23(S); Nat.ShiftUpBits(17, T, 3, 0, t1); SecP521R1Field.Reduce23(t1); SecP521R1FieldElement X3 = new SecP521R1FieldElement(T); SecP521R1Field.Square(M, X3.x); SecP521R1Field.Subtract(X3.x, S, X3.x); SecP521R1Field.Subtract(X3.x, S, X3.x); SecP521R1FieldElement Y3 = new SecP521R1FieldElement(S); SecP521R1Field.Subtract(S, X3.x, Y3.x); SecP521R1Field.Multiply(Y3.x, M, Y3.x); SecP521R1Field.Subtract(Y3.x, t1, Y3.x); SecP521R1FieldElement Z3 = new SecP521R1FieldElement(M); SecP521R1Field.Twice(Y1.x, Z3.x); if (!Z1IsOne) { SecP521R1Field.Multiply(Z3.x, Z1.x, Z3.x); } return(new SecP521R1Point(curve, X3, Y3, new ECFieldElement[] { Z3 }, IsCompressed)); }
public static void SquareAddToExt(ulong[] x, ulong[] zz) { ulong[] tt = Nat.Create64(5); ImplSquare(x, tt); AddExt(zz, tt, zz); }
public static void Square(ulong[] x, ulong[] z) { ulong[] tt = Nat.Create64(5); ImplSquare(x, tt); Reduce(tt, z); }
public override bool TestBitZero() { return(Nat.GetBit(x, 0) == 1); }
public SecP384R1FieldElement() { x = Nat.Create(12); }
public override BigInteger ToBigInteger() { return(Nat.ToBigInteger(17, x)); }
public override ECFieldElement Add(ECFieldElement b) { uint[] z = Nat.Create(12); SecP384R1Field.Add(x, ((SecP384R1FieldElement)b).x, z); return(new SecP384R1FieldElement(z)); }
public override ECFieldElement Multiply(ECFieldElement b) { uint[] z = Nat.Create(17); SecP521R1Field.Multiply(x, ((SecP521R1FieldElement)b).x, z); return(new SecP521R1FieldElement(z)); }
public override ECFieldElement Square() { uint[] z = Nat.Create(12); SecP384R1Field.Square(x, z); return(new SecP384R1FieldElement(z)); }
public override ECPoint Twice() { if (this.IsInfinity) { return(this); } ECCurve curve = this.Curve; SecP256K1FieldElement Y1 = (SecP256K1FieldElement)this.RawYCoord; if (Y1.IsZero) { return(curve.Infinity); } SecP256K1FieldElement X1 = (SecP256K1FieldElement)this.RawXCoord, Z1 = (SecP256K1FieldElement)this.RawZCoords[0]; uint c; uint[] Y1Squared = Nat256.Create(); SecP256K1Field.Square(Y1.x, Y1Squared); uint[] T = Nat256.Create(); SecP256K1Field.Square(Y1Squared, T); uint[] M = Nat256.Create(); SecP256K1Field.Square(X1.x, M); c = Nat256.AddBothTo(M, M, M); SecP256K1Field.Reduce32(c, M); uint[] S = Y1Squared; SecP256K1Field.Multiply(Y1Squared, X1.x, S); c = Nat.ShiftUpBits(8, S, 2, 0); SecP256K1Field.Reduce32(c, S); uint[] t1 = Nat256.Create(); c = Nat.ShiftUpBits(8, T, 3, 0, t1); SecP256K1Field.Reduce32(c, t1); SecP256K1FieldElement X3 = new SecP256K1FieldElement(T); SecP256K1Field.Square(M, X3.x); SecP256K1Field.Subtract(X3.x, S, X3.x); SecP256K1Field.Subtract(X3.x, S, X3.x); SecP256K1FieldElement Y3 = new SecP256K1FieldElement(S); SecP256K1Field.Subtract(S, X3.x, Y3.x); SecP256K1Field.Multiply(Y3.x, M, Y3.x); SecP256K1Field.Subtract(Y3.x, t1, Y3.x); SecP256K1FieldElement Z3 = new SecP256K1FieldElement(M); SecP256K1Field.Twice(Y1.x, Z3.x); if (!Z1.IsOne) { SecP256K1Field.Multiply(Z3.x, Z1.x, Z3.x); } return(new SecP256K1Point(curve, X3, Y3, new ECFieldElement[] { Z3 }, IsCompressed)); }
public override ECFieldElement Invert() { uint[] z = Nat.Create(12); Mod.Invert(SecP384R1Field.P, x, z); return(new SecP384R1FieldElement(z)); }
protected static void ImplMultiply(ulong[] x, ulong[] y, ulong[] zz) { //for (int i = 0; i < 9; ++i) //{ // ImplMulwAcc(x, y[i], zz, i); //} /* * Precompute table of all 4-bit products of y */ ulong[] T0 = new ulong[9 << 4]; Array.Copy(y, 0, T0, 9, 9); // Reduce5(T0, 9); int tOff = 0; for (int i = 7; i > 0; --i) { tOff += 18; Nat.ShiftUpBit64(9, T0, tOff >> 1, 0UL, T0, tOff); Reduce5(T0, tOff); Add(T0, 9, T0, tOff, T0, tOff + 9); } /* * Second table with all 4-bit products of B shifted 4 bits */ ulong[] T1 = new ulong[T0.Length]; Nat.ShiftUpBits64(T0.Length, T0, 0, 4, 0L, T1, 0); uint MASK = 0xF; /* * Lopez-Dahab algorithm */ for (int k = 56; k >= 0; k -= 8) { for (int j = 1; j < 9; j += 2) { uint aVal = (uint)(x[j] >> k); uint u = aVal & MASK; uint v = (aVal >> 4) & MASK; AddBothTo(T0, (int)(9 * u), T1, (int)(9 * v), zz, j - 1); } Nat.ShiftUpBits64(16, zz, 0, 8, 0L); } for (int k = 56; k >= 0; k -= 8) { for (int j = 0; j < 9; j += 2) { uint aVal = (uint)(x[j] >> k); uint u = aVal & MASK; uint v = (aVal >> 4) & MASK; AddBothTo(T0, (int)(9 * u), T1, (int)(9 * v), zz, j); } if (k > 0) { Nat.ShiftUpBits64(18, zz, 0, 8, 0L); } } }
public static ulong[] FromBigInteger(BigInteger x) { return(Nat.FromBigInteger64(571, x)); }
private void OnDeviceFound(object sender, Nat.DeviceEventArgs args) { logger.Info("UPnP Device found"); // FIXME: What happens if more then one device is found? Yeeek, bad news device = args.Device; MapPort(); }
public static void MultiplyAddToExt(uint[] x, uint[] y, uint[] zz) { if ((Nat224.MulAddTo(x, y, zz) != 0 || (zz[13] == uint.MaxValue && Nat.Gte(14, zz, PExt))) && Nat.AddTo(PExtInv.Length, PExtInv, zz) != 0) { Nat.IncAt(14, zz, PExtInv.Length); } }