static public void Print(Formatter formatter, string curveName) { CurveNames curveEnum = GetCurveName(curveName); ECParams ecp = ECRecommendedParameters.ecParams[(int)curveEnum]; ecp.Oid = ECRecommendedParameters.OID[(int)curveEnum]; formatter.PrintText("OID", ecp.Oid); formatter.PrintBigInteger("p", "UCHAR", null, (ecp.parameters.Curve as FpCurve).Q); formatter.PrintBigInteger("a", "UCHAR", null, ecp.parameters.Curve.A.ToBigInteger()); formatter.PrintBigInteger("b", "UCHAR", null, ecp.parameters.Curve.B.ToBigInteger()); formatter.PrintBigInteger("n", "UCHAR", null, ecp.parameters.N); formatter.PrintBigInteger("h", "UCHAR", null, ecp.parameters.H); formatter.PrintPoint("g", "UCHAR", null, ecp.parameters.G as FpPoint); // g_1 ... g_n for (int i = 1; i <= NumberOfPregeneratedGenerators; i++) { formatter.PrintPoint("g" + i, "UCHAR", null, ecp.g_i[i - 1], ecp.counter[i - 1]); } // g_t formatter.PrintPoint("gt", "UCHAR", null, ecp.g_t, ecp.counter_t); // g_d formatter.PrintPoint("gd", "UCHAR", null, ecp.g_d, ecp.counter_d); }
internal static void Print(Formatter formatter, string groupName) { SGNames sgNameEnum = GetSGName(groupName); SGParams sgp = SubgroupRecommendedParameters.sgParams[(int)sgNameEnum]; sgp.Oid = SubgroupRecommendedParameters.OID[(int)sgNameEnum]; formatter.PrintText("OID", "UCHAR", null, sgp.Oid); formatter.PrintBigInteger("p", "UCHAR", null, sgp.p); formatter.PrintBigInteger("q", "UCHAR", null, sgp.q); formatter.PrintBigInteger("g", "UCHAR", null, sgp.g); formatter.PrintHex("domainParamSeed", "UCHAR", null, sgp.domain_parameter_seed); formatter.PrintBigInteger("e", "UCHAR", null, sgp.e); // g_1 ... g_n for (int i = 1; i <= NumberOfPregeneratedGenerators; i++) { formatter.PrintBigInteger("g" + i, "UCHAR", null, sgp.g_i[i - 1], sgp.counter[i - 1]); } // g_t formatter.PrintBigInteger("gt", "UCHAR", null, sgp.g_t, sgp.counter_t); // g_d formatter.PrintBigInteger("gd", "UCHAR", null, sgp.g_d, sgp.counter_d); }
/// <summary> /// Generates the recommeded parameters. /// </summary> /// <param name="args">Output directory.</param> static void Main(string[] args) { string outputPath; if (args != null && args.Length > 1) { outputPath = args[0]; if (!Directory.Exists(outputPath)) { throw new ArgumentException(outputPath + " does not exist"); } } else { outputPath = Directory.GetCurrentDirectory(); } System.IO.StreamWriter writer = null; try { foreach (Formatter.Type formatterType in formatterTypes) { foreach (string groupName in groupNames) { string outputFile = Path.Combine(outputPath, "recommendedparams_" + groupName + "_" + formatterType + ".txt"); writer = new System.IO.StreamWriter(outputFile); Formatter formater = new Formatter(formatterType, writer); formater.PrintText("U-Prove Recommended Parameters (" + groupName + ")"); if (groupName.StartsWith("L")) { SubgroupRecommendedParameters.Print(formater, groupName); } else { ECRecommendedParameters.Print(formater, groupName); } Console.WriteLine("recommended parameters " + groupName + " written to " + outputFile); writer.Close(); writer = null; } } } catch (Exception e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } finally { if (writer != null) { writer.Close(); } } Console.WriteLine("completed"); Console.ReadLine(); }