-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat(zeroize): added zeorizing to Felt
#100
base: main
Are you sure you want to change the base?
Conversation
This is feature-gated behind the `zeroing` flag
@@ -44,6 +46,7 @@ serde = ["alloc", "dep:serde"] | |||
prime-bigint = ["dep:lazy_static"] | |||
num-traits = [] | |||
papyrus-serialization = ["std"] | |||
zeroing = ["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.
zeroing = ["dep:zeroize"]
in ordr to disable the implicit feature.
https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies
Currently you have two features available
zeroing
the one you defined
and
zeroize
from the default behaviour of optional = true
@@ -44,6 +46,7 @@ serde = ["alloc", "dep:serde"] | |||
prime-bigint = ["dep:lazy_static"] | |||
num-traits = [] | |||
papyrus-serialization = ["std"] | |||
zeroing = ["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.
for this types of feature that just depend on one single crate, I tend to name the feature by the crate name. Here zeroize
rather than zeroing
. Wdyt?
@@ -1062,6 +1062,18 @@ mod errors { | |||
} | |||
} | |||
|
|||
mod zeroing { |
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.
you don't really need to create a new module here. Or if you do, it should be behind the feature flag. Here it will happen in the path, even if it is empty, when the feature is not enabled
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.
I would recommend to make it a file. zeroize.rs
. And put mod
import behind the feature flag in felt/mod.rs
use super::*; | ||
|
||
#[cfg(feature = "zeroing")] | ||
impl zeroize::Zeroize for Felt { |
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.
Can't you just use leverage https://docs.rs/zeroize/latest/zeroize/trait.DefaultIsZeroes.html?
#[cfg(feature = "zeroing")] | ||
#[test] | ||
fn zeroing_felt() { | ||
use zeroize::Zeroize; | ||
|
||
let mut felt = Felt::from_hex_unchecked("0x01"); | ||
felt.zeroize(); | ||
assert_eq!(felt, Felt::ZERO); | ||
} |
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.
move this tests to the new file too
This is feature-gated behind the
zeroing
flagPull Request type
What is the current behavior?
Felt
provides no option to zeroize its memory, which can be an issue when dealing with sensitive cryptographic information such as private keys.Resolves: #99
What is the new behavior?
Felt
through thezeroize
crate. Whilezeroize
is not used directly, Felt implements manually theZeroize
trait in the hopes of making this behavior more 'standard'. This has been gated behind thezeroing
feature.Note
Contrarily to
zeroize
, this is done using safe rust by leveragingcore::mem::take
to replace the in-memory representation of a felt with its default value ofFelt::ZERO
.Does this introduce a breaking change?
No. While the
zeroing
feature has been added todefault
, zeroing has not been implemented on drop, both because this would interfere with theCopy
trait ofFelt
but also because it seems like it should be up to the end user to determine when they are dealing with sensitive information.