示例#1
0
        public static SplitSecret Split(SecretShareType shareType, byte[] secret, int threshold, Diffuser diffuser)
        {
            var irreduciblePolynomial = IrreduciblePolynomial.CreateOfByteSize(secret.Length);
            var rawSecret             = secret.ToBigIntegerFromBigEndianUnsignedBytes();
            var diffusedSecret        = diffuser.Scramble(rawSecret, secret.Length);
            var secretCoefficient     = new FiniteFieldPolynomial(irreduciblePolynomial, diffusedSecret);

            var allCoefficients = new[] { secretCoefficient }
            .Concat(
                GetRandomPolynomials(
                    irreduciblePolynomial,
                    threshold - 1)
                )
            .ToArray();

            var passPhrase = new SecureString();

            try {
                foreach (var currentChar in secret.ToHexString())
                {
                    passPhrase.AppendChar(currentChar);
                }
            }
            catch {
                passPhrase = null;
            }

            if ((passPhrase == null) || (passPhrase.Length == 0))
            {
                passPhrase = null;
            }

            return(new SplitSecret(shareType, threshold, irreduciblePolynomial, allCoefficients, passPhrase));
        }
示例#2
0
        public static SplitSecret Split(SecretShareType shareType, byte[] secret, int threshold, Diffuser diffuser)
        {
            var irreduciblePolynomial = IrreduciblePolynomial.CreateOfByteSize(secret.Length);
            var rawSecret = secret.ToBigIntegerFromBigEndianUnsignedBytes();
            var diffusedSecret = diffuser.Scramble(rawSecret, secret.Length);
            var secretCoefficient = new FiniteFieldPolynomial(irreduciblePolynomial, diffusedSecret);

            var allCoefficients = new[] { secretCoefficient }
                .Concat(
                    GetRandomPolynomials(
                        irreduciblePolynomial,
                        threshold - 1)
                )
                .ToArray();

            var passPhrase = new SecureString();

            try {
                foreach (var currentChar in secret.ToHexString()) {
                    passPhrase.AppendChar(currentChar);
                }
            }
            catch {
                passPhrase = null;
            }

            if((passPhrase == null) || (passPhrase.Length == 0)) {
                passPhrase = null;
            }

            return new SplitSecret(shareType, threshold, irreduciblePolynomial, allCoefficients, passPhrase);
        }
示例#3
0
 public SplitSecret(SecretShareType shareType, int threshold, IrreduciblePolynomial irreduciblePolynomial, FiniteFieldPolynomial[] allCoefficients, SecureString passPhrase = null)
 {
     _ShareType             = shareType;
     Threshold              = threshold;
     _IrreduciblePolynomial = irreduciblePolynomial;
     _AllCoefficients       = allCoefficients;
     _PassPhrase            = passPhrase;
 }
示例#4
0
 public CombinedSecret(SecretShareType shareType, byte[] recoveredBytes)
 {
     ShareType = shareType;
     // TODO: Use ProtectedData.Protect, but that'd pull in another DLL
     RecoveredBytes = recoveredBytes;
 }
示例#5
0
 public CombinedSecret(SecretShareType shareType, byte[] recoveredBytes) {
     ShareType = shareType;
     // TODO: Use ProtectedData.Protect, but that'd pull in another DLL
     RecoveredBytes = recoveredBytes;
 }
示例#6
0
 private static SplitSecret Split(SecretShareType shareType, byte[] secret, int threshold)
 {
     return(Split(shareType, secret, threshold, DefaultDiffuser));
 }
示例#7
0
 private static SplitSecret Split(SecretShareType shareType, byte[] secret, int threshold)
 {
     return Split(shareType, secret, threshold, DefaultDiffuser);
 }
示例#8
0
 public SplitSecret(SecretShareType shareType, int threshold, IrreduciblePolynomial irreduciblePolynomial, FiniteFieldPolynomial[] allCoefficients, SecureString passPhrase = null)
 {
     _ShareType = shareType;
     Threshold = threshold;
     _IrreduciblePolynomial = irreduciblePolynomial;
     _AllCoefficients = allCoefficients;
     _PassPhrase = passPhrase;
 }
示例#9
0
 public SecretShare(SecretShareType shareType, FiniteFieldPoint point, string checksum = null) {
     ShareType = shareType;
     Point = point;
     Checksum = checksum;
 }
示例#10
0
 public SecretShare(SecretShareType shareType, FiniteFieldPoint point, string checksum = null)
 {
     ShareType = shareType;
     Point     = point;
     Checksum  = checksum;
 }