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() + } +}