This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from knkski/consensus-seal-refactoring
Add consensus seal to PBFT
- Loading branch information
Showing
12 changed files
with
785 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// Contains common hashing functions | ||
use openssl::sha::{Sha256, Sha512}; | ||
|
||
use error::PbftError; | ||
|
||
/// Hashes the given bytes with SHA-256 | ||
pub fn hash_sha256(bytes: &[u8]) -> Vec<u8> { | ||
let mut sha = Sha256::new(); | ||
sha.update(bytes); | ||
let mut bytes = Vec::new(); | ||
bytes.extend(sha.finish().iter()); | ||
bytes | ||
} | ||
|
||
/// Hashes the given bytes with SHA-512 | ||
pub fn hash_sha512(bytes: &[u8]) -> Vec<u8> { | ||
let mut sha = Sha512::new(); | ||
sha.update(bytes); | ||
let mut bytes = Vec::new(); | ||
bytes.extend(sha.finish().iter()); | ||
bytes | ||
} | ||
|
||
/// Verifies that the SHA-512 hash of the given content matches the given hash | ||
pub fn verify_sha512(content: &[u8], content_hash: &[u8]) -> Result<(), PbftError> { | ||
let computed_sha512 = hash_sha512(&content); | ||
|
||
if computed_sha512 != content_hash { | ||
Err(PbftError::InternalError(format!( | ||
"Hash verification failed! Content: `{:?}`, Hash: `{:?}`", | ||
content, content_hash | ||
))) | ||
} else { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.