Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Commit 22c1af1

Browse files
committed
Fixed constant-time comparison in Digest.
1 parent 69cbacd commit 22c1af1

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.1.3
2+
* **Security vulnerability**: Fixed constant-time comparison in `Digest`.
3+
14
## 2.1.2
25
* Fix bug in SHA-2 384/512 blocksize.
36
* Added HMAC-SHA-2 test vectors

lib/src/digest.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,22 @@ class Digest {
1717
/// This should be used instead of manual comparisons to avoid leaking
1818
/// information via timing.
1919
@override
20-
bool operator ==(Object other) =>
21-
other is Digest && const ListEquality().equals(bytes, other.bytes);
20+
bool operator ==(Object other) {
21+
if (other is Digest) {
22+
final a = bytes;
23+
final b = other.bytes;
24+
if (a.length != b.length) {
25+
return false;
26+
}
27+
final n = a.length;
28+
int mismatch = 0;
29+
for (int i = 0; i < n; i++) {
30+
mismatch |= a[i] ^ b[i];
31+
}
32+
return mismatch == 0;
33+
}
34+
return false;
35+
}
2236

2337
@override
2438
int get hashCode => const ListEquality().hash(bytes);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: crypto
2-
version: 2.1.2
2+
version: 2.1.3
33
author: Dart Team <misc@dartlang.org>
44
description: Library of cryptographic functions.
55
homepage: https://www.github.com/dart-lang/crypto

0 commit comments

Comments
 (0)