Skip to content
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

Implement Zeroize for scalars and points #136

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/dusk_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
test_nightly_std:
name: Nightly tests std
uses: dusk-network/.github/.github/workflows/run-tests.yml@main
with:
test_flags: --features=zeroize

test_nightly_no_std:
name: Nightly tests no_std
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `Zeroize` trait for `JubJubScalar`, `JubJubAffine` and `JubJubExtended` [#135]
- Add `zeroize` optional dependency [#135]

## [0.14.0] - 2023-12-13

### Removed
Expand Down Expand Up @@ -214,6 +219,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Initial fork from [`zkcrypto/jubjub`]

<!-- ISSUES -->
[#135]: https://github.com/dusk-network/jubjub/issues/135
[#129]: https://github.com/dusk-network/jubjub/issues/129
[#127]: https://github.com/dusk-network/jubjub/issues/127
[#126]: https://github.com/dusk-network/jubjub/issues/126
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ version = "0.1"
version = "0.7"
optional = true
default-features = false

[dependencies.zeroize]
version = "1"
optional = true
default-features = false
# End Dusk dependendencies

[dev-dependencies]
Expand Down
20 changes: 20 additions & 0 deletions src/dusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ use dusk_bytes::{Error as BytesError, Serializable};

use crate::{Fr, JubJubAffine, JubJubExtended, EDWARDS_D};

#[cfg(feature = "zeroize")]
impl zeroize::DefaultIsZeroes for JubJubAffine {}

#[cfg(feature = "zeroize")]
impl zeroize::DefaultIsZeroes for JubJubExtended {}

/// Compute a shared secret `secret · public` using DHKE protocol
pub fn dhke(secret: &Fr, public: &JubJubExtended) -> JubJubAffine {
public.mul(secret).into()
Expand Down Expand Up @@ -341,3 +347,17 @@ mod fuzz {
}
}
}

#[cfg(feature = "zeroize")]
#[test]
fn test_zeroize() {
use zeroize::Zeroize;

let mut point: JubJubAffine = GENERATOR;
point.zeroize();
assert!(bool::from(point.is_identity()));

let mut point: JubJubExtended = GENERATOR_EXTENDED;
point.zeroize();
assert!(bool::from(point.is_identity()));
}
13 changes: 13 additions & 0 deletions src/fr/dusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use dusk_bytes::{Error as BytesError, Serializable};
use super::{Fr, MODULUS, R2};
use crate::util::sbb;

#[cfg(feature = "zeroize")]
impl zeroize::DefaultIsZeroes for Fr {}

impl Fr {
/// Creates a `Fr` from arbitrary bytes by hashing the input with BLAKE2b
/// into a 512-bits number, and then converting the number into its scalar
Expand Down Expand Up @@ -353,3 +356,13 @@ mod fuzz {
}
}
}

#[cfg(feature = "zeroize")]
#[test]
fn test_zeroize() {
use zeroize::Zeroize;

let mut scalar = Fr::one();
scalar.zeroize();
assert_eq!(scalar, Fr::zero());
}