Skip to content

Commit

Permalink
Add DomainSeparationTag type.
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Jun 3, 2020
1 parent d7e2793 commit 9f1c86b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
12 changes: 10 additions & 2 deletions storage-proofs/core/src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ pub mod pedersen;
pub mod sloth;
pub mod xor;

pub fn derive_porep_domain_seed(domain_separation_tag: &str, porep_id: [u8; 32]) -> [u8; 32] {
pub struct DomainSeparationTag(&'static str);

pub const DRSAMPLE_DST: DomainSeparationTag = DomainSeparationTag("Filecoin_DRSample");
pub const FEISTEL_DST: DomainSeparationTag = DomainSeparationTag("Filecoin_Feistel");

pub fn derive_porep_domain_seed(
domain_separation_tag: DomainSeparationTag,
porep_id: [u8; 32],
) -> [u8; 32] {
Sha256::new()
.chain(domain_separation_tag)
.chain(domain_separation_tag.0)
.chain(porep_id)
.result()
.into()
Expand Down
4 changes: 2 additions & 2 deletions storage-proofs/core/src/drgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rand::{rngs::OsRng, Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;
use sha2::{Digest, Sha256};

use crate::crypto::derive_porep_domain_seed;
use crate::crypto::{derive_porep_domain_seed, DRSAMPLE_DST};
use crate::error::*;
use crate::fr32::bytes_into_fr_repr_safe;
use crate::hasher::{Hasher, PoseidonArity};
Expand Down Expand Up @@ -218,7 +218,7 @@ impl<H: Hasher> Graph<H> for BucketGraph<H> {
);

let mut drg_seed = [0; 28];
let raw_seed = derive_porep_domain_seed("Filecoin_DRSample", porep_id);
let raw_seed = derive_porep_domain_seed(DRSAMPLE_DST, porep_id);
drg_seed.copy_from_slice(&raw_seed[..28]);

Ok(BucketGraph {
Expand Down
3 changes: 2 additions & 1 deletion storage-proofs/porep/src/stacked/vanilla/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use storage_proofs_core::{
crypto::{
derive_porep_domain_seed,
feistel::{self, FeistelPrecomputed},
FEISTEL_DST,
},
drgraph::BASE_DEGREE,
drgraph::{BucketGraph, Graph},
Expand Down Expand Up @@ -187,7 +188,7 @@ where
let bg_id = base_graph.identifier();

let mut feistel_keys = [0u64; 4];
let raw_seed = derive_porep_domain_seed("Filecoin_Feistel", porep_id);
let raw_seed = derive_porep_domain_seed(FEISTEL_DST, porep_id);
feistel_keys[0] = u64::from_le_bytes(raw_seed[0..8].try_into().unwrap());
feistel_keys[1] = u64::from_le_bytes(raw_seed[8..16].try_into().unwrap());
feistel_keys[2] = u64::from_le_bytes(raw_seed[16..24].try_into().unwrap());
Expand Down

0 comments on commit 9f1c86b

Please sign in to comment.