From 506e7ea9c92422b2c509816f32e4c435073b2ec5 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Sat, 14 Jul 2018 22:58:08 +0000 Subject: [PATCH] Use ed25519_init() for faster failures --- src/sigverify.rs | 18 ++++++++++++++++++ src/sigverify_stage.rs | 1 + 2 files changed, 19 insertions(+) diff --git a/src/sigverify.rs b/src/sigverify.rs index ffe7698e09c8e0..1264626f142828 100644 --- a/src/sigverify.rs +++ b/src/sigverify.rs @@ -22,6 +22,8 @@ struct Elems { #[cfg(feature = "cuda")] #[link(name = "cuda_verify_ed25519")] extern "C" { + fn ed25519_init() -> bool; + fn ed25519_set_verbose(val: bool); fn ed25519_verify_many( vecs: *const Elems, num: u32, //number of vecs @@ -34,6 +36,11 @@ extern "C" { ) -> u32; } +#[cfg(not(feature = "cuda"))] +pub fn init() { + // stub +} + #[cfg(not(feature = "cuda"))] fn verify_packet(packet: &Packet) -> u8 { use ring::signature; @@ -88,6 +95,17 @@ pub fn ed25519_verify(batches: &Vec) -> Vec> { rv } +#[cfg(feature = "cuda")] +pub fn init() { + unsafe { + ed25519_set_verbose(true); + if !ed25519_init() { + panic!("ed25519_init() failed"); + } + ed25519_set_verbose(false); + } +} + #[cfg(feature = "cuda")] pub fn ed25519_verify(batches: &Vec) -> Vec> { use packet::PACKET_DATA_SIZE; diff --git a/src/sigverify_stage.rs b/src/sigverify_stage.rs index 57ffa020e76a9a..26cee3f42632bb 100644 --- a/src/sigverify_stage.rs +++ b/src/sigverify_stage.rs @@ -25,6 +25,7 @@ pub struct SigVerifyStage { impl SigVerifyStage { pub fn new(packet_receiver: Receiver) -> (Self, Receiver) { + sigverify::init(); let (verified_sender, verified_receiver) = channel(); let thread_hdls = Self::verifier_services(packet_receiver, verified_sender); (SigVerifyStage { thread_hdls }, verified_receiver)