Skip to content

Commit 6571cd8

Browse files
committed
Correct documentation of integer_division_remainder_used
1. Barrett Reduction isn't constant-time, so that was eliminated. 2. The "use instead" example didn't solve the timing attack, so it was eliminated as well. 3. Added some context and recommendations for the user.
1 parent c057abd commit 6571cd8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

clippy_lints/src/integer_division_remainder_used.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ declare_clippy_lint! {
1212
///
1313
/// ### Why restrict this?
1414
/// In cryptographic contexts, division can result in timing sidechannel vulnerabilities,
15-
/// and needs to be replaced with constant-time code instead (e.g. Barrett reduction).
15+
/// and needs to be replaced with constant-time code instead.
16+
///
17+
/// Most often, the compiler will optimize away any constant-time implementation of
18+
/// an algorithm. The solution to achieve constant-time operation is often to either implement
19+
/// a constant-time algorithm in assembly code, or to delegate such operations to a well-known,
20+
/// audited and / or certified cryptographic library.
1621
///
1722
/// ### Example
1823
/// ```no_run
19-
/// let my_div = 10 / 2;
20-
/// ```
21-
/// Use instead:
22-
/// ```no_run
23-
/// let my_div = 10 >> 1;
24+
/// let _ = 10 / 2; // This will run faster because it's a division by a multiple of 2.
25+
/// let _ = 10 / 3; // This will run slower than the above.
2426
/// ```
2527
#[clippy::version = "1.79.0"]
2628
pub INTEGER_DIVISION_REMAINDER_USED,

0 commit comments

Comments
 (0)