rfc6979: apply and fix workspace-level lints (#1336)

Applies the workspace-level config added in #1323 to this crate and
fixes any failures.
This commit is contained in:
Tony Arcieri
2026-05-06 11:54:08 -06:00
committed by GitHub
parent 78c2b75436
commit 8c849e0e2f
6 changed files with 27 additions and 19 deletions
+1
View File
@@ -52,6 +52,7 @@ missing_docs = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unreachable_pub = "warn"
unsafe_code = "forbid"
unused_lifetimes = "warn"
unused_qualifications = "warn"
-1
View File
@@ -3,7 +3,6 @@
#![doc = include_str!("../README.md")]
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]
#![allow(non_snake_case)]
#![forbid(unsafe_code)]
//! # Using Ed25519 generically over algorithm implementations/providers
//!
-9
View File
@@ -3,15 +3,6 @@
#![doc = include_str!("../README.md")]
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]
#![allow(non_snake_case)]
#![forbid(unsafe_code)]
#![warn(
clippy::unwrap_used,
missing_docs,
rust_2018_idioms,
unused_lifetimes,
unused_qualifications,
unreachable_pub
)]
//! # Using Ed448 generically over algorithm implementations/providers
//!
+3
View File
@@ -22,3 +22,6 @@ subtle = { version = "2", default-features = false }
[dev-dependencies]
hex-literal = "1"
sha2 = "0.11"
[lints]
workspace = true
+2 -2
View File
@@ -47,8 +47,8 @@ pub(crate) fn lt(a: &[u8], b: &[u8]) -> Choice {
// Perform subtraction with borrow a byte-at-a-time, interpreting a
// no-borrow condition as the less-than case
for (&a, &b) in a.iter().zip(b.iter()).rev() {
let c = (b as u16).wrapping_add(borrow >> (u8::BITS - 1));
borrow = (a as u16).wrapping_sub(c) >> u8::BITS as u8;
let c = u16::from(b).wrapping_add(borrow >> (u8::BITS - 1));
borrow = u16::from(a).wrapping_sub(c) >> u8::BITS;
}
!borrow.ct_eq(&0)
+21 -7
View File
@@ -1,7 +1,5 @@
#![no_std]
#![doc = include_str!("../README.md")]
#![forbid(unsafe_code, clippy::unwrap_used)]
#![warn(missing_docs, rust_2018_idioms, unreachable_pub)]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
@@ -42,6 +40,7 @@ mod ct;
pub use hmac;
pub use hmac::digest::array::typenum::consts;
use core::fmt::{self, Debug};
use hmac::{
HmacReset,
digest::{
@@ -86,6 +85,9 @@ where
/// - `q`: field modulus
/// - `h`: hash/digest of input message: must be reduced modulo `q` in advance
/// - `data`: additional associated data, e.g. CSRNG output used as added entropy
///
/// # Panics
/// If `x`, `q`, `h`, and `k` are not all the same length.
#[inline]
pub fn generate_k_mut<D>(x: &[u8], q: &[u8], h: &[u8], data: &[u8], k: &mut [u8])
where
@@ -135,7 +137,9 @@ impl<D> HmacDrbg<D>
where
D: EagerHash,
{
/// Initialize `HMAC_DRBG`
/// Initialize `HMAC_DRBG`.
#[must_use]
#[allow(clippy::missing_panics_doc, reason = "should not panic")]
pub fn new(entropy_input: &[u8], nonce: &[u8], personalization_string: &[u8]) -> Self {
let mut k = HmacReset::new(&Default::default());
let mut v = Array::default();
@@ -148,7 +152,7 @@ where
k.update(entropy_input);
k.update(nonce);
k.update(personalization_string);
k = HmacReset::new_from_slice(&k.finalize().into_bytes()).expect("HMAC error");
k = HmacReset::new_from_slice(&k.finalize().into_bytes()).expect("should work");
// Steps 3.2.e,g: v = HMAC_k(v)
k.update(&v);
@@ -159,6 +163,7 @@ where
}
/// Write the next `HMAC_DRBG` output to the given byte slice.
#[allow(clippy::missing_panics_doc, reason = "should not panic")]
pub fn fill_bytes(&mut self, out: &mut [u8]) {
let mut out_chunks = out.chunks_exact_mut(self.v.len());
@@ -178,12 +183,21 @@ where
self.k.update(&self.v);
self.k.update(&[0x00]);
self.k =
HmacReset::new_from_slice(&self.k.finalize_reset().into_bytes()).expect("HMAC error");
HmacReset::new_from_slice(&self.k.finalize_reset().into_bytes()).expect("should work");
self.k.update(&self.v);
self.v = self.k.finalize_reset().into_bytes();
}
}
impl<D> Debug for HmacDrbg<D>
where
D: EagerHash,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("HmacDrbg").finish_non_exhaustive()
}
}
#[cfg(test)]
mod tests {
use crate::{
@@ -196,8 +210,8 @@ mod tests {
/// "Detailed Example" from RFC6979 Appendix A.1.
///
/// Example for ECDSA on the curve K-163 described in FIPS 186-4 (also known as
/// "ansix9t163k1" in X9.62), defined over a field GF(2^163)
/// Example for ECDSA on the curve K-163 described in FIPS 186-4 (also known as "ansix9t163k1"
/// in X9.62), defined over a field GF(2^163)
#[test]
fn k163_sha256() {
let q = hex!("04000000000000000000020108A2E0CC0D99F8A5EF");