コード例 #1
0
ファイル: Program.cs プロジェクト: maplewzx/secret-sharing-1
        private static string BenchmarkPrimeToPersistenceStorage(int MinN, int MaxN, int MinK, int MaxK, int step, string[] Keys)
        {
            ///define the chunk sizes here for the experiment
            int[] Chunks = new int[] {
                1
                , 2,
                4,
                8
                , 16
                , 32
                , 64
                , 128
                , 256
            };



            //int MaxN = 100;
            //int MaxK = 60;
            //int step = 5;
            int iterate = 100;
            ShamirAntixBenchmark benchmark = new ShamirAntixBenchmark();
            //define the key size to experiment here
            //String key = benchmark.key256bit;

            var reports = benchmark.BenchmarkPrimeWithChunkSize(Chunks, MinN, MaxN, MinK, MaxK, Keys, step, SecretSharingBenchmarkReport.OperationType.ShareGeneration
                                                                | SecretSharingBenchmarkReport.OperationType.SecretReconstruction
                                                                , iterate);
            var serializer           = new XMLSerializer <PersistanceReport>();
            PersistanceReport report = new PersistanceReport();

            report.Reports = reports.ToList();
            report.N       = MaxN;
            report.K       = MaxK;
            report.Iterate = iterate;
            report.Step    = step;
            //report.KeySize = key.Length * 8;

            string filePath = string.Format("SerializedReports-prime-n{0}-k{1}-iterate{2}.xml"
                                            , /*key.Length * 8*/ MaxN, MaxK, iterate);

            serializer.Serialize(report, filePath);
            return(filePath);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: maplewzx/secret-sharing-1
        private static string BenchmarkToPersistenceStorage(int MinN, int MaxN, int MinK, int MaxK, int step, string[] Keys
                                                            , SecretSharing.Benchmark.SecretSharingBenchmarkReport.SSAlgorithm alg, List <LoadedPrimeNumber> loadedPrimes)
        {
            ///define the chunk sizes here for the experiment
            int[] Chunks = new int[] {
                1
                , 2,
                4,
                8
                , 16
                , 32
                , 64
                , 128
                , 256
            };



            //int MaxN = 100;
            //int MaxK = 60;
            //int step = 5;
            int iterate = 0;

            //define the key size to experiment here
            //String key = benchmark.key256bit;
            var reports = new List <SecretSharingBenchmarkReport>();

            if (alg == SecretSharingBenchmarkReport.SSAlgorithm.Shamir)
            {
                iterate = 100;
                ShamirAntixBenchmark benchmark = new ShamirAntixBenchmark();
                reports = benchmark.BenchmarkAllKeysWithChunkSize(Chunks, MinN, MaxN, MinK, MaxK, Keys, step, SecretSharingBenchmarkReport.OperationType.ShareGeneration
                                                                  | SecretSharingBenchmarkReport.OperationType.SecretReconstruction
                                                                  , iterate, loadedPrimes);
            }
            else if (alg == SecretSharingBenchmarkReport.SSAlgorithm.Schoenmakers)
            {
                SchoenmakersBenchmark benchmark = new SchoenmakersBenchmark();
                iterate = 10;
                reports = benchmark.BenchmarkAllKeys(MinN, MaxN, MinK, MaxK, Keys, step, SecretSharingBenchmarkReport.OperationType.InitProtocol |
                                                     SecretSharingBenchmarkReport.OperationType.RandomSecretReconstruction | SecretSharingBenchmarkReport.OperationType.ShareGenerationRandomSecret
                                                     | SecretSharingBenchmarkReport.OperationType.ShareGenerationSpecialSecret | SecretSharingBenchmarkReport.OperationType.SpecialSecretReconstruction
                                                     | SecretSharingBenchmarkReport.OperationType.VerifyPooledShares | SecretSharingBenchmarkReport.OperationType.VerifyShares
                                                     | SecretSharingBenchmarkReport.OperationType.DecryptShares
                                                     , iterate, loadedPrimes);
            }
            var serializer           = new XMLSerializer <PersistanceReport>();
            PersistanceReport report = new PersistanceReport();

            report.Reports = reports.ToList();
            report.N       = MaxN;
            report.K       = MaxK;
            report.Iterate = iterate;
            report.Step    = step;
            //report.KeySize = key.Length * 8;

            string filePath = string.Format("SerializedReports-n{0}-k{1}-iterate{2}-alg{3}-{4}.xml"
                                            , /*key.Length * 8*/ MaxN, MaxK, iterate, alg.ToString(), DateTime.Now.Ticks.ToString());

            serializer.Serialize(report, filePath);
            return(filePath);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: maplewzx/secret-sharing-1
        static void HandleReportsGeneric(PersistanceReport report, string output, PersistanceReport reportcompared)
        {
            //group by key and handle for each key following outputs

            int[] PerformanceK = new int[] { 5, 20, 50 };
            int[] PerformanceN = new int[] { 50, 100 };


            var filtered = report.Reports.GroupBy(rp => new { opr = rp.Operation, keyLength = rp.keyLength })
                           .Select(grp => new { KeyLength = grp.Key.keyLength, Operation = grp.Key.opr,
                                                Reports   = report.Reports.Where(po => po.Operation == grp.Key.opr && po.keyLength == grp.Key.keyLength) });

            var filteredcompared = reportcompared.Reports.GroupBy(rp => new { opr = rp.Operation, keyLength = rp.keyLength })
                                   .Select(grp => new
            {
                KeyLength = grp.Key.keyLength,
                Operation = grp.Key.opr,
                Reports   = reportcompared.Reports.Where(po => po.Operation == grp.Key.opr && po.keyLength == grp.Key.keyLength)
            });
            PDFGenerator pdfreport = new PDFGenerator();


            foreach (var reportGroup in filtered)
            {
                PerormanceAnalysisForm perfViewer = new PerormanceAnalysisForm();
                var curves = new List <IEnumerable <SecretSharingBenchmarkReport> >();
                //curves.Add(reportGroup.Reports);
                var titles = new List <String>();// { reportGroup.Operation.ToString() };
                Func <SecretSharingBenchmarkReport, long> selector;
                string selectorTitle = "n";
                switch (reportGroup.Operation)
                {
                case SecretSharingBenchmarkReport.OperationType.SecretReconstruction:

                case SecretSharingBenchmarkReport.OperationType.RandomSecretReconstruction:
                case SecretSharingBenchmarkReport.OperationType.SpecialSecretReconstruction:
                    selector      = delegate(SecretSharingBenchmarkReport po) { return(po.k); };
                    selectorTitle = "k";

                    break;

                case SecretSharingBenchmarkReport.OperationType.VerifyPooledShares:
                case SecretSharingBenchmarkReport.OperationType.ShareGeneration:
                case SecretSharingBenchmarkReport.OperationType.VerifyShares:
                case SecretSharingBenchmarkReport.OperationType.DecryptShares:
                case SecretSharingBenchmarkReport.OperationType.ShareGenerationRandomSecret:
                case SecretSharingBenchmarkReport.OperationType.ShareGenerationSpecialSecret:
                case SecretSharingBenchmarkReport.OperationType.InitProtocol:
                default:
                    selector = delegate(SecretSharingBenchmarkReport po) { return(po.n); };

                    break;
                }
                var temp = reportGroup.Reports.GroupBy(po => selectorTitle != "k" ? po.k : po.n).Select(grp => new
                {
                    Axis    = grp.Key,
                    reports = reportGroup.Reports.Where(rpt => (selectorTitle != "k" ? rpt.k : rpt.n) == grp.Key)
                });
                var sortedTemp = temp.OrderByDescending(po => po.Axis);
                foreach (var groupedAxis in sortedTemp)
                {
                    curves.Add(groupedAxis.reports);
                    titles.Add(string.Format("{0}={1}", selectorTitle != "k" ? "k" : "n", groupedAxis.Axis));
                    if (reportGroup.Operation == SecretSharingBenchmarkReport.OperationType.DecryptShares ||
                        reportGroup.Operation == SecretSharingBenchmarkReport.OperationType.VerifyPooledShares ||
                        reportGroup.Operation == SecretSharingBenchmarkReport.OperationType.RandomSecretReconstruction)
                    {
                        break;
                    }
                }

                perfViewer.ExportPerformanceReportsAsPNG_PDF(curves, titles, "",/*String.Format("{0}-Key length:{1}"reportGroup.Operation.ToString(), reportGroup.KeyLength),*/
                                                             false, true, selector, selectorTitle, po => (double)po.Average() / (double)TimeSpan.TicksPerMillisecond, "Time (ms)",
                                                             string.Format("{0}perf_{1}_{2}bits", output, reportGroup.Operation.ToString(), reportGroup.KeyLength));
                var comparereport = filteredcompared.Where(po => po.KeyLength * 2 == reportGroup.KeyLength && (po.Operation == reportGroup.Operation || (po.Operation == SecretSharingBenchmarkReport.OperationType.ShareGeneration && reportGroup.Operation == SecretSharingBenchmarkReport.OperationType.ShareGenerationRandomSecret)));

                pdfreport.GenBenchmarkDoc(string.Format("{0}{1}bit_n{2}_k{3}_{4}.pdf", output, report.KeySize, report.N, report.K, reportGroup.Operation.ToString()), reportGroup.Reports, comparereport == null || comparereport.Count() == 0?null:comparereport.Single().Reports);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: maplewzx/secret-sharing-1
        static void Main(string[] args)
        {
            //BenalohLeichterBenchmark blb = new BenalohLeichterBenchmark();
            //blb.ExploreAllPossibleAccessStructures(new QualifiedSubset("p1^p2^p3").Parties);

            //Console.Read();
            //return;

            if (args.Length == 0)
            {
                printHelp(); return;
            }
            string op       = args[0].Trim().ToLower();
            var    filePath = "";

            if (op == "benchmark-shamir")
            {
                var minN         = Convert.ToInt32(args[1]);
                var maxN         = Convert.ToInt32(args[2]);
                var minK         = Convert.ToInt32(args[3]);
                var maxK         = Convert.ToInt32(args[4]);
                var step         = Convert.ToInt32(args[5]);
                var Keys         = args[6].Split(',');
                var primePath    = args[7];
                var primeXML     = new XMLSerializer <PrimePersistanceReport>();
                var loadedPrimes = primeXML.Deserialize(primePath.Replace("output=", ""));
                //var primes =

                filePath = BenchmarkToPersistenceStorage(minN, maxN, minK, maxK, step, Keys, SecretSharingBenchmarkReport.SSAlgorithm.Shamir, loadedPrimes.Primes);
                Console.WriteLine(string.Format("Benchmarking is done!\nResults are dumped to {0}", filePath));
            }
            else if (op == "generate-prime")
            {
                var                    sizes    = args[1].Split(',');
                var                    count    = Convert.ToInt32(args[2]);
                var                    path     = args[3].Replace("output=", "");
                BenchmarkPrime         gprime   = new BenchmarkPrime();
                var                    re       = gprime.BenchmarkPrimes(sizes, count);
                var                    ser      = new XMLSerializer <PrimePersistanceReport>();
                PrimePersistanceReport primeXml = new PrimePersistanceReport();
                primeXml.Primes = re;
                ser.Serialize(primeXml, path);
            }
            else if (op == "benchmark-schoen")
            {
                var minN         = Convert.ToInt32(args[1]);
                var maxN         = Convert.ToInt32(args[2]);
                var minK         = Convert.ToInt32(args[3]);
                var maxK         = Convert.ToInt32(args[4]);
                var step         = Convert.ToInt32(args[5]);
                var Keys         = args[6].Split(',');
                var primePath    = args[7];
                var primeXML     = new XMLSerializer <PrimePersistanceReport>();
                var loadedPrimes = primeXML.Deserialize(primePath);

                filePath = BenchmarkToPersistenceStorage(minN, maxN, minK, maxK, step, Keys, SecretSharingBenchmarkReport.SSAlgorithm.Schoenmakers, loadedPrimes.Primes);
                Console.WriteLine(string.Format("Benchmarking is done!\nResults are dumped to {0}", filePath));
            }
            else if (op == "benchmark-benaloh")
            {
                var access  = new QualifiedSubset(args[1]);
                var iterate = Convert.ToInt32(args[2]);
                var Keys    = args[3].Split(',');
                var type    = args[4];
                List <LoadedPrimeNumber> primes = null;
                if (args.Count() > 5)
                {
                    var primeXML     = new XMLSerializer <PrimePersistanceReport>();
                    var loadedPrimes = primeXML.Deserialize(args[5]);
                    primes = loadedPrimes.Primes;
                }
                if (string.IsNullOrEmpty(type) || (type != "scheme" && type != "share"))
                {
                    throw new Exception("scheme or share please define");
                }
                filePath = BenchmarkBenalohToPersistenceStorage(access.Parties, Keys, iterate, type, primes);
                Console.WriteLine(string.Format("Benchmarking is done!\nResults are dumped to {0}", filePath));
            }
            else if (op == "benchmarkprime")
            {
                var minN = Convert.ToInt32(args[1]);
                var maxN = Convert.ToInt32(args[2]);
                var minK = Convert.ToInt32(args[3]);
                var maxK = Convert.ToInt32(args[4]);
                var step = Convert.ToInt32(args[5]);
                var Keys = args[6].Split(',');

                filePath = BenchmarkPrimeToPersistenceStorage(minN, maxN, minK, maxK, step, Keys);
                Console.WriteLine(string.Format("Benchmarking is done!\nResults are dumped to {0}", filePath));
            }
            else if (op == "report-shamir" || op == "report-schoen")
            {
                if (args.Length == 1 || string.IsNullOrEmpty(args[1]) || !File.Exists(args[1]))
                {
                    printHelp();
                    return;
                }
                filePath = args[1];
                var outputPath  = args[2].Replace("output=", "");
                var comparepath = "";

                var ser = new XMLSerializer <PersistanceReport>();
                PersistanceReport compareReport = null;
                if (args.Length > 2)
                {
                    comparepath   = args[3];
                    compareReport = ser.Deserialize(comparepath);
                }

                //var filePath = "SerializedReports-n100-k60-iterate100.xml";
                var report = ser.Deserialize(filePath);
                var rep    = from r in report.Reports
                             group r by r.keyLength into g
                             select g;


                foreach (var item in rep)
                {
                    PersistanceReport grep = new PersistanceReport();
                    grep.Reports = item.ToList();
                    grep.KeySize = item.Key;
                    grep.N       = item.Max(po => po.n); // report.N;
                    grep.K       = item.Max(po => po.k); // report.K;
                    grep.Step    = report.Step;
                    grep.Iterate = report.Iterate;

                    if (op == "report-shamir")
                    {
                        HandleReports(grep, outputPath);
                    }
                    else
                    {
                        HandleReportsGeneric(grep, outputPath, compareReport);

                        //Generate aggeragted decrypt + verify poold + reconstruct
                        if (item.Key / 2 >= 128)
                        {
                            var compreport   = compareReport.Reports.Where(po => po.keyLength == item.Key / 2 && po.Operation == SecretSharingBenchmarkReport.OperationType.SecretReconstruction);
                            var printImroves = true;
                            var pdfreport    = new PDFGenerator();
                            pdfreport.GenAggreagativeBenchmarkDoc("reconstruct-aggregative-" + item.Key + "bit.pdf", item.Key / 2, printImroves, compreport == null || compreport.Count() == 0 ? null : compreport);
                        }
                    }
                }
                Console.WriteLine("Report files are generated in current path... Old files has been replaced.");
            }
            else if (op == "report-benaloh")
            {
                if (args.Length == 1 || string.IsNullOrEmpty(args[1]) || !File.Exists(args[1]))
                {
                    printHelp();
                    return;
                }
                filePath = args[1];
                var outputPath = args[2].Replace("output=", "");
                var type       = args[3];
                if (string.IsNullOrEmpty(type) || (type != "scheme" && type != "share"))
                {
                    throw new Exception("scheme or share please define");
                }

                var ser = new XMLSerializer <BenalohPersistanceReport>();
                //var filePath = "SerializedReports-n100-k60-iterate100.xml";
                var report = ser.Deserialize(filePath);
                if (type == "share")
                {
                    HandleBenalohReport(report, outputPath, type);
                }
                else
                {
                    HandleReportsGenericBenaloh(report, outputPath);
                }
                Console.WriteLine("Report files are generated in current path... Old files has been replaced.");
            }
            else if (op == "merge")
            {
                var ser = new XMLSerializer <PersistanceReport>();
                PersistanceReport mergedReports = new PersistanceReport();
                mergedReports.Reports = new List <SecretSharingBenchmarkReport>();
                var outputPath = "";
                foreach (var file in args)
                {
                    if (file == "merge")
                    {
                        continue;
                    }
                    if (file.Contains("output="))
                    {
                        outputPath = file.Replace("output=", "");
                        continue;
                    }
                    var report = ser.Deserialize(file);
                    mergedReports.Reports.AddRange(report.Reports.ToList());
                    mergedReports.Step    = report.Step;
                    mergedReports.Iterate = report.Iterate;
                }
                if (!string.IsNullOrEmpty(outputPath))
                {
                    ser.Serialize(mergedReports, outputPath);
                    Console.WriteLine("mergerd file suceffully geenrated {0}", outputPath);
                }
            }
            Console.ReadLine();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: maplewzx/secret-sharing-1
        static void HandleReports(PersistanceReport report, string output = "")
        {
            //group by key and handle for each key following outputs

            int[] PerformanceK = new int[] { 5, 20, 50 };
            int[] PerformanceN = new int[] { 50, 100 };

            var filteredreconrep = report.Reports.Where(po => po.Operation == SecretSharingBenchmarkReport.OperationType.SecretReconstruction);
            var filteredgenrep   = report.Reports.Where(po => po.Operation == SecretSharingBenchmarkReport.OperationType.ShareGeneration);
            var filteredprime    = report.Reports.Where(po => po.Operation == SecretSharingBenchmarkReport.OperationType.PrimeGneration);

            PDFGenerator pdfreport = new PDFGenerator();

            List <IEnumerable <SecretSharingBenchmarkReport> >[] generationPerformanceCurves     = new List <IEnumerable <SecretSharingBenchmarkReport> > [PerformanceK.Length];
            List <IEnumerable <SecretSharingBenchmarkReport> >[] reconstructionPerformanceCurves = new List <IEnumerable <SecretSharingBenchmarkReport> > [PerformanceN.Length];
            List <IEnumerable <SecretSharingBenchmarkReport> >[] primePerformanceCurves          = new List <IEnumerable <SecretSharingBenchmarkReport> > [PerformanceK.Length];

            List <string>[] genTitles   = new List <string> [PerformanceK.Length];
            List <string>[] primeTitles = new List <string> [PerformanceK.Length];
            List <string>[] reconTitles = new List <string> [PerformanceN.Length];
            for (int i = 1; i <= report.KeySize; i *= 2)
            {
                var chunk         = i;
                var queryreconrep = filteredreconrep.Where(po => po.chunkSize == chunk);
                var querygenrep   = filteredgenrep.Where(po => po.chunkSize == chunk);
                var queryprime    = filteredprime.Where(po => po.chunkSize == chunk);

                for (int kiterate = 0; kiterate < PerformanceK.Length; kiterate++)
                {
                    if (generationPerformanceCurves[kiterate] == null)
                    {
                        generationPerformanceCurves[kiterate] = new List <IEnumerable <SecretSharingBenchmarkReport> >();
                    }
                    if (primePerformanceCurves[kiterate] == null)
                    {
                        primePerformanceCurves[kiterate] = new List <IEnumerable <SecretSharingBenchmarkReport> >();
                    }
                    if (genTitles[kiterate] == null)
                    {
                        genTitles[kiterate] = new List <string>();
                    }
                    if (primeTitles[kiterate] == null)
                    {
                        primeTitles[kiterate] = new List <string>();
                    }
                    var wantedK = PerformanceK[kiterate];

                    var performanceCurveReport = querygenrep.Where(po => po.k == wantedK);
                    if (performanceCurveReport.Count() > 0)
                    {
                        generationPerformanceCurves[kiterate].Add(performanceCurveReport);
                        genTitles[kiterate].Add(string.Format("chunk={0}bit", chunk * 8));
                    }

                    var performancePrimeCurve = queryprime.Where(po => po.k == wantedK);
                    if (performancePrimeCurve.Count() > 0)
                    {
                        primePerformanceCurves[kiterate].Add(performancePrimeCurve);
                        primeTitles[kiterate].Add(string.Format("chunk={0}bit", chunk * 8));
                    }
                }

                for (int niterate = 0; niterate < PerformanceN.Length; niterate++)
                {
                    var wantedN = PerformanceN[niterate];
                    var performanceCurveReport = querygenrep.Where(po => po.n == wantedN);
                    if (reconstructionPerformanceCurves[niterate] == null)
                    {
                        reconstructionPerformanceCurves[niterate] = new List <IEnumerable <SecretSharingBenchmarkReport> >();
                    }
                    if (reconTitles[niterate] == null)
                    {
                        reconTitles[niterate] = new List <string>();
                    }
                    performanceCurveReport = queryreconrep.Where(po => po.n == wantedN);
                    if (performanceCurveReport.Count() > 0)
                    {
                        reconstructionPerformanceCurves[niterate].Add(performanceCurveReport);
                        reconTitles[niterate].Add(string.Format("chunk={0}bit", chunk * 8));
                    }
                }

                pdfreport.GenBenchmarkDoc(string.Format("{0}{1}bit_n{2}_k{3}_recon_chunk{4}bit.pdf", output, report.KeySize, report.N, report.K, chunk * 8), queryreconrep);
                pdfreport.GenBenchmarkDoc(string.Format("{0}{1}bit_n{2}_k{3}_gen_chunk{4}bit.pdf", output, report.KeySize, report.N, report.K, chunk * 8), querygenrep);
            }

            PerormanceAnalysisForm perfViewer = new PerormanceAnalysisForm();

            for (int l = 0; l < PerformanceK.Length; l++)
            {
#if calcPrimeTime
                perfViewer.ExportPerformanceReportsAsPNG_PDF(generationPerformanceCurves[l], genTitles[l]
                                                             , string.Format("Generate no prime KeySize={0}  K={1} ", report.KeySize, PerformanceK[l])
                                                             , true, false,
                                                             string.Format("{0}perf_NoPrime_gen_Key{1}bits_K{2}", output, report.KeySize, PerformanceK[l])
                                                             );

                perfViewer.ExportPerformanceReportsAsPNG_PDF(generationPerformanceCurves[l], genTitles[l]
                                                             , string.Format("Generate timeKeySize={0}  K={1}", report.KeySize, PerformanceK[l]), true, true,
                                                             string.Format("{0}perf_PrimeAndNoPrime_gen_Key{1}bits_K{2}", output, report.KeySize, PerformanceK[l])
                                                             );
#endif
                perfViewer.ExportPerformanceReportsAsPNG_PDF(generationPerformanceCurves[l], genTitles[l]
                                                             , string.Format("Share Generation KeySize={0}  K={1}", report.KeySize, PerformanceK[l])
                                                             , false, true, po => po.n, "n", po => (double)po.Average() / (double)TimeSpan.TicksPerMillisecond, "ms",
                                                             string.Format("{0}perf_Gen_Key{1}bits_K{2}", output, report.KeySize, PerformanceK[l])
                                                             );
                perfViewer.ExportPerformanceReportsAsPNG_PDF(primePerformanceCurves[l], primeTitles[l]
                                                             , string.Format("Prime KeySize={0}  K={1}", report.KeySize, PerformanceK[l])
                                                             , false, true, po => po.n, "n", po => perfViewer.StandardDeviation(po.ToList()), "Standard-D",
                                                             string.Format("{0}perf_Prime_Key{1}bits_K{2}", output, report.KeySize, PerformanceK[l])
                                                             );
            }

            for (int l = 0; l < PerformanceN.Length; l++)
            {
                perfViewer.ExportPerformanceReportsAsPNG_PDF(reconstructionPerformanceCurves[l], reconTitles[l]
                                                             , string.Format("Reconstruction KeySize={0}  N={1}", report.KeySize, PerformanceN[l])
                                                             , false, true, po => po.k, "k", po => (double)po.Average() / (double)TimeSpan.TicksPerMillisecond, "ms",
                                                             string.Format("{0}perf_recon_Key{1}bits_N{2}", output, report.KeySize, PerformanceN[l])
                                                             );
            }
        }