Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secp256k1-tr: fix no-std support #782

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frost-ed25519/dkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The DKG module supports generating FROST key shares in a distributed manner,
without a trusted dealer.

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

The distributed key generation process has 3 parts, with 2 communication rounds
Expand Down
2 changes: 1 addition & 1 deletion frost-ed448/dkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The DKG module supports generating FROST key shares in a distributed manner,
without a trusted dealer.

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

The distributed key generation process has 3 parts, with 2 communication rounds
Expand Down
13 changes: 6 additions & 7 deletions frost-secp256k1-tr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ edition = "2021"
# When releasing to crates.io:
# - Update CHANGELOG.md
# - Create git tag.
version = "2.0.0-rc.0"
version = "2.0.0"
authors = [
"Deirdre Connolly <durumcrustulum@gmail.com>",
"Chelsea Komlo <me@chelseakomlo.com>",
Expand All @@ -23,17 +23,16 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
document-features = "0.2.7"
frost-core = { path = "../frost-core", version = "2.0.0-rc.0", default-features = false }
frost-rerandomized = { path = "../frost-rerandomized", version = "2.0.0-rc.0", default-features = false }
frost-core = { path = "../frost-core", version = "2.0.0", default-features = false }
frost-rerandomized = { path = "../frost-rerandomized", version = "2.0.0", default-features = false }
k256 = { version = "0.13.0", features = ["arithmetic", "expose-field", "hash2curve"], default-features = false }
serde = { version = "1.0.160", features = ["derive"], optional = true }
rand_core = "0.6"
sha2 = { version = "0.10.2", default-features = false }

[dev-dependencies]
criterion = "0.5"
frost-core = { path = "../frost-core", version = "2.0.0-rc.0", features = ["test-impl"] }
frost-rerandomized = { path = "../frost-rerandomized", version = "2.0.0-rc.0", features = ["test-impl"] }
frost-core = { path = "../frost-core", version = "2.0.0", features = ["test-impl"] }
frost-rerandomized = { path = "../frost-rerandomized", version = "2.0.0", features = ["test-impl"] }
insta = { version = "1.31.0", features = ["yaml"] }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
lazy_static = "1.4"
Expand All @@ -52,7 +51,7 @@ std = ["frost-core/std"]
## Enable `serde` support for types that need to be communicated. You
## can use `serde` to serialize structs with any encoder that supports
## `serde` (e.g. JSON with `serde_json`).
serde = ["frost-core/serde", "dep:serde"]
serde = ["frost-core/serde"]
## Enable a default serialization format. Enables `serde`.
serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"]
## Enable cheater detection
Expand Down
2 changes: 1 addition & 1 deletion frost-secp256k1-tr/dkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The DKG module supports generating FROST key shares in a distributed manner,
without a trusted dealer.

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

The distributed key generation process has 3 parts, with 2 communication rounds
Expand Down
28 changes: 10 additions & 18 deletions frost-secp256k1-tr/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(non_snake_case)]
#![deny(missing_docs)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
Expand All @@ -7,10 +8,8 @@

extern crate alloc;

use alloc::borrow::Cow;
use alloc::borrow::ToOwned;
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
use alloc::vec;
use alloc::{borrow::Cow, collections::BTreeMap, vec::Vec};

use frost_rerandomized::RandomizedCiphersuite;
use k256::{
Expand Down Expand Up @@ -167,9 +166,9 @@ fn hash_to_array(inputs: &[&[u8]]) -> [u8; 32] {
output
}

fn hash_to_scalar(domain: &[u8], msg: &[u8]) -> Scalar {
fn hash_to_scalar(domain: &[&[u8]], msg: &[u8]) -> Scalar {
let mut u = [Secp256K1ScalarField::zero()];
hash_to_field::<ExpandMsgXmd<Sha256>, Scalar>(&[msg], &[domain], &mut u)
hash_to_field::<ExpandMsgXmd<Sha256>, Scalar>(&[msg], domain, &mut u)
.expect("should never return error according to error cases described in ExpandMsgXmd");
u[0]
}
Expand Down Expand Up @@ -245,7 +244,7 @@ impl Ciphersuite for Secp256K1Sha256TR {
///
/// [spec]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-14.html#section-6.5-2.2.2.1
fn H1(m: &[u8]) -> <<Self::Group as Group>::Field as Field>::Scalar {
hash_to_scalar((CONTEXT_STRING.to_owned() + "rho").as_bytes(), m)
hash_to_scalar(&[CONTEXT_STRING.as_bytes(), b"rho"], m)
}

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

/// H4 for FROST(secp256k1, SHA-256)
Expand All @@ -280,18 +279,12 @@ impl Ciphersuite for Secp256K1Sha256TR {

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

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

// Sign, negating the key if required by BIP-340.
Expand Down Expand Up @@ -496,7 +489,7 @@ impl Ciphersuite for Secp256K1Sha256TR {
impl RandomizedCiphersuite for Secp256K1Sha256TR {
fn hash_randomizer(m: &[u8]) -> Option<<<Self::Group as Group>::Field as Field>::Scalar> {
Some(hash_to_scalar(
(CONTEXT_STRING.to_owned() + "randomizer").as_bytes(),
&[CONTEXT_STRING.as_bytes(), b"randomizer"],
m,
))
}
Expand All @@ -510,7 +503,6 @@ pub type Identifier = frost::Identifier<S>;
/// FROST(secp256k1, SHA-256) keys, key generation, key shares.
pub mod keys {
use super::*;
use std::collections::BTreeMap;

/// The identifier list to use when generating key shares.
pub type IdentifierList<'a> = frost::keys::IdentifierList<'a, S>;
Expand Down
2 changes: 1 addition & 1 deletion frost-secp256k1/dkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The DKG module supports generating FROST key shares in a distributed manner,
without a trusted dealer.

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

The distributed key generation process has 3 parts, with 2 communication rounds
Expand Down
Loading