在构建底层运行时模块时,我可以访问哪些散列算法?
我是否可以导入其他散列算法,以便在衬底运行时模块中使用?
发布于 2019-05-28 19:26:18
在写这篇文章的时候,底层在core/sr-io机箱中提供了一个HashingApi特征,它提供了以下散列函数:
export_api! {
pub(crate) trait HashingApi {
/// Conduct a 256-bit Keccak hash.
fn keccak_256(data: &[u8]) -> [u8; 32] ;
/// Conduct a 128-bit Blake2 hash.
fn blake2_128(data: &[u8]) -> [u8; 16];
/// Conduct a 256-bit Blake2 hash.
fn blake2_256(data: &[u8]) -> [u8; 32];
/// Conduct four XX hashes to give a 256-bit result.
fn twox_256(data: &[u8]) -> [u8; 32];
/// Conduct two XX hashes to give a 128-bit result.
fn twox_128(data: &[u8]) -> [u8; 16];
/// Conduct two XX hashes to give a 64-bit result.
fn twox_64(data: &[u8]) -> [u8; 8];
}
}因为这些函数是为Runtime编写的,而Runtime必须构建为Wasm,所以它们必须在不使用标准Rust库(std)的情况下进行编译。
如果你想在你的底层运行时引入新的散列算法或任何新的库,你必须确保它也可以在没有std的情况下构建,但除此之外,我相信天空是有限的。
https://stackoverflow.com/questions/56341171
复制相似问题