Exemplo n.º 1
0
        public byte[] Generate(int degree, byte input)
        {
            var polynomial = new byte[degree + 1];

            do
            {
                _rng.GetBytes(polynomial);
            } while (Degree(polynomial) != degree);

            polynomial[0] = input;

            return(polynomial);
        }
Exemplo n.º 2
0
        public IEnumerable <byte[]> Split(byte[] secret, int parts, int minimum)
        {
            var values = new byte[parts][];

            var length = secret.Length;

            for (var i = 0; i < parts; i++)
            {
                values[i] = new byte[length];
            }

            for (var i = 0; i < length; i++)
            {
                var polynomial = _gf256.Generate(minimum - 1, secret[i]);

                for (var j = 0; j < parts; j++)
                {
                    values[j][i] = _gf256.Evaluate(polynomial, (byte)(j + 1));
                }
            }

            var result = new List <byte[]>();

            for (var i = 0; i < parts; i++)
            {
                var value = new byte[length + 1];

                _rng.GetBytes(value);

                // Note, this is to make the output look more random, but limits parts to 16
                value[0] = (byte)((value[0] & 0xF0) + i + 1);
                Array.Copy(values[i], 0, value, 1, length);

                result.Add(value);
            }

            return(result);
        }
Exemplo n.º 3
0
 public static double GetDouble(this IRng rng) => BitConverter.ToDouble(rng.GetBytes(8), 0);
Exemplo n.º 4
0
        public static long GetInt64(this IRng rng)
        {
            var bytes = rng.GetBytes(8);

            return(BitConverter.ToInt64(bytes, 0));
        }
Exemplo n.º 5
0
        public static int GetInt32(this IRng rng)
        {
            var bytes = rng.GetBytes(4);

            return(BitConverter.ToInt32(bytes, 0));
        }