Skip to content

Crypto: use a rich object to represent a message digest (instead of list of bytes) #176

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

Closed
DartBot opened this issue Jun 4, 2015 · 3 comments
Labels
package:crypto type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@DartBot
Copy link

DartBot commented Jun 4, 2015

Originally opened as dart-lang/sdk#2875

This issue was originally filed by [email protected]


In its current shape, the hash and HMAC functions in the crypto library return List<int> as a message digest. This has several deficiencies:

  1. If you want to print it, you need an extra function to convert it to string (see issue #2839).
  2. If you want to compare it and use the hashes for passwords, you have to be very careful to avoid timing attacks (se http://codahale.com/a-lesson-in-timing-attacks/).

Therefore, I propose to use a rich object called Digest instead. It would look like this:

interface Digest {
  final List<int> bytes;

  // TODO operator equals, when implemented
  bool operator ==(Digest other);

  String toString();
}

I'm attaching a patch with complete implementation (necessary modifications to tests included). Note that if you accept this, it supersedes issue #2839.

Please note that I DON'T really understand crypto, so if you decide to accept this API change, proper crypto review is a good idea :-)


Attachment:
0001-represent-message-digest-as-a-rich-object-with-bette.patch (9.72 KB)

@DartBot
Copy link
Author

DartBot commented Jun 4, 2015

Comment by madsager


Added Area-Library, Triaged labels.

@DartBot DartBot added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Jun 4, 2015
@DartBot
Copy link
Author

DartBot commented Jun 4, 2015

Comment by ladicek


This comment was originally written by [email protected]

To increase likelihood of getting this applied (or at least considered), I'm attaching a new version of the patch that applies cleanly to current Dart tree.

I intentionally didn't remove the CryptoUtils.bytesToHex function, because it might be useful for other stuff too, not only for digests.

Attachment:
0001-represent-message-digest-as-a-rich-object-with-bette.patch (10.87 KB)

@sethladd
Copy link
Contributor

Dupe of #177

@mosuem mosuem transferred this issue from dart-archive/crypto Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:crypto type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants