dev: implement standard traits for ChaCha20-Poly1305 data types
What changed, and why it matters
This commit adds common Rust traits like Copy, Clone, Eq, Ord, and Hash to ChaCha20-Poly1305 cryptographic types. It is a routine developer-facing API improvement. The commit deliberately avoids adding Debug to types that hold secret keys or nonces to prevent accidental leakage in logs. There is no direct security vulnerability in the diff itself.
No action required. Reviewers may want to confirm that deriving Hash/Ord/Eq on secret-bearing types is acceptable for the intended API use cases, but the change itself is not a security fix or vulnerability.
Security signals we found
Cryptographic code touched but algorithm unchanged
Debug intentionally omitted on secret-bearing types
Standard traits added to key/nonce/cipher structures
Evidence from the diff
The patch derives standard library traits for Poly1305, Key, Nonce, U32x4, State, ChaCha20, and ChaCha20Poly1305. It adds Debug only to internal non-sensitive types (U32x4, State) and explicitly omits Debug for Key, Nonce, and ChaCha20 to protect sensitive material. No cryptographic logic, memory handling, or algorithm behavior is changed. The main security consideration is that adding Hash/Ord/Eq to secret-bearing types could theoretically enable accidental use in hash maps or ordered collections, but this is not a vulnerability and the commit notes the intentional Debug omission.
Changed components
chacha20_poly1305/src/chacha20.rschacha20_poly1305/src/lib.rschacha20_poly1305/src/poly1305.rsInspect captured patch +7 / −4
diff --git a/chacha20_poly1305/src/chacha20.rs b/chacha20_poly1305/src/chacha20.rs
index 13c4f5f4..ee021e01 100644
--- a/chacha20_poly1305/src/chacha20.rs
+++ b/chacha20_poly1305/src/chacha20.rs
@@ -14,7 +14,7 @@ const WORD_4: u32 = 0x6b206574;
const CHACHA_BLOCKSIZE: usize = 64;
/// A 256-bit secret key shared by the parties communicating.
-#[derive(Clone, Copy)]
+#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Key([u8; 32]);
impl Key {
@@ -23,7 +23,7 @@ impl Key {
}
/// A 96-bit initialization vector (IV), or nonce.
-#[derive(Clone, Copy)]
+#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Nonce([u8; 12]);
impl Nonce {
@@ -64,7 +64,7 @@ impl UpTo3<3> for () {}
/// In the future, a "blacklist" for the alignment option might be useful to
/// disable it on architectures which definitely do not support SIMD in order to avoid
/// needless memory inefficiencies.
-#[derive(Clone, Copy, PartialEq)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct U32x4([u32; 4]);
impl U32x4 {
@@ -143,7 +143,7 @@ impl BitXor for U32x4 {
/// 4 5 6 7
/// 8 9 10 11
/// 12 13 14 15
-#[derive(Clone, Copy, PartialEq)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct State {
matrix: [U32x4; 4],
}
@@ -252,6 +252,7 @@ impl State {
///
/// The 20-round IETF version uses a 96-bit nonce and 32-bit block counter. This is the
/// variant used in the Bitcoin ecosystem, including BIP-0324.
+#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ChaCha20 {
/// Secret key shared by the parties communicating.
key: Key,
diff --git a/chacha20_poly1305/src/lib.rs b/chacha20_poly1305/src/lib.rs
index 88283d4b..c3f4d40f 100644
--- a/chacha20_poly1305/src/lib.rs
+++ b/chacha20_poly1305/src/lib.rs
@@ -58,6 +58,7 @@ impl std::error::Error for Error {
}
/// Encrypt and decrypt content along with an authentication tag.
+#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ChaCha20Poly1305 {
key: Key,
nonce: Nonce,
diff --git a/chacha20_poly1305/src/poly1305.rs b/chacha20_poly1305/src/poly1305.rs
index cf560bd0..d5734e07 100644
--- a/chacha20_poly1305/src/poly1305.rs
+++ b/chacha20_poly1305/src/poly1305.rs
@@ -13,6 +13,7 @@ const CARRY: u32 = 26;
/// Poly1305 authenticator takes a 32-byte one-time key and a message and produces a 16-byte tag.
///
/// 64-bit constant time multiplication and addition implementation.
+#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Poly1305 {
/// r part of the secret key.
r: [u32; 5],
Why this scored 17/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.