[zk-token-sdk] Make inner scalar and ristretto point of `PedersenOpening` and `PedersenCommitment` private (#32187)
* make `PedersenOpening` inner scalar private * make `PedersenCommitment` inner point private
This commit is contained in:
parent
469661d217
commit
1616123b84
|
@ -133,7 +133,7 @@ impl ElGamal {
|
||||||
fn decrypt(secret: &ElGamalSecretKey, ciphertext: &ElGamalCiphertext) -> DiscreteLog {
|
fn decrypt(secret: &ElGamalSecretKey, ciphertext: &ElGamalCiphertext) -> DiscreteLog {
|
||||||
DiscreteLog::new(
|
DiscreteLog::new(
|
||||||
*G,
|
*G,
|
||||||
&ciphertext.commitment.0 - &(&secret.0 * &ciphertext.handle.0),
|
ciphertext.commitment.get_point() - &(&secret.0 * &ciphertext.handle.0),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,7 +520,8 @@ pub struct ElGamalCiphertext {
|
||||||
}
|
}
|
||||||
impl ElGamalCiphertext {
|
impl ElGamalCiphertext {
|
||||||
pub fn add_amount<T: Into<Scalar>>(&self, amount: T) -> Self {
|
pub fn add_amount<T: Into<Scalar>>(&self, amount: T) -> Self {
|
||||||
let commitment_to_add = PedersenCommitment(amount.into() * &(*G));
|
let point = amount.into() * &(*G);
|
||||||
|
let commitment_to_add = PedersenCommitment::new(point);
|
||||||
ElGamalCiphertext {
|
ElGamalCiphertext {
|
||||||
commitment: &self.commitment + &commitment_to_add,
|
commitment: &self.commitment + &commitment_to_add,
|
||||||
handle: self.handle,
|
handle: self.handle,
|
||||||
|
@ -528,7 +529,8 @@ impl ElGamalCiphertext {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subtract_amount<T: Into<Scalar>>(&self, amount: T) -> Self {
|
pub fn subtract_amount<T: Into<Scalar>>(&self, amount: T) -> Self {
|
||||||
let commitment_to_subtract = PedersenCommitment(amount.into() * &(*G));
|
let point = amount.into() * &(*G);
|
||||||
|
let commitment_to_subtract = PedersenCommitment::new(point);
|
||||||
ElGamalCiphertext {
|
ElGamalCiphertext {
|
||||||
commitment: &self.commitment - &commitment_to_subtract,
|
commitment: &self.commitment - &commitment_to_subtract,
|
||||||
handle: self.handle,
|
handle: self.handle,
|
||||||
|
@ -650,7 +652,7 @@ define_mul_variants!(
|
||||||
pub struct DecryptHandle(RistrettoPoint);
|
pub struct DecryptHandle(RistrettoPoint);
|
||||||
impl DecryptHandle {
|
impl DecryptHandle {
|
||||||
pub fn new(public: &ElGamalPubkey, opening: &PedersenOpening) -> Self {
|
pub fn new(public: &ElGamalPubkey, opening: &PedersenOpening) -> Self {
|
||||||
Self(&public.0 * &opening.0)
|
Self(&public.0 * opening.get_scalar())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_point(&self) -> &RistrettoPoint {
|
pub fn get_point(&self) -> &RistrettoPoint {
|
||||||
|
|
|
@ -67,8 +67,12 @@ impl Pedersen {
|
||||||
/// Instances of Pedersen openings are zeroized on drop.
|
/// Instances of Pedersen openings are zeroized on drop.
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, Zeroize)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, Zeroize)]
|
||||||
#[zeroize(drop)]
|
#[zeroize(drop)]
|
||||||
pub struct PedersenOpening(pub(crate) Scalar);
|
pub struct PedersenOpening(Scalar);
|
||||||
impl PedersenOpening {
|
impl PedersenOpening {
|
||||||
|
pub fn new(scalar: Scalar) -> Self {
|
||||||
|
Self(scalar)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_scalar(&self) -> &Scalar {
|
pub fn get_scalar(&self) -> &Scalar {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
@ -163,8 +167,12 @@ define_mul_variants!(
|
||||||
|
|
||||||
/// Pedersen commitment type.
|
/// Pedersen commitment type.
|
||||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||||
pub struct PedersenCommitment(pub(crate) RistrettoPoint);
|
pub struct PedersenCommitment(RistrettoPoint);
|
||||||
impl PedersenCommitment {
|
impl PedersenCommitment {
|
||||||
|
pub fn new(point: RistrettoPoint) -> Self {
|
||||||
|
Self(point)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_point(&self) -> &RistrettoPoint {
|
pub fn get_point(&self) -> &RistrettoPoint {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue