Crate rs_shield

source ·
Expand description

RustyShield: Advanced Cryptographic Library for Modern Applications

This library provides comprehensive cryptographic functions inspired by OpenSSL, within the Rust ecosystem. The vision behind RustyShield is to establish a solid foundation within the Rust language by seamlessly integrating with its core library. As a result, RustyShield furnishes a reliable, user-friendly, standards-compliant, and platform-agnostic suite of encryption tools.


This create delivers its functionality via an API that seamlessly integrates with Rust’s core library. By adhering to the Hash, Hasher, and BuildHasher design pattern from Rust’s core library design pattern from Rust’s core library, the API enables users to effortlessly employ any algorithm, provided they possess a basic understanding of these traits.


The following example demonstrate how to use some of the functionalities provided by RustyShield.

Although only the SHA-1 example is demonstrated, this pattern for extracting an u64, or [u8; N], or a String will be consistent with all implementations below.


let mut sha1hasher = Sha1State::default().build_hasher();
let u64result = sha1hasher.finish();
let bytes_result = HasherContext::finish(&mut sha1hasher);

assert_eq!(u64result, 0xAAF4C61DDCC5E8A2);
        0xAA, 0xF4, 0xC6, 0x1D, 0xDC, 0xC5, 0xE8, 0xA2, 0xDA, 0xBE,
        0xDE, 0x0F, 0x3B, 0x48, 0x2C, 0xD9, 0xAE, 0xA9, 0x43, 0x4D
assert_eq!(format!("{bytes_result:02x}"), "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d")

For examples on a specific algorithm click on it below:

Current algorithms

CiphersHashing FunctionsPublic-key
AES - coming soonSHA-1 - rs_sha1RSA - coming soon
Blowfish - coming soonSHA-224 - rs_sha224DSA - coming soon
Camellia - coming soonSHA-256 - rs_sha256Diffie-Hellman key exchange - coming soon
Chacha20 - coming soonSHA-384 - rs_sha384Elliptic curve - coming soon
Poly1305 - coming soonSHA-512 - rs_sha512X25519 - coming soon
SEED - coming soonSHA-512/224 - rs_sha512_224Ed25519 - coming soon
CAST-128 - coming soonSHA-512/256 - rs_sha512_256X448 - coming soon
DES - coming soonSHA3-224 - rs_sha3_224Ed448 - coming soon
IDEA - coming soonSHA3-256 - rs_sha3_256GOST R 34.10-2001 - coming soon
RC2 - coming soonSHA3-384 - rs_sha3_384SM2 - coming soon
RC4 - coming soonSHA3-512 - rs_sha3_512
RC5 - coming soonSHAKE128 - rs_shake128
Triple DES - coming soonSHAKE256 - rs_shake256
GOST 28147-89 - coming soonHMAC - rs_hmac
SM4 - coming soonGeneric Keccak {200, 400, 800, 1600} - rs_keccak_nbits
BLAKE2 - coming soon
GOST R 34.11-94 - coming soon
MD2 - coming soon
MD4 - coming soon
MD5 - coming soon
MDC-2 - coming soon
RIPEMD-160 - coming soon
SM3 - coming soon
Whirlpool - coming soon

On Hash Trait and Trailing Byte

The Rust Hash trait includes a mechanism to guard against prefix collision attacks that appends a trailing byte 0xFF if to the data fed is of type &str and is passed through the hash function.

This behavior can have implications when using the Hash trait for data processing. If you pass data to the hash function through the Hash trait, it will include this additional 0xFF byte at the end. While this does not affect the general usage of the hash function, it does modify the input data.

Therefore, if you need to get a hash of exact input data (without a trailing 0xFF), you should not use the Hash trait. Instead, directly use the provided hashing algorithm API.

It’s worth noting that this 0xFF trailing byte is not a part of the original algorithm specification, but a part of the Rust Hash trait’s design to prevent prefix collision attacks. Thus, when comparing hash values generated from this library with values generated by different implementations, ensure the input data includes the 0xFF trailing byte or pass the input data as a byte slice to the Hasher::write() on this API.


  • Hmac<H: Default + HashAlgorithm, const OUTPUT_SIZE: usize> is a generic struct that provides the HMAC (Hash-based Message Authentication Code) in Rust.
  • NBitKeccakHasher is a type that provides the Keccak-nBits hashing algorithm in RustyShield.
  • NBitKeccakState represents the state of a Keccak-nBits hashing process.
  • Sha1Hasher is a type that provides the SHA-1 hashing algorithm in RustyShield.
  • Sha1State represents the state of a SHA-1 hashing process.
  • Sha3_224Hasher is a type that provides the SHA3-224 hashing algorithm in Rust.
  • Sha3_224State represents the state of a SHA3-224 hashing process.
  • Sha3_256Hasher is a type that implements the SHA3-256 hashing algorithm in Rust.
  • Sha3_256State embodies the state of a SHA3-256 hashing operation.
  • Sha3_384Hasher is a type that provides the SHA3-384 hashing algorithm in Rust.
  • Sha3_384State represents the state of a SHA3-384 hashing process.
  • Sha3_512Hasher is a type that provides the SHA3-512 hashing algorithm in Rust.
  • Sha3_512State represents the state of a SHA3-512 hashing process.
  • Sha224Hasher is a type that provides the SHA-224 hashing algorithm in RustyShield.
  • Sha224State represents the state of a SHA-1 hashing process.
  • Sha256Hasher is a type in RustyShield that facilitates the SHA-256 hashing algorithm.
  • Sha256State signifies the state of a SHA-256 hashing operation.
  • Sha384Hasher is a type that provides the SHA-384 hashing algorithm in RustyShield.
  • Sha384State represents the state of a SHA-384 hashing process.
  • Sha512Hasher is a type that provides the SHA-512 hashing algorithm in RustyShield.
  • Sha512State represents the state of a SHA-512 hashing process.
  • Sha512_224Hasher is a type that provides the SHA-512/224 hashing algorithm in RustyShield.
  • Sha512_224State represents the state of a SHA-512/224 hashing process.
  • Sha512_256Hasher is a type that provides the SHA-512/256 hashing algorithm in RustyShield.
  • Sha512_256State represents the state of a SHA-512/256 hashing process.
  • Shake128Hasher is a type that provides the SHAKE128 hashing algorithm in Rust.
  • Shake128State represents the state of a SHAKE128 hashing process.
  • Shake256Hasher is a type that provides the SHAKE256 hashing algorithm in Rust.
  • Shake256State represents the state of a SHAKE256 hashing process.


  • Overloads the finish Hasher method for a version that mutates itself