Skip to content

Commit

Permalink
feat: hashing api (#106)
Browse files Browse the repository at this point in the history
Naive hashing of data for various applications (key derivation,
signature challenges, hmacs, group generators, etc.) can have subtle
security implications if not done carefully. The hashing API strives to
adopt the implicit use of best practices for these applications using an
API that is:
* super ergonomic and stays largely out of the way.
* leverages the Rust type system to achieve zero-cost abstractions and
  guarantees that best practices are being followed.
* Performing these best practices in tari-crypto, and letting clients
  focus on their applications.

The API makes heavy use of traits (incl marker traits) and generics to
keep the API as flexible and broadly applicable as possible.

- Add a set of unit tests covering the hashing API
- Add a domain generation use case to the Ristretto module

* fix: remove unstable feature

* prepend dst key length

For additional collision restance, we now prepend the domain tag length
to the digest ahead of supplying the tag itself. Without this, there is
still a very small chance that a collision could be constructed.

A new test is provided that illustrates the exact process.

* fix: review comments
  • Loading branch information
CjS77 authored Jul 1, 2022
1 parent 60c7673 commit fcb02af
Show file tree
Hide file tree
Showing 4 changed files with 589 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use serde::{Deserialize, Serialize};
use tari_utilities::ByteArrayError;
use thiserror::Error;

#[derive(Debug, Clone, Error, PartialEq, Deserialize, Serialize)]
Expand All @@ -44,3 +45,13 @@ pub enum CommitmentError {
#[error("Inconsistent extension degree: `{0}`")]
ExtensionDegree(String),
}

#[derive(Debug, Error)]
pub enum HashingError {
#[error("The input to the hashing function is too short.")]
InputTooShort,
#[error("Converting a byte string into a secret key failed. {0}")]
ConversionFromBytes(#[from] ByteArrayError),
#[error("The digest does does produce enough output. {0} bytes are required.")]
DigestTooShort(usize),
}
Loading

0 comments on commit fcb02af

Please sign in to comment.