Exemple #1
0
        public static byte[] ComputeHash(byte[] data, int start, int count, Blake2BConfig config)
        {
            var hasher = Create(config);

            hasher.Update(data, start, count);
            return(hasher.Finish());
        }
Exemple #2
0
    public static byte[] GetHashBlake2Sharp()
    {
        var cfg = new Blake2Sharp.Blake2BConfig()
        {
            OutputSizeInBytes = BenchConfig.HashBytes,
            Key = BenchConfig.Key
        };

        return(Blake2Sharp.Blake2B.ComputeHash(BenchConfig.Data, cfg));
    }
Exemple #3
0
 public Blake2BConfig Clone()
 {
     var result = new Blake2BConfig();
     result.OutputSizeInBytes = OutputSizeInBytes;
     if (Key != null)
         result.Key = (byte[])Key.Clone();
     if (Personalization != null)
         result.Personalization = (byte[])Personalization.Clone();
     if (Salt != null)
         result.Salt = (byte[])Salt.Clone();
     return result;
 }
 public Blake2BHasher(Blake2BConfig config)
 {
     if (config == null)
         config = DefaultConfig;
     rawConfig = Blake2IvBuilder.ConfigB(config, null);
     if (config.Key != null && config.Key.Length != 0)
     {
         key = new byte[128];
         Array.Copy(config.Key, key, config.Key.Length);
     }
     outputSizeInBytes = config.OutputSizeInBytes;
     Init();
 }
        public static ulong[] ConfigB(Blake2BConfig config, Blake2BTreeConfig treeConfig)
        {
            bool isSequential = treeConfig == null;
            if (isSequential)
                treeConfig = SequentialTreeConfig;
            var rawConfig = new ulong[8];
            var result = new ulong[8];

            //digest length
            if (config.OutputSizeInBytes <= 0 | config.OutputSizeInBytes > 64)
                throw new ArgumentOutOfRangeException("config.OutputSize");
            rawConfig[0] |= (ulong)(uint)config.OutputSizeInBytes;

            //Key length
            if (config.Key != null)
            {
                if (config.Key.Length > 64)
                    throw new ArgumentException("config.Key", "Key too long");
                rawConfig[0] |= (ulong)((uint)config.Key.Length << 8);
            }
            // FanOut
            rawConfig[0] |= (uint)treeConfig.FanOut << 16;
            // Depth
            rawConfig[0] |= (uint)treeConfig.MaxHeight << 24;
            // Leaf length
            rawConfig[0] |= ((ulong)(uint)treeConfig.LeafSize) << 32;
            // Inner length
            if (!isSequential && (treeConfig.IntermediateHashSize <= 0 || treeConfig.IntermediateHashSize > 64))
                throw new ArgumentOutOfRangeException("treeConfig.TreeIntermediateHashSize");
            rawConfig[2] |= (uint)treeConfig.IntermediateHashSize << 8;
            // Salt
            if (config.Salt != null)
            {
                if (config.Salt.Length != 16)
                    throw new ArgumentException("config.Salt has invalid length");
                rawConfig[4] = Blake2BCore.BytesToUInt64(config.Salt, 0);
                rawConfig[5] = Blake2BCore.BytesToUInt64(config.Salt, 8);
            }
            // Personalization
            if (config.Personalization != null)
            {
                if (config.Personalization.Length != 16)
                    throw new ArgumentException("config.Personalization has invalid length");
                rawConfig[6] = Blake2BCore.BytesToUInt64(config.Personalization, 0);
                rawConfig[6] = Blake2BCore.BytesToUInt64(config.Personalization, 8);
            }

            return rawConfig;
        }
Exemple #6
0
 public Blake2BHasher(Blake2BConfig config)
 {
     if (config == null)
     {
         config = DefaultConfig;
     }
     rawConfig = Blake2IvBuilder.ConfigB(config, null);
     if (config.Key != null && config.Key.Length != 0)
     {
         key = new byte[128];
         Array.Copy(config.Key, key, config.Key.Length);
     }
     outputSizeInBytes = config.OutputSizeInBytes;
     Init();
 }
Exemple #7
0
        public static ulong[] ConfigB(Blake2BConfig config, Blake2BTreeConfig treeConfig)
        {
            bool flag = treeConfig == null;

            if (flag)
            {
                treeConfig = SequentialTreeConfig;
            }
            ulong[] array  = new ulong[8];
            ulong[] array2 = new ulong[8];
            if ((config.OutputSizeInBytes <= 0) | (config.OutputSizeInBytes > 64))
            {
                throw new ArgumentOutOfRangeException("config.OutputSize");
            }
            ref ulong reference = ref array[0];
        public Blake2BConfig Clone()
        {
            var result = new Blake2BConfig();

            result.OutputSizeInBytes = OutputSizeInBytes;
            if (Key != null)
            {
                result.Key = (byte[])Key.Clone();
            }
            if (Personalization != null)
            {
                result.Personalization = (byte[])Personalization.Clone();
            }
            if (Salt != null)
            {
                result.Salt = (byte[])Salt.Clone();
            }
            return(result);
        }
        public Blake2BConfig Clone()
        {
            Blake2BConfig blake2BConfig = new Blake2BConfig();

            blake2BConfig.OutputSizeInBytes = OutputSizeInBytes;
            if (Key != null)
            {
                blake2BConfig.Key = (byte[])Key.Clone();
            }
            if (Personalization != null)
            {
                blake2BConfig.Personalization = (byte[])Personalization.Clone();
            }
            if (Salt != null)
            {
                blake2BConfig.Salt = (byte[])Salt.Clone();
            }
            return(blake2BConfig);
        }
Exemple #10
0
 public static byte[] ComputeHash(byte[] data, Blake2BConfig config)
 {
     return(ComputeHash(data, 0, data.Length, config));
 }
Exemple #11
0
 public static Hasher Create(Blake2BConfig config)
 {
     return(new Blake2BHasher(config));
 }
Exemple #12
0
        public static ulong[] ConfigB(Blake2BConfig config, Blake2BTreeConfig treeConfig)
        {
            bool isSequential = treeConfig == null;

            if (isSequential)
            {
                treeConfig = SequentialTreeConfig;
            }
            var rawConfig = new ulong[8];
            var result    = new ulong[8];

            //digest length
            if (config.OutputSizeInBytes <= 0 | config.OutputSizeInBytes > 64)
            {
                throw new ArgumentOutOfRangeException("config.OutputSize");
            }
            rawConfig[0] |= (ulong)(uint)config.OutputSizeInBytes;

            //Key length
            if (config.Key != null)
            {
                if (config.Key.Length > 64)
                {
                    throw new ArgumentException("config.Key", "Key too long");
                }
                rawConfig[0] |= (ulong)((uint)config.Key.Length << 8);
            }
            // FanOut
            rawConfig[0] |= (uint)treeConfig.FanOut << 16;
            // Depth
            rawConfig[0] |= (uint)treeConfig.MaxHeight << 24;
            // Leaf length
            rawConfig[0] |= ((ulong)(uint)treeConfig.LeafSize) << 32;
            // Inner length
            if (!isSequential && (treeConfig.IntermediateHashSize <= 0 || treeConfig.IntermediateHashSize > 64))
            {
                throw new ArgumentOutOfRangeException("treeConfig.TreeIntermediateHashSize");
            }
            rawConfig[2] |= (uint)treeConfig.IntermediateHashSize << 8;
            // Salt
            if (config.Salt != null)
            {
                if (config.Salt.Length != 16)
                {
                    throw new ArgumentException("config.Salt has invalid length");
                }
                rawConfig[4] = Blake2BCore.BytesToUInt64(config.Salt, 0);
                rawConfig[5] = Blake2BCore.BytesToUInt64(config.Salt, 8);
            }
            // Personalization
            if (config.Personalization != null)
            {
                if (config.Personalization.Length != 16)
                {
                    throw new ArgumentException("config.Personalization has invalid length");
                }
                rawConfig[6] = Blake2BCore.BytesToUInt64(config.Personalization, 0);
                rawConfig[7] = Blake2BCore.BytesToUInt64(config.Personalization, 8);
            }

            return(rawConfig);
        }
Exemple #13
0
 public static Hasher Create(Blake2BConfig config)
 {
     return new Blake2BHasher(config);
 }
Exemple #14
0
 public static byte[] ComputeHash(byte[] data, int start, int count, Blake2BConfig config)
 {
     var hasher = Create(config);
     hasher.Update(data, start, count);
     return hasher.Finish();
 }
Exemple #15
0
 public static byte[] ComputeHash(byte[] data, Blake2BConfig config)
 {
     return ComputeHash(data, 0, data.Length, config);
 }