Skip to content

Conversation

@rozbb
Copy link
Contributor

@rozbb rozbb commented Dec 9, 2025

The alloc feature wasn't doing anything as far as I can discern. And the precomputed_tables features only offers speedups for Edwards mults, which diffie_hellman() does not do (I verified this by benchmarking on my machine).

So I removed those two features and documented the rest in the README.

Resolves #699

@rozbb rozbb requested a review from tarcieri December 9, 2025 13:28
@tarcieri
Copy link
Contributor

tarcieri commented Dec 9, 2025

@rozbb precomputed-tables likely still offers a speedup for fixed-based Montgomery scalar multiplication, since that uses the Edwards basepoint tables

@rozbb
Copy link
Contributor Author

rozbb commented Dec 9, 2025

@tarcieri odd, I can't seem to make it show any difference on my machine. Do you see a perf difference when precomputed-tables is enabled vs disabled on main?

@tarcieri
Copy link
Contributor

tarcieri commented Dec 9, 2025

@rozbb I don't see a benchmark for fixed-base scalar multiplication e.g. From<&'a EphemeralSecret> for PublicKey in x25519-dalek

@rozbb
Copy link
Contributor Author

rozbb commented Dec 9, 2025

Ah you're right. I added a benchmark. But now I'm seeing something very weird. On this branch (and main too for that matter), it appears that precomputed-tables does not change the library size of x25519-dalek at all, even as it increases the size of curve25519-dalek:

~/c/curve25519-dalek (cleanup-x-features)$ ./sizediff.sh
Enter the crate name (curve|x|ed): curve
    Finished `release` profile [optimized] target(s) in 0.02s
    Finished `release` profile [optimized] target(s) in 0.01s
Using precomputed-tables adds 397512 bytes
~/c/curve25519-dalek (cleanup-x-features)$ ./sizediff.sh
Enter the crate name (curve|x|ed): x
    Finished `release` profile [optimized] target(s) in 0.02s
    Finished `release` profile [optimized] target(s) in 0.01s
Using precomputed-tables adds 16 bytes

The script sizediff.sh I'm running:

#!/bin/bash

set -eu

read -p "Enter the crate name (curve|x|ed): " CRATE

cargo build --release --no-default-features -p "${CRATE}25519-dalek"
SIZE_PLAIN=$(wc -c < "./target/release/lib${CRATE}25519_dalek.rlib")
cargo build --release --no-default-features -p "${CRATE}25519-dalek" --features "precomputed-tables"
SIZE_WITH_TABLES=$(wc -c < "./target/release/lib${CRATE}25519_dalek.rlib")

SIZE_DIFF=$(($SIZE_WITH_TABLES - $SIZE_PLAIN))

echo "Using precomputed-tables adds ${SIZE_DIFF} bytes"

What's weirder is that when I do a cargo bench I see a 64% speedup with precomputed-tables set.

@tarcieri
Copy link
Contributor

tarcieri commented Dec 9, 2025

@rozbb possibly feature unification? Try running cargo hack build

@rozbb
Copy link
Contributor Author

rozbb commented Dec 9, 2025

Hmm that doesn't seem like it either. I put a dummy optional dep under curve25519-dalek/precomputed-tables. It shows up in cargo tree -e features -p x25519-dalek, and doesn't show up in cargo tree -e features --no-default-features -p x25519-dalek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mention the need to add the feature flag getrandom on README file

3 participants