From db15d51a901b686a5f3ba88a27b97f5453a9c0e2 Mon Sep 17 00:00:00 2001 From: maurges Date: Thu, 11 Jun 2026 14:39:58 +0200 Subject: [PATCH] Add Zeroize impl for encoded point and scalar Signed-off-by: maurges --- generic-ec/src/encoded.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/generic-ec/src/encoded.rs b/generic-ec/src/encoded.rs index 8725157..deabec4 100644 --- a/generic-ec/src/encoded.rs +++ b/generic-ec/src/encoded.rs @@ -1,8 +1,11 @@ use core::{fmt, ops}; +use zeroize::Zeroize; + use crate::{as_raw::AsRaw, core::ByteArray, Curve}; /// Bytes representation of an elliptic point +#[derive(Zeroize)] pub struct EncodedPoint(EncodedPointInner); impl EncodedPoint { @@ -67,6 +70,24 @@ impl AsRef<[u8]> for EncodedPoint { } } +impl AsMut<[u8]> for EncodedPoint { + fn as_mut(&mut self) -> &mut [u8] { + match &mut self.0 { + EncodedPointInner::Compressed(a) => a.as_mut(), + EncodedPointInner::Uncompressed(a) => a.as_mut(), + } + } +} + +impl Zeroize for EncodedPointInner { + fn zeroize(&mut self) { + match self { + EncodedPointInner::Compressed(a) => a.as_mut().zeroize(), + EncodedPointInner::Uncompressed(a) => a.as_mut().zeroize(), + } + } +} + /// Bytes representation of a scalar (either in big-endian or in little-endian) #[derive(Clone)] pub struct EncodedScalar(E::ScalarArray); @@ -133,3 +154,9 @@ impl AsRaw for EncodedScalar { &self.0 } } + +impl Zeroize for EncodedScalar { + fn zeroize(&mut self) { + self.as_mut().zeroize() + } +}