rust-lang / rust-lang/rfcs

Include constant time integer operation inside core

Open
#1,814 14 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

Go-Lang has it's subtle to help developers write secure systems and servers by providing functions to do constant time integer operations.

Rust's goal is identical to this (writing secure systems and servers), so ideally shouldn't it provide a similar functionality?

These are simple re-definitions of primitive operations:

  • Equality checking on Ints (u8, u16, u32, u64, usize)
  • Equality checking on Slices ( &[u8], &[u16], &[u32], &[u64], &[usize])
  • Conditional Copying of Slices (of Ints)
  • Conditional Swapping of Ints

I am NOT proposing changes to std/core on how integer and/or slices work. Solid performance defaults are important.

I am proposing the inclusion of a few dozen free functions in core that are OPT IN ONLY. Where I'm not 100% sure. The swap/equality checking seems like they should be attached to their primitives. The slice comparisons, and cloning are weird.

Lastly the traditional method of doing this requires a degree of UB on how bit masking is done:

Returns X if Flag == 1

Returns Y if Flag == 0

Returns undefined values Flag is not 1 or 0

I've made a demo crate. But it is un-audited.

Edit 1:

I've implemented the boolean conversion and verified the ASM generated uses no branching or conditionals on x86/x86_64.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the proposed operations in the issue and the linked consistenttime demo crate, then compare them with the existing core primitives and slice APIs. Work out the API placement and opt-in scope for constant-time integer and slice operations, and verify the generated x86/x86_64 assembly has no branches or conditionals.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.