Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

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

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

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

atenjin opened this issue May 16, 2019 · 4 comments

Comments

@atenjin
Copy link
Contributor

atenjin 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!

@gui1117
Copy link
Contributor

gui1117 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

@atenjin
Copy link
Contributor Author

atenjin commented May 17, 2019

thank you very much!

@gui1117
Copy link
Contributor

gui1117 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 :-)

@gui1117 gui1117 closed this as completed May 17, 2019
@atenjin
Copy link
Contributor Author

atenjin 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants