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 part of crypto; | 5 library crypto.hmac; |
| 6 |
| 7 import 'hash.dart'; |
6 | 8 |
7 /** | 9 /** |
8 * Hash-based Message Authentication Code support. | 10 * Hash-based Message Authentication Code support. |
9 * | 11 * |
10 * The [add] method is used to add data to the message. The [digest] and | 12 * The [add] method is used to add data to the message. The [digest] and |
11 * [close] methods are used to extract the message authentication code. | 13 * [close] methods are used to extract the message authentication code. |
12 */ | 14 */ |
13 // TODO(floitsch): make Hash implement Sink, EventSink or similar. | 15 // TODO(floitsch): make Hash implement Sink, EventSink or similar. |
14 class HMAC { | 16 class HMAC { |
15 final List<int> _message; | 17 final List<int> _message; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 'Invalid digest size: ${digest.length} in HMAC.verify. ' | 105 'Invalid digest size: ${digest.length} in HMAC.verify. ' |
104 'Expected: ${_hash.blockSize}.'); | 106 'Expected: ${_hash.blockSize}.'); |
105 } | 107 } |
106 int result = 0; | 108 int result = 0; |
107 for (var i = 0; i < digest.length; i++) { | 109 for (var i = 0; i < digest.length; i++) { |
108 result |= digest[i] ^ computedDigest[i]; | 110 result |= digest[i] ^ computedDigest[i]; |
109 } | 111 } |
110 return result == 0; | 112 return result == 0; |
111 } | 113 } |
112 } | 114 } |
OLD | NEW |