-
Notifications
You must be signed in to change notification settings - Fork 26
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
API usage and confusion #156
Comments
I got confused when thinking about this code from mirage-crypto's hmac_drbg RNG: let rec go off k v = function
| 0 -> v
| 1 ->
let v = H.hmac_string ~key:k v |> H.to_raw_string in
let len =
let rem = len mod H.digest_size in
if rem = 0 then H.digest_size else rem
in
Bytes.unsafe_blit_string v 0 buf off len;
v
| i ->
let v = H.hmac_string ~key:k v |> H.to_raw_string in
Bytes.unsafe_blit_string v 0 buf off H.digest_size;
go (off + H.digest_size) k v (pred i) To avoid further allocations, also a |
#155 fixes your issue? |
I think I'm still curious whether/why we need both As example, in the Poly1305 in mirage-crypto, we have (an incomplete interface in contrast to digestif) -- which avoids the module type S = sig
type 'a iter = 'a Uncommon.iter
type t
val mac_size : int
val empty : key:string -> t
val feed : t -> string -> t
val feedi : t -> string iter -> t
val get : t -> string
val mac : key:string -> string -> string
val maci : key:string -> string iter -> string
val mac_into : key:string -> (string * int * int) list -> bytes -> dst_off:int -> unit
val unsafe_mac_into : key:string -> (string * int * int) list -> bytes -> dst_off:int -> unit
end The second comment is about val get_into_bytes : ctx -> ?off:int -> bytes -> unit
(** [get_into_bytes ctx ?off buf] writes the result into the given [buf] at
[off] (defaults to [0]).
It's equivalent to:
{[
let get_into_bytes ctx ?(off = 0) buf =
let t = get ctx in
let str = to_raw_string t in
Bytes.blit_string str 0 buf off digest_size
]}
except [get_into_bytes] does not allocate an intermediate string. *) Where the "digest_size" provided to Bytes.blit_string would then be configurable. I'm not certain this complexity in Digestif pays off, though. |
Hey,
I'm not entirely sure I understand the API design. We have two types,
ctx
andt
-- but what is the fundamental difference?A
ctx
we can create by eitherempty
orinit
-- hold on, should thectx
returned byempty
be immutable or better not being used?A
t
we receive fromget
, but also from the functions that take care of computing the hash of a string / string list /...Now, the nicely introduced
get_into_bytes
is defined onctx
, so if I computed the hash withdigest_string
, I can't extract it into an existing byte vector.Would it be possible to simplify the API and only provide a single type t? Since it is private anyways, I'd expect no issues... What do you think?
The text was updated successfully, but these errors were encountered: