mirleft / ocaml-nocrypto

OCaml cryptographic library
ISC License
111 stars 53 forks source link

Add {to,from}_hex_string convenience functions #50

Closed trevorsummerssmith closed 9 years ago

trevorsummerssmith commented 9 years ago

Currently nocrypto has debug functions that are helpful for debugging. However many protocols use hex encoding to share encrypted objects. Eg AWS authorization http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html

I don't know if this should go here or in Cstruct, but I think it would be very useful. Something like:

val cstruct_of_hex_string : string -> Cstruct.t val hex_string_of_cstruct : Cstruct.t -> string

Happy to submit a pull request if there is a consensus on including an idea like this.

nojb commented 9 years ago

Note that Uncommon.Cs.of_hex is already there...

On Sunday, March 29, 2015, Trevor Summers Smith notifications@github.com wrote:

Currently nocrypto has debug functions that are helpful for debugging. However many protocols use hex encoding to share encrypted objects. Eg AWS authorization http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html

I don't know if this should go here or in Cstruct, but I think it would be very useful. Something like:

val cstruct_of_hex_string : string -> Cstruct.t val hex_string_of_cstruct : Cstruct.t -> string

Happy to submit a pull request if there is a consensus on including an idea like this.

— Reply to this email directly or view it on GitHub https://github.com/mirleft/ocaml-nocrypto/issues/50.

samoht commented 9 years ago

Could also extend ocaml-hex to add Cstruct related functions.

trevorsummerssmith commented 9 years ago

@nojb oops I missed that. Sorry!

@samoht I'm open to either/both. Given that of_hex is already in Nocrypto it seems natural to add to_hex. Unless, of course, it is really there as a workaround and it should lie in ocaml-hex or elsewhere.

hannesm commented 9 years ago

I personally would prefer to have of_hex / to_hex directly in cstruct. maybe also dotted_hex!? The reasoning is that cstruct already has a hexdump utility, and it sounds wrong to reimplement hex conversions all over (maybe merge it with ocaml-hex, which does string -> hexstring conversions)...

avsm commented 9 years ago

I think putting to/from hex into Cstruct is reasonable, given that it's a major usecase of that library.

nojb commented 9 years ago

And could we please add some of the other functions of Nocrypto.Uncommon.Cs (notably concat and equal) while we are at it?

On Friday, April 3, 2015, Anil Madhavapeddy notifications@github.com wrote:

I think putting to/from hex into Cstruct is reasonable, given that it's a major usecase of that library.

— Reply to this email directly or view it on GitHub https://github.com/mirleft/ocaml-nocrypto/issues/50#issuecomment-89374682 .

pqwy commented 9 years ago

@nojb Basic equal is there since 1.6.0; constant-time version (~mask:true) is perhaps misplaced in the general library.

As for the other functions, honestly, I find the number of utilities I need for working with cstructs to be ever-growing. Not sure where to draw the line, exactly.

But concat and append would probably make sense in the core. @avsm Want me to cut them out of nocrypto and PR cstruct?

avsm commented 9 years ago

Concur about concat and append in cstruct -- pr would be great.

On 4 Apr 2015, at 03:10, David Kaloper notifications@github.com wrote:

@nojb Basic equal is there since 1.6.0; constant-time version (~mask:true) is perhaps misplaced in the general library.

As for the other functions, honestly, I find the number of utilities I need for working with cstructs to be ever-growing. Not sure where to draw the line, exactly.

But concat and append would probably make sense in the core. @avsm Want me to cut them out of nocrypto and PR cstruct?

— Reply to this email directly or view it on GitHub.

trevorsummerssmith commented 9 years ago

@pqwy are you also taking care of a pr for the hex stuff or would you like me to do that? Thanks

pqwy commented 9 years ago

Which PR, in the end?

Hex decoding in nocrypto is used for storing large published vectors. I don't think a crypto library is quite the place to keep general hex converters because you could obviously want to use that kind of encoding for cstructs without crypto.

I'm also not sure cstruct proper is a place for various codecs. sexplib is an exception as it travels with the type.

@trevorsummerssmith What I would like to see is what @samoht suggested: ocaml-hex extended with cstruct support, ideally with an optional parameter to describe which kinds of characters to ignore, which would make all of pretty-printed hex, dotted hex and strict hex special cases. I would probably reuse that and remove the version here.

pqwy commented 9 years ago

It seems that now ocaml-hex is taking care of this.