Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Expose interface to keyed Blake2 #364

Conversation

MatthiasValvekens
Copy link

@MatthiasValvekens MatthiasValvekens commented Apr 24, 2022

Earlier today I noticed an old open issue for keyed Blake2 support (see #196). Since I need Blake2b-MAC for one of my own pet projects, and it was a simple matter of properly exposing an existing C interface, I figured I'd have a go at adding it myself.

Here's a summary of the changes:

  • Expose keyed init functions for all Blake2 variants (as suggested in a comment from @vincenthz on Support keyed BLAKE2 #196)
  • Add HashBlake2 typeclass in Crypto.Hash.Blake2 to support keyed initialisation.
  • Add a KeyedBlake2 module to Crypto.MAC with an interface that's essentially isomorphic to the other modules in Crypto.MAC
  • Add tests for all variants. I used the same methodology as the tests for KMAC that were already in the test suite. I got my test vectors from https://github.com/BLAKE2/BLAKE2/.

Note that this is my first time messing around with cryptonite internals, and my experience with the foreign function interface is also pretty limited. In particular, I'd really appreciate a sanity check on the following points:

  • Organisation of the new API.
  • The function signatures for the various cryptonite_blake2XYZ_init_key entry points in the C layer.
  • My implementation of initialize in Crypto.MAC.KeyedBlake2 (the only nontrivial piece of unsafe code)

If there's anything else I need to address, please don't hesitate to tell me.

Thanks a lot!

This fixes haskell-crypto#196.

 - FFI: expose keyed init functions for all Blake2 variants
 - Add HashBlake2 typeclass in Crypto.Hash.Blake2 to support keyed init
 - Add KeyedBlake2 module to Crypto.MAC
Uses KAT vectors from BLAKE2/BLAKE2 repository, plus quickcheck tests
analogous to those in the KAT_KMAC test module.
@vincenthz
Copy link
Member

archiving repository

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants