Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1049)

Unified Diff: sdk/lib/crypto/hmac.dart

Issue 11417138: Add verify method to HMAC instances to have a comparison utility that does not leak information thr… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/crypto/crypto.dart ('k') | tests/lib/crypto/hmac_md5_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/crypto/hmac.dart
diff --git a/sdk/lib/crypto/hmac.dart b/sdk/lib/crypto/hmac.dart
index c73bd8fec54e03bf95eef3b41e2282991d2d4d8c..d7e3d98055b79d5ffe45f65acaa81d7b5b756a35 100644
--- a/sdk/lib/crypto/hmac.dart
+++ b/sdk/lib/crypto/hmac.dart
@@ -49,6 +49,20 @@ class _HMAC implements HMAC {
return _hash.update(padding).update(innerHash).digest();
}
+ bool verify(List<int> digest) {
+ var computedDigest = this.digest();
+ if (digest.length != computedDigest.length) {
+ throw new ArgumentError(
+ 'Invalid digest size: ${digest.length} in HMAC.verify. '
+ 'Expected: ${_hash.blockSize}.');
+ }
+ int result = 0;
+ for (var i = 0; i < digest.length; i++) {
+ result |= digest[i] ^ computedDigest[i];
+ }
+ return result == 0;
+ }
+
// HMAC internal state.
Hash _hash;
List<int> _key;
« no previous file with comments | « sdk/lib/crypto/crypto.dart ('k') | tests/lib/crypto/hmac_md5_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698