Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: aarch64-dit
name: dit

on:
pull_request:
paths:
- ".github/workflows/aarch64-dit.yml"
- "aarch64-dit/**"
- ".github/workflows/dit.yml"
- "dit/**"
- "Cargo.*"
push:
branches: master
Expand All @@ -14,7 +14,7 @@ permissions:

defaults:
run:
working-directory: aarch64-dit
working-directory: dit

env:
CARGO_INCREMENTAL: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Publish to crates.io
on:
push:
tags: [
'aarch64-dit-v*',
'blobby-v*',
'block-buffer-v*',
'block-padding-v*',
Expand All @@ -13,6 +12,7 @@ on:
'dbl-v*',
'digest-io-async-v*',
'digest-io-v*',
'dit-v*',
'hex-literal-v*',
'inout-v*',
'sponge-cursor-v*',
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"ctutils",
"cpufeatures",
"dbl",
"dit",
"hex-literal",
"inout",
"sponge-cursor",
Expand All @@ -17,8 +18,6 @@ members = [
"zeroize_derive",
]
exclude = [
# Works only on AArch64
"aarch64-dit",
# Results in circular dependencies
"digest-io",
"digest-io-async",
Expand All @@ -40,7 +39,6 @@ cast_precision_loss = "warn"
cast_sign_loss = "warn"
checked_conversions = "warn"
doc_markdown = "warn"
from_iter_instead_of_collect = "warn"
implicit_saturating_sub = "warn"
manual_assert = "warn"
map_unwrap_or = "warn"
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ This repository contains various utility crates used in the RustCrypto project.

## Crates

| Name | crates.io | Docs | Description |
|------|:---------:|:----:|-------------|
| [`aarch64-dit`] | [![crates.io](https://img.shields.io/crates/v/aarch64-dit.svg)](https://crates.io/crates/aarch64-dit) | [![Documentation](https://docs.rs/aarch64-dit/badge.svg)](https://docs.rs/aarch64-dit) | Wrappers for enabling/disabling the Data Independent Timing (DIT) feature on AArch64 CPUs |
| [`blobby`] | [![crates.io](https://img.shields.io/crates/v/blobby.svg)](https://crates.io/crates/blobby) | [![Documentation](https://docs.rs/blobby/badge.svg)](https://docs.rs/blobby) | Decoder of the simple de-duplicated binary blob storage format |
| [`block-buffer`] | [![crates.io](https://img.shields.io/crates/v/block-buffer.svg)](https://crates.io/crates/block-buffer) | [![Documentation](https://docs.rs/block-buffer/badge.svg)](https://docs.rs/block-buffer) | Fixed size buffer for block processing of data |
| Name | crates.io | Docs | Description |
|------|:---------------------------------------------------------------------------------------------------------:|:----:|-------------|
| [`blobby`] | [![crates.io](https://img.shields.io/crates/v/blobby.svg)](https://crates.io/crates/blobby) | [![Documentation](https://docs.rs/blobby/badge.svg)](https://docs.rs/blobby) | Decoder of the simple de-duplicated binary blob storage format |
| [`block-buffer`] | [![crates.io](https://img.shields.io/crates/v/block-buffer.svg)](https://crates.io/crates/block-buffer) | [![Documentation](https://docs.rs/block-buffer/badge.svg)](https://docs.rs/block-buffer) | Fixed size buffer for block processing of data |
| [`block‑padding`] | [![crates.io](https://img.shields.io/crates/v/block-padding.svg)](https://crates.io/crates/block-padding) | [![Documentation](https://docs.rs/block-padding/badge.svg)](https://docs.rs/block-padding) | Padding and unpadding of messages divided into blocks |
| [`cmov`] | [![crates.io](https://img.shields.io/crates/v/cmov.svg)](https://crates.io/crates/cmov) | [![Documentation](https://docs.rs/cmov/badge.svg)](https://docs.rs/cmov) | Conditional move intrinsics |
| [`cpubits`] | [![crates.io](https://img.shields.io/crates/v/cpubits.svg)](https://crates.io/crates/cpubits) | [![Documentation](https://docs.rs/cpubits/badge.svg)](https://docs.rs/cpubits) | Compile-time detection heuristics for the optimal word size to use for the target CPU |
| [`cpufeatures`] | [![crates.io](https://img.shields.io/crates/v/cpufeatures.svg)](https://crates.io/crates/cpufeatures) | [![Documentation](https://docs.rs/cpufeatures/badge.svg)](https://docs.rs/cpufeatures) | Lightweight and efficient alternative to the `is_x86_feature_detected!` macro |
| [`ctutils`] | [![crates.io](https://img.shields.io/crates/v/ctutils.svg)](https://crates.io/crates/ctutils) | [![Documentation](https://docs.rs/ctutils/badge.svg)](https://docs.rs/ctutils) | Constant-time utility library with selection and equality testing support targeting cryptographic applications |
| [`dbl`] | [![crates.io](https://img.shields.io/crates/v/dbl.svg)](https://crates.io/crates/dbl) | [![Documentation](https://docs.rs/dbl/badge.svg)](https://docs.rs/dbl) | Double operation in Galois Field (GF) |
| [`digest-io`] | [![crates.io](https://img.shields.io/crates/v/digest-io.svg)](https://crates.io/crates/digest-io) | [![Documentation](https://docs.rs/digest-io/badge.svg)](https://docs.rs/digest-io) | `std::io`-compatibility wrappers for traits defined in the `digest` crate |
| [`hex-literal`] | [![crates.io](https://img.shields.io/crates/v/hex-literal.svg)](https://crates.io/crates/hex-literal) | [![Documentation](https://docs.rs/hex-literal/badge.svg)](https://docs.rs/hex-literal) | A macro for converting hexadecimal strings to a byte array at compile time |
| [`inout`] | [![crates.io](https://img.shields.io/crates/v/inout.svg)](https://crates.io/crates/inout) | [![Documentation](https://docs.rs/inout/badge.svg)](https://docs.rs/inout) | Custom reference types for code generic over in-place and buffer-to-buffer modes of operation |
| [`cmov`] | [![crates.io](https://img.shields.io/crates/v/cmov.svg)](https://crates.io/crates/cmov) | [![Documentation](https://docs.rs/cmov/badge.svg)](https://docs.rs/cmov) | Conditional move intrinsics |
| [`cpubits`] | [![crates.io](https://img.shields.io/crates/v/cpubits.svg)](https://crates.io/crates/cpubits) | [![Documentation](https://docs.rs/cpubits/badge.svg)](https://docs.rs/cpubits) | Compile-time detection heuristics for the optimal word size to use for the target CPU |
| [`cpufeatures`] | [![crates.io](https://img.shields.io/crates/v/cpufeatures.svg)](https://crates.io/crates/cpufeatures) | [![Documentation](https://docs.rs/cpufeatures/badge.svg)](https://docs.rs/cpufeatures) | Lightweight and efficient alternative to the `is_x86_feature_detected!` macro |
| [`ctutils`] | [![crates.io](https://img.shields.io/crates/v/ctutils.svg)](https://crates.io/crates/ctutils) | [![Documentation](https://docs.rs/ctutils/badge.svg)](https://docs.rs/ctutils) | Constant-time utility library with selection and equality testing support targeting cryptographic applications |
| [`dbl`] | [![crates.io](https://img.shields.io/crates/v/dbl.svg)](https://crates.io/crates/dbl) | [![Documentation](https://docs.rs/dbl/badge.svg)](https://docs.rs/dbl) | Double operation in Galois Field (GF) |
| [`digest-io`] | [![crates.io](https://img.shields.io/crates/v/digest-io.svg)](https://crates.io/crates/digest-io) | [![Documentation](https://docs.rs/digest-io/badge.svg)](https://docs.rs/digest-io) | `std::io`-compatibility wrappers for traits defined in the `digest` crate |
| [`dit`] | [![crates.io](https://img.shields.io/crates/v/dit.svg)](https://crates.io/crates/dit) | [![Documentation](https://docs.rs/dit/badge.svg)](https://docs.rs/dit) | Wrappers for enabling/disabling the Data Independent Timing (DIT) feature on AArch64 CPUs |
| [`hex-literal`] | [![crates.io](https://img.shields.io/crates/v/hex-literal.svg)](https://crates.io/crates/hex-literal) | [![Documentation](https://docs.rs/hex-literal/badge.svg)](https://docs.rs/hex-literal) | A macro for converting hexadecimal strings to a byte array at compile time |
| [`inout`] | [![crates.io](https://img.shields.io/crates/v/inout.svg)](https://crates.io/crates/inout) | [![Documentation](https://docs.rs/inout/badge.svg)](https://docs.rs/inout) | Custom reference types for code generic over in-place and buffer-to-buffer modes of operation |
| [`sponge-cursor`] | [![crates.io](https://img.shields.io/crates/v/sponge-cursor.svg)](https://crates.io/crates/sponge-cursor) | [![Documentation](https://docs.rs/sponge-cursor/badge.svg)](https://docs.rs/sponge-cursor) | Cursor for sponge-based absorption and squeezing |
| [`wycheproof2blb`] | | | Utility for converting [Wycheproof] test vectors to the blobby format |
| [`zeroize`] | [![crates.io](https://img.shields.io/crates/v/zeroize.svg)](https://crates.io/crates/zeroize) | [![Documentation](https://docs.rs/zeroize/badge.svg)](https://docs.rs/zeroize) | Securely zero memory while avoiding compiler optimizations |
| [`wycheproof2blb`] | | | Utility for converting [Wycheproof] test vectors to the blobby format |
| [`zeroize`] | [![crates.io](https://img.shields.io/crates/v/zeroize.svg)](https://crates.io/crates/zeroize) | [![Documentation](https://docs.rs/zeroize/badge.svg)](https://docs.rs/zeroize) | Securely zero memory while avoiding compiler optimizations |

## License

Expand All @@ -49,7 +49,7 @@ Unless you explicitly state otherwise, any contribution intentionally submitted

[//]: # (crates)

[`aarch64-dit`]: ./aarch64-dit
[`dit`]: ./dit
[`blobby`]: ./blobby
[`block-buffer`]: ./block-buffer
[`block‑padding`]: ./block-padding
Expand Down
23 changes: 0 additions & 23 deletions aarch64-dit/Cargo.lock

This file was deleted.

File renamed without changes.
6 changes: 3 additions & 3 deletions aarch64-dit/Cargo.toml → dit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "aarch64-dit"
version = "0.2.0-pre"
name = "dit"
version = "0.0.0"
authors = ["RustCrypto Developers"]
edition = "2024"
rust-version = "1.85"
documentation = "https://docs.rs/aarch64-dit"
documentation = "https://docs.rs/dit"
readme = "README.md"
repository = "https://github.com/RustCrypto/utils"
license = "Apache-2.0 OR MIT"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion aarch64-dit/LICENSE-MIT → dit/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2024-2025 The RustCrypto Project Developers
Copyright (c) 2024-2026 The RustCrypto Project Developers

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
14 changes: 7 additions & 7 deletions aarch64-dit/README.md → dit/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [RustCrypto]: AArch64 Data-Independent Timing (DIT)
# [RustCrypto]: Data-Independent Timing (DIT)

[![Crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
Expand Down Expand Up @@ -36,14 +36,14 @@ additional terms or conditions.

[//]: # (badges)

[crate-image]: https://img.shields.io/crates/v/aarch64-dit.svg
[crate-link]: https://crates.io/crates/aarch64-dit
[docs-image]: https://docs.rs/aarch64-dit/badge.svg
[docs-link]: https://docs.rs/aarch64-dit/
[crate-image]: https://img.shields.io/crates/v/dit.svg
[crate-link]: https://crates.io/crates/dit
[docs-image]: https://docs.rs/dit/badge.svg
[docs-link]: https://docs.rs/dit/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[msrv-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
[build-image]: https://github.com/RustCrypto/utils/actions/workflows/aarch64-dit.yml/badge.svg?branch=master
[build-link]: https://github.com/RustCrypto/utils/actions/workflows/aarch64-dit.yml?query=branch:master
[build-image]: https://github.com/RustCrypto/utils/actions/workflows/dit.yml/badge.svg?branch=master
[build-link]: https://github.com/RustCrypto/utils/actions/workflows/dit.yml?query=branch:master

[//]: # (links)

Expand Down
30 changes: 21 additions & 9 deletions aarch64-dit/src/lib.rs → dit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@
//! ## Usage
//!
//! ```
//! use aarch64_dit::Dit;
//! use dit::Dit;
//!
//! let dit = Dit::init();
//! assert!(!dit.is_enabled());
//! let _guard = dit.enable();
//! assert!(dit.is_enabled());
//! ```

#[cfg(not(target_arch = "aarch64"))]
compile_error!("This crate only builds on `aarch64` targets");

#[cfg(target_arch = "aarch64")]
use core::arch::asm;

#[cfg(target_arch = "aarch64")]
cpufeatures::new!(dit_supported, "dit");

/// Data-Independent Timing: support for enabling features of AArch64 CPUs which improve
/// constant-time operation.
pub struct Dit {
#[cfg(target_arch = "aarch64")]
supported: dit_supported::InitToken,
}

impl Dit {
/// Initialize Data-Independent Timing using runtime CPU feature detection.
#[cfg(target_arch = "aarch64")]
pub fn init() -> Self {
Self {
supported: dit_supported::init(),
Expand All @@ -41,6 +42,7 @@ impl Dit {
/// Enable Data-Independent Timing (if available).
///
/// Returns an RAII guard that will return DIT to its previous state when dropped.
#[cfg(target_arch = "aarch64")]
#[must_use]
pub fn enable(&self) -> Guard<'_> {
let was_enabled = if self.is_supported() {
Expand All @@ -57,20 +59,25 @@ impl Dit {

/// Check if DIT has been enabled.
pub fn is_enabled(&self) -> bool {
#[cfg(target_arch = "aarch64")]
if self.is_supported() {
unsafe { get_dit_enabled() }
} else {
false
return unsafe { get_dit_enabled() };
}

false
}

/// Check if DIT is supported by this CPU.
pub fn is_supported(&self) -> bool {
self.supported.get()
#[cfg(target_arch = "aarch64")]
return self.supported.get();
#[cfg(not(target_arch = "aarch64"))]
false
}
}

/// RAII guard which returns DIT to its previous state when dropped.
#[cfg(target_arch = "aarch64")]
pub struct Guard<'a> {
/// DIT implementation.
dit: &'a Dit,
Expand All @@ -79,6 +86,7 @@ pub struct Guard<'a> {
was_enabled: bool,
}

#[cfg(target_arch = "aarch64")]
impl Drop for Guard<'_> {
fn drop(&mut self) {
if self.dit.supported.get() {
Expand All @@ -88,6 +96,7 @@ impl Drop for Guard<'_> {
}

/// Detect if DIT is enabled for the current thread by checking the processor state register.
#[cfg(target_arch = "aarch64")]
#[target_feature(enable = "dit")]
unsafe fn get_dit_enabled() -> bool {
let mut dit: u64;
Expand All @@ -104,6 +113,7 @@ unsafe fn get_dit_enabled() -> bool {
/// Enable DIT for the current thread.
///
/// Returns the previous DIT state prior to enabling DIT.
#[cfg(target_arch = "aarch64")]
#[target_feature(enable = "dit")]
unsafe fn set_dit_enabled() -> bool {
unsafe {
Expand All @@ -114,6 +124,7 @@ unsafe fn set_dit_enabled() -> bool {
}

/// Restore DIT state depending on the enabled bit.
#[cfg(target_arch = "aarch64")]
#[target_feature(enable = "dit")]
unsafe fn restore_dit(enabled: bool) {
if !enabled {
Expand All @@ -122,9 +133,10 @@ unsafe fn restore_dit(enabled: bool) {
}
}

#[cfg(target_arch = "aarch64")]
#[cfg(test)]
mod tests {
use super::{get_dit_enabled, restore_dit, set_dit_enabled, Dit};
use super::{Dit, get_dit_enabled, restore_dit, set_dit_enabled};
cpufeatures::new!(dit_supported, "dit");

#[test]
Expand Down
Loading