givre 0.3.0

TSS Schnorr/EdDSA implementation based on FROST
Documentation
//! Round 1 - Commitment
//!
//! In the first round, signers [generate](commit) nonces and their corresponding commitments.
//!
//! For more details, refer to [parent module](super) docs, or [Section 5.1] of the draft
//!
//! [Section 5.1]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-15.html#name-round-one-commitment

use generic_ec::{Curve, Point, SecretScalar};
use rand_core::{CryptoRng, RngCore};

use crate::ciphersuite::{AdditionalEntropy, Ciphersuite};

/// Nonces generated by the signer that must be kept secret
#[derive(Clone)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Serialize, serde::Deserialize),
    serde(bound = "")
)]
pub struct SecretNonces<E: Curve> {
    /// Hiding nonce
    pub hiding_nonce: SecretScalar<E>,
    /// Binding nonce
    pub binding_nonce: SecretScalar<E>,
}

impl<E: Curve> SecretNonces<E> {
    /// Derives public commitments corresponding to the secret nonces
    pub fn public_commitments(&self) -> PublicCommitments<E> {
        PublicCommitments {
            hiding_comm: Point::generator() * &self.hiding_nonce,
            binding_comm: Point::generator() * &self.binding_nonce,
        }
    }
}

/// Commitments generated by the signer that need to be shared with other signers
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Serialize, serde::Deserialize),
    serde(bound = "")
)]
pub struct PublicCommitments<E: Curve> {
    /// Commitment to the hiding nonce
    pub hiding_comm: Point<E>,
    /// Commitment to the binding nonce
    pub binding_comm: Point<E>,
}

/// Generates nonces and their corresponding commitments
///
/// Nonces need to be kept in secret, while commitments has to be shared with other signers.
///
/// `additional_entropy` can be a key share or any other secret data that's known only to the signer
pub fn commit<C: Ciphersuite>(
    rng: &mut (impl RngCore + CryptoRng),
    additional_entropy: &impl AdditionalEntropy<C>,
) -> (SecretNonces<C::Curve>, PublicCommitments<C::Curve>) {
    let hiding_nonce = crate::ciphersuite::generate_nonce::<C>(rng, additional_entropy);
    let binding_nonce = crate::ciphersuite::generate_nonce::<C>(rng, additional_entropy);
    let nonces = SecretNonces {
        hiding_nonce,
        binding_nonce,
    };
    let comms = nonces.public_commitments();

    (nonces, comms)
}