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

question: how to import `blake2_512` into runtime for wasm #2605

Closed
JKingdom opened this issue May 16, 2019 · 4 comments

Comments

@JKingdom
Copy link
Contributor

commented May 16, 2019

sr_io just import Blake2Hasher in to wasm, which is blake2_256
But in our project, we need blake2_512 to do the ss58 check for generating checksum
I have read the file core/primitives/src/hashing.rs

pub mod blake2 {
	use super::{Hasher, Hash256StdHasher, H256};
	#[cfg(feature = "std")]
	use crate::hashing::blake2_256;

	#[cfg(not(feature = "std"))]
	extern "C" {
		fn ext_blake2_256(data: *const u8, len: u32, out: *mut u8);
	}
	#[cfg(not(feature = "std"))]
	fn blake2_256(data: &[u8]) -> [u8; 32] {
		let mut result: [u8; 32] = Default::default();
		unsafe {
			ext_blake2_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr());
		}
		result
	}

	/// Concrete implementation of Hasher using Blake2b 256-bit hashes
	#[derive(Debug)]
	pub struct Blake2Hasher;

	impl Hasher for Blake2Hasher {
		type Out = H256;
		type StdHasher = Hash256StdHasher;
		const LENGTH: usize = 32;
		fn hash(x: &[u8]) -> Self::Out {
			blake2_256(x).into()
		}
	}
}

and I just find for wasm like

	#[cfg(not(feature = "std"))]
	extern "C" {
		fn ext_blake2_256(data: *const u8, len: u32, out: *mut u8);
	}

But I don't know where is ext_blake2_256 impl?
And how the implementation link to extern "C"

So could you tell me how can I impl std and no_std blake2_512 for our project?
thank you very much!

@thiolliere

This comment has been minimized.

Copy link
Contributor

commented May 16, 2019

ext_blake2_256 in implemented in ./core/executor/src/wasm_executor.rs:523
to implement blake2_512 for std and no_std in a similar way to blake2_256, you need to modifie sr-io/with_std, sr-io/without_std and core/executor/src/wasm_executor

@JKingdom

This comment has been minimized.

Copy link
Contributor Author

commented May 17, 2019

thank you very much!

@thiolliere

This comment has been minimized.

Copy link
Contributor

commented May 17, 2019

is the question solved ? you can open it again if you need more details or if you want it to be implemented in substrate. But currently it seems question is anwsered :-)

@thiolliere thiolliere closed this May 17, 2019

@JKingdom

This comment has been minimized.

Copy link
Contributor Author

commented May 17, 2019

is the question solved ? you can open it again if you need more details or if you want it to be implemented in substrate. But currently it seems question is anwsered :-)

thank you very much again for I have implemented it for our project! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.