• Stars
    star
    126
  • Rank 282,890 (Top 6 %)
  • Language
    C
  • License
    MIT License
  • Created about 6 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

high-performance implementations of BLAKE2b/s/bp/sp in pure Rust with dynamic SIMD

blake2b_simd Actions Status docs.rs crates.io
blake2s_simd Actions Status docs.rs crates.io

An implementation of the BLAKE2(b/s/bp/sp) family of hash functions with:

  • 100% stable Rust.
  • SIMD implementations based on Samuel Neves' blake2-avx2. These are very fast. See the Performance section below.
  • Portable, safe implementations for other platforms.
  • Dynamic CPU feature detection. Binaries include multiple implementations by default and choose the fastest one the processor supports at runtime.
  • All the features from the the BLAKE2 spec, like adjustable length, keying, and associated data for tree hashing.
  • The blake2 command line utility, published as the blake2_bin crate, with command line flags for all the BLAKE2 variants and associated data features.
  • no_std support. The std Cargo feature is on by default, for CPU feature detection and for implementing std::io::Write.
  • Support for computing multiple BLAKE2b and BLAKE2s hashes in parallel, matching the efficiency of BLAKE2bp and BLAKE2sp. See the many module in each crate.

Example

use blake2b_simd::{blake2b, Params};

let expected = "ca002330e69d3e6b84a46a56a6533fd79d51d97a3bb7cad6c2ff43b354185d6d\
                c1e723fb3db4ae0737e120378424c714bb982d9dc5bbd7a0ab318240ddd18f8d";
let hash = blake2b(b"foo");
assert_eq!(expected, &hash.to_hex());

let hash = Params::new()
    .hash_length(16)
    .key(b"The Magic Words are Squeamish Ossifrage")
    .personal(b"L. P. Waterhouse")
    .to_state()
    .update(b"foo")
    .update(b"bar")
    .update(b"baz")
    .finalize();
assert_eq!("ee8ff4e9be887297cf79348dc35dab56", &hash.to_hex());

An example using the included blake2 command line utility:

$ cargo install blake2_bin
$ echo hi | blake2 -sp
49228db2a2fa8d25e8b3b2aca5a70234c71490516eaca9cba007b27d59c532b8

Performance

To run small benchmarks yourself, run cargo +nightly bench. If you have OpenSSL, libsodium, and Clang installed on your machine, you can add --all-features to include comparison benchmarks with other native libraries.

The benches/bench_multiprocess sub-crate runs various hash functions on long inputs in memory and tries to average over many sources of variability. Here are the results from my laptop for cargo run --release (lower is better):

  • Intel Core i5-8250U (Kaby Lake Refresh)
  • libsodium version 1.0.18
  • OpenSSL version 1.1.1.d
  • rustc 1.40.0
  • clang 9.0.1
╭─────────────────────────┬──────────╮
│ BLAKE3                  │ 0.95 cpb │
│ blake2s_simd many::hash │ 1.31 cpb │
│ blake2s_simd BLAKE2sp   │ 1.32 cpb │
│ blake2b_simd many::hash │ 1.43 cpb │
│ blake2b_simd BLAKE2bp   │ 1.44 cpb │
│ blake2b_simd BLAKE2b    │ 2.81 cpb │
│ libsodium BLAKE2b       │ 3.07 cpb │
│ OpenSSL SHA-1           │ 3.51 cpb │
│ blake2s_simd BLAKE2s    │ 4.66 cpb │
│ OpenSSL SHA-512         │ 5.11 cpb │
╰─────────────────────────┴──────────╯

Links

More Repositories

1

duct.rs

a Rust library for running child processes
Rust
807
star
2

sha256_project

The SHA-256 Project, developed for NYU Tandon's Applied Cryptography course
Python
533
star
3

bao

an implementation of BLAKE3 verified streaming
Rust
465
star
4

clinacl

a command line tool for playing with NaCl
Python
253
star
5

blake3-py

Python bindings for the BLAKE3 cryptographic hash function
Python
139
star
6

duct.py

a Python library for running child processes
Python
113
star
7

fbmessenger

[deprecated] a PyQt clone of Facebook Messenger for Windows
Python
102
star
8

os_pipe.rs

a cross-platform library for opening OS pipes in Rust
Rust
97
star
9

blake3-6502

the BLAKE3 hash function implemented in 6502 assembly
Assembly
56
star
10

shared_child.rs

a wrapper around std::process::Child that lets multiple threads wait or kill at once
Rust
39
star
11

applied_crypto_2021_fall

problem sets for CS-GY 6903 Applied Cryptography
Python
39
star
12

bessie

an authenticated, chunked cipher based on BLAKE3
Rust
21
star
13

pure_python_blake3

a pure Python implementation of BLAKE3
Python
15
star
14

dotfiles

Jack's config files
Shell
12
star
15

blake3_reference_impl_c

a C port of the BLAKE3 Rust reference implementation
C
10
star
16

blake2_c.rs

a safe wrapper around the BLAKE2 C implementation (deprecated in favor of blake2b_simd and blake2s_simd)
Rust
7
star
17

riddance

a reservable, retiring, recyclable slotmap/arena (WIP)
Rust
6
star
18

kangarootwelve_xkcp.rs

A Rust wrapper around the XKCP implementation of the KangarooTwelve hash function
C
6
star
19

unsafe_rust_is_not_c_talk

6
star
20

founder

A wrapper around fzf and fd, which keeps track of files you've opened before
Rust
6
star
21

arch

Jack's install scripts for Arch Linux.
Shell
5
star
22

bao_presentation

HTML
5
star
23

bao_experiments

benchmarks for various design changes to github.com/oconnor663/bao
HTML
4
star
24

avx512_test

Rust
4
star
25

rust-examples

scary things that Rust keeps you safe from
Rust
4
star
26

mersenne_breaker

Rust
4
star
27

copy_in_place

[deprecated] a single-function Rust crate providing a safe wrapper around ptr::copy for efficient copying within slices
Rust
4
star
28

jacko.io

source files for my personal website
Rust
4
star
29

blake3_aead

experimental
Rust
4
star
30

chacha20_simd

experimental
Rust
4
star
31

pure_python_salsa_chacha

pure Python implementations of Salsa20, XSalsa20, ChaCha20 (IETF), and XChaCha20
Python
4
star
32

simd_examples

Rust
3
star
33

happy_eyeballs

A demo comparison between futures in Rust and in Python's Trio
Rust
3
star
34

thread_tester

dummy project
Rust
3
star
35

blake2s_simd

DEPRECATED
Rust
3
star
36

keybase_validator

Rust
3
star
37

zsh-sensible

zsh defaults that everyone can agree on
Shell
3
star
38

atomic_examples

Rust
3
star
39

async_demo

teaching examples for async Rust
Rust
3
star
40

baokeshed

Rust
3
star
41

easy_steps_chinese_vocab

Python
3
star
42

test

funny filenames
3
star
43

cpp_rust_talk

https://youtu.be/IPmRDS0OSxM
JavaScript
3
star
44

tosqlite

Python
3
star
45

cooper_pair_box

Jack's physics senior project. A model of the inductively-shunted Cooper pair box.
Python
2
star
46

cell_talk

JavaScript
2
star
47

dungeon_of_despair

a great text-based dungeon crawler from our undergraduate years
Scheme
2
star
48

qol-armor

Lua
2
star
49

rust_blake3_c_bindings

C
2
star
50

supercop

Jack's working copy of the SUPERCOP source tree, for BLAKE3 submissions (see crypto_hash/blake3/)
C
2
star
51

scratch

2
star
52

unsound_helpers

Rust
2
star
53

incremental_messagepack

Example implementation of an incremental MessagePack decoder.
Python
2
star
54

appveyor-exec-py

reproducing a bug where python scripts don't execute on AppVeyor
Python
2
star
55

cryptopals-rust

HTML
2
star
56

pooter

for Mi
Objective-C
2
star
57

basex_gmp

C
2
star
58

clap_unicode_test

exercising a bug in the Rust Clap library
Rust
2
star
59

palindrompit

A palindromic tip calculator for Android
Scala
2
star
60

pyo3_pybuffer_repro

repro code for a memory corruption issue with PyO3 + PyPy
Rust
1
star
61

broken-make

a demo of a broken Make build
C
1
star
62

blog_os

Rust
1
star
63

actions-test

messing around with GitHub Actions
Rust
1
star
64

curve25519

code from an interview, not interesting :)
Python
1
star
65

rust-practice

Rust
1
star
66

cell_utils

EXPERIMENTAL CODE, not published on crates.io
Rust
1
star
67

fsanitize_example

Rust
1
star
68

ttt

Tic-Tac-Toe
Python
1
star
69

codingexamples

Python
1
star
70

yalie

Yet Another Lisp Interpreting Experiment: Jack's comp sci senior project. An interpreter for an object-oriented Lisp.
Python
1
star
71

go_calling_rust_example

Go
1
star
72

find_xor_collisions

Rust
1
star
73

peru-server

a Flask web site that can host peru modules and generate a peru.yaml for you
Python
1
star
74

peru-pygit2-example

an example project using peru and make to build against pygit2
Makefile
1
star
75

cc_hello_world

minimal demo project for testing `cc` changes
Rust
1
star