Initial commit
This commit is contained in:
commit
1557a5a0df
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "ecrecover"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["John Newby <john@newby.org>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
c_vec = "1.3.3"
|
||||||
|
libc = "0.2.60"
|
||||||
|
parity-bytes = "0.1.0"
|
||||||
|
ethcore-builtin = { path = "../parity-ethereum/ethcore/builtin" }
|
36
src/lib.rs
Normal file
36
src/lib.rs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
extern crate c_vec;
|
||||||
|
extern crate ethcore_builtin;
|
||||||
|
extern crate libc;
|
||||||
|
extern crate parity_bytes;
|
||||||
|
|
||||||
|
use std::ffi::*;
|
||||||
|
use ethcore_builtin::EcRecover;
|
||||||
|
use crate::ethcore_builtin::Implementation;
|
||||||
|
use c_vec::{CVec};
|
||||||
|
use parity_bytes::BytesRef;
|
||||||
|
use std::ptr::copy_nonoverlapping;
|
||||||
|
|
||||||
|
const LENGTH: usize = 32;
|
||||||
|
#[repr(C)]
|
||||||
|
struct Buffer {
|
||||||
|
data: *mut [u8;LENGTH],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn ecrecover(input: *const libc::c_uchar, output: *mut libc::c_uchar) {
|
||||||
|
let ecrecover = EcRecover { };
|
||||||
|
let mut byte_ref = Vec::new();
|
||||||
|
ecrecover.execute(unsafe { std::slice::from_raw_parts(input as *const u8, LENGTH) },
|
||||||
|
&mut BytesRef::Flexible(&mut byte_ref));
|
||||||
|
let mut ptr: &mut[u8] = unsafe { std::slice::from_raw_parts_mut(output as *mut u8, LENGTH) };
|
||||||
|
ptr.copy_from_slice(byte_ref.as_slice());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
assert_eq!(2 + 2, 4);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user