Repository: RustCrypto/hashes (language: rust)

Issue:
Regression in blake2 v0.10.0 - new `reset` feature fails to compile
Introduced in https://github.com/RustCrypto/hashes/commit/75298d36b9400654ad3bbee072b59c5ffed27aa4

A new feature flag, `reset`, was introduced to gate features where hashers can reset their internal state (nit: this was not noted in the changelog as a breaking change).

This feature does not appear to be tested in the github actions CI, and consequently is broken.

Compiling `master` locally with rust 1.57.0 I see:

```
$ cargo build --features reset                                                                                                                                                                                                                                                        ✔
   Compiling blake2 v0.10.0 (/home/tom/personal/hashes/blake2)
error[E0308]: mismatched types
   --> blake2/src/macros.rs:407:53
    |
394 |         impl<OutSize> FixedOutputReset for $name<OutSize>
    |              ------- this type parameter
...
407 |                 core.finalize_variable_core(buffer, out);
    |                                                     ^^^ expected struct `UInt`, found type parameter `OutSize`
    |
   ::: blake2/src/lib.rs:143:1
    |
143 | blake2_mac_impl!(Blake2bMac, Blake2bVarCore, U64, "Blake2b MAC function");
    | ------------------------------------------------------------------------- in this macro invocation
    |
    = note: expected mutable reference `&mut GenericArray<u8, UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>`
               found mutable reference `&mut GenericArray<u8, OutSize>`
    = note: this error originates in the macro `blake2_mac_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
   --> blake2/src/macros.rs:407:53
    |
394 |         impl<OutSize> FixedOutputReset for $name<OutSize>
    |              ------- this type parameter
...
407 |                 core.finalize_variable_core(buffer, out);
    |                                                     ^^^ expected struct `UInt`, found type parameter `OutSize`
    |
   ::: blake2/src/lib.rs:173:1
    |
173 | blake2_mac_impl!(Blake2sMac, Blake2sVarCore, U32, "Blake2s MAC function");
    | ------------------------------------------------------------------------- in this macro invocation
    |
    = note: expected mutable reference `&mut GenericArray<u8, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>>`
               found mutable reference `&mut GenericArray<u8, OutSize>`
    = note: this error originates in the macro `blake2_mac_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0308`.
error: could not compile `blake2` due to 2 previous errors
```

I would be happy to submit a PR if some guidance can be given on the most appropriate fix, I'll see if I can work out a potential fix now.


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/blake2.yml b/.github/workflows/blake2.yml
index 51f49050a..b0eb0eeae 100644
--- a/.github/workflows/blake2.yml
+++ b/.github/workflows/blake2.yml
@@ -45,14 +45,15 @@ jobs:
           - 1.41.0 # MSRV
           - stable
     steps:
-    - uses: actions/checkout@v1
-    - uses: actions-rs/toolchain@v1
-      with:
-        profile: minimal
-        toolchain: ${{ matrix.rust }}
-        override: true
-    - run: cargo test --no-default-features
-    - run: cargo test
+      - uses: actions/checkout@v1
+      - uses: actions-rs/toolchain@v1
+        with:
+          profile: minimal
+          toolchain: ${{ matrix.rust }}
+          override: true
+      - run: cargo test --no-default-features
+      - run: cargo test
+      - run: cargo test --features reset
   simd:
     runs-on: ubuntu-latest
     steps:
diff --git a/blake2/CHANGELOG.md b/blake2/CHANGELOG.md
index d6678159a..3e36c9a58 100644
--- a/blake2/CHANGELOG.md
+++ b/blake2/CHANGELOG.md
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - `Blake2b` and `Blake2s` renamed into `Blake2b512` and `Blake2s256` respectively.
   New `Blake2b` and `Blake2s` are generic over output size. `VarBlake2b` and `VarBlake2s`
   renamed into `Blake2bVar` and `Blake2sVar` respectively. ([#217])
+- Hasher reset functionality moved behind a new non-default feature, `reset`.
+  This must be enabled to use the methods `reset`, `finalize_reset` and `finalize_into_reset`.
 
 ### Removed
 - `Blake2b` and `Blake2s` no longer support MAC functionality. ([#217])
diff --git a/blake2/src/macros.rs b/blake2/src/macros.rs
index 393c1fe1f..ece46e718 100644
--- a/blake2/src/macros.rs
+++ b/blake2/src/macros.rs
@@ -404,7 +404,9 @@ macro_rules! blake2_mac_impl {
                     key_block,
                     ..
                 } = self;
-                core.finalize_variable_core(buffer, out);
+                let mut full_res = Default::default();
+                core.finalize_variable_core(buffer, &mut full_res);
+                out.copy_from_slice(&full_res[..OutSize::USIZE]);
                 core.reset();
                 *buffer = LazyBuffer::new(key_block);
             }


Test patch: