subtle

Pure-Rust traits and utilities for writing constant-time cryptographic code that resists timing side-channel attacks.

Library
Cargo
v2.6.1
310stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
39/100Needs Attention
Development Activity0
Maintenance0
Community76
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture78
Code Quality88
Innovation55
Learning Curve70

subtle provides a small set of Rust traits and a Choice wrapper type for writing constant-time cryptographic code, i.e. code whose control flow and memory access patterns do not depend on secret values. Where ordinary Rust code compares byte slices or conditionally selects a value with == or if, subtle supplies ConstantTimeEq, ConditionallySelectable, ConditionallyNegatable, ConstantTimeGreater, and ConstantTimeLess implementations that use bitwise operations and an optimization barrier instead of branches, guarding against compiler optimizations that would reintroduce a timing side-channel.

Built no_std by default so it compiles for embedded and constrained targets, subtle is a foundational building block of the dalek-cryptography ecosystem (curve25519-dalek, ed25519-dalek, x25519-dalek) and is depended on by hundreds of other Rust cryptography crates, with over 660 million downloads on crates.io. It positions itself as the Rust equivalent of Go’s crypto/subtle package.

What You Get

  • Choice type - a u8 wrapper representing a boolean that has been passed through an optimization barrier to resist compiler branch-reintroduction
  • ConstantTimeEq trait - constant-time equality (ct_eq) and inequality (ct_ne) for byte slices, Choice, cmp::Ordering, and more
  • ConditionallySelectable trait - branchless conditional assignment (conditional_select, conditional_assign, conditional_swap) for copyable types, including fixed-size arrays via const generics
  • ConditionallyNegatable trait - constant-time conditional negation for any type implementing Neg and ConditionallySelectable
  • ConstantTimeGreater / ConstantTimeLess traits - constant-time ordering comparisons for unsigned integer types
  • CtOption<T> - a constant-time analogue of Option<T> that avoids branching on presence or absence of a value

Common Use Cases

  • MAC/signature verification - comparing computed vs expected authentication tags without leaking timing information about where they first differ
  • Elliptic-curve point and scalar arithmetic - conditionally selecting between two curve points or scalars based on a secret bit, as used throughout curve25519-dalek and ed25519-dalek
  • Password/key comparison - checking secrets like API keys or password hashes without a data-dependent early-exit comparison
  • Embedded/no_std cryptography - building constant-time primitives for microcontrollers and other constrained targets where std isn’t available

Under The Hood

Architecture subtle is deliberately a single ~1,000-line src/lib.rs with no submodules: it defines a Choice newtype wrapping a u8, then a handful of small traits (ConstantTimeEq, ConditionallySelectable, ConditionallyNegatable, ConstantTimeGreater, ConstantTimeLess) plus the CtOption<T> type, each with blanket or per-type trait implementations rather than a class hierarchy. The Choice-to-u8 conversion is routed through a volatile read to act as an optimization barrier, and every trait method is implemented with bitwise AND/OR/XOR/NOT instead of branches so the compiler has no natural place to reintroduce a conditional jump. There is no runtime state, no allocation, and no I/O — the entire architecture is a set of composable, side-effect-free trait implementations, which is the appropriate shape for a primitive this narrow in scope.

Tech Stack Pure Rust, #![no_std] by default with opt-in std, i128, and const-generics Cargo features (the last enabling trait impls over [T; N]), and a single dev-dependencies entry on rand used only by the test suite. The CI matrix builds and tests against stable, beta, nightly, and the crate’s MSRV of Rust 1.41, runs every feature-flag combination, and cross-compiles to the thumbv7em-none-eabi embedded target to guarantee the no-std build stays intact.

Code Quality tests/mod.rs carries a couple dozen #[test] functions exercising equality, conditional-select/assign/swap, conditional-negate, ordering comparisons, and CtOption, and a separate fuzz/ directory wires up cargo-fuzz harnesses for property-style fuzzing — notable rigor for a crate whose entire value proposition is subtle correctness bugs. #![deny(missing_docs)] forces every public item to carry rustdoc, and debug_asserts guard invariants in debug builds while staying out of release binaries. There’s no separate lint/format CI step visible, but the multi-toolchain, multi-feature-flag test matrix substitutes for much of what a linter would catch.

API Design The public surface is intentionally tiny and idiomatic: a handful of traits that mirror standard-library conventions (ct_eq next to PartialEq, CtOption<T> next to Option<T>) so callers already familiar with Rust need almost no ramp-up beyond understanding why constant-time variants exist. Every public item carries rustdoc explaining both usage and the security rationale, and the crate documents explicit caveats (debug-only invariant checks, release-mode intent, hardware-level limits of software timing protection) rather than overselling its guarantees.

Used by 6 apps in this directory

MIT

OpenClaw

AI Assistants · AI Agents

389,987

An open-source AI assistant that runs on your own hardware and meets you in Discord, Slack, WhatsApp, iMessage, Telegram, and 20+ other channels, with native apps for every major platform.

View details
88
Repo Health
88
Technical
0
Dependency
C++
43%
MIT

openduck

Databases · Data Engineering

571

OpenDuck brings MotherDuck-style cloud capabilities to self-hosted DuckDB — attach remote databases, run hybrid queries across local and remote nodes, and own your data with an open gRPC and Arrow IPC protocol.

View details
27
Repo Health
76
Technical
76
Dependency
Built with
C++43%
Rust38%
HTML13%
Updated 4 months ago
Python
54%
Other

PostHog

Analytics · Monitoring · Developer Tools

39,797

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python54%
TypeScript36%
Updated 2 days ago
Apache 2.0

Temps

Devops · Monitoring · Analytics

756

A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.

View details
80
Repo Health
86
Technical
0
Dependency
Rust
83%
AGPL 3.0

Vaultwarden

Password Manager · Security

67,556

Unofficial Bitwarden-compatible server in Rust — run the full Bitwarden ecosystem on a Raspberry Pi using every official client you already have, without the multi-container overhead.

View details
88
Repo Health
69
Technical
70
Dependency
Built with
Rust83%
Updated 4 days ago
Rust
50%
Apache 2.0

Vibe Kanban

AI Agents · AI Code Assistants · Project Management

28,083

A kanban board for planning work and dispatching Claude Code, Codex, Gemini CLI, and eight other coding agents into isolated git worktrees, then reviewing and merging their diffs from one UI.

View details
63
Repo Health
75
Technical
64
Dependency
Built with
Rust50%
TypeScript46%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search