Exemple #1
0
        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);
        }
Exemple #2
0
        private static string BenchmarkBenalohToPersistenceStorage(List <Trustee> participants, string[] Keys, int iterate, string type, List <LoadedPrimeNumber> loadedPrimes)
        {
            var benalohBenchmark = new BenalohLeichterBenchmark();
            var results          = new List <BenalohLeichterBenchmarkReportSet>();
            var allAccesses      = BenalohLeichterBenchmark.ExploreAllPossibleAccessStructures(participants);

            foreach (var key in Keys)
            {
                results.AddRange(benalohBenchmark.BenchmarkAllAccesses(participants, key, iterate, allAccesses, type, loadedPrimes));
            }
            BenalohPersistanceReport bpr = new BenalohPersistanceReport();

            bpr.Reports = results;
            var    serializer = new XMLSerializer <BenalohPersistanceReport>();
            string path       = String.Format("Benaloh-SerializedReport-{0}.xml", DateTime.Now.Ticks);

            serializer.Serialize(bpr, path);
            return(path);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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();
        }