Crystal: Move Crypto::MD5 to Digest and consolidate its API

Created on 12 Feb 2017  路  5Comments  路  Source: crystal-lang/crystal

Hello,

Right now MD5 lives in the Crypto module, while SHA1 lives in the Digest module.
I think the latter would be a better fit for MD5. Further, I'd love to see the MD5 API to mirror the one of SHA1:

| Digest::SHA1 | Crypto::MD5 |
|---------|--------|
| Is a module | Is a class |
| Context is private | Context is public |
| .digest(String | Bytes) | Doesn't exist |
| .hexdigest(String | Bytes) No underscore | .hex_digest(String | Bytes) Has underscore |
| Doesn't exist | .hex_digest() with yield |
| .base64digest(String | Bytes) | Doesn't exist |

I'd thus like to do:

  1. Move MD5 to Digest
  2. Make both a module OR a class
  3. Rename hex_digest to hexdigest
  4. Add missing methods (from above) to both of them

I could work on this, though I'd like to get community feedback first before wasting everyones time :)

Cheers!

Most helpful comment

MD5 has nothing to do in Crypto land. Digest is a better place.

All 5 comments

great analysis and breakdown of the differences between the two!
fwiw in Ruby it's Digest::MD5 and Digest::SHA1. :+1: for mirroring the APIs.

edit: forgot to +1

I'm always hesitant to use crystal implementations of crypto functions, mainly because of the possibility of timing attacks. AFAIK openssl uses mostly hand-written assembly to help ensure this constant-time.

MD5 has nothing to do in Crypto land. Digest is a better place.

Thanks y'all for the positive feedback. I'll work on it tomorrow (Tuesday) then.

As #4037 was merged (Thanks!), I'll close this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jhass picture jhass  路  3Comments

lgphp picture lgphp  路  3Comments

asterite picture asterite  路  3Comments

TechMagister picture TechMagister  路  3Comments

nabeelomer picture nabeelomer  路  3Comments