Repository navigation
Add Zeroize impl for encoded point and scalar #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<E: Curve>(EncodedPointInner<E>); | ||
|
|
||
| impl<E: Curve> EncodedPoint<E> { | ||
|
|
@@ -67,6 +70,24 @@ impl<E: Curve> AsRef<[u8]> for EncodedPoint<E> { | |
| } | ||
| } | ||
|
|
||
| impl<E: Curve> AsMut<[u8]> for EncodedPoint<E> { | ||
| fn as_mut(&mut self) -> &mut [u8] { | ||
| match &mut self.0 { | ||
| EncodedPointInner::Compressed(a) => a.as_mut(), | ||
| EncodedPointInner::Uncompressed(a) => a.as_mut(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<E: Curve> Zeroize for EncodedPointInner<E> { | ||
| 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: Curve>(E::ScalarArray); | ||
|
|
@@ -133,3 +154,9 @@ impl<E: Curve> AsRaw for EncodedScalar<E> { | |
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| impl<E: Curve> Zeroize for EncodedScalar<E> { | ||
| fn zeroize(&mut self) { | ||
| self.as_mut().zeroize() | ||
| } | ||
| } | ||
|
Comment on lines
+158
to
+162
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we might wanna add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting idea. Right now I'm thinking about a SecretPoint and it would make a better and safer interface in this case |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it ever happen that an elliptic point represents a sensitive info? I don't recall any such case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, we would need a
SecretPoint<E>...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, like in ECIES or ECDH when a point is fed to KDF - that's a secret info that we want to zeroize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right... But I see a little value in adding Zeroize to EncodedPoint, when the point itself is not Zeroize... But making a point Zeroize brings little value without adding SecretPoint...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah the point is Zeroize already! Ok, then let's do
Zeroize for EncodedPointand leaveSecretPointas a thought for the future