#running-time #function-call #attack #sync #async #password-hash #user-password

dtf

Obsecure the running time of a function call to diminish timing attacks

1 unstable release

Uses new Rust 2024

0.1.0 Apr 6, 2025

#1480 in Cryptography

MIT/Apache

5KB

Deterministic Time Functions

Sync Example

use std::time::Duration;

use dtf::sync::dtf;

let sensitive_method = || {
    if let Some(user) = users.get(user_id) {
        if user.password_hash.validate(password) {
            return Ok(());
        }
    }
    return Err("invalid credentials");
}

let min_duration = Duration::from_millis(1500);
let jitter = Duration::from_millis(100);

let result = dtf(min_duration, jitter, sensitive_method);

Async Example

Requires the async feature be enabled.

use std::time::Duration;

use dtf::future::dtf;

let sensitive_method = async || {
    if let Some(user) = users.get(user_id) {
        if user.password_hash.validate(password) {
            return Ok(());
        }
    }
    return Err("invalid credentials");
}

let min_duration = Duration::from_millis(1500);
let jitter = Duration::from_millis(100);

let result = dtf(min_duration, jitter, sensitive_method).await;

Dependencies

~0.4–11MB
~67K SLoC