Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Merge requests
!163
[opti] crypto: use sha2-asm in supported arch
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
[opti] crypto: use sha2-asm in supported arch
elois/hash-opti
into
dev
Overview
0
Commits
1
Pipelines
0
Changes
3
Merged
[opti] crypto: use sha2-asm in supported arch
Éloïs
requested to merge
elois/hash-opti
into
dev
May 31, 2019
Overview
0
Commits
1
Pipelines
0
Changes
3
0
0
Merge request reports
Compare
dev
version 2
5563bf18
May 31, 2019
version 1
309a0713
May 31, 2019
dev (base)
and
latest version
latest version
918a5086
1 commit,
May 31, 2019
version 2
5563bf18
1 commit,
May 31, 2019
version 1
309a0713
1 commit,
May 31, 2019
3 files
+
110
−
12
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
lib/tools/crypto/src/hashs/mod.rs
+
24
−
3
View file @ 918a5086
Edit in single-file editor
Open in Web IDE
Show full file
@@ -16,11 +16,16 @@
//! Provide wrappers for cryptographic hashs
use
crate
::
bases
::
*
;
use
crypto
::
digest
::
Digest
;
use
crypto
::
sha2
::
Sha256
;
use
rand
::{
thread_rng
,
Rng
};
use
std
::
fmt
::{
Debug
,
Display
,
Error
,
Formatter
};
#[cfg(not(all(unix,
any(target_arch
=
"x86"
,
target_arch
=
"x86_64"
))))]
use
crypto
::
digest
::
Digest
;
#[cfg(not(all(unix,
any(target_arch
=
"x86"
,
target_arch
=
"x86_64"
))))]
use
crypto
::
sha2
::
Sha256
;
#[cfg(all(unix,
any(target_arch
=
"x86"
,
target_arch
=
"x86_64"
)))]
use
sha2
::{
Digest
,
Sha256
};
/// A hash wrapper.
///
/// A hash is often provided as string composed of 64 hexadecimal character (0 to 9 then A to F).
@@ -61,6 +66,22 @@ impl Hash {
Hash
(
hash_bytes_arr
)
}
#[cfg(all(unix,
any(target_arch
=
"x86"
,
target_arch
=
"x86_64"
)))]
/// Compute hash of any binary datas
pub
fn
compute
(
datas
:
&
[
u8
])
->
Hash
{
let
hasher
=
Sha256
::
new
();
let
mut
hash
=
Hash
::
default
();
hash
.0
.copy_from_slice
(
hasher
.chain
(
datas
)
.result
()
.as_slice
());
hash
}
#[cfg(all(unix,
any(target_arch
=
"x86"
,
target_arch
=
"x86_64"
)))]
#[inline]
/// Compute hash of a string
pub
fn
compute_str
(
str_datas
:
&
str
)
->
Hash
{
Hash
::
compute
(
str_datas
.as_bytes
())
}
#[cfg(not(all(unix,
any(target_arch
=
"x86"
,
target_arch
=
"x86_64"
))))]
/// Compute hash of any binary datas
pub
fn
compute
(
datas
:
&
[
u8
])
->
Hash
{
let
mut
sha
=
Sha256
::
new
();
@@ -69,7 +90,7 @@ impl Hash {
sha
.result
(
&
mut
hash_buffer
);
Hash
(
hash_buffer
)
}
#[cfg(not(all(unix,
any(target_arch
=
"x86"
,
target_arch
=
"x86_64"
))))]
/// Compute hash of a string
pub
fn
compute_str
(
str_datas
:
&
str
)
->
Hash
{
let
mut
sha256
=
Sha256
::
new
();
Loading