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 #library('dart:crypto'); | 5 #library('dart:crypto'); |
6 | 6 |
7 #import('dart:math'); | 7 #import('dart:math'); |
8 | 8 |
9 #source('crypto_utils.dart'); | 9 #source('crypto_utils.dart'); |
10 #source('hash_utils.dart'); | 10 #source('hash_utils.dart'); |
(...skipping 26 matching lines...) Expand all Loading... |
37 * a list of bytes. | 37 * a list of bytes. |
38 */ | 38 */ |
39 List<int> digest(); | 39 List<int> digest(); |
40 | 40 |
41 /** | 41 /** |
42 * Returns a new instance of this hash function. | 42 * Returns a new instance of this hash function. |
43 */ | 43 */ |
44 Hash newInstance(); | 44 Hash newInstance(); |
45 | 45 |
46 /** | 46 /** |
47 * Block size of the hash in bytes. | 47 * Internal block size of the hash in bytes. |
| 48 * |
| 49 * This is exposed for use by the HMAC class which needs to know the |
| 50 * block size for the [Hash] it is using. |
48 */ | 51 */ |
49 int get blockSize; | 52 int get blockSize; |
50 } | 53 } |
51 | 54 |
52 /** | 55 /** |
53 * SHA1 hash function implementation. | 56 * SHA1 hash function implementation. |
54 */ | 57 */ |
55 abstract class SHA1 implements Hash { | 58 abstract class SHA1 implements Hash { |
56 factory SHA1() => new _SHA1(); | 59 factory SHA1() => new _SHA1(); |
57 } | 60 } |
(...skipping 30 matching lines...) Expand all Loading... |
88 /** | 91 /** |
89 * Add a list of bytes to the message. | 92 * Add a list of bytes to the message. |
90 */ | 93 */ |
91 HMAC update(List<int> data); | 94 HMAC update(List<int> data); |
92 | 95 |
93 /** | 96 /** |
94 * Perform the actual computation and extract the message digest | 97 * Perform the actual computation and extract the message digest |
95 * as a list of bytes. | 98 * as a list of bytes. |
96 */ | 99 */ |
97 List<int> digest(); | 100 List<int> digest(); |
| 101 |
| 102 /** |
| 103 * Verify that the HMAC computed for the data so far matches the |
| 104 * given message digest. |
| 105 * |
| 106 * This method should be used instead of memcmp-style comparisons |
| 107 * to avoid leaking information via timing. |
| 108 * |
| 109 * Throws an exception if the given digest does not have the same |
| 110 * size as the digest computed by this HMAC instance. |
| 111 */ |
| 112 bool verify(List<int> digest); |
98 } | 113 } |
99 | 114 |
100 /** | 115 /** |
101 * Utility methods for working with message digests. | 116 * Utility methods for working with message digests. |
102 */ | 117 */ |
103 abstract class CryptoUtils { | 118 abstract class CryptoUtils { |
104 /** | 119 /** |
105 * Convert a list of bytes (for example a message digest) into a hex | 120 * Convert a list of bytes (for example a message digest) into a hex |
106 * string. | 121 * string. |
107 */ | 122 */ |
(...skipping 14 matching lines...) Expand all Loading... |
122 /** | 137 /** |
123 * HashExceptions are thrown on invalid use of a Hash | 138 * HashExceptions are thrown on invalid use of a Hash |
124 * object. | 139 * object. |
125 */ | 140 */ |
126 class HashException { | 141 class HashException { |
127 HashException(String this.message); | 142 HashException(String this.message); |
128 toString() => "HashException: $message"; | 143 toString() => "HashException: $message"; |
129 String message; | 144 String message; |
130 } | 145 } |
131 | 146 |
OLD | NEW |