Skip to content

Commit

Permalink
Add support for deprecated signatures (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harrm authored Sep 21, 2021
1 parent 5921a34 commit e3ae940
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name = "schnorrkel_crust"
crate-type = ["cdylib", "staticlib"]

[dependencies]
schnorrkel = { version="0.9.1" }
schnorrkel = { version="0.9.1", features = ["preaudit_deprecated"] }
ed25519-dalek = { version="1.0.0" }
rand_chacha = "0.2.2"
merlin = { version = "2.0", default-features = false }
Expand Down
26 changes: 24 additions & 2 deletions src/sr25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn create_from_seed(seed: &[u8]) -> Keypair {
fn create_from_pair(pair: &[u8]) -> Keypair {
match Keypair::from_bytes(pair) {
Ok(pair) => return pair,
Err(_) => panic!(format!("Provided pair is invalid: {:?}", pair)),
Err(_) => panic!("Provided pair is invalid: {:?}", pair),
}
}

Expand Down Expand Up @@ -249,6 +249,29 @@ pub unsafe extern "C" fn sr25519_sign(
);
}

/// Verify a message and its corresponding against a public key;
///
/// * signature_ptr: verify this signature
/// * message_ptr: Arbitrary message; input buffer of message_length bytes
/// * message_length: Message size
/// * public_ptr: verify with this public key; input buffer of SR25519_PUBLIC_SIZE bytes
///
/// * returned true if signature is valid, false otherwise
#[allow(unused_attributes)]
#[no_mangle]
pub unsafe extern "C" fn sr25519_verify_deprecated(
signature_ptr: *const u8,
message_ptr: *const u8,
message_length: c_ulong,
public_ptr: *const u8,
) -> bool {
let public = slice::from_raw_parts(public_ptr, SR25519_PUBLIC_SIZE as usize);
let signature = slice::from_raw_parts(signature_ptr, SR25519_SIGNATURE_SIZE as usize);
let message = slice::from_raw_parts(message_ptr, message_length as usize);

create_public(public).verify_simple_preaudit_deprecated(SIGNING_CTX, message, &signature).is_ok()
}

/// Verify a message and its corresponding against a public key;
///
/// * signature_ptr: verify this signature
Expand All @@ -272,7 +295,6 @@ pub unsafe extern "C" fn sr25519_verify(
Ok(signature) => signature,
Err(_) => return false,
};

create_public(public).verify_simple(SIGNING_CTX, message, &signature).is_ok()
}

Expand Down
2 changes: 2 additions & 0 deletions test/ed25519/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <array>

#include <gtest/gtest.h>
#include <gmock/gmock.h>

Expand Down

0 comments on commit e3ae940

Please sign in to comment.