Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
allow-unwrap-in-consts = true
allow-unwrap-in-tests = true
2 changes: 1 addition & 1 deletion .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.85.0
toolchain: 1.95.0
components: clippy
- run: cargo clippy --all -- -D warnings

Expand Down
39 changes: 39 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,42 @@ members = [

[profile.dev]
opt-level = 2

[workspace.lints.clippy]
borrow_as_ptr = "warn"
cast_lossless = "warn"
cast_possible_truncation = "warn"
cast_possible_wrap = "warn"
cast_precision_loss = "warn"
cast_sign_loss = "warn"
checked_conversions = "warn"
from_iter_instead_of_collect = "warn"
implicit_saturating_sub = "warn"
manual_assert = "warn"
map_unwrap_or = "warn"
missing_errors_doc = "warn"
missing_panics_doc = "warn"
mod_module_files = "warn"
must_use_candidate = "warn"
needless_range_loop = "allow"
ptr_as_ptr = "warn"
redundant_closure_for_method_calls = "warn"
ref_as_ptr = "warn"
return_self_not_must_use = "warn"
semicolon_if_nothing_returned = "warn"
trivially_copy_pass_by_ref = "warn"
std_instead_of_alloc = "warn"
std_instead_of_core = "warn"
undocumented_unsafe_blocks = "warn"
unnecessary_safety_comment = "warn"
unwrap_in_result = "warn"
unwrap_used = "warn"

[workspace.lints.rust]
missing_copy_implementations = "warn"
missing_debug_implementations = "warn"
missing_docs = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
3 changes: 3 additions & 0 deletions ascon-xof128/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ default = ["alloc"]
alloc = ["digest/alloc"]
zeroize = ["digest/zeroize", "sponge-cursor/zeroize"]

[lints]
workspace = true

[package.metadata.docs.rs]
all-features = true
1 change: 1 addition & 0 deletions ascon-xof128/benches/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Basic benchmarks
#![feature(test)]
extern crate test;

Expand Down
2 changes: 1 addition & 1 deletion ascon-xof128/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const CXOF_IV: u64 = 0x0000_0800_00CC_0004;
pub(crate) const XOF_INIT_STATE: State = init_state(XOF_IV);
pub(crate) const CXOF_INIT_STATE: State = init_state(CXOF_IV);

const fn init_state(iv: u64) -> ascon::State {
const fn init_state(iv: u64) -> State {
let mut state = [iv, 0, 0, 0, 0];
ascon::permute12(&mut state);
state
Expand Down
4 changes: 3 additions & 1 deletion ascon-xof128/src/cxof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ pub struct AsconCxof128 {

impl TryCustomizedInit for AsconCxof128 {
type Error = InvalidCustomizationError;

#[inline]
#[allow(clippy::unwrap_in_result)]
fn try_new_customized(customization: &[u8]) -> Result<Self, InvalidCustomizationError> {
if customization.len() > MAX_CUSTOMIZATION_LEN {
return Err(InvalidCustomizationError);
Expand Down Expand Up @@ -97,7 +99,7 @@ impl ExtendableOutput for AsconCxof128 {

impl AlgorithmName for AsconCxof128 {
#[inline]
fn write_alg_name(f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Ascon-CXOF128")
}
}
Expand Down
1 change: 0 additions & 1 deletion ascon-xof128/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_docs, unreachable_pub)]
#![forbid(unsafe_code)]

pub use digest::{self, ExtendableOutput, TryCustomizedInit, Update, XofReader};
Expand Down
2 changes: 1 addition & 1 deletion ascon-xof128/src/xof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Reset for AsconXof128 {

impl AlgorithmName for AsconXof128 {
#[inline]
fn write_alg_name(f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Ascon-XOF128")
}
}
Expand Down
5 changes: 3 additions & 2 deletions ascon-xof128/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Basic tests
use ascon_xof128::{AsconCxof128, AsconXof128};
use core::fmt::Debug;
use digest::{
Expand All @@ -8,11 +9,11 @@ use digest::{
use hex_literal::hex;

// Test vectors from:
// https://github.com/ascon/ascon-c/blob/main/crypto_hash/asconxof128/LWC_XOF_KAT_128_512.txt
// <https://github.com/ascon/ascon-c/blob/main/crypto_hash/asconxof128/LWC_XOF_KAT_128_512.txt>
digest::new_test!(ascon_xof128_kat, AsconXof128, xof_reset_test);

/// Test vectors from:
/// https://github.com/ascon/ascon-c/blob/main/crypto_cxof/asconcxof128/LWC_CXOF_KAT_128_512.txt
/// <https://github.com/ascon/ascon-c/blob/main/crypto_cxof/asconcxof128/LWC_CXOF_KAT_128_512.txt>
#[test]
fn ascon_cxof128_kat() {
digest::dev::blobby::parse_into_structs!(
Expand Down
3 changes: 3 additions & 0 deletions bash-prg-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ alloc = ["digest/alloc"]
oid = ["digest/oid"]
zeroize = ["digest/zeroize", "sponge-cursor/zeroize"]

[lints]
workspace = true

[package.metadata.docs.rs]
all-features = true
1 change: 1 addition & 0 deletions bash-prg-hash/benches/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Basic benchmarks
#![feature(test)]
extern crate test;

Expand Down
14 changes: 11 additions & 3 deletions bash-prg-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_docs, rust_2018_idioms)]
#![forbid(unsafe_code)]

pub use digest::{self, Digest};
Expand Down Expand Up @@ -63,6 +62,7 @@ impl<const RATE: usize, const CAPACITY: usize> TryCustomizedInit for BashPrgHash
type Error = InvalidHeaderError;

#[inline]
#[allow(clippy::unwrap_in_result)]
fn try_new_customized(header: &[u8]) -> Result<Self, Self::Error> {
const {
assert!(
Expand All @@ -71,7 +71,7 @@ impl<const RATE: usize, const CAPACITY: usize> TryCustomizedInit for BashPrgHash
(160, 1) | (128, 2) | (144, 1) | (96, 2) | (128, 1) | (64, 2)
),
"invalid combination of RATE and CAPACITY"
)
);
}

const MAX_HEADER_LEN: usize = 60;
Expand Down Expand Up @@ -212,6 +212,14 @@ impl<const RATE: usize, const CAPACITY: usize> XofReader for BashPrgHashReader<R
}
}

impl<const RATE: usize, const CAPACITY: usize> fmt::Debug for BashPrgHashReader<RATE, CAPACITY> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let level = 8 * (192 - RATE) / (2 * CAPACITY);
write!(f, "BashPrgHashReader{level}{CAPACITY} {{ ... }}")
}
}

impl<const RATE: usize, const CAPACITY: usize> Drop for BashPrgHashReader<RATE, CAPACITY> {
#[inline]
fn drop(&mut self) {
Expand All @@ -231,7 +239,7 @@ impl<const RATE: usize, const CAPACITY: usize> digest::zeroize::ZeroizeOnDrop
}

/// Invalid `bash-prg-hash` header error.
#[derive(Debug)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub struct InvalidHeaderError;

impl fmt::Display for InvalidHeaderError {
Expand Down
3 changes: 2 additions & 1 deletion bash-prg-hash/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Basic tests
use bash_prg_hash::{
BashPrgHash1281, BashPrgHash1282, BashPrgHash1921, BashPrgHash1922, BashPrgHash2561,
BashPrgHash2562,
};
use core::fmt::Debug;
use digest::{ExtendableOutput, TryCustomizedInit, Update};
use hex_literal::hex;
use std::fmt::Debug;

#[derive(Debug, Clone, Copy)]
struct TestVector {
Expand Down
3 changes: 3 additions & 0 deletions cshake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ default = ["alloc"]
alloc = ["digest/alloc"]
zeroize = ["digest/zeroize", "sponge-cursor/zeroize"]

[lints]
workspace = true

[package.metadata.docs.rs]
all-features = true
1 change: 1 addition & 0 deletions cshake/benches/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Basic benchmarks
#![feature(test)]
extern crate test;

Expand Down
6 changes: 3 additions & 3 deletions cshake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(unsafe_code)]
#![warn(missing_docs, missing_debug_implementations)]
#![warn(unreachable_pub)]

pub use digest;

Expand Down Expand Up @@ -56,6 +54,8 @@ impl<const RATE: usize> CShake<RATE> {
///
/// Note that the function name is intended for use by NIST and should only be set to
/// values defined by NIST. You probably don't need to use this function.
#[must_use]
#[allow(clippy::missing_panics_doc, reason = "the method is panic-free")]
pub fn new_with_function_name(function_name: &[u8], customization: &[u8]) -> Self {
const {
assert!(RATE == 168 || RATE == 136, "unsupported rate");
Expand All @@ -77,7 +77,7 @@ impl<const RATE: usize> CShake<RATE> {
fn left_encode(val: u64, b: &mut [u8; 9]) -> &[u8] {
b[1..].copy_from_slice(&val.to_be_bytes());
let i = b[1..8].iter().take_while(|&&a| a == 0).count();
b[i] = (8 - i) as u8;
b[i] = u8::try_from(8 - i).expect("the result always fits into u8");
&b[i..]
}

Expand Down
9 changes: 5 additions & 4 deletions cshake/tests/cshake.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Basic tests
use digest::{CustomizedInit, ExtendableOutput};

#[derive(Debug, Clone, Copy)]
pub struct TestVector {
pub customization: &'static [u8],
pub input: &'static [u8],
pub output: &'static [u8],
struct TestVector {
customization: &'static [u8],
input: &'static [u8],
output: &'static [u8],
}

pub(crate) fn cshake_test<D>(
Expand Down
3 changes: 3 additions & 0 deletions k12/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ default = ["alloc"]
alloc = ["digest/alloc"]
zeroize = ["digest/zeroize", "sponge-cursor/zeroize"]

[lints]
workspace = true

[package.metadata.docs.rs]
all-features = true
14 changes: 0 additions & 14 deletions k12/benches/kt256.rs

This file was deleted.

11 changes: 11 additions & 0 deletions k12/benches/kt128.rs → k12/benches/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Basic benchmarks
#![feature(test)]
extern crate test;

Expand All @@ -12,3 +13,13 @@ digest::bench_update!(
kt128_5_100k 100_000;
kt128_6_1m 1_000_000;
);

digest::bench_update!(
k12::Kt256::default();
kt256_1_10 10;
kt256_2_100 100;
kt256_3_1k 1000;
kt256_4_10k 10_000;
kt256_5_100k 100_000;
kt256_6_1m 1_000_000;
);
1 change: 1 addition & 0 deletions k12/src/custom/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl<'a, const RATE: usize> CustomRefKt<'a, RATE> {
/// Note that this is an inherent method and `CustomRefKt` does not implement
/// the [`CustomizedInit`][digest::CustomizedInit] trait.
#[inline]
#[must_use]
pub fn new_customized(customization: &'a [u8]) -> Self {
Self {
customization,
Expand Down
1 change: 0 additions & 1 deletion k12/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(unsafe_code)]
#![warn(missing_docs, unreachable_pub)]

pub use digest::{self, ExtendableOutput, Update, XofReader};

Expand Down
1 change: 1 addition & 0 deletions k12/src/node_turbo_shake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ mod tests {
const KT128_CVS_LEN: usize = KT128_CV_LEN * CHUNKS;
const KT256_CVS_LEN: usize = KT256_CV_LEN * CHUNKS;

#[allow(clippy::cast_possible_truncation)]
const DATA: &[u8] = &{
let mut buf = [0u8; CHUNKS * CHUNK_SIZE];
let mut i = 0;
Expand Down
2 changes: 1 addition & 1 deletion k12/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub(crate) fn xor_block(state: &mut State1600, block: &[u8]) {

let mut chunks = block.chunks_exact(size_of::<u64>());
for (s, chunk) in state.iter_mut().zip(&mut chunks) {
*s ^= u64::from_le_bytes(chunk.try_into().unwrap());
*s ^= u64::from_le_bytes(chunk.try_into().expect("chunk has correct length"));
}

let rem = chunks.remainder();
Expand Down
Loading