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

feat: add Zeroize support to key types, and create new shared secret type #137

Merged
merged 4 commits into from
Oct 25, 2022

Conversation

AaronFeickert
Copy link
Contributor

@AaronFeickert AaronFeickert commented Oct 21, 2022

Adds support for Zeroize to both the RistrettoSecretKey and RistrettoPublicKey types, and creates a new shared secret type. Adds a test for both key types.

This work adds derived Zeroize support to RistrettoSecretKey to support the use case where we want to clear a secret key in scope.

It also adds custom Zeroize support to RistrettoPublicKey. In this case, we zeroize both the underlying RistrettoPoint and the CompressedRistrettoPoint contained in a OnceCell. This is useful in the case where a RistrettoPublicKey represents secret data, like in the case of a Diffie-Hellman shared secret. Note that we do not zeroize on drop, so this use case must be handled manually, ideally through the use of a Zeroizing wrapper.

Finally, it adds a new generic DiffieHellmanSharedSecret<P> type for P: Zeroize. This type zeroizes on drop. It does not provide direct access to the underlying public key, but only gives an as_bytes array view. This removes the need for zeroize support by implementations, and provides safer use of shared secrets.

@AaronFeickert AaronFeickert changed the title Add Zeroize support to key types feat: add Zeroize support to key types Oct 21, 2022
CjS77
CjS77 previously approved these changes Oct 22, 2022
Copy link
Contributor

@CjS77 CjS77 left a comment

Choose a reason for hiding this comment

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

LGTM

@hansieodendaal
Copy link
Contributor

utACK

@AaronFeickert AaronFeickert requested a review from CjS77 October 24, 2022 13:45
@AaronFeickert AaronFeickert changed the title feat: add Zeroize support to key types feat: add Zeroize support to key types, and create new shared secret type Oct 24, 2022
Copy link
Contributor

@stringhandler stringhandler left a comment

Choose a reason for hiding this comment

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

utACK

@CjS77 CjS77 merged commit 532ccc0 into tari-project:main Oct 25, 2022
@AaronFeickert AaronFeickert deleted the zeroize branch October 25, 2022 15:45
stringhandler pushed a commit to tari-project/tari that referenced this pull request Nov 7, 2022
Description
---
Ensures safer use of ECDH shared secrets by switching to the new `DiffieHellmanSharedSecret` type. Updates `tari-crypto` to v0.15.7 to accomplish this.

Motivation and Context
---
Currently, an ECDH secret used for message keys is produced as a `RistrettoPublicKey`, converted to bytes, and returned as a byte array. However, neither the `RistrettoPublicKey` nor the byte array are cleared when dropped. In conjunction with `tari-crypto` [PR 137](tari-project/tari-crypto#137), this work ensures both the `RistrettoPublicKey` and byte array representations of the ECDH secret are zeroized on drop by using that PR's new `DiffieHellmanSharedSecret` type.

How Has This Been Tested?
---
Tested after applying `tari-crypto` [PR 137](tari-project/tari-crypto#137), which adds the new `DiffieHellmanSharedSecret` generic type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-merge The PR can me merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants