mirage / digestif

Simple hash algorithms in OCaml
MIT License
87 stars 26 forks source link

Implement feedable hmac #155

Open reynir opened 7 months ago

reynir commented 7 months ago

Analogous to ctx and feed_* but for computing hmacs incrementally. For when hmaci_* is not suitable. Fixes #154.

I'm open for suggestions in naming. The type hmac could be hmac_ctx for example, and the functions could be feed_hmac_bytes instead of hmac_feed_bytes.

reynir commented 7 months ago

I struggled a bit with the tests as k Digestif.t is opaque and we don't have the type equality k Digestif.t = k :(

dinosaure commented 6 months ago

Do you have a reason to define type hmac and not to use type ctx?

reynir commented 6 months ago

Yes. type hmac = ctx * string where the string is the "outer" part of the key. We could as well use ctx, but then:

Another possible solution is to define a type 'a ctx' and use a phantom type to keep track of whether we're computing a hmac (where we must do some extra initial and final steps) or a digest.

dinosaure commented 6 months ago

Another possible solution is to define a type 'a ctx' and use a phantom type to keep track of whether we're computing a hmac (where we must do some extra initial and final steps) or a digest.

Yes but it will breaks the API. I'm ok with the initial change. I will merge that when I have a time :+1:.