des/
lib.rs

1//! Pure Rust implementation of the [Data Encryption Standard][DES] (DES),
2//! including [Triple DES] (TDES, 3DES) block ciphers.
3//!
4//! # ⚠️ Security Warning: Hazmat!
5//!
6//! This crate implements only the low-level block cipher function, and is intended
7//! for use for implementing higher-level constructions *only*. It is NOT
8//! intended for direct use in applications.
9//!
10//! USE AT YOUR OWN RISK!
11//!
12//! [DES]: https://en.wikipedia.org/wiki/Data_Encryption_Standard
13//! [Triple DES]: https://en.wikipedia.org/wiki/Triple_DES
14
15#![no_std]
16#![doc(
17    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg",
18    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg"
19)]
20#![deny(unsafe_code)]
21#![cfg_attr(docsrs, feature(doc_auto_cfg))]
22#![warn(missing_docs, rust_2018_idioms)]
23
24pub use cipher;
25
26mod consts;
27mod des;
28mod tdes;
29mod utils;
30
31pub use crate::des::Des;
32pub use crate::tdes::{TdesEde2, TdesEde3, TdesEee2, TdesEee3};
33
34/// Checks whether the key is weak.
35///
36/// Returns 1 if the key is weak; otherwise, returns 0.
37fn weak_key_test(key: u64) -> u8 {
38    let mut is_weak = 0u8;
39    for &weak_key in crate::consts::WEAK_KEYS {
40        is_weak |= u8::from(key == weak_key);
41    }
42    is_weak
43}