Skip to content

Commit

Permalink
Make rfc-6979 nonce optional
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy committed Apr 15, 2024
1 parent 548ebaf commit 798b92f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ark-serialize = { version = "0.4.2", default-features = false }
rand_core = { version = "0.6.4", default-features = false, optional = true }
rand_chacha = { version = "0.3.1", default-features = false }
zeroize = { version = "1.7.0", default-features = false }
hmac = {version = "0.12.1", default-features = false }
hmac = {version = "0.12.1", default-features = false, optional = true }
digest = { version = "0.10.7", default-features = false }
# Curves
ark-secp256r1 = { version = "0.4.0", default-features = false, optional = true }
Expand Down Expand Up @@ -48,7 +48,10 @@ curves = [
"ed25519",
"bandersnatch",
]
secp256r1 = [ "ark-secp256r1" ]
secp256r1 = [
"ark-secp256r1",
"rfc-6979",
]
ed25519 = [ "ark-ed25519" ]
bandersnatch = [ "ark-ed-on-bls12-381-bandersnatch" ]
parallel = [
Expand All @@ -63,3 +66,4 @@ ring = [
"ark-bls12-381/curve",
"merlin",
]
rfc-6979 = [ "hmac" ]
9 changes: 6 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{AffinePoint, ScalarField, Suite};

use ark_ff::PrimeField;
use digest::{core_api::BlockSizeUser, Digest};
use digest::Digest;

#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
Expand Down Expand Up @@ -34,8 +35,9 @@ pub(crate) fn hash<H: Digest>(data: &[u8]) -> digest::Output<H> {
}

/// Generic HMAC wrapper.
#[cfg(feature = "rfc-6979")]
#[inline(always)]
pub(crate) fn hmac<H: Digest + BlockSizeUser>(sk: &[u8], data: &[u8]) -> Vec<u8> {
pub(crate) fn hmac<H: Digest + digest::core_api::BlockSizeUser>(sk: &[u8], data: &[u8]) -> Vec<u8> {
use hmac::{Mac, SimpleHmac};
SimpleHmac::<H>::new_from_slice(sk)
.expect("HMAC can take key of any size")
Expand Down Expand Up @@ -128,9 +130,10 @@ pub fn nonce_rfc_8032<S: Suite>(sk: &ScalarField<S>, input: &AffinePoint<S>) ->
///
/// The algorithm generate the nonce value in a deterministic
/// pseudorandom fashion.
#[cfg(feature = "rfc-6979")]
pub fn nonce_rfc_6979<S: Suite>(sk: &ScalarField<S>, input: &AffinePoint<S>) -> ScalarField<S>
where
S::Hasher: BlockSizeUser,
S::Hasher: digest::core_api::BlockSizeUser,
{
let raw = encode_point::<S>(input);
let h1 = hash::<S::Hasher>(&raw);
Expand Down

0 comments on commit 798b92f

Please sign in to comment.