protected void InitCore(Blake2BCore.Blake2BConfig config) { Blake2BCore.Blake2BConfig cfg = config ?? DefaultConfig; _rawConfig = Blake2BCore.ConfigB(cfg); if (cfg.Key.IsNullOrZeroLength() == false) { _key = new byte[128]; cfg.Key.DeepCopy_NoChecks(0, _key, 0, cfg.Key.Length); } HashSize = cfg.OutputSizeInBytes; ResetCore(); }
protected Blake2BDigest(int sizeInBits, bool init) : base((HashFunction)Enum.Parse(typeof(HashFunction), "Blake2B" + sizeInBits)) { HashSize = sizeInBits / 8; if (!init) { return; } var config = new Blake2BCore.Blake2BConfig { Key = null, Salt = null, Personalization = null, OutputSizeInBytes = sizeInBits / 8, }; InitCore(config); }
/// <summary> /// Initialise the MAC primitive with a key and/or salt and/or a tag. /// </summary> /// <param name="key">Key for the MAC. Maximum 64 bytes.</param> /// <param name="salt">Salt for the MAC. Maximum 16 bytes.</param> /// <param name="tag">Tag/personalisation to include in the IV for the MAC. Maximum 16 bytes.</param> public void Init(byte[] key, byte[] salt, byte[] tag) { byte[] keyBytes = null, saltBytes = null, tagBytes = null; if (key != null) { if (key.Length > 64) { throw new ArgumentOutOfRangeException("key", "Key is longer than 64 bytes."); } keyBytes = new byte[key.Length]; Array.Copy(key, keyBytes, key.Length); } if (salt != null) { if (salt.Length > 16) { throw new ArgumentOutOfRangeException("salt", "Salt is longer than 16 bytes."); } saltBytes = new byte[16]; Array.Copy(salt, saltBytes, salt.Length); } if (tag != null) { if (tag.Length > 16) { throw new ArgumentOutOfRangeException("tag", "Tag is longer than 16 bytes."); } tagBytes = new byte[16]; Array.Copy(tag, tagBytes, tag.Length); } var config = new Blake2BCore.Blake2BConfig { Key = keyBytes, Salt = saltBytes, Personalization = tagBytes, OutputSizeInBytes = base.OutputSize, }; _isInitialised = true; base.InitCore(config); }