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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/crypto/crypto.dart ('k') | tests/lib/crypto/hmac_md5_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class _HMAC implements HMAC { 5 class _HMAC implements HMAC {
6 _HMAC(Hash this._hash, List<int> this._key) : _message = []; 6 _HMAC(Hash this._hash, List<int> this._key) : _message = [];
7 7
8 HMAC update(List<int> data) { 8 HMAC update(List<int> data) {
9 _message.addAll(data); 9 _message.addAll(data);
10 return this; 10 return this;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // Compute outer padding. 42 // Compute outer padding.
43 for (var i = 0; i < blockSize; i++) { 43 for (var i = 0; i < blockSize; i++) {
44 padding[i] = 0x5c ^ _key[i]; 44 padding[i] = 0x5c ^ _key[i];
45 } 45 }
46 46
47 // Outer hash computation which is the result. 47 // Outer hash computation which is the result.
48 _hash = _hash.newInstance(); 48 _hash = _hash.newInstance();
49 return _hash.update(padding).update(innerHash).digest(); 49 return _hash.update(padding).update(innerHash).digest();
50 } 50 }
51 51
52 bool verify(List<int> digest) {
53 var computedDigest = this.digest();
54 if (digest.length != computedDigest.length) {
55 throw new ArgumentError(
56 'Invalid digest size: ${digest.length} in HMAC.verify. '
57 'Expected: ${_hash.blockSize}.');
58 }
59 int result = 0;
60 for (var i = 0; i < digest.length; i++) {
61 result |= digest[i] ^ computedDigest[i];
62 }
63 return result == 0;
64 }
65
52 // HMAC internal state. 66 // HMAC internal state.
53 Hash _hash; 67 Hash _hash;
54 List<int> _key; 68 List<int> _key;
55 List<int> _message; 69 List<int> _message;
56 } 70 }
OLDNEW
« 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