Skip to content

Commit 223e068

Browse files
authored
Update dalek (#188)
1 parent 70778ad commit 223e068

File tree

9 files changed

+46
-56
lines changed

9 files changed

+46
-56
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: Rustfmt
1313
runs-on: ubuntu-22.04
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
- name: Cache cargo
1717
uses: Swatinem/rust-cache@v1
1818
- uses: IronCoreLabs/rust-toolchain@v1
@@ -50,7 +50,7 @@ jobs:
5050
- os: windows-2019
5151
target: x86_64-pc-windows-msvc
5252
steps:
53-
- uses: actions/checkout@v2
53+
- uses: actions/checkout@v4
5454
- name: Cache cargo
5555
uses: Swatinem/rust-cache@v1
5656
- uses: IronCoreLabs/rust-toolchain@v1
@@ -75,7 +75,7 @@ jobs:
7575
- 1.70.0 #MSRV
7676
fail-fast: false
7777
steps:
78-
- uses: actions/checkout@v2
78+
- uses: actions/checkout@v4
7979
- name: Cache cargo
8080
uses: Swatinem/rust-cache@v1
8181
- uses: IronCoreLabs/rust-toolchain@v1
@@ -98,7 +98,7 @@ jobs:
9898
- name: base
9999
ref: ${{ github.base_ref }}
100100
steps:
101-
- uses: actions/checkout@v2
101+
- uses: actions/checkout@v4
102102
with:
103103
ref: ${{ matrix.ref }}
104104
- name: Cache cargo
@@ -128,7 +128,7 @@ jobs:
128128
name: Upload benchmark results
129129
runs-on: ubuntu-22.04
130130
steps:
131-
- uses: actions/checkout@v2
131+
- uses: actions/checkout@v4
132132
- name: Cache cargo
133133
uses: Swatinem/rust-cache@v1
134134
- name: Retrieve benchmark results

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Changelog
22

3-
## Unreleased
3+
## 0.14.0 (2024-12-03)
44

5+
- [[#184](https://github.com/IronCoreLabs/recrypt-rs/pull/188)]
6+
- Switch from `ed25519-dalek-fiat` to `ed25519-dalek`.
7+
- Remove `u64_backend` and `u32_backend` features.
58
- [[#184](https://github.com/IronCoreLabs/recrypt-rs/pull/184)]
69
- Change MSRV to Rust 1.70.0
710
- [[#177](https://github.com/IronCoreLabs/recrypt-rs/pull/177)]

Cargo.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "recrypt"
3-
version = "0.13.1"
3+
version = "0.14.0"
44
authors = ["IronCore Labs <[email protected]>"]
55
readme = "README.md"
66
license = "AGPL-3.0-only"
@@ -23,7 +23,7 @@ cfg-if = "1"
2323
clear_on_drop = "0.2"
2424
derivative = "2.1"
2525
# Disable all features for ed25519 and enable the proper ones down in the [features] section below
26-
ed25519-dalek = {version = "=0.1.0", default-features = false, features = ["std"], package = "ed25519-dalek-fiat"}
26+
ed25519-dalek = {version = "2.1.1", default-features = false, features = ["std", "rand_core"]}
2727
# Explicit dependency so we can pass the wasm-bindgen flag to it
2828
getrandom = {version = "0.2", optional = true}
2929
gridiron = "0.10"
@@ -55,10 +55,7 @@ debug = false
5555
lto = true
5656

5757
[features]
58-
default = ["u64_backend"]
59-
u64_backend = ["ed25519-dalek/u64_backend"]
60-
u32_backend = ["ed25519-dalek/u32_backend"]
61-
wasm = ["u32_backend", "clear_on_drop/no_cc", "getrandom/js"]
58+
wasm = ["clear_on_drop/no_cc", "getrandom/js"]
6259
#Can be used to disable the automatic mlock detection for architectures.
6360
disable_memlock = []
6461

flake.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
22
profile = "default"
3-
channel = "1.80.1"
3+
channel = "1.82.0"

src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Recrypt<Sha256, Ed25519, RandomBytes<DefaultRng>> {
5151
Recrypt::new_with_rand(ReseedingRng::new(
5252
rand_chacha::ChaChaCore::from_entropy(),
5353
BYTES_BEFORE_RESEEDING,
54-
rand::rngs::OsRng::default(),
54+
rand::rngs::OsRng,
5555
))
5656
}
5757
}

src/api_480.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Recrypt480<Sha256, Ed25519, RandomBytes<DefaultRng>> {
5050
Recrypt480::new_with_rand(ReseedingRng::new(
5151
rand_chacha::ChaChaCore::from_entropy(),
5252
BYTES_BEFORE_RESEEDING,
53-
rand::rngs::OsRng::default(),
53+
rand::rngs::OsRng,
5454
))
5555
}
5656
}
@@ -934,13 +934,13 @@ impl SixtyBytes {
934934

935935
impl fmt::Debug for SixtyBytes {
936936
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
937-
write!(f, "{:?}", self.0.to_vec())
937+
write!(f, "{:?}", self.0)
938938
}
939939
}
940940

941941
impl fmt::LowerHex for SixtyBytes {
942942
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
943-
write!(f, "{}", hex::encode(self.0.to_vec()))
943+
write!(f, "{}", hex::encode(self.0))
944944
}
945945
}
946946

src/internal/ed25519.rs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::internal::ByteVector;
55
use crate::internal::{array_split_64, take_lock};
66
use clear_on_drop::clear::Clear;
77
use ed25519_dalek;
8-
use ed25519_dalek::PublicKey;
98
use quick_error::quick_error;
109
use rand;
1110
use std;
@@ -64,10 +63,10 @@ impl From<SigningKeypair> for [u8; 64] {
6463
impl SigningKeypair {
6564
const ENCODED_SIZE_BYTES: usize = 64;
6665
pub fn new<CR: rand::RngCore + rand::CryptoRng>(rng: &Mutex<CR>) -> SigningKeypair {
67-
let keypair = ed25519_dalek::Keypair::generate::<CR>(&mut *take_lock(rng));
66+
let signing_key = ed25519_dalek::SigningKey::generate::<CR>(&mut *take_lock(rng));
6867

6968
//Unchecked is safe because the public is on the curve and the size is statically guaranteed.
70-
SigningKeypair::new_unchecked(keypair.to_bytes())
69+
SigningKeypair::new_unchecked(signing_key.to_keypair_bytes())
7170
}
7271
///
7372
///Create a SigningKeypair from a byte array slice. If the array is not the right length or if the public
@@ -94,10 +93,10 @@ impl SigningKeypair {
9493
///
9594
pub fn from_bytes(sized_bytes: &[u8; 64]) -> Result<SigningKeypair, Ed25519Error> {
9695
let (priv_key, pub_key) = array_split_64(sized_bytes);
97-
//This can't fail because it's statically guaranteed to be 32 bytes long.
98-
let ed25519_dalek_secret = ed25519_dalek::SecretKey::from_bytes(&priv_key).unwrap();
96+
let ed25519_dalek_secret = ed25519_dalek::SigningKey::from_bytes(&priv_key);
9997
//Calculate the public key to check that the value passed in is correct.
100-
let ed25519_dalek_pub = ed25519_dalek::PublicKey::from(&ed25519_dalek_secret);
98+
99+
let ed25519_dalek_pub = ed25519_dalek::VerifyingKey::from(&ed25519_dalek_secret);
101100
if ed25519_dalek_pub.to_bytes() == pub_key {
102101
Ok(SigningKeypair::new_unchecked(*sized_bytes))
103102
} else {
@@ -151,9 +150,8 @@ pub struct Ed25519;
151150
impl Ed25519Signing for Ed25519 {
152151
fn sign<T: Hashable>(&self, t: &T, signing_key: &SigningKeypair) -> Ed25519Signature {
153152
use ed25519_dalek::Signer;
154-
//This unwrap cannot fail. The only thing that the `from_bytes` does for validation is that the
155-
//value is 64 bytes long, which we guarantee statically.
156-
let key_pair = ed25519_dalek::Keypair::from_bytes(&signing_key.bytes[..]).unwrap();
153+
let (priv_key, _) = array_split_64(&signing_key.bytes);
154+
let key_pair = ed25519_dalek::SigningKey::from_bytes(&priv_key);
157155
let sig = key_pair.sign(&t.to_bytes()[..]);
158156

159157
Ed25519Signature::new(sig.to_bytes())
@@ -166,10 +164,10 @@ impl Ed25519Signing for Ed25519 {
166164
) -> bool {
167165
use ed25519_dalek::Verifier;
168166

169-
PublicKey::from_bytes(&public_key.bytes[..])
167+
ed25519_dalek::VerifyingKey::from_bytes(&public_key.bytes)
170168
.and_then(|pk| {
171-
TryFrom::try_from(&signature.bytes[..])
172-
.and_then(|sig| pk.verify(&t.to_bytes()[..], &sig))
169+
let sig = ed25519_dalek::Signature::from_bytes(&signature.bytes);
170+
pk.verify(&t.to_bytes()[..], &sig)
173171
})
174172
.map(|_| true)
175173
.unwrap_or(false)
@@ -197,7 +195,6 @@ pub trait Ed25519Signing {
197195
pub(crate) mod test {
198196
use super::*;
199197
use crate::internal::array_concat_32;
200-
use ed25519_dalek::SecretKey;
201198

202199
pub fn good_signing_keypair() -> SigningKeypair {
203200
SigningKeypair::new_unchecked([
@@ -209,18 +206,13 @@ pub(crate) mod test {
209206

210207
#[test]
211208
fn real_ed25519_matches_verify_good_message() {
212-
let sec_key = SecretKey::from_bytes(&[1; 32]).unwrap();
213-
let dalek_pub_key = ed25519_dalek::PublicKey::from(&sec_key);
214-
let priv_key = SigningKeypair {
215-
bytes: array_concat_32(&sec_key.to_bytes(), &dalek_pub_key.to_bytes()),
209+
let sec_key = ed25519_dalek::SigningKey::from_bytes(&[1; 32]);
210+
let keypair = SigningKeypair {
211+
bytes: sec_key.to_keypair_bytes(),
216212
};
217213
let message = [100u8; 32].to_vec();
218-
let result = Ed25519.sign(&message, &priv_key);
219-
let verify_result = Ed25519.verify(
220-
&message,
221-
&result,
222-
&PublicSigningKey::new(dalek_pub_key.to_bytes()),
223-
);
214+
let result = Ed25519.sign(&message, &keypair);
215+
let verify_result = Ed25519.verify(&message, &result, &keypair.public_key());
224216
assert!(verify_result);
225217
}
226218

@@ -238,10 +230,9 @@ pub(crate) mod test {
238230

239231
#[test]
240232
fn signing_keypair_into_bytes() {
241-
let sec_key = SecretKey::from_bytes(&[1; 32]).unwrap();
242-
let dalek_pub_key = ed25519_dalek::PublicKey::from(&sec_key);
233+
let dalek_pub_key = ed25519_dalek::VerifyingKey::from_bytes(&[1u8; 32]).unwrap();
243234
let key_pair = SigningKeypair {
244-
bytes: array_concat_32(&sec_key.to_bytes(), &dalek_pub_key.to_bytes()),
235+
bytes: array_concat_32(&[1u8; 32], &dalek_pub_key.to_bytes()),
245236
};
246237
let key_pair_bytes = key_pair.bytes().clone();
247238
let bytes: [u8; 64] = key_pair.into();

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg_attr(feature = "unstable", feature(test))]
21
#![doc(html_no_source)] // use github for source browsing
32

43
//! Recrypt implements a set of cryptographic primitives for building a

0 commit comments

Comments
 (0)