Skip to content

Commit

Permalink
Merge pull request #58 from trilitech/emturner@p256-sig
Browse files Browse the repository at this point in the history
crypto: add `secp256k1`, `p256` sigs
  • Loading branch information
emturner authored Dec 18, 2023
2 parents 20b9b00 + 03a1693 commit 2347939
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
38 changes: 32 additions & 6 deletions crypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ mod prefix_bytes {
pub const SEED_ED25519: [u8; 4] = [13, 15, 58, 7];
pub const SECRET_KEY_ED25519: [u8; 4] = [43, 246, 78, 7];
pub const SECRET_KEY_BLS: [u8; 4] = [3, 150, 192, 40];
pub const ED22519_SIGNATURE_HASH: [u8; 5] = [9, 245, 205, 134, 18];
pub const GENERIC_SIGNATURE_HASH: [u8; 3] = [4, 130, 43];
pub const ED22519_SIGNATURE_HASH: [u8; 5] = [9, 245, 205, 134, 18];
pub const SECP256K1_SIGNATURE_HASH: [u8; 5] = [13, 115, 101, 19, 63];
pub const P256_SIGNATURE_HASH: [u8; 4] = [54, 240, 44, 52];
pub const BLS_SIGNATURE_HASH: [u8; 4] = [40, 171, 64, 207];
pub const NONCE_HASH: [u8; 3] = [69, 220, 169];
pub const OPERATION_LIST_HASH: [u8; 2] = [133, 233];
Expand Down Expand Up @@ -306,8 +308,10 @@ define_hash!(PublicKeyBls);
define_hash!(SeedEd25519);
define_hash!(SecretKeyEd25519);
define_hash!(SecretKeyBls);
define_hash!(Ed25519Signature);
define_hash!(Signature);
define_hash!(Ed25519Signature);
define_hash!(Secp256k1Signature);
define_hash!(P256Signature);
define_hash!(BlsSignature);
define_hash!(NonceHash);
define_hash!(OperationListHash);
Expand Down Expand Up @@ -362,10 +366,14 @@ pub enum HashType {
SecretKeyEd25519,
// "\003\150\192\040" (* BLsk(54) *)
SecretKeyBls,
// "\009\245\205\134\018" (* edsig(99) *)
Ed25519Signature,
// "\004\130\043" (* sig(96) *)
Signature,
// "\009\245\205\134\018" (* edsig(99) *)
Ed25519Signature,
// "\013\115\101\019\063" (* spsig1(99) *)
Secp256k1Signature,
// "\054\240\044\052" (* p2sig(98) *)
P256Signature,
// "\040\171\064\207" (* BLsig(142) *)
BlsSignature,
// "\069\220\169" (* nce(53) *)
Expand Down Expand Up @@ -404,8 +412,10 @@ impl HashType {
HashType::SeedEd25519 => &SEED_ED25519,
HashType::SecretKeyEd25519 => &SECRET_KEY_ED25519,
HashType::SecretKeyBls => &SECRET_KEY_BLS,
HashType::Ed25519Signature => &ED22519_SIGNATURE_HASH,
HashType::Signature => &GENERIC_SIGNATURE_HASH,
HashType::Ed25519Signature => &ED22519_SIGNATURE_HASH,
HashType::Secp256k1Signature => &SECP256K1_SIGNATURE_HASH,
HashType::P256Signature => &P256_SIGNATURE_HASH,
HashType::BlsSignature => &BLS_SIGNATURE_HASH,
HashType::NonceHash => &NONCE_HASH,
HashType::OperationListHash => &OPERATION_LIST_HASH,
Expand Down Expand Up @@ -439,7 +449,11 @@ impl HashType {
HashType::PublicKeySecp256k1 | HashType::PublicKeyP256 => 33,
HashType::SeedEd25519 | HashType::SecretKeyBls => 32,
HashType::PublicKeyBls => 48,
HashType::SecretKeyEd25519 | HashType::Ed25519Signature | HashType::Signature => 64,
HashType::SecretKeyEd25519
| HashType::Ed25519Signature
| HashType::Secp256k1Signature
| HashType::P256Signature
| HashType::Signature => 64,
HashType::BlsSignature => 96,
}
}
Expand Down Expand Up @@ -1273,6 +1287,18 @@ mod tests {

test!(ed25519_sig, Ed25519Signature, ["edsigtXomBKi5CTRf5cjATJWSyaRvhfYNHqSUGrn4SdbYRcGwQrUGjzEfQDTuqHhuA8b2d8NarZjz8TRf65WkpQmo423BtomS8Q"]);

test!(
sig_secp256k1,
Secp256k1Signature,
["spsig1PPUFZucuAQybs5wsqsNQ68QNgFaBnVKMFaoZZfi1BtNnuCAWnmL9wVy5HfHkR6AeodjVGxpBVVSYcJKyMURn6K1yknYLm"]
);

test!(
sig_p256,
P256Signature,
["p2sigRmXDp38VNVaEQH28LYukfLPn8QB5hPEberhvQrrUpRscDZJrrApbRh2u46PTVTwKXjxTLKNN9dyLhPQU6U6jWPGxe4d9v"]
);

test!(generic_sig, Signature, ["sigNCaj9CnmD94eZH9C7aPPqBbVCJF72fYmCFAXqEbWfqE633WNFWYQJFnDUFgRUQXR8fQ5tKSfJeTe6UAi75eTzzQf7AEc1"]);

test!(
Expand Down
2 changes: 2 additions & 0 deletions tezos-encoding/src/enc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ encode_hash!(crypto::hash::SecretKeyEd25519);
encode_hash!(crypto::hash::SecretKeyBls);
encode_hash!(crypto::hash::Signature);
encode_hash!(crypto::hash::Ed25519Signature);
encode_hash!(crypto::hash::Secp256k1Signature);
encode_hash!(crypto::hash::P256Signature);
encode_hash!(crypto::hash::BlsSignature);
encode_hash!(crypto::hash::NonceHash);
encode_hash!(crypto::hash::SmartRollupHash);
Expand Down
2 changes: 2 additions & 0 deletions tezos-encoding/src/nom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ hash_nom_reader!(SecretKeyEd25519);
hash_nom_reader!(SecretKeyBls);
hash_nom_reader!(Signature);
hash_nom_reader!(Ed25519Signature);
hash_nom_reader!(Secp256k1Signature);
hash_nom_reader!(P256Signature);
hash_nom_reader!(BlsSignature);
hash_nom_reader!(NonceHash);
hash_nom_reader!(SmartRollupHash);
Expand Down

0 comments on commit 2347939

Please sign in to comment.