Cleanup constants
This commit is contained in:
parent
81e2b36d38
commit
6fd32fe850
35
src/ecdsa.rs
35
src/ecdsa.rs
|
@ -1,27 +1,8 @@
|
||||||
// Cuda-only imports
|
use packet::{Packet, SharedPackets};
|
||||||
#[cfg(feature = "cuda")]
|
use transaction::{PUB_KEY_OFFSET, SIGNED_DATA_OFFSET, SIG_OFFSET};
|
||||||
use packet::PACKET_DATA_SIZE;
|
|
||||||
#[cfg(feature = "cuda")]
|
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
|
||||||
// Non-cuda imports
|
|
||||||
#[cfg(not(feature = "cuda"))]
|
|
||||||
use rayon::prelude::*;
|
|
||||||
#[cfg(not(feature = "cuda"))]
|
|
||||||
use ring::signature;
|
|
||||||
#[cfg(not(feature = "cuda"))]
|
|
||||||
use untrusted;
|
|
||||||
|
|
||||||
// Shared imports
|
|
||||||
use packet::{Packet, SharedPackets};
|
|
||||||
|
|
||||||
pub const TX_OFFSET: usize = 4;
|
pub const TX_OFFSET: usize = 4;
|
||||||
pub const SIGNED_DATA_OFFSET: usize = 112;
|
|
||||||
pub const SIG_OFFSET: usize = 8;
|
|
||||||
pub const PUB_KEY_OFFSET: usize = 80;
|
|
||||||
|
|
||||||
pub const SIG_SIZE: usize = 64;
|
|
||||||
pub const PUB_KEY_SIZE: usize = 32;
|
|
||||||
|
|
||||||
#[cfg(feature = "cuda")]
|
#[cfg(feature = "cuda")]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -47,11 +28,15 @@ extern "C" {
|
||||||
|
|
||||||
#[cfg(not(feature = "cuda"))]
|
#[cfg(not(feature = "cuda"))]
|
||||||
fn verify_packet(packet: &Packet) -> u8 {
|
fn verify_packet(packet: &Packet) -> u8 {
|
||||||
|
use ring::signature;
|
||||||
|
use untrusted;
|
||||||
|
use signature::{PublicKey, Signature};
|
||||||
|
|
||||||
let msg_start = TX_OFFSET + SIGNED_DATA_OFFSET;
|
let msg_start = TX_OFFSET + SIGNED_DATA_OFFSET;
|
||||||
let sig_start = TX_OFFSET + SIG_OFFSET;
|
let sig_start = TX_OFFSET + SIG_OFFSET;
|
||||||
let sig_end = sig_start + SIG_SIZE;
|
let sig_end = sig_start + size_of::<Signature>();
|
||||||
let pub_key_start = TX_OFFSET + PUB_KEY_OFFSET;
|
let pub_key_start = TX_OFFSET + PUB_KEY_OFFSET;
|
||||||
let pub_key_end = pub_key_start + PUB_KEY_SIZE;
|
let pub_key_end = pub_key_start + size_of::<PublicKey>();
|
||||||
|
|
||||||
if packet.meta.size <= msg_start {
|
if packet.meta.size <= msg_start {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -68,6 +53,8 @@ fn verify_packet(packet: &Packet) -> u8 {
|
||||||
|
|
||||||
#[cfg(not(feature = "cuda"))]
|
#[cfg(not(feature = "cuda"))]
|
||||||
pub fn ed25519_verify(batches: &Vec<SharedPackets>) -> Vec<Vec<u8>> {
|
pub fn ed25519_verify(batches: &Vec<SharedPackets>) -> Vec<Vec<u8>> {
|
||||||
|
use rayon::prelude::*;
|
||||||
|
|
||||||
batches
|
batches
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
|
@ -83,6 +70,8 @@ pub fn ed25519_verify(batches: &Vec<SharedPackets>) -> Vec<Vec<u8>> {
|
||||||
|
|
||||||
#[cfg(feature = "cuda")]
|
#[cfg(feature = "cuda")]
|
||||||
pub fn ed25519_verify(batches: &Vec<SharedPackets>) -> Vec<Vec<u8>> {
|
pub fn ed25519_verify(batches: &Vec<SharedPackets>) -> Vec<Vec<u8>> {
|
||||||
|
use packet::PACKET_DATA_SIZE;
|
||||||
|
|
||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
let mut elems = Vec::new();
|
let mut elems = Vec::new();
|
||||||
let mut locks = Vec::new();
|
let mut locks = Vec::new();
|
||||||
|
|
|
@ -7,6 +7,10 @@ use plan::{Condition, Payment, Plan};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use signature::{KeyPair, KeyPairUtil, PublicKey, Signature, SignatureUtil};
|
use signature::{KeyPair, KeyPairUtil, PublicKey, Signature, SignatureUtil};
|
||||||
|
|
||||||
|
pub const SIGNED_DATA_OFFSET: usize = 112;
|
||||||
|
pub const SIG_OFFSET: usize = 8;
|
||||||
|
pub const PUB_KEY_OFFSET: usize = 80;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct TransactionData {
|
pub struct TransactionData {
|
||||||
pub tokens: i64,
|
pub tokens: i64,
|
||||||
|
@ -125,7 +129,6 @@ pub fn verify_transactions(transactions: &[Transaction]) -> bool {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use bincode::{deserialize, serialize};
|
use bincode::{deserialize, serialize};
|
||||||
use ecdsa;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_claim() {
|
fn test_claim() {
|
||||||
|
@ -196,9 +199,9 @@ mod tests {
|
||||||
let tr = test_tx();
|
let tr = test_tx();
|
||||||
let sign_data = tr.get_sign_data();
|
let sign_data = tr.get_sign_data();
|
||||||
let tx = serialize(&tr).unwrap();
|
let tx = serialize(&tr).unwrap();
|
||||||
assert_matches!(memfind(&tx, &sign_data), Some(ecdsa::SIGNED_DATA_OFFSET));
|
assert_matches!(memfind(&tx, &sign_data), Some(SIGNED_DATA_OFFSET));
|
||||||
assert_matches!(memfind(&tx, &tr.sig), Some(ecdsa::SIG_OFFSET));
|
assert_matches!(memfind(&tx, &tr.sig), Some(SIG_OFFSET));
|
||||||
assert_matches!(memfind(&tx, &tr.from), Some(ecdsa::PUB_KEY_OFFSET));
|
assert_matches!(memfind(&tx, &tr.from), Some(PUB_KEY_OFFSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue