Don’t allow calling `reveal` in release builds

Some structs have a `reveal` method, which deliberately leaks secret
information for debug builds.  There is no legitimate reason to use
them for anything other than debugging, and no uses at all in any of the
other codebases I am working on.

To ensure that no new uses of this method are added, make this method
only available when debug assertions are turned on.  This ensures that
any attempts to uses this method will break release builds, and thus be
quickly discovered.
This commit is contained in:
Demi M. Obenour 2018-12-01 19:56:42 -05:00
parent a2fa8a4b8f
commit 5b57f59e13
No known key found for this signature in database
GPG Key ID: B288B55FFF9C22C1
2 changed files with 4 additions and 0 deletions

View File

@ -487,6 +487,7 @@ impl SecretKey {
/// Generates a non-redacted debug string. This method differs from
/// the `Debug` implementation in that it *does* leak the secret prime
/// field element.
#[cfg(debug_assertions)]
pub fn reveal(&self) -> String {
let uncomp = self.public_key().0.into_affine().into_uncompressed();
let bytes = uncomp.as_ref();
@ -580,6 +581,7 @@ impl SecretKeyShare {
/// Generates a non-redacted debug string. This method differs from
/// the `Debug` implementation in that it *does* leak the secret prime
/// field element.
#[cfg(debug_assertions)]
pub fn reveal(&self) -> String {
let uncomp = self.0.public_key().0.into_affine().into_uncompressed();
let bytes = uncomp.as_ref();

View File

@ -699,6 +699,7 @@ impl Poly {
/// Generates a non-redacted debug string. This method differs from
/// the `Debug` implementation in that it *does* leak the secret prime
/// field elements.
#[cfg(debug_assertions)]
pub fn reveal(&self) -> String {
format!("Poly {{ coeff: {:?} }}", self.coeff)
}
@ -982,6 +983,7 @@ impl BivarPoly {
/// Generates a non-redacted debug string. This method differs from the
/// `Debug` implementation in that it *does* leak the the struct's
/// internal state.
#[cfg(debug_assertions)]
pub fn reveal(&self) -> String {
format!(
"BivarPoly {{ degree: {}, coeff: {:?} }}",