-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBlake3HashAlgorithm.cs
More file actions
47 lines (40 loc) · 1.24 KB
/
Blake3HashAlgorithm.cs
File metadata and controls
47 lines (40 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.
using System;
using System.Security.Cryptography;
namespace Cryptography.Blake3
{
/// <summary>
/// Implementation of <see cref="HashAlgorithm"/> for BLAKE3.
/// </summary>
public class Blake3HashAlgorithm : HashAlgorithm
{
private Hasher _hasher;
public Blake3HashAlgorithm()
{
_hasher = Hasher.New();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_hasher.Dispose();
}
protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
var span = new byte[cbSize];
Array.Copy(array, ibStart, span, 0, cbSize);
_hasher.Update(span);
}
protected override byte[] HashFinal()
{
var hash = new byte[Blake3.Hash.Size];
_hasher.Finalize(hash);
return hash;
}
public override void Initialize()
{
_hasher.Reset();
}
}
}