Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ed25519 dalek rust #4752

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ Testing

# Autogenerated Build Prep artifacts
util/build_prep/*/prep.sh

cargo
cmake-build-debug/
rust/target
nano/lib/rsnano.hpp
build/
.cache/
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET

project(nano-node)

# Build the Rust part
# ---------------------
find_package(Corrosion REQUIRED)
corrosion_import_crate(MANIFEST_PATH rust/ffi/Cargo.toml)
# ---------------------

# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
Expand Down
4 changes: 3 additions & 1 deletion nano/crypto_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ target_link_libraries(ed25519 nano_ed25519)
add_library(crypto_lib random_pool.hpp random_pool.cpp random_pool_shuffle.hpp
secure_memory.hpp secure_memory.cpp)

target_link_libraries(crypto_lib blake2 ed25519 ${CRYPTOPP_LIBRARY})
target_link_libraries(crypto_lib blake2 ed25519 ${CRYPTOPP_LIBRARY} rsnano_ffi)

add_dependencies(crypto_lib cargo-build_rsnano_ffi)
5 changes: 3 additions & 2 deletions nano/lib/numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ nano::public_key nano::pub_key (nano::raw_key const & raw_key_a)
nano::signature nano::sign_message (nano::raw_key const & private_key, nano::public_key const & public_key, uint8_t const * data, size_t size)
{
nano::signature result;
ed25519_sign (data, size, private_key.bytes.data (), public_key.bytes.data (), result.bytes.data ());
if (rsnano::rsn_sign_message (private_key.bytes.data (), public_key.bytes.data (), data, size, result.bytes.data ()) != 0)
throw std::runtime_error ("could not sign message");
return result;
}

Expand All @@ -420,7 +421,7 @@ nano::signature nano::sign_message (nano::raw_key const & private_key, nano::pub

bool nano::validate_message (nano::public_key const & public_key, uint8_t const * data, size_t size, nano::signature const & signature)
{
return 0 != ed25519_sign_open (data, size, public_key.bytes.data (), signature.bytes.data ());
return rsnano::rsn_validate_message ((uint8_t (*)[32])public_key.bytes.data (), data, size, (uint8_t (*)[64])signature.bytes.data ());
}

bool nano::validate_message (nano::public_key const & public_key, nano::uint256_union const & message, nano::signature const & signature)
Expand Down
29 changes: 29 additions & 0 deletions nano/lib/rsnano.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef rs_nano_bindings_hpp
#define rs_nano_bindings_hpp

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

namespace rsnano {

extern "C" {

int32_t rsn_sign_message(const uint8_t *priv_key,
const uint8_t *pub_key,
const uint8_t *message,
uintptr_t len,
uint8_t *signature);

bool rsn_validate_message(const uint8_t (*pub_key)[32],
const uint8_t *message,
uintptr_t len,
const uint8_t (*signature)[64]);

} // extern "C"

} // namespace rsnano

#endif // rs_nano_bindings_hpp
6 changes: 6 additions & 0 deletions rust/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[alias]
xtask = "run --package xtask --"

[build]
target-dir = "../build/cargo"
#jobs = 4
Loading
Loading