1212using System . Security . Cryptography ;
1313#endif
1414
15+ using Blake2Fast . Implementation ;
16+
1517namespace Blake2Fast
1618{
1719 /// <summary>Static helper methods for BLAKE2b hashing.</summary>
@@ -23,7 +25,7 @@ namespace Blake2Fast
2325 static class Blake2b
2426 {
2527 /// <summary>The default hash digest length in bytes. For BLAKE2b, this value is 64.</summary>
26- public const int DefaultDigestLength = Blake2bContext . HashBytes ;
28+ public const int DefaultDigestLength = Blake2bHashState . HashBytes ;
2729
2830 /// <inheritdoc cref="ComputeHash(int, ReadOnlySpan{byte}, ReadOnlySpan{byte})" />
2931 public static byte [ ] ComputeHash ( ReadOnlySpan < byte > input ) => ComputeHash ( DefaultDigestLength , default , input ) ;
@@ -42,10 +44,10 @@ static class Blake2b
4244 /// <returns>The computed hash digest from the message bytes in <paramref name="input" />.</returns>
4345 public static byte [ ] ComputeHash ( int digestLength , ReadOnlySpan < byte > key , ReadOnlySpan < byte > input )
4446 {
45- var ctx = default ( Blake2bContext ) ;
46- ctx . Init ( digestLength , key ) ;
47- ctx . Update ( input ) ;
48- return ctx . Finish ( ) ;
47+ var hs = default ( Blake2bHashState ) ;
48+ hs . Init ( digestLength , key ) ;
49+ hs . Update ( input ) ;
50+ return hs . Finish ( ) ;
4951 }
5052
5153 /// <inheritdoc cref="ComputeAndWriteHash(ReadOnlySpan{byte}, ReadOnlySpan{byte}, Span{byte})" />
@@ -69,31 +71,31 @@ public static void ComputeAndWriteHash(int digestLength, ReadOnlySpan<byte> key,
6971 if ( output . Length < digestLength )
7072 throw new ArgumentException ( $ "Output buffer must have a capacity of at least { digestLength } bytes.", nameof ( output ) ) ;
7173
72- var ctx = default ( Blake2bContext ) ;
73- ctx . Init ( digestLength , key ) ;
74- ctx . Update ( input ) ;
75- ctx . TryFinish ( output , out int _ ) ;
74+ var hs = default ( Blake2bHashState ) ;
75+ hs . Init ( digestLength , key ) ;
76+ hs . Update ( input ) ;
77+ hs . Finish ( output ) ;
7678 }
7779
7880 /// <inheritdoc cref="CreateIncrementalHasher(int, ReadOnlySpan{byte})" />
79- public static IBlake2Incremental CreateIncrementalHasher ( ) => CreateIncrementalHasher ( DefaultDigestLength , default ) ;
81+ public static Blake2bHashState CreateIncrementalHasher ( ) => CreateIncrementalHasher ( DefaultDigestLength , default ) ;
8082
8183 /// <inheritdoc cref="CreateIncrementalHasher(int, ReadOnlySpan{byte})" />
82- public static IBlake2Incremental CreateIncrementalHasher ( int digestLength ) => CreateIncrementalHasher ( digestLength , default ) ;
84+ public static Blake2bHashState CreateIncrementalHasher ( int digestLength ) => CreateIncrementalHasher ( digestLength , default ) ;
8385
8486 /// <inheritdoc cref="CreateIncrementalHasher(int, ReadOnlySpan{byte})" />
85- public static IBlake2Incremental CreateIncrementalHasher ( ReadOnlySpan < byte > key ) => CreateIncrementalHasher ( DefaultDigestLength , key ) ;
87+ public static Blake2bHashState CreateIncrementalHasher ( ReadOnlySpan < byte > key ) => CreateIncrementalHasher ( DefaultDigestLength , key ) ;
8688
8789 /// <summary>Create and initialize an incremental BLAKE2b hash computation.</summary>
8890 /// <remarks>If you will receive the input in segments rather than all at once, this is the most efficient way to calculate the hash.</remarks>
8991 /// <param name="digestLength">The hash digest length in bytes. Valid values are 1 to 64.</param>
9092 /// <param name="key">0 to 64 bytes of input for initializing a keyed hash.</param>
91- /// <returns>An <see cref="IBlake2Incremental " /> interface for updating and finalizing the hash.</returns>
92- public static IBlake2Incremental CreateIncrementalHasher ( int digestLength , ReadOnlySpan < byte > key )
93+ /// <returns>An <see cref="Blake2bHashState " /> instance for updating and finalizing the hash.</returns>
94+ public static Blake2bHashState CreateIncrementalHasher ( int digestLength , ReadOnlySpan < byte > key )
9395 {
94- var ctx = default ( Blake2bContext ) ;
95- ctx . Init ( digestLength , key ) ;
96- return ctx ;
96+ var hs = default ( Blake2bHashState ) ;
97+ hs . Init ( digestLength , key ) ;
98+ return hs ;
9799 }
98100
99101#if BLAKE2_CRYPTOGRAPHY
0 commit comments