Skip to content

Commit

Permalink
Introduce SIGNATURE_LENGTH constant
Browse files Browse the repository at this point in the history
Schnorr and ECDSA have different signature length.
  • Loading branch information
kseo committed Jul 10, 2018
1 parent 37a34b8 commit 418d472
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions key/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ use secp256k1::{key, Error as SecpError, Message as SecpMessage, RecoverableSign

use super::{public_to_address, Address, Error, Message, Private, Public, SECP256K1};

pub const ECDSA_SIGNATURE_LENGTH: usize = 65;

/// Signature encoded as RSV components
#[repr(C)]
pub struct ECDSASignature([u8; 65]);
Expand Down
3 changes: 2 additions & 1 deletion key/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use codechain_types::H256;
#[cfg(feature = "ecdsa")]
pub use ecdsa::{
recover_ecdsa as recover, sign_ecdsa as sign, verify_ecdsa as verify, verify_ecdsa_address as verify_address,
ECDSASignature as Signature,
ECDSASignature as Signature, ECDSA_SIGNATURE_LENGTH as SIGNATURE_LENGTH,
};
pub use error::Error;
pub use exchange::exchange;
Expand All @@ -56,6 +56,7 @@ pub use rustc_serialize::hex;
pub use schnorr::{
recover_schnorr as recover, sign_schnorr as sign, verify_schnorr as verify,
verify_schnorr_address as verify_address, SchnorrSignature as Signature,
SCHNORR_SIGNATURE_LENGTH as SIGNATURE_LENGTH,
};

/// 32 bytes long signable message
Expand Down
2 changes: 2 additions & 0 deletions key/src/schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use secp256k1::{key, schnorr, Error as SecpError, Message as SecpMessage};

use super::{public_to_address, Address, Error, Message, Private, Public, SECP256K1};

pub const SCHNORR_SIGNATURE_LENGTH: usize = 64;

pub struct SchnorrSignature([u8; 64]);

// manual implementation large arrays don't have trait impls by default.
Expand Down
4 changes: 2 additions & 2 deletions vm/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use ccrypto::{blake256, keccak256, ripemd160, sha256};
use ckey::{verify, Signature};
use ckey::{verify, Signature, SIGNATURE_LENGTH};
use ctypes::{H256, H520, Public};

use instruction::{is_valid_unlock_script, Instruction};
Expand Down Expand Up @@ -209,7 +209,7 @@ pub fn execute(
}
Instruction::ChkSig => {
let pubkey = Public::from_slice(stack.pop()?.assert_len(64)?.as_ref());
let signature = Signature::from(H520::from(stack.pop()?.assert_len(65)?.as_ref()));
let signature = Signature::from(H520::from(stack.pop()?.assert_len(SIGNATURE_LENGTH)?.as_ref()));
let result = match verify(&pubkey, &signature, &tx_hash) {
Ok(true) => 1,
_ => 0,
Expand Down

0 comments on commit 418d472

Please sign in to comment.