Exemplo n.º 1
0
        public override byte[] Split(byte[] secretClear, int shareCount, int threshold)
        {
            Shares = HashiCorpShamir.Split(secretClear, shareCount, threshold);

            // All encoded data is contained within the encoded shares,
            // so there is no transformed form of the secret to return
            return(new byte[0]);
        }
Exemplo n.º 2
0
        public void TestSplit()
        {
            var secret = Encoding.UTF8.GetBytes("test");

            var ret = HashiCorpShamir.Split(secret, 5, 3);

            Assert.Equal(5, ret.Length);

            foreach (var share in ret)
            {
                Assert.Equal(share.Length, secret.Length + 1);
            }
        }
Exemplo n.º 3
0
        public void TestSplit_invalid()
        {
            var secret = Encoding.UTF8.GetBytes("test");

            Assert.ThrowsAny <ArgumentException>(
                () => HashiCorpShamir.Split(secret, 0, 0));

            Assert.ThrowsAny <ArgumentException>(
                () => HashiCorpShamir.Split(secret, 2, 3));

            Assert.ThrowsAny <ArgumentException>(
                () => HashiCorpShamir.Split(secret, 1000, 3));

            Assert.ThrowsAny <ArgumentException>(
                () => HashiCorpShamir.Split(secret, 10, 1));

            Assert.ThrowsAny <ArgumentException>(
                () => HashiCorpShamir.Split(new byte[0], 3, 2));

            Assert.ThrowsAny <ArgumentException>(
                () => HashiCorpShamir.Split(null, 3, 2));

            // if _, err := Split(secret, 0, 0); err == nil {
            //     t.Fatalf("expect error")
            // }

            // if _, err := Split(secret, 2, 3); err == nil {
            //     t.Fatalf("expect error")
            // }

            // if _, err := Split(secret, 1000, 3); err == nil {
            //     t.Fatalf("expect error")
            // }

            // if _, err := Split(secret, 10, 1); err == nil {
            //     t.Fatalf("expect error")
            // }

            // if _, err := Split(nil, 3, 2); err == nil {
            //     t.Fatalf("expect error")
            // }
        }
Exemplo n.º 4
0
        public void TestCombine()
        {
            var secret = Encoding.UTF8.GetBytes("test");

            var ret = HashiCorpShamir.Split(secret, 5, 3);

            // There is 5*4*3 possible choices,
            // we will just brute force try them all
            for (int i = 0; i < 5; i++)
            {
                for (var j = 0; j < 5; j++)
                {
                    if (j == i)
                    {
                        continue;
                    }

                    for (var k = 0; k < 5; k++)
                    {
                        if (k == i || k == j)
                        {
                            continue;
                        }

                        var parts  = new byte[][] { ret[i], ret[j], ret[k] };
                        var recomb = HashiCorpShamir.Combine(parts);

                        Assert.Equal(recomb, secret);
                        // if !bytes.Equal(recomb, secret) {
                        //     t.Errorf("parts: (i:%d, j:%d, k:%d) %v", i, j, k, parts)
                        //     t.Fatalf("bad: %v %v", recomb, secret)
                        // }
                    }
                }
            }
        }