Skip to content

Add Zeroize impl for encoded point and scalar - #90

Closed
maurges wants to merge 1 commit into
mfrom
zeroize-encoded
Closed

Add Zeroize impl for encoded point and scalar#90
maurges wants to merge 1 commit into
mfrom
zeroize-encoded

Conversation

@maurges

@maurges maurges commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

These values are sometimes used in secure contexts like KEM, and it would be useful to wrap then in Zeroizing

Signed-off-by: maurges <git@morj.men>
@maurges
maurges marked this pull request as ready for review June 11, 2026 12:45
@maurges
maurges requested a review from survived June 11, 2026 12:45
Comment thread generic-ec/src/encoded.rs
Comment on lines +82 to +89
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(),
}
}
}

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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>...

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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...

Copy link
Copy Markdown
Contributor

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 EncodedPoint and leave SecretPoint as a thought for the future

Comment thread generic-ec/src/encoded.rs
Comment on lines +158 to +162
impl<E: Curve> Zeroize for EncodedScalar<E> {
fn zeroize(&mut self) {
self.as_mut().zeroize()
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might wanna add SecretScalar::{to_be_bytes, to_le_bytes} methods that return Zeroizing<Box<EncodedScalar>> (Box cuz otherwise Rust will leave copies of encoded scalar everywhere on the stack)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

@maurges

maurges commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

I got too excited and implemented SecretPoint, and rebased some stuff, so I'll close this MR and open a new one

@maurges maurges closed this Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants