Skip to content

Commit 908289d

Browse files
authored
secp256k1-tr: fix no-std support (#782)
* secp256k1-tr: fix no-std support * apply recent secp256k1 changes
1 parent 102320b commit 908289d

File tree

6 files changed

+19
-28
lines changed

6 files changed

+19
-28
lines changed

frost-ed25519/dkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The DKG module supports generating FROST key shares in a distributed manner,
44
without a trusted dealer.
55

6-
Before starting, each participant needs an unique identifier, which can be built from
6+
Before starting, each participant needs a unique identifier, which can be built from
77
a `u16`. The process in which these identifiers are allocated is up to the application.
88

99
The distributed key generation process has 3 parts, with 2 communication rounds

frost-ed448/dkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The DKG module supports generating FROST key shares in a distributed manner,
44
without a trusted dealer.
55

6-
Before starting, each participant needs an unique identifier, which can be built from
6+
Before starting, each participant needs a unique identifier, which can be built from
77
a `u16`. The process in which these identifiers are allocated is up to the application.
88

99
The distributed key generation process has 3 parts, with 2 communication rounds

frost-secp256k1-tr/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@ rustdoc-args = ["--cfg", "docsrs"]
2323

2424
[dependencies]
2525
document-features = "0.2.7"
26-
frost-core = { path = "../frost-core", version = "2.0.0-rc.0", default-features = false }
27-
frost-rerandomized = { path = "../frost-rerandomized", version = "2.0.0-rc.0", default-features = false }
26+
frost-core = { path = "../frost-core", version = "2.0.0", default-features = false }
27+
frost-rerandomized = { path = "../frost-rerandomized", version = "2.0.0", default-features = false }
2828
k256 = { version = "0.13.0", features = ["arithmetic", "expose-field", "hash2curve"], default-features = false }
29-
serde = { version = "1.0.160", features = ["derive"], optional = true }
3029
rand_core = "0.6"
3130
sha2 = { version = "0.10.2", default-features = false }
3231

3332
[dev-dependencies]
3433
criterion = "0.5"
35-
frost-core = { path = "../frost-core", version = "2.0.0-rc.0", features = ["test-impl"] }
36-
frost-rerandomized = { path = "../frost-rerandomized", version = "2.0.0-rc.0", features = ["test-impl"] }
34+
frost-core = { path = "../frost-core", version = "2.0.0", features = ["test-impl"] }
35+
frost-rerandomized = { path = "../frost-rerandomized", version = "2.0.0", features = ["test-impl"] }
3736
insta = { version = "1.31.0", features = ["yaml"] }
3837
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
3938
lazy_static = "1.4"
@@ -52,7 +51,7 @@ std = ["frost-core/std"]
5251
## Enable `serde` support for types that need to be communicated. You
5352
## can use `serde` to serialize structs with any encoder that supports
5453
## `serde` (e.g. JSON with `serde_json`).
55-
serde = ["frost-core/serde", "dep:serde"]
54+
serde = ["frost-core/serde"]
5655
## Enable a default serialization format. Enables `serde`.
5756
serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"]
5857
## Enable cheater detection

frost-secp256k1-tr/dkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The DKG module supports generating FROST key shares in a distributed manner,
44
without a trusted dealer.
55

6-
Before starting, each participant needs an unique identifier, which can be built from
6+
Before starting, each participant needs a unique identifier, which can be built from
77
a `u16`. The process in which these identifiers are allocated is up to the application.
88

99
The distributed key generation process has 3 parts, with 2 communication rounds

frost-secp256k1-tr/src/lib.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg_attr(not(feature = "std"), no_std)]
12
#![allow(non_snake_case)]
23
#![deny(missing_docs)]
34
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
@@ -7,10 +8,8 @@
78

89
extern crate alloc;
910

10-
use alloc::borrow::Cow;
11-
use alloc::borrow::ToOwned;
12-
use alloc::collections::BTreeMap;
13-
use alloc::vec::Vec;
11+
use alloc::vec;
12+
use alloc::{borrow::Cow, collections::BTreeMap, vec::Vec};
1413

1514
use frost_rerandomized::RandomizedCiphersuite;
1615
use k256::elliptic_curve::ops::Reduce;
@@ -168,9 +167,9 @@ fn hash_to_array(inputs: &[&[u8]]) -> [u8; 32] {
168167
output
169168
}
170169

171-
fn hash_to_scalar(domain: &[u8], msg: &[u8]) -> Scalar {
170+
fn hash_to_scalar(domain: &[&[u8]], msg: &[u8]) -> Scalar {
172171
let mut u = [Secp256K1ScalarField::zero()];
173-
hash_to_field::<ExpandMsgXmd<Sha256>, Scalar>(&[msg], &[domain], &mut u)
172+
hash_to_field::<ExpandMsgXmd<Sha256>, Scalar>(&[msg], domain, &mut u)
174173
.expect("should never return error according to error cases described in ExpandMsgXmd");
175174
u[0]
176175
}
@@ -248,7 +247,7 @@ impl Ciphersuite for Secp256K1Sha256TR {
248247
///
249248
/// [spec]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-14.html#section-6.5-2.2.2.1
250249
fn H1(m: &[u8]) -> <<Self::Group as Group>::Field as Field>::Scalar {
251-
hash_to_scalar((CONTEXT_STRING.to_owned() + "rho").as_bytes(), m)
250+
hash_to_scalar(&[CONTEXT_STRING.as_bytes(), b"rho"], m)
252251
}
253252

254253
/// H2 for FROST(secp256k1, SHA-256)
@@ -264,7 +263,7 @@ impl Ciphersuite for Secp256K1Sha256TR {
264263
///
265264
/// [spec]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-14.html#section-6.5-2.2.2.3
266265
fn H3(m: &[u8]) -> <<Self::Group as Group>::Field as Field>::Scalar {
267-
hash_to_scalar((CONTEXT_STRING.to_owned() + "nonce").as_bytes(), m)
266+
hash_to_scalar(&[CONTEXT_STRING.as_bytes(), b"nonce"], m)
268267
}
269268

270269
/// H4 for FROST(secp256k1, SHA-256)
@@ -283,18 +282,12 @@ impl Ciphersuite for Secp256K1Sha256TR {
283282

284283
/// HDKG for FROST(secp256k1, SHA-256)
285284
fn HDKG(m: &[u8]) -> Option<<<Self::Group as Group>::Field as Field>::Scalar> {
286-
Some(hash_to_scalar(
287-
(CONTEXT_STRING.to_owned() + "dkg").as_bytes(),
288-
m,
289-
))
285+
Some(hash_to_scalar(&[CONTEXT_STRING.as_bytes(), b"dkg"], m))
290286
}
291287

292288
/// HID for FROST(secp256k1, SHA-256)
293289
fn HID(m: &[u8]) -> Option<<<Self::Group as Group>::Field as Field>::Scalar> {
294-
Some(hash_to_scalar(
295-
(CONTEXT_STRING.to_owned() + "id").as_bytes(),
296-
m,
297-
))
290+
Some(hash_to_scalar(&[CONTEXT_STRING.as_bytes(), b"id"], m))
298291
}
299292

300293
// Sign, negating the key if required by BIP-340.
@@ -499,7 +492,7 @@ impl Ciphersuite for Secp256K1Sha256TR {
499492
impl RandomizedCiphersuite for Secp256K1Sha256TR {
500493
fn hash_randomizer(m: &[u8]) -> Option<<<Self::Group as Group>::Field as Field>::Scalar> {
501494
Some(hash_to_scalar(
502-
(CONTEXT_STRING.to_owned() + "randomizer").as_bytes(),
495+
&[CONTEXT_STRING.as_bytes(), b"randomizer"],
503496
m,
504497
))
505498
}
@@ -513,7 +506,6 @@ pub type Identifier = frost::Identifier<S>;
513506
/// FROST(secp256k1, SHA-256) keys, key generation, key shares.
514507
pub mod keys {
515508
use super::*;
516-
use std::collections::BTreeMap;
517509

518510
/// The identifier list to use when generating key shares.
519511
pub type IdentifierList<'a> = frost::keys::IdentifierList<'a, S>;

frost-secp256k1/dkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The DKG module supports generating FROST key shares in a distributed manner,
44
without a trusted dealer.
55

6-
Before starting, each participant needs an unique identifier, which can be built from
6+
Before starting, each participant needs a unique identifier, which can be built from
77
a `u16`. The process in which these identifiers are allocated is up to the application.
88

99
The distributed key generation process has 3 parts, with 2 communication rounds

0 commit comments

Comments
 (0)