Skip to content

Commit

Permalink
Use Blake for stealth addresses (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
xevisalle authored Apr 5, 2024
1 parent 238edf5 commit 529035e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Update bls12_381-bls -> 0.2
- Update jubjub-schnorr -> 0.2
- Use Blake for computing the stealth addresses, instead of Poseidon.

## [0.25.0] - 2024-01-24

Expand Down
8 changes: 8 additions & 0 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar};

pub mod public;
pub mod secret;
pub mod stealth;
pub mod view;

/// Hashes a JubJub's ExtendedPoint into a JubJub's Scalar using the JubJub's
/// hash to scalar function
pub fn hash(p: &JubJubExtended) -> JubJubScalar {
JubJubScalar::hash_to_scalar(&JubJubAffine::from(p).to_bytes())
}
4 changes: 2 additions & 2 deletions src/keys/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::{permutation, SecretKey, StealthAddress, ViewKey};
use crate::{keys::hash, SecretKey, StealthAddress, ViewKey};

use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar};

Expand Down Expand Up @@ -50,7 +50,7 @@ impl PublicKey {
let R = G * r;

let rA = self.A * r;
let rA = permutation::hash(&rA);
let rA = hash(&rA);
let rA = G * rA;

let pk_r = rA + self.B;
Expand Down
4 changes: 2 additions & 2 deletions src/keys/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::{permutation, StealthAddress};
use crate::{keys::hash, StealthAddress};
use dusk_jubjub::JubJubScalar;
use ff::Field;
use jubjub_schnorr::SecretKey as NoteSecretKey;
Expand Down Expand Up @@ -58,7 +58,7 @@ impl SecretKey {
/// With the formula: `sk_r = H(a · R) + b`
pub fn sk_r(&self, sa: &StealthAddress) -> NoteSecretKey {
let aR = sa.R() * self.a;
let aR = permutation::hash(&aR);
let aR = hash(&aR);

(aR + self.b).into()
}
Expand Down
4 changes: 2 additions & 2 deletions src/keys/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use crate::keys::stealth;

use crate::{permutation, SecretKey};
use crate::{keys::hash, SecretKey};

use dusk_bytes::{DeserializableSlice, Error, Serializable};
use dusk_jubjub::{
Expand Down Expand Up @@ -69,7 +69,7 @@ impl ViewKey {
let sa = owner.stealth_address();

let aR = sa.R() * self.a();
let aR = permutation::hash(&aR);
let aR = hash(&aR);
let aR = GENERATOR_EXTENDED * aR;
let pk_r = aR + self.B();

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub mod note;
/// Phoenix Core Keys & Addresses
mod keys;

mod permutation;

/// Hash function
pub use keys::hash;
/// Public (Spend) Key
pub use keys::public::PublicKey;
/// Secret (Spend) Key
Expand Down
14 changes: 0 additions & 14 deletions src/permutation.rs

This file was deleted.

0 comments on commit 529035e

Please sign in to comment.