Exemple #1
0
        public static List <AccessStructure> ExploreAllPossibleAccessStructures(IEnumerable <Trustee> participants)
        {
            List <QualifiedSubset> qss = new List <QualifiedSubset>();

            // build up all possible access structure for given input trustees
            for (int i = 1; i <= participants.Count(); i++)
            {
                var combs = GetKCombs <Trustee>(participants, i);
                foreach (var com in combs)
                {
                    QualifiedSubset qs = new QualifiedSubset(com);
                    qss.Add(qs);
                    Console.Write(qs.ToString() + '\t');
                }
                Console.WriteLine();
            }

            List <AccessStructure> accesses = new List <AccessStructure>();

            for (int i = 2; i <= qss.Count; i++)
            {
                var combinedaccesses = GetKCombs <QualifiedSubset>(qss, i);
                foreach (var ac in combinedaccesses)
                {
                    var access = new AccessStructure(ac.ToList());
                    accesses.Add(access);
                    Console.Write(access.ToString() + '\t');
                }

                Console.WriteLine();
            }

            return(accesses);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //p1^p2^p3,p2^p3^p4,p1^p3^p4,p1^p2^p4,p4^p5^p6,p4^p5^p7,p4^p6^p7
            //P1^P2,P2^P3,P3^p4,p3^p5,p3^p6,p6^p7,p7^p8,p8^p1
            //P1^P2,P2^P3,P3^p4,p4^p5,p5^p6,p6^p7,p7^p8,p8^p1
            AccessStructure acc          = new AccessStructure("P1^P2,P2^P3,P3^p4,p4^p5,p5^p6,p6^p7,p7^p8,p8^p1");
            var             expanded     = new List <QualifiedSubset>();
            var             qualified    = new List <QualifiedSubset>();
            var             thresholds   = new List <ThresholdSubset>();
            var             remaining    = new List <QualifiedSubset>();
            var             attempts     = new List <String>();
            var             tryIntersect = true;

            ThresholdHelper.ServeThresholdDetection(acc, tryIntersect, out expanded, out qualified, out thresholds, out attempts, out remaining);
            //foreach (var att in attempts)
            //{
            //    Console.WriteLine(att);
            //}
            Console.WriteLine("all threshold attempts:{0}", attempts.Count);
            Console.WriteLine("all fixed threshold attempts:{0}", ThresholdSubset.fixedAttemptTrace.Count);
            Console.WriteLine("all found thresholds:");
            foreach (var thre in thresholds)
            {
                Console.WriteLine(thre);
            }
            Console.WriteLine("all unique thresholds:");
            foreach (var thre in ThresholdSubset.CheckInclusiveThresholds(thresholds))
            {
                Console.WriteLine(thre);
            }
            Console.Read();
            return;
        }
Exemple #3
0
        //
        // GET: /Home/Details/5

        public ActionResult DetectThreshold(string access)
        {
            var start = DateTime.Now;

            if (!string.IsNullOrEmpty(access))
            {
                try
                {
                    AccessStructure acc          = new AccessStructure(access);
                    var             expanded     = new List <QualifiedSubset>();
                    var             qualified    = new List <QualifiedSubset>();
                    var             thresholds   = new List <ThresholdSubset>();
                    var             remaining    = new List <QualifiedSubset>();
                    var             attempts     = new List <String>();
                    var             tryIntersect = true;
                    ThresholdHelper.ServeThresholdDetection(acc, tryIntersect, out expanded, out qualified, out thresholds, out attempts, out remaining);

                    ViewBag.expanded   = expanded;
                    ViewBag.qualified  = qualified;
                    ViewBag.thresholds = thresholds;
                    ViewBag.remaining  = remaining;
                    ViewBag.attempts   = attempts;
                }
                catch (Exception exc)
                {
                    ViewBag.error = exc.Message;
                }
            }
            ViewBag.elapsedSeconds = (DateTime.Now - start).TotalSeconds;
            return(View());
        }
        public void TestReconstructSecret()
        {
            //assign
            var secret       = "12345678";
            var secretbytes  = Encoding.UTF8.GetBytes(secret.ToCharArray());
            var benaloh      = new BenalohLeichter();
            var access       = new AccessStructure("p1^p2^p3,p2^p3^p4,p1^p3^p4,p1^p2^p4");
            var tryIntersect = true;

            //arrange
            var optimisedAccess = ThresholdHelper.OptimiseAccessStructure(access, tryIntersect);
            var shares          = benaloh.DivideSecret(secretbytes, access);

            foreach (var item in shares)
            {
                var reconSecret = Encoding.UTF8.GetString(benaloh.ReconstructSecret(item));

                Assert.AreEqual(secret, reconSecret, "secret and reconstructed secret are not the same");
            }


            //assert
            Assert.IsNotNull(shares);
            Assert.IsTrue(shares.Count > 0);
        }
        public static void DetectThresholds(AccessStructure access, bool tryIntersect, out List <ThresholdSubset> thresholds, out List <QualifiedSubset> notMatchingSet)
        {
            var expanded  = new List <QualifiedSubset>();
            var qualified = new List <QualifiedSubset>();
            var attempts  = new List <String>();

            ThresholdHelper.ServeThresholdDetection(access, tryIntersect, out expanded, out qualified, out thresholds, out attempts, out notMatchingSet);
        }
Exemple #6
0
        public void TestDetectThreshold()
        {
            var access       = new AccessStructure("p1^p2^p3,p2^p3^p4,p1^p3^p4,p1^p2^p4");
            var tryIntersect = true;

            //arrange
            var optimisedAccess = ThresholdHelper.OptimiseAccessStructure(access, tryIntersect);

            Assert.IsTrue(optimisedAccess.ToString() == "Threshold(3,4)[(P1∧P2∧P3∧P4)]");
        }
Exemple #7
0
        private int getMockShares(AccessStructure access)
        {
            var sum = 0;

            foreach (var qs in access.Accesses)
            {
                sum += qs.getShareBranchesCount();
            }
            return(sum);
        }
        public static AccessStructure OptimiseAccessStructure(AccessStructure access, bool tryIntersect)
        {
            var thresholds = new List <ThresholdSubset>();
            var remaining  = new List <QualifiedSubset>();

            DetectThresholds(access, tryIntersect, out thresholds, out remaining);
            if (IsThresholdShareShorter(access, thresholds, remaining))
            {
                var optimisedAccess = new AccessStructure();
                optimisedAccess.Accesses.AddRange(thresholds);
                optimisedAccess.Accesses.AddRange(remaining);
                return(optimisedAccess);
            }
            return(access);
        }
Exemple #9
0
        private List <IShareCollection> wrappedDivideSecret(AccessStructure access, string secret, ref List <Int64> elapsedTicks)
        {
            var benaloh     = new BenalohLeichter();
            var sw          = new Stopwatch();
            var secretbytes = Encoding.UTF8.GetBytes(secret.ToCharArray());

            sw.Start();
            var shares = benaloh.DivideSecret(secretbytes, access);

            sw.Stop();

            elapsedTicks.Add(sw.ElapsedTicks);

            return(shares);
        }
Exemple #10
0
        public void IsThresholdShareShorterTestFail()
        {
            //assign
            var nothresholdAccess = "P1^P2,P2^P3,P3^p4,p4^p5,p5^p6,p6^p7,p7^p8,p8^p1";
            var tryIntersect      = true;
            //arrange
            AccessStructure a          = new AccessStructure(nothresholdAccess);
            var             thresholds = new List <ThresholdSubset>();
            var             remaining  = new List <QualifiedSubset>();

            ThresholdHelper.DetectThresholds(a, tryIntersect, out thresholds, out remaining);
            bool isEfficicent = ThresholdHelper.IsThresholdShareShorter(a, thresholds, remaining);

            //assert
            Assert.IsFalse(isEfficicent);
        }
Exemple #11
0
        public void IsThresholdShareShorterTestPass()
        {
            //assign
            var nothresholdAccess = "p1^p2^p3,p2^p3^p4,p1^p3^p4,p1^p2^p4,p4^p5^p6,p4^p5^p7,p4^p6^p7";
            var tryIntersect      = true;
            //arrange
            AccessStructure a          = new AccessStructure(nothresholdAccess);
            var             thresholds = new List <ThresholdSubset>();
            var             remaining  = new List <QualifiedSubset>();

            ThresholdHelper.DetectThresholds(a, tryIntersect, out thresholds, out remaining);
            bool isEfficicent = ThresholdHelper.IsThresholdShareShorter(a, thresholds, remaining);

            //assert
            Assert.IsTrue(isEfficicent);
        }
        public void TestDivideSecret()
        {
            //assign
            var secret       = "12345678";
            var secretbytes  = Encoding.UTF8.GetBytes(secret.ToCharArray());
            var benaloh      = new BenalohLeichter();
            var access       = new AccessStructure("p1^p2^p3,p2^p3^p4,p1^p3^p4,p1^p2^p4");
            var tryIntersect = true;

            //arrange
            var optimisedAccess = ThresholdHelper.OptimiseAccessStructure(access, tryIntersect);
            var shares          = benaloh.DivideSecret(secretbytes, optimisedAccess);

            //assert
            Assert.IsNotNull(shares);
            Assert.IsTrue(shares.Count > 0);
        }
Exemple #13
0
        private IEnumerable <BenalohLeichterBenchmarkReportSet> benchmarkScheme(AccessStructure access, string key, int iterate, List <LoadedPrimeNumber> primes)
        {
            Console.WriteLine("benchmarking {0}...", access);
            var filteredPrimes = primes.Where(po => po.PrimeSize == key.Length).ToList();

            PrimeGenerator.SetLoadedPrimes(filteredPrimes);
            List <BenalohLeichterBenchmarkReportSet> results = new List <BenalohLeichterBenchmarkReportSet>();
            List <long>             elapsedDivide            = new List <long>();
            List <long>             elapsedReconstruction    = new List <long>();
            List <IShareCollection> shares = null;

            Antix.Testing.Benchmark.Run(() =>
            {
                shares = wrappedDivideSecret(access, key, ref elapsedDivide);
            }, iterate);
            BenalohLeichterBenchmarkReport divideReport = new BenalohLeichterBenchmarkReport()
            {
                Access       = access.ToString(),
                ElapsedTicks = elapsedDivide.ToArray(),
                KeyLength    = key.Length * 8,
                Operation    = OperationType.DivideSecret
            };

            Antix.Testing.Benchmark.Run(() =>
            {
                wrappedConstructSecret(shares, ref elapsedReconstruction);
            }, iterate);

            BenalohLeichterBenchmarkReport reconstructReport = new BenalohLeichterBenchmarkReport()
            {
                Access       = access.ToString(),
                ElapsedTicks = elapsedReconstruction.ToArray(),
                KeyLength    = key.Length * 8,
                Operation    = OperationType.ReconstructSecret
            };
            var setReport = new BenalohLeichterBenchmarkReportSet()
            {
                divideItem      = divideReport,
                reconstructItem = reconstructReport,
            };

            results.Add(setReport);
            return(results);
        }
Exemple #14
0
        public void TestExpandAccessStructure()
        {
            Trustee p1, p2, p3, p4;

            p1 = new Trustee(1);
            p2 = new Trustee(2);
            p3 = new Trustee(3);
            p4 = new Trustee(4);

            QualifiedSubset qs1, qs2, qs3;

            qs1 = new QualifiedSubset();
            qs1.Parties.Add(p2);
            qs1.Parties.Add(p3);

            qs2 = new QualifiedSubset();
            qs2.Parties.Add(p1);
            qs2.Parties.Add(p2);
            qs2.Parties.Add(p4);

            qs3 = new QualifiedSubset();
            qs3.Parties.Add(p1);
            qs3.Parties.Add(p3);
            qs3.Parties.Add(p4);

            AccessStructure access = new AccessStructure();

            access.Accesses.Add(qs1);
            access.Accesses.Add(qs2);
            access.Accesses.Add(qs3);

            List <Trustee> trustees = new List <Trustee>()
            {
                p1, p2, p3
            };

            ExpandAllAccessPaths(trustees);
        }
Exemple #15
0
        private int wrappedShareLengthDivideSecret(AccessStructure access, bool optimise, bool tryIntersect, string secret, ref List <Int64> elapsedTicks, ref AccessStructure optimisedAccess)
        {
            //return new List<IShareCollection>();

            optimisedAccess = null;
            var benaloh     = new BenalohLeichter();
            var sw          = new Stopwatch();
            var secretbytes = Encoding.UTF8.GetBytes(secret.ToCharArray());

            sw.Start();
            if (optimise)
            {
                access          = ThresholdHelper.OptimiseAccessStructure(access, tryIntersect);
                optimisedAccess = access;
            }
            var shares = getMockShares(access); //benaloh.DivideSecret(secretbytes, access);

            sw.Stop();

            elapsedTicks.Add(sw.ElapsedTicks);

            return(shares);
        }
        public static bool IsThresholdShareShorter(AccessStructure access, List <ThresholdSubset> thresholds
                                                   , List <QualifiedSubset> notMatchingSet)
        {
            // caclulate shares given in case of using thresholds
            var sumThresholdShare = 0;

            foreach (var th in thresholds)
            {
                sumThresholdShare += th.getPartiesCount();
            }
            //append shares from the not matching sets
            foreach (var qs in notMatchingSet)
            {
                sumThresholdShare += qs.Parties.Count;
            }
            var sumNoThreshold = 0;

            //now let's see how it would be if we just divide simply
            foreach (var qs in access.Accesses)
            {
                sumNoThreshold += qs.getPartiesCount();
            }
            return(sumThresholdShare < sumNoThreshold);
        }
        public static void ServeThresholdDetection(AccessStructure access, bool tryIntersect, out List <QualifiedSubset> expandedSet
                                                   , out List <QualifiedSubset> qualifiedSet, out List <ThresholdSubset> thresholds, out List <string> attempts,
                                                   out List <QualifiedSubset> notMatchingSet)
        {
            ThresholdSubset.attemptTrace      = new List <string>();
            ThresholdSubset.fixedAttemptTrace = new List <string>();

            List <Trustee> trustees = access.GetAllParties().OrderBy(po => po.partyId).ToList();

            //discover all possible expansion of the access structures
            List <QualifiedSubset> subsets = AccessStructure.ExpandPersonPaths(null, trustees).Distinct().ToList();

            expandedSet = subsets;

            //return;

            //we don't care about longer paths which are not mentioned in the access structure
            int longestQualifiedSubsetAccepted = access.GetLongestLength();//GetLongestLength(access);

            //calculate the share of each party in qualified subsets
            int i = 0;
            List <Tuple <Trustee, int> > allsubsetsparties       = new List <Tuple <Trustee, int> >();
            List <QualifiedSubset>       qualifiedExpandedSubset = new List <QualifiedSubset>();

            Console.WriteLine("All qualified expanded subsets:");
            foreach (QualifiedSubset subset in subsets)
            {
                //delete unqualified subsets based on minimum access structure
                if (subset.Parties.Count > longestQualifiedSubsetAccepted)
                {
                    continue;
                }
                bool isqualified = AccessStructure.IsQualifiedSubset(subset, access);
                if (isqualified)
                {
                    //add the subset to expanded qualified
                    qualifiedExpandedSubset.Add(subset);
                    allsubsetsparties.AddRange(subset.Parties.Select(po => new Tuple <Trustee, int>(po, subset.Parties.Count)));
                    Console.WriteLine("{0}.\t [{1}] q:{2}", i++, subset.ToString(), isqualified);
                }
            }

            qualifiedSet = qualifiedExpandedSubset.ToList();



            List <ThresholdSubset> thresholdsubsets = new List <ThresholdSubset>();
            var normalTH = qualifiedExpandedSubset.GroupBy(po => po.Parties.Count).Select(info => new { Depth = info.Key, Count = info.Count() });

            foreach (var th in normalTH)
            {
                var candidateSets = qualifiedExpandedSubset.Where(po => po.Parties.Count == th.Depth);

                ///find threshold in sets
                var threshold = ThresholdSubset.findThreshold(candidateSets, th.Depth, trustees.Count,
                                                              ThresholdSubset.GetNumberOfRequiredSetsForThreshold(trustees.Count, th.Depth, candidateSets.Count()), tryIntersect);
                if (threshold != null && threshold.Count != 0)
                {
                    thresholdsubsets.AddRange(threshold);
                }
            }

            var uniqueInclusiveThresholds = ThresholdSubset.CheckInclusiveThresholds(thresholdsubsets.Distinct());

            foreach (ThresholdSubset th in uniqueInclusiveThresholds)
            {
                Console.WriteLine(th);
                var coveredsets = ThresholdSubset.ExploreAllSubsets(th);
                qualifiedExpandedSubset = qualifiedExpandedSubset.Except(coveredsets).ToList();
            }
            thresholds     = uniqueInclusiveThresholds.ToList();
            notMatchingSet = qualifiedExpandedSubset.ToList();

            attempts = ThresholdSubset.attemptTrace;
        }
Exemple #18
0
        private IEnumerable <BenalohLeichterBenchmarkReportSet> benchmarkShareLengthAccessStructure(AccessStructure access, string key, int iterate)
        {
            List <BenalohLeichterBenchmarkReportSet> results = new List <BenalohLeichterBenchmarkReportSet>();
            List <long>     elapsedDivideOptimisdIntersected = new List <long>();
            List <long>     elapsedDivideOptimisd            = new List <long>();
            List <long>     elapsedDivide         = new List <long>();
            List <long>     elapsedReconstruction = new List <long>();
            int             shares         = 0;
            AccessStructure optimsedAccess = null;

            Antix.Testing.Benchmark.Run(() =>
            {
                shares = wrappedShareLengthDivideSecret(access, true, true, key, ref elapsedDivideOptimisdIntersected, ref optimsedAccess);
            }, iterate);

            var numberOfShares = shares;
            BenalohLeichterBenchmarkReport divideReportOptimisedIntersected = new BenalohLeichterBenchmarkReport()
            {
                Access          = access.ToString(),
                ElapsedTicks    = elapsedDivideOptimisdIntersected.ToArray(),
                KeyLength       = key.Length * 8,
                NumberOfShares  = numberOfShares,
                Operation       = OperationType.DivideSecretOptimisedIntersected,
                OptimisedAccess = optimsedAccess.ToString(),
            };

            Antix.Testing.Benchmark.Run(() =>
            {
                shares = wrappedShareLengthDivideSecret(access, true, false, key, ref elapsedDivideOptimisd, ref optimsedAccess);
            }, iterate);
            numberOfShares = shares;
            BenalohLeichterBenchmarkReport divideReportOptimised = new BenalohLeichterBenchmarkReport()
            {
                Access          = access.ToString(),
                ElapsedTicks    = elapsedDivideOptimisd.ToArray(),
                KeyLength       = key.Length * 8,
                NumberOfShares  = numberOfShares,
                Operation       = OperationType.DivideSecretOptimised,
                OptimisedAccess = optimsedAccess.ToString(),
            };

            Antix.Testing.Benchmark.Run(() =>
            {
                shares = wrappedShareLengthDivideSecret(access, false, false, key, ref elapsedDivide, ref optimsedAccess);
            }, iterate);
            numberOfShares = shares;
            BenalohLeichterBenchmarkReport divideReport = new BenalohLeichterBenchmarkReport()
            {
                Access         = access.ToString(),
                ElapsedTicks   = elapsedDivide.ToArray(),
                KeyLength      = key.Length * 8,
                NumberOfShares = numberOfShares,
                Operation      = OperationType.DivideSecret
            };

            var setReport = new BenalohLeichterBenchmarkReportSet()
            {
                divideItem      = divideReport,
                optimisedItem   = divideReportOptimised,
                IntersectedItem = divideReportOptimisedIntersected
            };

            results.Add(setReport);


            return(results);
        }