Lockstitch
Lockstitch is an incremental, stateful cryptographic primitive for symmetric-key cryptographic operations (e.g. hashing, encryption, message authentication codes, and authenticated encryption) in complex protocols. Inspired by TupleHash, STROBE, Noise Protocol's stateful objects, and Xoodyak's Cyclist mode, Lockstitch combines BLAKE3 and ChaCha8 to provide GiB/sec performance on modern processors at a 128-bit security level.
⚠️ WARNING: You should not use this. ⚠️
Neither the design nor the implementation of this library have been independently evaluated.
Design
A Lockstitch protocol is a stateful object which has five different operations:
Mix: Mixes a piece of data into the protocol's state, making all future outputs dependent on it.Derive: Outputs bytes of pseudo-random data dependent on the protocol's prior state.Encrypt/Decrypt: Encrypts and decrypts data using the protocol's state as the key.Tag/CheckTag: Generates and verifies authenticator tags of the protocol's state.Ratchet: Irreversibly modifies the protocol's state, preventing rollback.
Using these operations, one can construct a wide variety of symmetric-key constructions.
Use
Lockstitch is used to compose cryptographic protocols.
For example, we can create message digests:
assert_eq!;
assert_ne!;
We can create message authentication codes:
assert_eq!;
We can even create authenticated encryption:
let plaintext = b"a message".to_vec;
let ciphertext = aead_encrypt;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let mut bad_ciphertext = ciphertext.to_vec;
bad_ciphertext ^= 1; // flip one bit
assert_eq!;
Cargo Features
std: Enables features based on the Rust standard library. Enabled by default.hedge: Enables hedged random value generation withrand_core. Enabled by default.
The SIMD optimizations in blake3 and chacha20 require setting RUSTFLAGS="-C target-cpu=native"
in your build.
Additional Information
For more information on the design of Lockstitch, see design.md.
For more information on performance, see perf.md.
License
Copyright © 2022 Coda Hale
Distributed under the Apache License 2.0 or MIT License.