public static byte[] ComputeHash(byte[] data, int start, int count, Blake2bConfig config) { var hasher = Create(config); hasher.Update(data, start, count); return(hasher.Finish()); }
public static UInt64[] ConfigB(Blake2bConfig config) { var rawConfig = new UInt64[8]; // //var result = new UInt64[8]; // //digest length if (config.OutputSizeInBytes <= 0 | config.OutputSizeInBytes > 64) // { throw new ArgumentOutOfRangeException("config.OutputSize"); } rawConfig[0] = (UInt32)config.OutputSizeInBytes; // //Key length if (config.Key != null) { if (config.Key.Length > 64) // { throw new ArgumentException("config.Key", "Key too long"); } rawConfig[0] |= (UInt64)(config.Key.LongLength << 8); // } // Fan Out =1 and Max Height / Depth = 1 rawConfig[0] |= 1 << 16; rawConfig[0] |= 1 << 24; // Leaf Length and Inner Length 0, no need to worry about them // 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); }
public Blake2bHasher(Blake2bConfig config) { if (config == null) { config = DefaultConfig; } rawConfig = Blake2bIvBuilder.ConfigB(config); //, null); no tree config; if (config.Key != null && config.Key.Length != 0) { key = new byte[Blake2bCore.BlockSizeInBytes]; Array.Copy(config.Key, key, config.Key.Length); } outputSizeInBytes = config.OutputSizeInBytes; Init(); }
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 static byte[] ComputeHash(byte[] data, Blake2bConfig config) { return(ComputeHash(data, 0, data.Length, config)); }
public static Hasher Create(Blake2bConfig config) { return(new Blake2bHasher(config)); }