| OLD | NEW |
| 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 Loading... |
| 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 } |
| OLD | NEW |