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
add multiple strings to hmac-sha1 and get digest #66
Comments
Seems that the only solution is to keep an internal buffer. |
So... if there is one design principle behind Why are you not using |
I decide to use and, is my idea of using internal buffer OK? |
I didn't mean to push As for the buffer, looks ok. I would bypass several copies just on principle and do something more like this: let cs_of_strings ss =
let res = Cstruct.create (List.fold_left (fun a s -> a + String.length s) 0 ss) in
List.fold_left (fun i s ->
let n = String.length s in Cstruct.blit_from_string s 0 res i n ; i + n)
0 ss ;
res ... and then use a Then again, looking at how you use incremental hashing, I think it could be made simpler still: let hmacv ~key ss = Hash.SHA1.hmac ~key (cs_of_strings ss) With this, you can just massage the parts of the string you are trying to hash over into a list and MAC it in a single go, essentially replacing your |
Thanks for you advice. I don't want to use two crypto libraries either and I really want to use one if possible... :) |
Hi,
I am writing an OAuth module that can work on both Unix and Mirage (Xen). I need to generate random bytes and do HMAC_SHA1
For Unix, I use Cryptokit
The code is here:
However, for Mirage, I read the API doc of nocrypto and I am not sure if there is an equivalent function to perform
hash#add_string
as in Cryptokit.Is it possible to initialize a hmac_sha1 box with a key and keep adding strings one at a time until I want to get the digest?
Thank you
The text was updated successfully, but these errors were encountered: