Skip to content

Commit 1d35370

Browse files
committed
aes: Avoid unwanted overflow check when using u32::MAX as the counter.
The problem occurs: * release mode with `RUSTFLAGS="-C overflow-checks"` * release mode with `overflow-checks = true` in the Cargo.toml profile. * debug mode. Thanks to Mike (GitHub user MikeRomaniuk).
1 parent a40c3a9 commit 1d35370

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/aead/aes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Counter {
154154
pub(super) fn increment_by_less_safe(&mut self, increment_by: NonZeroU32) {
155155
let [.., c0, c1, c2, c3] = &mut self.0;
156156
let old_value: u32 = u32::from_be_bytes([*c0, *c1, *c2, *c3]);
157-
let new_value = old_value + increment_by.get();
157+
let new_value = old_value.wrapping_add(increment_by.get());
158158
[*c0, *c1, *c2, *c3] = u32::to_be_bytes(new_value);
159159
}
160160
}

tests/quic_aes_128_tests.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
KEY = e8904ecc2e37a6e4cc02271e319c804b
22
SAMPLE = 13484ec85dc4d36349697c7d4ea1a159
33
MASK = 67387ebf3a
4+
5+
KEY = e8904ecc2e37a6e4cc02271e319c804b
6+
SAMPLE = 00000000000000000000000fffffffff
7+
MASK = feb191f8af
8+
9+
KEY = e8904ecc2e37a6e4cc02271e319c804b
10+
SAMPLE = 000000000000000fffffffffffffffff
11+
MASK = 6f23441ee8

tests/quic_aes_256_tests.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
KEY = 85af7213814aec7b92ace6284a906643912ec8853d00d158a927b8697c7ff585
22
SAMPLE = 82a0db90f4cee12fa4afeddb74396cf6
33
MASK = 670897adf5
4+
5+
KEY = 85af7213814aec7b92ace6284a906643912ec8853d00d158a927b8697c7ff585
6+
SAMPLE = 000000000000000000000000ffffffff
7+
MASK = b77a18bb3f
8+
9+
KEY = 85af7213814aec7b92ace6284a906643912ec8853d00d158a927b8697c7ff585
10+
SAMPLE = 000000000000000fffffffffffffffff
11+
MASK = 4aadd3cbef

0 commit comments

Comments
 (0)