Skip to content

Commit

Permalink
Add option to sign with extra nonce
Browse files Browse the repository at this point in the history
Add option to create an adaptor signature by signing with an extra
nonce
  • Loading branch information
GeneFerneau committed May 20, 2021
1 parent cd90352 commit 2af953e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion core/src/core/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ impl TxKernel {
&sig,
&self.msg_to_sign()?,
None,
None,
&pubkey,
Some(&pubkey),
false,
Expand Down Expand Up @@ -2400,7 +2401,7 @@ mod test {
let pubkey = excess.to_pubkey(&keychain.secp()).unwrap();

let excess_sig =
aggsig::sign_single(&keychain.secp(), &msg, &skey, None, Some(&pubkey)).unwrap();
aggsig::sign_single(&keychain.secp(), &msg, &skey, None, None, Some(&pubkey)).unwrap();

kernel.excess = excess;
kernel.excess_sig = excess_sig;
Expand Down
31 changes: 26 additions & 5 deletions core/src/libtx/aggsig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub fn calculate_partial_sig(
secp: &Secp256k1,
sec_key: &SecretKey,
sec_nonce: &SecretKey,
sec_nonce_extra: Option<&SecretKey>,
nonce_sum: &PublicKey,
pubkey_sum: Option<&PublicKey>,
msg: &secp::Message,
Expand All @@ -106,7 +107,7 @@ pub fn calculate_partial_sig(
&msg,
sec_key,
Some(sec_nonce),
None,
sec_nonce_extra,
Some(nonce_sum),
pubkey_sum,
Some(nonce_sum),
Expand Down Expand Up @@ -179,6 +180,7 @@ pub fn verify_partial_sig(
secp: &Secp256k1,
sig: &Signature,
pub_nonce_sum: &PublicKey,
pub_nonce_extra: Option<&PublicKey>,
pubkey: &PublicKey,
pubkey_sum: Option<&PublicKey>,
msg: &secp::Message,
Expand All @@ -188,6 +190,7 @@ pub fn verify_partial_sig(
sig,
&msg,
Some(&pub_nonce_sum),
pub_nonce_extra,
pubkey,
pubkey_sum,
true,
Expand Down Expand Up @@ -323,7 +326,7 @@ pub fn verify_single_from_commit(
commit: &Commitment,
) -> Result<(), Error> {
let pubkey = commit.to_pubkey(secp)?;
if !verify_single(secp, sig, msg, None, &pubkey, Some(&pubkey), false) {
if !verify_single(secp, sig, msg, None, None, &pubkey, Some(&pubkey), false) {
return Err(ErrorKind::Signature("Signature validation error".to_string()).into());
}
Ok(())
Expand Down Expand Up @@ -391,7 +394,7 @@ pub fn verify_completed_sig(
pubkey_sum: Option<&PublicKey>,
msg: &secp::Message,
) -> Result<(), Error> {
if !verify_single(secp, sig, msg, None, pubkey, pubkey_sum, true) {
if !verify_single(secp, sig, msg, None, None, pubkey, pubkey_sum, true) {
return Err(ErrorKind::Signature("Signature validation error".to_string()).into());
}
Ok(())
Expand All @@ -414,9 +417,19 @@ pub fn sign_single(
msg: &Message,
skey: &SecretKey,
snonce: Option<&SecretKey>,
snonce_extra: Option<&SecretKey>,
pubkey_sum: Option<&PublicKey>,
) -> Result<Signature, Error> {
let sig = aggsig::sign_single(secp, &msg, skey, snonce, None, None, pubkey_sum, None)?;
let sig = aggsig::sign_single(
secp,
&msg,
skey,
snonce,
snonce_extra,
None,
pubkey_sum,
None,
)?;
Ok(sig)
}

Expand All @@ -426,12 +439,20 @@ pub fn verify_single(
sig: &Signature,
msg: &Message,
pubnonce: Option<&PublicKey>,
pubnonce_extra: Option<&PublicKey>,
pubkey: &PublicKey,
pubkey_sum: Option<&PublicKey>,
is_partial: bool,
) -> bool {
aggsig::verify_single(
secp, sig, msg, pubnonce, pubkey, pubkey_sum, None, is_partial,
secp,
sig,
msg,
pubnonce,
pubkey,
pubkey_sum,
pubnonce_extra,
is_partial,
)
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/libtx/secp_ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ mod test {
let mut msg = [0u8; 32];
thread_rng().fill(&mut msg);
let msg = Message::from_slice(&msg).unwrap();
let sig = aggsig::sign_single(&secp, &msg, &sk, None, None).unwrap();
let sig = aggsig::sign_single(&secp, &msg, &sk, None, None, None).unwrap();
let mut commit = [0u8; 33];
commit[0] = 0x09;
thread_rng().fill(&mut commit[1..]);
Expand Down

0 comments on commit 2af953e

Please sign in to comment.