feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
[package]
|
||||
name = "pezsp-crypto-hashing"
|
||||
version = "0.1.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license = "Apache-2.0"
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
description = "Hashing primitives."
|
||||
documentation = "https://docs.rs/pezsp-crypto-hashing"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
||||
[[bench]]
|
||||
name = "bench"
|
||||
harness = false
|
||||
|
||||
[dependencies]
|
||||
blake2b_simd = { workspace = true }
|
||||
byteorder = { workspace = true }
|
||||
digest = { workspace = true }
|
||||
sha2 = { workspace = true }
|
||||
sha3 = { workspace = true }
|
||||
twox-hash = { features = ["digest_0_10"], workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { workspace = true, default-features = true }
|
||||
pezsp-crypto-hashing-proc-macro = { workspace = true, default-features = true }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"blake2b_simd/std",
|
||||
"byteorder/std",
|
||||
"digest/std",
|
||||
"sha2/std",
|
||||
"sha3/std",
|
||||
"twox-hash/std",
|
||||
]
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Bencher, BenchmarkId, Criterion};
|
||||
|
||||
// Min 32 bytes buffer
|
||||
const MIN_EXP: usize = 5;
|
||||
// Max 1 MB buffer
|
||||
const MAX_EXP: usize = 20;
|
||||
|
||||
fn bench_blake2_128(b: &mut Bencher, buf: &Vec<u8>) {
|
||||
b.iter(|| {
|
||||
let _a = pezsp_crypto_hashing::blake2_128(black_box(buf));
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_twox_128(b: &mut Bencher, buf: &Vec<u8>) {
|
||||
b.iter(|| {
|
||||
let _a = pezsp_crypto_hashing::twox_128(black_box(buf));
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_blake2_256(b: &mut Bencher, buf: &Vec<u8>) {
|
||||
b.iter(|| {
|
||||
let _a = pezsp_crypto_hashing::blake2_256(black_box(buf));
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_twox_256(b: &mut Bencher, buf: &Vec<u8>) {
|
||||
b.iter(|| {
|
||||
let _a = pezsp_crypto_hashing::twox_256(black_box(buf));
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_sha_256(b: &mut Bencher, buf: &Vec<u8>) {
|
||||
b.iter(|| {
|
||||
let _a = pezsp_crypto_hashing::sha2_256(black_box(buf));
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_keccak_256(b: &mut Bencher, buf: &Vec<u8>) {
|
||||
b.iter(|| {
|
||||
let _a = pezsp_crypto_hashing::keccak_256(black_box(buf));
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_hash(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("hashing-128");
|
||||
let buf = vec![0u8; 1 << MAX_EXP];
|
||||
|
||||
for i in MIN_EXP..=MAX_EXP {
|
||||
let size = 1 << i;
|
||||
group.bench_with_input(BenchmarkId::new("blake2-128", size), &buf, bench_blake2_128);
|
||||
group.bench_with_input(BenchmarkId::new("twox-128", size), &buf, bench_twox_128);
|
||||
}
|
||||
group.finish();
|
||||
|
||||
let mut group = c.benchmark_group("hashing-256");
|
||||
for i in MIN_EXP..=MAX_EXP {
|
||||
let size = 1 << i;
|
||||
group.bench_with_input(BenchmarkId::new("blake2-256", size), &buf, bench_blake2_256);
|
||||
group.bench_with_input(BenchmarkId::new("twox-256", size), &buf, bench_twox_256);
|
||||
group.bench_with_input(BenchmarkId::new("sha-256", size), &buf, bench_sha_256);
|
||||
group.bench_with_input(BenchmarkId::new("keccak-256", size), &buf, bench_keccak_256);
|
||||
}
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_hash);
|
||||
criterion_main!(benches);
|
||||
@@ -0,0 +1,24 @@
|
||||
[package]
|
||||
name = "pezsp-crypto-hashing-proc-macro"
|
||||
version = "0.1.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license = "Apache-2.0"
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
description = "Procedural macros for calculating static hashes."
|
||||
documentation = "https://docs.rs/pezsp-crypto-hashing-proc-macro"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
quote = { workspace = true }
|
||||
pezsp-crypto-hashing = { workspace = true }
|
||||
syn = { features = ["full", "parsing"], workspace = true }
|
||||
@@ -0,0 +1,124 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use quote::quote;
|
||||
use syn::parse::{Parse, ParseStream};
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
pub(super) struct InputBytes(pub Vec<u8>);
|
||||
|
||||
pub(super) struct MultipleInputBytes(pub Vec<Vec<u8>>);
|
||||
|
||||
impl MultipleInputBytes {
|
||||
pub(super) fn concatenated(mut self) -> Vec<u8> {
|
||||
if self.0.is_empty() {
|
||||
Vec::new()
|
||||
} else {
|
||||
let mut result = core::mem::take(&mut self.0[0]);
|
||||
for other in self.0[1..].iter_mut() {
|
||||
result.append(other);
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for InputBytes {
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
match syn::ExprArray::parse(input) {
|
||||
Ok(array) => {
|
||||
let mut bytes = Vec::<u8>::new();
|
||||
for expr in array.elems.iter() {
|
||||
match expr {
|
||||
syn::Expr::Lit(lit) => match &lit.lit {
|
||||
syn::Lit::Int(b) => bytes.push(b.base10_parse()?),
|
||||
syn::Lit::Byte(b) => bytes.push(b.value()),
|
||||
_ =>
|
||||
return Err(syn::Error::new(
|
||||
input.span(),
|
||||
"Expected array of u8 elements.".to_string(),
|
||||
)),
|
||||
},
|
||||
_ =>
|
||||
return Err(syn::Error::new(
|
||||
input.span(),
|
||||
"Expected array of u8 elements.".to_string(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
return Ok(InputBytes(bytes));
|
||||
},
|
||||
Err(_e) => (),
|
||||
}
|
||||
// use rust names as a vec of their utf8 bytecode.
|
||||
match syn::Ident::parse(input) {
|
||||
Ok(ident) => return Ok(InputBytes(ident.to_string().as_bytes().to_vec())),
|
||||
Err(_e) => (),
|
||||
}
|
||||
Ok(InputBytes(syn::LitByteStr::parse(input)?.value()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for MultipleInputBytes {
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
let elts =
|
||||
syn::punctuated::Punctuated::<InputBytes, syn::token::Comma>::parse_terminated(input)?;
|
||||
Ok(MultipleInputBytes(elts.into_iter().map(|elt| elt.0).collect()))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn twox_64(bytes: Vec<u8>) -> TokenStream {
|
||||
bytes_to_array(pezsp_crypto_hashing::twox_64(bytes.as_slice()))
|
||||
}
|
||||
|
||||
pub(super) fn twox_128(bytes: Vec<u8>) -> TokenStream {
|
||||
bytes_to_array(pezsp_crypto_hashing::twox_128(bytes.as_slice()))
|
||||
}
|
||||
|
||||
pub(super) fn blake2b_512(bytes: Vec<u8>) -> TokenStream {
|
||||
bytes_to_array(pezsp_crypto_hashing::blake2_512(bytes.as_slice()))
|
||||
}
|
||||
|
||||
pub(super) fn blake2b_256(bytes: Vec<u8>) -> TokenStream {
|
||||
bytes_to_array(pezsp_crypto_hashing::blake2_256(bytes.as_slice()))
|
||||
}
|
||||
|
||||
pub(super) fn blake2b_64(bytes: Vec<u8>) -> TokenStream {
|
||||
bytes_to_array(pezsp_crypto_hashing::blake2_64(bytes.as_slice()))
|
||||
}
|
||||
|
||||
pub(super) fn keccak_256(bytes: Vec<u8>) -> TokenStream {
|
||||
bytes_to_array(pezsp_crypto_hashing::keccak_256(bytes.as_slice()))
|
||||
}
|
||||
|
||||
pub(super) fn keccak_512(bytes: Vec<u8>) -> TokenStream {
|
||||
bytes_to_array(pezsp_crypto_hashing::keccak_512(bytes.as_slice()))
|
||||
}
|
||||
|
||||
pub(super) fn sha2_256(bytes: Vec<u8>) -> TokenStream {
|
||||
bytes_to_array(pezsp_crypto_hashing::sha2_256(bytes.as_slice()))
|
||||
}
|
||||
|
||||
fn bytes_to_array(bytes: impl IntoIterator<Item = u8>) -> TokenStream {
|
||||
let bytes = bytes.into_iter();
|
||||
|
||||
quote!(
|
||||
[ #( #bytes ),* ]
|
||||
)
|
||||
.into()
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Macros to calculate constant hash bytes result.
|
||||
//!
|
||||
//! Macros from this crate does apply a specific hash function on input.
|
||||
//! Input can be literal byte array as `b"content"` or array of bytes
|
||||
//! as `[1, 2, 3]`.
|
||||
//! Rust identifier can also be use, in this case we use their utf8 string
|
||||
//! byte representation, for instance if the ident is `MyStruct`, then
|
||||
//! `b"MyStruct"` will be hashed.
|
||||
//! If multiple arguments comma separated are passed, they are concatenated
|
||||
//! then hashed.
|
||||
//!
|
||||
//! Examples:
|
||||
//!
|
||||
//! ```rust
|
||||
//! assert_eq!(
|
||||
//! pezsp_crypto_hashing_proc_macro::blake2b_256!(b"test"),
|
||||
//! pezsp_crypto_hashing::blake2_256(b"test"),
|
||||
//! );
|
||||
//! assert_eq!(
|
||||
//! pezsp_crypto_hashing_proc_macro::blake2b_256!([1u8]),
|
||||
//! pezsp_crypto_hashing::blake2_256(&[1u8]),
|
||||
//! );
|
||||
//! assert_eq!(
|
||||
//! pezsp_crypto_hashing_proc_macro::blake2b_256!([1, 2, 3]),
|
||||
//! pezsp_crypto_hashing::blake2_256(&[1, 2, 3]),
|
||||
//! );
|
||||
//! assert_eq!(
|
||||
//! pezsp_crypto_hashing_proc_macro::blake2b_256!(identifier),
|
||||
//! pezsp_crypto_hashing::blake2_256(b"identifier"),
|
||||
//! );
|
||||
//! assert_eq!(
|
||||
//! pezsp_crypto_hashing_proc_macro::blake2b_256!(identifier, b"/string"),
|
||||
//! pezsp_crypto_hashing::blake2_256(b"identifier/string"),
|
||||
//! );
|
||||
//! ```
|
||||
|
||||
mod impls;
|
||||
|
||||
use impls::MultipleInputBytes;
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
/// Process a Blake2 64-bit hash of bytes parameter outputs a `[u8; 8]`.
|
||||
/// Multiple inputs are concatenated before hashing.
|
||||
/// Input can be identifier (name of identifier as bytes is used), byte string or
|
||||
/// array of bytes.
|
||||
#[proc_macro]
|
||||
pub fn blake2b_64(input: TokenStream) -> TokenStream {
|
||||
impls::blake2b_64(syn::parse_macro_input!(input as MultipleInputBytes).concatenated())
|
||||
}
|
||||
|
||||
/// Apply a Blake2 256-bit hash of bytes parameter, outputs a `[u8; 32]`.
|
||||
/// Multiple inputs are concatenated before hashing.
|
||||
/// Input can be identifier (name of identifier as bytes is used), byte string or
|
||||
/// array of bytes.
|
||||
#[proc_macro]
|
||||
pub fn blake2b_256(input: TokenStream) -> TokenStream {
|
||||
impls::blake2b_256(syn::parse_macro_input!(input as MultipleInputBytes).concatenated())
|
||||
}
|
||||
|
||||
/// Apply a Blake2 512-bit hash of bytes parameter, outputs a `[u8; 64]`.
|
||||
/// Multiple inputs are concatenated before hashing.
|
||||
/// Input can be identifier (name of identifier as bytes is used), byte string or
|
||||
/// array of bytes.
|
||||
#[proc_macro]
|
||||
pub fn blake2b_512(input: TokenStream) -> TokenStream {
|
||||
impls::blake2b_512(syn::parse_macro_input!(input as MultipleInputBytes).concatenated())
|
||||
}
|
||||
|
||||
/// Apply a XX 64-bit hash on its bytes parameter, outputs a `[u8; 8]`.
|
||||
/// Multiple inputs are concatenated before hashing.
|
||||
/// Input can be identifier (name of identifier as bytes is used), byte string or
|
||||
/// array of bytes.
|
||||
#[proc_macro]
|
||||
pub fn twox_64(input: TokenStream) -> TokenStream {
|
||||
impls::twox_64(syn::parse_macro_input!(input as MultipleInputBytes).concatenated())
|
||||
}
|
||||
|
||||
/// Apply a XX 128-bit hash on its bytes parameter, outputs a `[u8; 16]`.
|
||||
/// Multiple inputs are concatenated before hashing.
|
||||
/// Input can be identifier (name of identifier as bytes is used), byte string or
|
||||
/// array of bytes.
|
||||
#[proc_macro]
|
||||
pub fn twox_128(input: TokenStream) -> TokenStream {
|
||||
impls::twox_128(syn::parse_macro_input!(input as MultipleInputBytes).concatenated())
|
||||
}
|
||||
|
||||
/// Apply a keccak 256-bit hash on its bytes parameter, outputs a `[u8; 32]`.
|
||||
/// Multiple inputs are concatenated before hashing.
|
||||
/// Input can be identifier (name of identifier as bytes is used), byte string or
|
||||
/// array of bytes.
|
||||
#[proc_macro]
|
||||
pub fn keccak_256(input: TokenStream) -> TokenStream {
|
||||
impls::keccak_256(syn::parse_macro_input!(input as MultipleInputBytes).concatenated())
|
||||
}
|
||||
|
||||
/// Apply a keccak 512-bit hash on its bytes parameter, outputs a `[u8; 64]`.
|
||||
/// Multiple inputs are concatenated before hashing.
|
||||
/// Input can be identifier (name of identifier as bytes is used), byte string or
|
||||
/// array of bytes.
|
||||
#[proc_macro]
|
||||
pub fn keccak_512(input: TokenStream) -> TokenStream {
|
||||
impls::keccak_512(syn::parse_macro_input!(input as MultipleInputBytes).concatenated())
|
||||
}
|
||||
|
||||
/// Apply a sha2 256-bit hash on its bytes parameter, outputs a `[u8; 32]`.
|
||||
/// Multiple inputs are concatenated before hashing.
|
||||
/// Input can be identifier (name of identifier as bytes is used), byte string or
|
||||
/// array of bytes.
|
||||
#[proc_macro]
|
||||
pub fn sha2_256(input: TokenStream) -> TokenStream {
|
||||
impls::sha2_256(syn::parse_macro_input!(input as MultipleInputBytes).concatenated())
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Hashing Functions.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use core::hash::Hasher;
|
||||
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use digest::Digest;
|
||||
|
||||
#[inline(always)]
|
||||
fn blake2<const N: usize>(data: &[u8]) -> [u8; N] {
|
||||
blake2b_simd::Params::new()
|
||||
.hash_length(N)
|
||||
.hash(data)
|
||||
.as_bytes()
|
||||
.try_into()
|
||||
.expect("slice is always the necessary length")
|
||||
}
|
||||
|
||||
/// Do a Blake2 512-bit hash and place result in `dest`.
|
||||
pub fn blake2_512_into(data: &[u8], dest: &mut [u8; 64]) {
|
||||
*dest = blake2(data);
|
||||
}
|
||||
|
||||
/// Do a Blake2 512-bit hash and return result.
|
||||
pub fn blake2_512(data: &[u8]) -> [u8; 64] {
|
||||
blake2(data)
|
||||
}
|
||||
|
||||
/// Do a Blake2 256-bit hash and return result.
|
||||
pub fn blake2_256(data: &[u8]) -> [u8; 32] {
|
||||
blake2(data)
|
||||
}
|
||||
|
||||
/// Do a Blake2 128-bit hash and return result.
|
||||
pub fn blake2_128(data: &[u8]) -> [u8; 16] {
|
||||
blake2(data)
|
||||
}
|
||||
|
||||
/// Do a Blake2 64-bit hash and return result.
|
||||
pub fn blake2_64(data: &[u8]) -> [u8; 8] {
|
||||
blake2(data)
|
||||
}
|
||||
|
||||
/// Do a XX 64-bit hash and place result in `dest`.
|
||||
pub fn twox_64_into(data: &[u8], dest: &mut [u8; 8]) {
|
||||
let r0 = twox_hash::XxHash::with_seed(0).chain_update(data).finish();
|
||||
LittleEndian::write_u64(&mut dest[0..8], r0);
|
||||
}
|
||||
|
||||
/// Do a XX 64-bit hash and return result.
|
||||
pub fn twox_64(data: &[u8]) -> [u8; 8] {
|
||||
let mut r: [u8; 8] = [0; 8];
|
||||
twox_64_into(data, &mut r);
|
||||
r
|
||||
}
|
||||
|
||||
/// Do a XX 128-bit hash and place result in `dest`.
|
||||
pub fn twox_128_into(data: &[u8], dest: &mut [u8; 16]) {
|
||||
let r0 = twox_hash::XxHash::with_seed(0).chain_update(data).finish();
|
||||
let r1 = twox_hash::XxHash::with_seed(1).chain_update(data).finish();
|
||||
LittleEndian::write_u64(&mut dest[0..8], r0);
|
||||
LittleEndian::write_u64(&mut dest[8..16], r1);
|
||||
}
|
||||
|
||||
/// Do a XX 128-bit hash and return result.
|
||||
pub fn twox_128(data: &[u8]) -> [u8; 16] {
|
||||
let mut r: [u8; 16] = [0; 16];
|
||||
twox_128_into(data, &mut r);
|
||||
r
|
||||
}
|
||||
|
||||
/// Do a XX 256-bit hash and place result in `dest`.
|
||||
pub fn twox_256_into(data: &[u8], dest: &mut [u8; 32]) {
|
||||
let r0 = twox_hash::XxHash::with_seed(0).chain_update(data).finish();
|
||||
let r1 = twox_hash::XxHash::with_seed(1).chain_update(data).finish();
|
||||
let r2 = twox_hash::XxHash::with_seed(2).chain_update(data).finish();
|
||||
let r3 = twox_hash::XxHash::with_seed(3).chain_update(data).finish();
|
||||
LittleEndian::write_u64(&mut dest[0..8], r0);
|
||||
LittleEndian::write_u64(&mut dest[8..16], r1);
|
||||
LittleEndian::write_u64(&mut dest[16..24], r2);
|
||||
LittleEndian::write_u64(&mut dest[24..32], r3);
|
||||
}
|
||||
|
||||
/// Do a XX 256-bit hash and return result.
|
||||
pub fn twox_256(data: &[u8]) -> [u8; 32] {
|
||||
let mut r: [u8; 32] = [0; 32];
|
||||
twox_256_into(data, &mut r);
|
||||
r
|
||||
}
|
||||
|
||||
/// Do a keccak 256-bit hash and return result.
|
||||
pub fn keccak_256(data: &[u8]) -> [u8; 32] {
|
||||
sha3::Keccak256::digest(data).into()
|
||||
}
|
||||
|
||||
/// Do a keccak 512-bit hash and return result.
|
||||
pub fn keccak_512(data: &[u8]) -> [u8; 64] {
|
||||
sha3::Keccak512::digest(data).into()
|
||||
}
|
||||
|
||||
/// Do a sha2 256-bit hash and return result.
|
||||
pub fn sha2_256(data: &[u8]) -> [u8; 32] {
|
||||
sha2::Sha256::digest(data).into()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn blake2b() {
|
||||
assert_eq!(pezsp_crypto_hashing_proc_macro::blake2b_64!(b""), blake2_64(b"")[..]);
|
||||
assert_eq!(pezsp_crypto_hashing_proc_macro::blake2b_256!(b"test"), blake2_256(b"test")[..]);
|
||||
assert_eq!(pezsp_crypto_hashing_proc_macro::blake2b_512!(b""), blake2_512(b"")[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keccak() {
|
||||
assert_eq!(pezsp_crypto_hashing_proc_macro::keccak_256!(b"test"), keccak_256(b"test")[..]);
|
||||
assert_eq!(pezsp_crypto_hashing_proc_macro::keccak_512!(b"test"), keccak_512(b"test")[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sha2() {
|
||||
assert_eq!(pezsp_crypto_hashing_proc_macro::sha2_256!(b"test"), sha2_256(b"test")[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn twox() {
|
||||
assert_eq!(pezsp_crypto_hashing_proc_macro::twox_128!(b"test"), twox_128(b"test")[..]);
|
||||
assert_eq!(pezsp_crypto_hashing_proc_macro::twox_64!(b""), twox_64(b"")[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn twox_concats() {
|
||||
assert_eq!(
|
||||
pezsp_crypto_hashing_proc_macro::twox_128!(b"test", b"123", b"45", b"", b"67890"),
|
||||
twox_128(&b"test1234567890"[..]),
|
||||
);
|
||||
assert_eq!(
|
||||
pezsp_crypto_hashing_proc_macro::twox_128!(b"test", test, b"45", b"", b"67890"),
|
||||
twox_128(&b"testtest4567890"[..]),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user