Skip to content

Commit 9cffcff

Browse files
committed
remove alloc, feature flag everything except group_key
1 parent 68879fd commit 9cffcff

File tree

10 files changed

+16
-75
lines changed

10 files changed

+16
-75
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ hex-literal = "0.4.1"
2424
rand = "0.8.5"
2525

2626
[features]
27-
default = ["signing"]
27+
default = ["dkg"]
2828

2929
std = []
3030
signing = ["dep:blake3", "dep:rand_chacha", "std"]

src/dkg/error.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ use crate::io;
88
use core::fmt;
99
use core::fmt::Debug;
1010

11-
#[cfg(not(feature = "std"))]
12-
extern crate alloc;
13-
#[cfg(not(feature = "std"))]
14-
use alloc::string::String;
15-
1611
#[derive(Debug)]
1712
pub enum Error {
1813
InvalidInput(String),

src/dkg/group_key.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ use crate::participant::Secret;
99
use rand_core::CryptoRng;
1010
use rand_core::RngCore;
1111

12-
#[cfg(not(feature = "std"))]
13-
extern crate alloc;
14-
#[cfg(not(feature = "std"))]
15-
use alloc::vec::Vec;
16-
1712
pub const GROUP_SECRET_KEY_LEN: usize = 32;
1813

1914
pub type GroupSecretKey = [u8; GROUP_SECRET_KEY_LEN];

src/dkg/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
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/. */
4-
4+
#[cfg(feature = "std")]
55
pub mod error;
66
pub mod group_key;
7+
#[cfg(feature = "std")]
78
pub mod round1;
9+
#[cfg(feature = "std")]
810
pub mod round2;
11+
#[cfg(feature = "std")]
912
pub mod round3;

src/dkg/round1.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ use rand_core::RngCore;
3131
use core::hash::Hasher;
3232
use core::mem;
3333

34-
#[cfg(not(feature = "std"))]
35-
extern crate alloc;
36-
#[cfg(not(feature = "std"))]
37-
use alloc::string::ToString;
38-
#[cfg(not(feature = "std"))]
39-
use alloc::vec::Vec;
40-
4134
type Scalar = <JubjubScalarField as Field>::Scalar;
4235

4336
/// Copy of the [`frost_core::dkg::round1::SecretPackage`] struct. Necessary to implement

src/dkg/round2.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ use rand_core::RngCore;
3636
#[cfg(feature = "std")]
3737
use std::collections::BTreeMap;
3838

39-
#[cfg(not(feature = "std"))]
40-
extern crate alloc;
41-
#[cfg(not(feature = "std"))]
42-
use alloc::collections::BTreeMap;
43-
#[cfg(not(feature = "std"))]
44-
use alloc::vec::Vec;
45-
4639
type Scalar = <JubjubScalarField as Field>::Scalar;
4740

4841
/// Copy of the [`frost_core::dkg::round2::SecretPackage`] struct. Necessary to implement

src/dkg/round3.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ use reddsa::frost::redjubjub::VerifyingKey;
2727
#[cfg(feature = "std")]
2828
use std::collections::BTreeMap;
2929

30-
#[cfg(not(feature = "std"))]
31-
extern crate alloc;
32-
#[cfg(not(feature = "std"))]
33-
use alloc::collections::BTreeMap;
34-
#[cfg(not(feature = "std"))]
35-
use alloc::string::ToString;
36-
#[cfg(not(feature = "std"))]
37-
use alloc::vec::Vec;
38-
3930
#[derive(Clone, Eq, PartialEq, Debug)]
4031
pub struct PublicKeyPackage {
4132
frost_public_key_package: FrostPublicKeyPackage,

src/lib.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ mod io {
3737
pub(crate) use std::io::Write;
3838
}
3939

40-
#[cfg(not(feature = "std"))]
41-
#[macro_use]
42-
#[cfg(not(feature = "std"))]
43-
extern crate alloc;
44-
4540
#[cfg(not(feature = "std"))]
4641
mod io {
4742
use core::cmp;
@@ -147,19 +142,3 @@ mod io {
147142
}
148143
}
149144
}
150-
151-
#[cfg(not(feature = "std"))]
152-
use alloc::vec::Vec;
153-
154-
#[cfg(not(feature = "std"))]
155-
impl io::Write for Vec<u8> {
156-
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
157-
self.extend_from_slice(buf);
158-
Ok(buf.len())
159-
}
160-
161-
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
162-
self.extend_from_slice(buf);
163-
Ok(())
164-
}
165-
}

src/multienc.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ use rand_core::RngCore;
2020
use x25519_dalek::PublicKey;
2121
use x25519_dalek::ReusableSecret;
2222

23-
#[cfg(not(feature = "std"))]
24-
extern crate alloc;
25-
#[cfg(not(feature = "std"))]
26-
use crate::alloc::borrow::ToOwned;
27-
#[cfg(not(feature = "std"))]
28-
use alloc::vec::Vec;
29-
3023
pub const HEADER_SIZE: usize = 56;
3124
pub const KEY_SIZE: usize = 32;
3225

@@ -36,6 +29,7 @@ pub const fn metadata_size(num_recipients: usize) -> usize {
3629
HEADER_SIZE + KEY_SIZE * num_recipients
3730
}
3831

32+
#[cfg(feature = "std")]
3933
pub fn read_encrypted_blob<R>(reader: &mut R) -> Result<Vec<u8>, io::Error>
4034
where
4135
R: crate::io::Read,
@@ -59,7 +53,8 @@ where
5953
Ok(result)
6054
}
6155

62-
#[must_use]
56+
// #[must_use]
57+
#[cfg(feature = "std")]
6358
pub fn encrypt<'a, I, R>(data: &[u8], recipients: I, csrng: R) -> Vec<u8>
6459
where
6560
I: IntoIterator<Item = &'a Identity>,
@@ -142,6 +137,7 @@ where
142137
Ok(())
143138
}
144139

140+
#[cfg(feature = "std")]
145141
/// Decrypts data produced by [`encrypt`] or [`encrypt_in_place`] using one participant secret.
146142
///
147143
/// This method expects the ciphertext and the metadata to be concatenated in one slice. Use
@@ -275,6 +271,7 @@ impl Header {
275271
}
276272

277273
#[cfg(test)]
274+
#[cfg(feature = "std")]
278275
mod tests {
279276
mod detached {
280277
use crate::multienc::decrypt;

src/serde.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
77
use crate::io;
88

9-
#[cfg(not(feature = "std"))]
10-
extern crate alloc;
11-
#[cfg(not(feature = "std"))]
12-
use alloc::vec::Vec;
13-
149
#[inline]
1510
#[cfg(feature = "dkg")]
1611
pub(crate) fn write_u16<W: io::Write>(mut writer: W, value: u16) -> io::Result<()> {
@@ -77,8 +72,8 @@ pub(crate) fn read_usize<R: io::Read>(reader: R) -> io::Result<usize> {
7772
read_u32(reader).map(|value| value as usize)
7873
}
7974

80-
#[inline]
81-
#[cfg(feature = "dkg")]
75+
// #[inline]
76+
#[cfg(feature = "std")]
8277
pub(crate) fn read_variable_length<R, F, T>(mut reader: R, f: F) -> io::Result<Vec<T>>
8378
where
8479
R: io::Read,
@@ -92,8 +87,8 @@ where
9287
Ok(items)
9388
}
9489

95-
#[inline]
96-
#[cfg(feature = "dkg")]
90+
// #[inline]
91+
#[cfg(feature = "std")]
9792
pub(crate) fn read_variable_length_bytes<R: io::Read>(mut reader: R) -> io::Result<Vec<u8>> {
9893
let len = read_usize(&mut reader)?;
9994
let mut bytes = vec![0u8; len];
@@ -172,7 +167,7 @@ mod test {
172167
}
173168

174169
#[test]
175-
#[cfg(feature = "dkg")]
170+
#[cfg(feature = "std")]
176171
fn write_read_variable_length() {
177172
test_serde!(
178173
Vec::<u16>::new(),
@@ -194,7 +189,7 @@ mod test {
194189
}
195190

196191
#[test]
197-
#[cfg(feature = "dkg")]
192+
#[cfg(feature = "std")]
198193
fn write_read_variable_length_bytes() {
199194
test_serde!(
200195
&b""[..],

0 commit comments

Comments
 (0)