Skip to content

Commit 9369aa4

Browse files
committed
Rename features
1 parent d4413ad commit 9369aa4

File tree

17 files changed

+142
-131
lines changed

17 files changed

+142
-131
lines changed

.github/workflows/ci.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ jobs:
8686

8787
- run: cargo generate-lockfile
8888
- uses: Swatinem/rust-cache@v2
89-
- run: cargo build --no-default-features --features openssl
89+
90+
- run: cargo build --no-default-features --features aes-openssl
9091
if: matrix.os != 'windows-latest'
91-
- run: cargo build --no-default-features --features pure
92-
- run: cargo build --no-default-features --features pure,x25519
93-
- run: cargo build --no-default-features --features pure,ed25519
92+
- run: cargo build --no-default-features --features aes-rust
93+
- run: cargo build --no-default-features --features aes-rust,x25519
94+
- run: cargo build --no-default-features --features aes-rust,ed25519

.vscode/settings.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"rust-analyzer.cargo.features": [
3-
"pure",
4-
"ed25519"
3+
"aes-rust"
54
],
65
"rust-analyzer.cargo.noDefaultFeatures": true,
76
"rust-analyzer.procMacro.enable": true,

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 0.2.9
44

55
- Add ed25519 support
6+
- Add renamed features: `aes-openssl`, `aes-rust`, `aes-short-nonce`. The old features (`openssl`, `pure`, `aes-12bytes-nonce`) are still supported, but will be removed in the future
67

78
## 0.2.8
89

Cargo.toml

+11-11
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ rand_core = { version = "0.6.4", default-features = false, features = [
5555
] }
5656

5757
# configuration
58-
once_cell = { version = "1.21.2", default-features = false, features = [
58+
once_cell = { version = "1.21.3", default-features = false, features = [
5959
"critical-section",
6060
] }
6161
parking_lot = "0.12.3"
6262

6363
[target.'cfg(all(target_arch = "wasm32", target_os="unknown"))'.dependencies]
6464
# only for js (browser or node). if it's not js, like substrate, it won't build
6565
getrandom = { version = "0.2.15", default-features = false, features = ["js"] }
66-
once_cell = { version = "1.21.2", default-features = false, features = ["std"] }
66+
once_cell = { version = "1.21.3", default-features = false, features = ["std"] }
6767
wasm-bindgen = { version = "0.2.100", default-features = false }
6868

6969
[target.'cfg(all(target_arch = "wasm32", not(target_os="unknown")))'.dependencies]
7070
# for wasm32-wasip2
71-
once_cell = { version = "1.21.2", default-features = false, features = ["std"] }
71+
once_cell = { version = "1.21.3", default-features = false, features = ["std"] }
7272

7373
[features]
74-
default = ["openssl"]
74+
default = ["aes-openssl"]
7575
std = ["hkdf/std", "sha2/std", "once_cell/std"]
7676

7777
# curves
@@ -81,18 +81,18 @@ x25519 = ["dep:curve25519-dalek", "dep:x25519-dalek"]
8181
ed25519 = ["dep:curve25519-dalek", "dep:ed25519-dalek"]
8282

8383
# aes
84-
aes-gcm-openssl = ["dep:openssl"]
85-
aes-gcm-rust = ["aes-gcm", "typenum"] # TODO: dep syntax
84+
aes-openssl = ["dep:openssl"]
85+
aes-rust = ["dep:aes-gcm", "dep:typenum"]
8686
# 12 bytes nonce, default: 16 bytes
87-
aes-gcm-short-nonce = []
87+
aes-short-nonce = []
8888

8989
# deprecated aes features, TODO: remove
90-
openssl = ["aes-gcm-openssl"]
91-
pure = ["aes-gcm-rust"]
92-
aes-12bytes-nonce = ["aes-gcm-short-nonce"]
90+
openssl = ["aes-openssl"]
91+
pure = ["aes-rust"]
92+
aes-12bytes-nonce = ["aes-short-nonce"]
9393

9494
# xchacha20
95-
xchacha20 = ["chacha20poly1305"] # TODO: dep syntax
95+
xchacha20 = ["dep:chacha20poly1305"]
9696

9797
[dev-dependencies]
9898
criterion = { version = "0.5.1", default-features = false }

README.md

+73-70
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This is the Rust version of [eciesjs](https://github.com/ecies/js).
1616

1717
This library can be compiled to the WASM target at your option, see [WASM compatibility](#wasm-compatibility).
1818

19-
## Quick Start
19+
## Quick start
2020

2121
`no_std` is enabled by default. You can enable `std` with `std` feature.
2222

@@ -43,7 +43,9 @@ assert_eq!(
4343
);
4444
```
4545

46-
## Optional x25519/ed25519 Support
46+
## Elliptic curve configuration
47+
48+
### Optional x25519/ed25519 support
4749

4850
You can choose to use x25519 (key exchange function on curve25519) or ed25519 (signature algorithm on curve25519) instead of secp256k1:
4951

@@ -52,22 +54,52 @@ ecies = {version = "0.2", features = ["x25519"]} # recommended
5254
ecies = {version = "0.2", features = ["ed25519"]} # or if you know what you are doing
5355
```
5456

55-
## Optional pure Rust AES backend
57+
### Secp256k1-specific configuration
58+
59+
Some behaviors can be configured by global static variable:
60+
61+
```rust
62+
pub struct Config {
63+
pub is_ephemeral_key_compressed: bool,
64+
pub is_hkdf_key_compressed: bool
65+
}
66+
```
67+
68+
On `is_ephemeral_key_compressed: true`, the payload would be like: `33 Bytes + AES` instead of `65 Bytes + AES`.
69+
70+
On `is_hkdf_key_compressed: true`, the hkdf key would be derived from `ephemeral public key (compressed) + shared public key (compressed)` instead of `ephemeral public key (uncompressed) + shared public key (uncompressed)`.
71+
72+
```rust
73+
use ecies::config::{Config, update_config};
74+
75+
update_config(Config {
76+
is_ephemeral_key_compressed: true,
77+
is_hkdf_key_compressed: true
78+
});
79+
```
80+
81+
For compatibility, make sure different applications share the same configuration. Normally configuration is only updated once on initialization, if not, beware of race condition.
82+
83+
## Symmetric cipher configuration
84+
85+
### Optional pure Rust AES backend
5686

5787
You can choose to use OpenSSL implementation or [pure Rust implementation](https://github.com/RustCrypto/AEADs) of AES-256-GCM:
5888

5989
```toml
60-
ecies = {version = "0.2", default-features = false, features = ["pure"]}
90+
ecies = {version = "0.2", default-features = false, features = ["aes-rust"]}
6191
```
6292

6393
Due to some [performance problem](https://github.com/RustCrypto/AEADs/issues/243), OpenSSL is the default backend.
6494

6595
Pure Rust implementation is sometimes useful, such as building on WASM:
6696

6797
```bash
68-
cargo build --no-default-features --features pure --target=wasm32-unknown-unknown
98+
cargo build --no-default-features --features aes-rust --target=wasm32-unknown-unknown
6999
```
70100

101+
#### Build on x86 CPUs
102+
71103
If you select the pure Rust backend on modern x86 CPUs, consider building with
72104

73105
```bash
@@ -76,55 +108,31 @@ RUSTFLAGS="-Ctarget-cpu=sandybridge -Ctarget-feature=+aes,+sse2,+sse4.1,+ssse3"
76108

77109
It can speed up AES encryption/decryption. This would be no longer necessary when [`aes-gcm` supports automatic CPU detection](https://github.com/RustCrypto/AEADs/issues/243#issuecomment-738821935).
78110

79-
On ARM CPUs, consider building with
111+
#### Build on ARM CPUs
112+
113+
On ARM CPUs (like Apple), consider building with
80114

81115
```bash
82-
RUSTFLAGS="--cfg aes_armv8" # Rust 1.61+
116+
RUSTFLAGS="--cfg aes_armv8"
83117
```
84118

85-
## WASM compatibility
86-
87-
It's also possible to build to the `wasm32-unknown-unknown` target (or `wasm32-wasip2`) with the pure Rust backend. Check out [this repo](https://github.com/ecies/rs-wasm) for more details.
88-
89-
## Configuration
90-
91-
You can enable 12 bytes nonce by `aes-12bytes-nonce` feature on OpenSSL or pure Rust AES backend.
92-
93-
```toml
94-
ecies = {version = "0.2", features = ["aes-12bytes-nonce"]} # it also works with "pure"
95-
```
119+
### Optional pure Rust XChaCha20-Poly1305 backend
96120

97121
You can also enable a pure Rust [XChaCha20-Poly1305](https://github.com/RustCrypto/AEADs/tree/master/chacha20poly1305) backend.
98122

99123
```toml
100124
ecies = {version = "0.2", default-features = false, features = ["xchacha20"]}
101125
```
102126

103-
### Secp256k1-specific configuration
104-
105-
Other behaviors can be configured by global static variable:
127+
On ARM CPUs, enable SIMD with
106128

107-
```rust
108-
pub struct Config {
109-
pub is_ephemeral_key_compressed: bool,
110-
pub is_hkdf_key_compressed: bool
111-
}
129+
```bash
130+
RUSTFLAGS="--cfg chacha20_force_neon"
112131
```
113132

114-
On `is_ephemeral_key_compressed: true`, the payload would be like: `33 Bytes + AES` instead of `65 Bytes + AES`.
115-
116-
On `is_hkdf_key_compressed: true`, the hkdf key would be derived from `ephemeral public key (compressed) + shared public key (compressed)` instead of `ephemeral public key (uncompressed) + shared public key (uncompressed)`.
117-
118-
```rust
119-
use ecies::config::{Config, update_config};
120-
121-
update_config(Config {
122-
is_ephemeral_key_compressed: true,
123-
is_hkdf_key_compressed: true
124-
});
125-
```
133+
## WASM compatibility
126134

127-
For compatibility, make sure different applications share the same configuration. Normally configuration is only updated once on initialization, if not, beware of race condition.
135+
It's also possible to build to the `wasm32-unknown-unknown` target (or `wasm32-wasip2`) with the pure Rust backend. Check out [this repo](https://github.com/ecies/rs-wasm) for more details.
128136

129137
## Security
130138

@@ -136,7 +144,7 @@ For key derivation functions on shared points between two asymmetric keys, HKDFs
136144

137145
### Why XChaCha20-Poly1305 instead of AES-256-GCM
138146

139-
XChaCha20-Poly1305 is a competitive alternative to AES-256-GCM because it's fast and constant-time without hardware acceleration (resistant to cache-timing attacks). It also has longer nonce length to alleviate the risk of birthday attacks when nonces are generated randomly.
147+
XChaCha20-Poly1305 is a competitive alternative to AES-256-GCM because it's fast and constant-time without dedicated hardware acceleration (resistant to cache-timing attacks). It also has longer nonce length to alleviate the risk of birthday attacks when nonces are generated randomly.
140148

141149
### Cross-language compatibility
142150

@@ -151,66 +159,61 @@ Following dependencies are audited:
151159

152160
## Benchmark
153161

154-
On MacBook Pro Mid 2015 (15-inch, 2.8 GHz Quad-Core Intel Core i7) on July 19, 2023.
162+
On Mac mini M4 Pro (24 GB) on Apr 2, 2025, secp256k1 only.
163+
164+
Rust version: 1.85.0 (4d91de4e4 2025-02-17)
155165

156166
### AES backend (OpenSSL)
157167

158168
```bash
159-
$ cargo bench --no-default-features --features openssl
160-
encrypt 100M time: [100.21 ms 100.79 ms 101.80 ms]
169+
$ cargo bench --no-default-features --features aes-openssl
161170

162-
encrypt 200M time: [377.84 ms 384.42 ms 390.58 ms]
171+
encrypt 100M time: [29.237 ms 29.827 ms 30.628 ms]
163172
Found 2 outliers among 10 measurements (20.00%)
164-
2 (20.00%) high mild
173+
1 (10.00%) low mild
174+
1 (10.00%) high mild
165175

166-
decrypt 100M time: [52.430 ms 55.605 ms 60.900 ms]
176+
encrypt 200M time: [86.005 ms 88.055 ms 89.282 ms]
177+
178+
decrypt 100M time: [17.222 ms 17.568 ms 17.977 ms]
167179
Found 1 outliers among 10 measurements (10.00%)
168-
1 (10.00%) high severe
180+
1 (10.00%) high mild
169181

170-
decrypt 200M time: [157.87 ms 158.98 ms 160.01 ms]
182+
decrypt 200M time: [38.884 ms 39.324 ms 39.693 ms]
171183
Found 1 outliers among 10 measurements (10.00%)
172184
1 (10.00%) high mild
173185
```
174186

175187
### AES backend (Pure Rust)
176188

177189
```bash
178-
$ export RUSTFLAGS="-Ctarget-cpu=sandybridge -Ctarget-feature=+aes,+sse2,+sse4.1,+ssse3"
179-
$ cargo bench --no-default-features --features pure
180-
encrypt 100M time: [196.63 ms 205.63 ms 222.25 ms]
190+
$ export RUSTFLAGS="--cfg aes_armv8"
191+
$ cargo bench --no-default-features --features aes-rust
192+
193+
encrypt 100M time: [120.40 ms 122.63 ms 127.09 ms]
181194
Found 1 outliers among 10 measurements (10.00%)
182195
1 (10.00%) high severe
183196

184-
Benchmarking encrypt 200M: Warming up for 3.0000 s
185-
encrypt 200M time: [587.78 ms 590.71 ms 592.46 ms]
186-
Found 1 outliers among 10 measurements (10.00%)
187-
1 (10.00%) high mild
197+
encrypt 200M time: [253.86 ms 256.43 ms 258.01 ms]
188198

189-
decrypt 100M time: [144.78 ms 145.54 ms 147.17 ms]
190-
Found 1 outliers among 10 measurements (10.00%)
191-
1 (10.00%) high mild
199+
decrypt 100M time: [113.73 ms 114.05 ms 114.39 ms]
192200

193-
decrypt 200M time: [363.14 ms 364.48 ms 365.74 ms]
201+
decrypt 200M time: [236.41 ms 237.82 ms 239.12 ms]
194202
```
195203

196204
### XChaCha20 backend
197205

198206
```bash
207+
$ export RUSTFLAGS="--cfg chacha20_force_neon"
199208
$ cargo bench --no-default-features --features xchacha20
200-
encrypt 100M time: [149.52 ms 150.06 ms 150.59 ms]
201-
Found 1 outliers among 10 measurements (10.00%)
202-
1 (10.00%) high mild
203209

204-
encrypt 200M time: [482.27 ms 484.95 ms 487.45 ms]
205-
Found 3 outliers among 10 measurements (30.00%)
206-
2 (20.00%) low severe
207-
1 (10.00%) high severe
210+
encrypt 100M time: [120.24 ms 120.98 ms 121.63 ms]
208211

209-
decrypt 100M time: [98.232 ms 100.37 ms 105.65 ms]
210-
Found 1 outliers among 10 measurements (10.00%)
211-
1 (10.00%) high severe
212+
encrypt 200M time: [257.24 ms 261.22 ms 264.06 ms]
213+
214+
decrypt 100M time: [114.39 ms 114.94 ms 116.03 ms]
212215

213-
decrypt 200M time: [265.62 ms 268.02 ms 269.85 ms]
216+
decrypt 200M time: [238.09 ms 240.60 ms 242.55 ms]
214217
```
215218

216219
## Changelog

scripts/check.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/sh
22
set -e
33

4-
cargo check --no-default-features --features $CURVE,openssl
5-
cargo check --no-default-features --features $CURVE,pure
4+
cargo check --no-default-features --features $CURVE,aes-openssl
5+
cargo check --no-default-features --features $CURVE,aes-rust
66
cargo check --no-default-features --features $CURVE,xchacha20
77

8-
cargo clippy --no-default-features --features $CURVE,openssl
9-
cargo clippy --no-default-features --features $CURVE,pure
8+
cargo clippy --no-default-features --features $CURVE,aes-openssl
9+
cargo clippy --no-default-features --features $CURVE,aes-rust
1010
cargo clippy --no-default-features --features $CURVE,xchacha20

scripts/cov.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
set -e
33

4-
cargo llvm-cov --no-report --no-default-features --features $CURVE,openssl,$STD
5-
cargo llvm-cov --no-report --no-default-features --features $CURVE,pure,$STD
4+
cargo llvm-cov --no-report --no-default-features --features $CURVE,aes-openssl,$STD
5+
cargo llvm-cov --no-report --no-default-features --features $CURVE,aes-rust,$STD
66

scripts/test-wasm.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
set -e
33

44
# Pure Rust AES on WASM target
5-
cargo test --no-default-features --features $CURVE,pure --target=wasm32-unknown-unknown
6-
cargo test --no-default-features --features $CURVE,pure,std --target=wasm32-unknown-unknown
7-
cargo test --no-default-features --features $CURVE,pure,aes-12bytes-nonce --target=wasm32-unknown-unknown
8-
cargo test --no-default-features --features $CURVE,pure,aes-12bytes-nonce,std --target=wasm32-unknown-unknown
5+
cargo test --no-default-features --features $CURVE,aes-rust --target=wasm32-unknown-unknown
6+
cargo test --no-default-features --features $CURVE,aes-rust,std --target=wasm32-unknown-unknown
7+
cargo test --no-default-features --features $CURVE,aes-rust,aes-12bytes-nonce --target=wasm32-unknown-unknown
8+
cargo test --no-default-features --features $CURVE,aes-rust,aes-12bytes-nonce,std --target=wasm32-unknown-unknown
99

1010
# XChaCha20 on WASM target
1111
cargo test --no-default-features --features $CURVE,xchacha20 --target=wasm32-unknown-unknown

scripts/test.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
set -e
33

44
# OpenSSL AES
5-
cargo test --no-default-features --features $CURVE,openssl
6-
cargo test --no-default-features --features $CURVE,openssl,std
7-
cargo test --no-default-features --features $CURVE,openssl,aes-12bytes-nonce
8-
cargo test --no-default-features --features $CURVE,openssl,aes-12bytes-nonce,std
5+
cargo test --no-default-features --features $CURVE,aes-openssl
6+
cargo test --no-default-features --features $CURVE,aes-openssl,std
7+
cargo test --no-default-features --features $CURVE,aes-openssl,aes-12bytes-nonce
8+
cargo test --no-default-features --features $CURVE,aes-openssl,aes-12bytes-nonce,std
99

1010
# Pure Rust AES
11-
cargo test --no-default-features --features $CURVE,pure
12-
cargo test --no-default-features --features $CURVE,pure,std
13-
cargo test --no-default-features --features $CURVE,pure,aes-12bytes-nonce
14-
cargo test --no-default-features --features $CURVE,pure,aes-12bytes-nonce,std
11+
cargo test --no-default-features --features $CURVE,aes-rust
12+
cargo test --no-default-features --features $CURVE,aes-rust,std
13+
cargo test --no-default-features --features $CURVE,aes-rust,aes-12bytes-nonce
14+
cargo test --no-default-features --features $CURVE,aes-rust,aes-12bytes-nonce,std
1515

1616
# XChaCha20
1717
cargo test --no-default-features --features $CURVE,xchacha20

0 commit comments

Comments
 (0)