Skip to content

Commit 6362ab4

Browse files
committed
Upgrade reddsa to 2.0.0-rc0 for compatibility with no-std
1 parent 1a3e331 commit 6362ab4

File tree

13 files changed

+199
-212
lines changed

13 files changed

+199
-212
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ chacha20poly1305 = "0.10.1"
1515
ed25519-dalek = { version = "2.1.0", features = ["rand_core"] }
1616
rand_chacha = { version = "0.3.1", optional = true }
1717
rand_core = "0.6.4"
18-
reddsa = { git = "https://github.com/ZcashFoundation/reddsa.git", rev = "311baf8865f6e21527d1f20750d8f2cf5c9e531a", features = ["frost", "frost-rerandomized"] }
18+
reddsa = { git = "https://github.com/ZcashFoundation/reddsa.git", rev = "b9c3107e6ec5333a89a7fa064f2d10f749a90cce", features = ["frost", "frost-rerandomized"] }
1919
siphasher = { version = "1.0.0", optional = true }
2020
x25519-dalek = { version = "2.0.0", features = ["reusable_secrets", "static_secrets"] }
2121

src/dkg/error.rs

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/dkg/group_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl GroupSecretKeyShard {
7979
}
8080

8181
pub fn import(secret: &Secret, exported: &[u8]) -> io::Result<Self> {
82-
let bytes = multienc::decrypt(secret, &exported).map_err(io::Error::other)?;
82+
let bytes = multienc::decrypt(secret, exported).map_err(io::Error::other)?;
8383

8484
if bytes.len() != GROUP_SECRET_KEY_LEN {
8585
return Err(io::Error::other(

src/dkg/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44

5-
pub mod error;
65
pub mod group_key;
76
pub mod round1;
87
pub mod round2;

src/dkg/round1.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use crate::checksum::Checksum;
66
use crate::checksum::ChecksumHasher;
77
use crate::checksum::CHECKSUM_LEN;
8-
use crate::dkg::error::Error;
98
use crate::dkg::group_key::GroupSecretKeyShard;
9+
use crate::error::IronfishFrostError;
1010
use crate::frost;
1111
use crate::frost::keys::dkg::round1::Package;
1212
use crate::frost::keys::dkg::round1::SecretPackage;
@@ -15,7 +15,6 @@ use crate::frost::Field;
1515
use crate::frost::Identifier;
1616
use crate::frost::JubjubScalarField;
1717
use crate::multienc;
18-
use crate::multienc::read_encrypted_blob;
1918
use crate::participant;
2019
use crate::participant::Identity;
2120
use crate::serde::read_u16;
@@ -80,23 +79,24 @@ impl<'a> From<&'a SerializableSecretPackage> for &'a SecretPackage {
8079
}
8180

8281
impl SerializableSecretPackage {
83-
fn serialize_into<W: io::Write>(&self, mut writer: W) -> io::Result<()> {
82+
fn serialize_into<W: io::Write>(&self, mut writer: W) -> Result<(), IronfishFrostError> {
8483
writer.write_all(&self.identifier.serialize())?;
8584
write_variable_length(&mut writer, &self.coefficients, |writer, scalar| {
8685
writer.write_all(&scalar.to_bytes())
8786
})?;
88-
write_variable_length(&mut writer, self.commitment.serialize(), |writer, array| {
87+
let serialized = self.commitment.serialize()?;
88+
write_variable_length(&mut writer, serialized, |writer, array| {
8989
writer.write_all(&array)
9090
})?;
9191
write_u16(&mut writer, self.min_signers)?;
9292
write_u16(&mut writer, self.max_signers)?;
9393
Ok(())
9494
}
9595

96-
fn deserialize_from<R: io::Read>(mut reader: R) -> io::Result<Self> {
96+
fn deserialize_from<R: io::Read>(mut reader: R) -> Result<Self, IronfishFrostError> {
9797
let mut identifier = [0u8; 32];
9898
reader.read_exact(&mut identifier)?;
99-
let identifier = Identifier::deserialize(&identifier).map_err(io::Error::other)?;
99+
let identifier = Identifier::deserialize(&identifier)?;
100100

101101
let coefficients = read_variable_length(&mut reader, |reader| {
102102
let mut scalar = [0u8; 32];
@@ -112,8 +112,7 @@ impl SerializableSecretPackage {
112112
reader.read_exact(&mut array)?;
113113
Ok(array)
114114
},
115-
)?)
116-
.map_err(io::Error::other)?;
115+
)?)?;
117116

118117
let min_signers = read_u16(&mut reader)?;
119118
let max_signers = read_u16(&mut reader)?;
@@ -153,8 +152,8 @@ pub fn export_secret_package<R: RngCore + CryptoRng>(
153152
pub fn import_secret_package(
154153
exported: &[u8],
155154
secret: &participant::Secret,
156-
) -> io::Result<SecretPackage> {
157-
let serialized = multienc::decrypt(secret, &exported).map_err(io::Error::other)?;
155+
) -> Result<SecretPackage, IronfishFrostError> {
156+
let serialized = multienc::decrypt(secret, exported).map_err(io::Error::other)?;
158157
SerializableSecretPackage::deserialize_from(&serialized[..]).map(|pkg| pkg.into())
159158
}
160159

@@ -247,22 +246,22 @@ impl PublicPackage {
247246
buf
248247
}
249248

250-
pub fn serialize_into<W: io::Write>(&self, mut writer: W) -> io::Result<()> {
249+
pub fn serialize_into<W: io::Write>(&self, mut writer: W) -> Result<(), IronfishFrostError> {
251250
self.identity.serialize_into(&mut writer)?;
252-
let frost_package = self.frost_package.serialize().map_err(io::Error::other)?;
251+
let frost_package = self.frost_package.serialize()?;
253252
write_variable_length_bytes(&mut writer, &frost_package)?;
254-
writer.write_all(&self.group_secret_key_shard_encrypted[..])?;
253+
write_variable_length_bytes(&mut writer, &self.group_secret_key_shard_encrypted)?;
255254
writer.write_all(&self.checksum.to_le_bytes())?;
256255
Ok(())
257256
}
258257

259-
pub fn deserialize_from<R: io::Read>(mut reader: R) -> io::Result<Self> {
258+
pub fn deserialize_from<R: io::Read>(mut reader: R) -> Result<Self, IronfishFrostError> {
260259
let identity = Identity::deserialize_from(&mut reader).expect("reading identity failed");
261260

262261
let frost_package = read_variable_length_bytes(&mut reader)?;
263-
let frost_package = Package::deserialize(&frost_package).map_err(io::Error::other)?;
262+
let frost_package = Package::deserialize(&frost_package)?;
264263

265-
let group_secret_key_shard_encrypted = read_encrypted_blob(&mut reader)?;
264+
let group_secret_key_shard_encrypted = read_variable_length_bytes(&mut reader)?;
266265

267266
let mut checksum = [0u8; CHECKSUM_LEN];
268267
reader.read_exact(&mut checksum)?;
@@ -282,7 +281,7 @@ pub fn round1<'a, I, R>(
282281
min_signers: u16,
283282
participants: I,
284283
mut csrng: R,
285-
) -> Result<(Vec<u8>, PublicPackage), Error>
284+
) -> Result<(Vec<u8>, PublicPackage), IronfishFrostError>
286285
where
287286
I: IntoIterator<Item = &'a Identity>,
288287
R: RngCore + CryptoRng,
@@ -294,25 +293,21 @@ where
294293
let participants = participants;
295294

296295
if !participants.contains(&self_identity) {
297-
return Err(Error::InvalidInput(
298-
"participants must include self_identity".to_string(),
299-
));
296+
return Err(IronfishFrostError::InvalidInput);
300297
}
301298

302-
let max_signers = u16::try_from(participants.len())
303-
.map_err(|_| Error::InvalidInput("too many participants".to_string()))?;
299+
let max_signers =
300+
u16::try_from(participants.len()).map_err(|_| IronfishFrostError::InvalidInput)?;
304301

305302
let (secret_package, public_package) = frost::keys::dkg::part1(
306303
self_identity.to_frost_identifier(),
307304
max_signers,
308305
min_signers,
309306
&mut csrng,
310-
)
311-
.map_err(Error::FrostError)?;
307+
)?;
312308

313309
let encrypted_secret_package =
314-
export_secret_package(&secret_package, self_identity, &mut csrng)
315-
.map_err(Error::EncryptionError)?;
310+
export_secret_package(&secret_package, self_identity, &mut csrng)?;
316311

317312
let group_secret_key_shard = GroupSecretKeyShard::random(&mut csrng);
318313

@@ -492,6 +487,13 @@ mod tests {
492487
let deserialized = PublicPackage::deserialize_from(&serialized[..])
493488
.expect("package deserialization failed");
494489

490+
assert_eq!(public_package.identity, deserialized.identity);
491+
assert_eq!(public_package.checksum, deserialized.checksum);
492+
assert_eq!(public_package.frost_package, deserialized.frost_package);
493+
assert_eq!(
494+
public_package.group_secret_key_shard_encrypted,
495+
deserialized.group_secret_key_shard_encrypted
496+
);
495497
assert_eq!(public_package, deserialized);
496498
}
497499

0 commit comments

Comments
 (0)