Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement feedable hmac #155

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Implement feedable hmac #155

wants to merge 4 commits into from

Conversation

reynir
Copy link
Member

@reynir reynir commented Apr 5, 2024

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.

Analogous to `ctx` and `feed_*` but for computing hmacs incrementally.
For when `hmaci_*` is not suitable.
@reynir
Copy link
Member Author

reynir commented Apr 5, 2024

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
Copy link
Member

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

@reynir
Copy link
Member Author

reynir commented Apr 15, 2024

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

  • both hmac_init and hmac_get would take the key whereas with this design only hmac_init takes the key => room for mixing up keys at init and get.
  • you might call get on a hmac ctx which results in the wrong hmac
  • you might call init instead of hmac_init or you might use empty and compute a "hmac" with that and finally call hmac_get ~key ctx to get a (wrong) hmac.

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
Copy link
Member

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 👍.

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

Successfully merging this pull request may close these issues.

Feed a hmac
2 participants