Fix naming cmstar -> cmstar_bytes and cm -> cmstar
This commit is contained in:
parent
00d04de547
commit
b2b3efd4c2
|
@ -74,8 +74,8 @@ pub trait Domain {
|
||||||
type IncomingViewingKey;
|
type IncomingViewingKey;
|
||||||
type OutgoingViewingKey;
|
type OutgoingViewingKey;
|
||||||
type ValueCommitment;
|
type ValueCommitment;
|
||||||
type NoteCommitment;
|
type ExtractedCommitment;
|
||||||
type ExtractedCommitment: Eq + TryFrom<Self::NoteCommitment>;
|
type ExtractedCommitmentBytes: Eq + TryFrom<Self::ExtractedCommitment>;
|
||||||
type Memo;
|
type Memo;
|
||||||
|
|
||||||
fn derive_esk(note: &Self::Note) -> Option<Self::EphemeralSecretKey>;
|
fn derive_esk(note: &Self::Note) -> Option<Self::EphemeralSecretKey>;
|
||||||
|
@ -111,7 +111,7 @@ pub trait Domain {
|
||||||
fn derive_ock(
|
fn derive_ock(
|
||||||
ovk: &Self::OutgoingViewingKey,
|
ovk: &Self::OutgoingViewingKey,
|
||||||
cv: &Self::ValueCommitment,
|
cv: &Self::ValueCommitment,
|
||||||
cm: &Self::NoteCommitment,
|
cmstar: &Self::ExtractedCommitment,
|
||||||
ephemeral_key: &EphemeralKeyBytes,
|
ephemeral_key: &EphemeralKeyBytes,
|
||||||
) -> OutgoingCipherKey;
|
) -> OutgoingCipherKey;
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ pub trait Domain {
|
||||||
check: F,
|
check: F,
|
||||||
) -> NoteValidity;
|
) -> NoteValidity;
|
||||||
|
|
||||||
fn note_commitment(note: &Self::Note) -> Self::NoteCommitment;
|
fn cmstar(note: &Self::Note) -> Self::ExtractedCommitment;
|
||||||
|
|
||||||
fn parse_note_plaintext_without_memo_ivk(
|
fn parse_note_plaintext_without_memo_ivk(
|
||||||
&self,
|
&self,
|
||||||
|
@ -157,7 +157,7 @@ pub trait Domain {
|
||||||
|
|
||||||
pub trait ShieldedOutput<D: Domain> {
|
pub trait ShieldedOutput<D: Domain> {
|
||||||
fn epk(&self) -> &D::EphemeralPublicKey;
|
fn epk(&self) -> &D::EphemeralPublicKey;
|
||||||
fn cmstar(&self) -> D::ExtractedCommitment;
|
fn cmstar_bytes(&self) -> D::ExtractedCommitmentBytes;
|
||||||
fn enc_ciphertext(&self) -> &[u8];
|
fn enc_ciphertext(&self) -> &[u8];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,11 +288,11 @@ impl<D: Domain> NoteEncryption<D> {
|
||||||
pub fn encrypt_outgoing_plaintext<R: RngCore>(
|
pub fn encrypt_outgoing_plaintext<R: RngCore>(
|
||||||
&self,
|
&self,
|
||||||
cv: &D::ValueCommitment,
|
cv: &D::ValueCommitment,
|
||||||
cm: &D::NoteCommitment,
|
cmstar: &D::ExtractedCommitment,
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
) -> [u8; OUT_CIPHERTEXT_SIZE] {
|
) -> [u8; OUT_CIPHERTEXT_SIZE] {
|
||||||
let (ock, input) = if let Some(ovk) = &self.ovk {
|
let (ock, input) = if let Some(ovk) = &self.ovk {
|
||||||
let ock = D::derive_ock(ovk, &cv, &cm, &D::epk_bytes(&self.epk));
|
let ock = D::derive_ock(ovk, &cv, &cmstar, &D::epk_bytes(&self.epk));
|
||||||
let input = D::outgoing_plaintext_bytes(&self.note, &self.esk);
|
let input = D::outgoing_plaintext_bytes(&self.note, &self.esk);
|
||||||
|
|
||||||
(ock, input)
|
(ock, input)
|
||||||
|
@ -355,7 +355,7 @@ pub fn try_note_decryption<D: Domain, Output: ShieldedOutput<D>>(
|
||||||
domain,
|
domain,
|
||||||
ivk,
|
ivk,
|
||||||
output.epk(),
|
output.epk(),
|
||||||
&output.cmstar(),
|
&output.cmstar_bytes(),
|
||||||
&plaintext,
|
&plaintext,
|
||||||
)?;
|
)?;
|
||||||
let memo = domain.extract_memo(&plaintext);
|
let memo = domain.extract_memo(&plaintext);
|
||||||
|
@ -367,12 +367,12 @@ fn parse_note_plaintext_without_memo_ivk<D: Domain>(
|
||||||
domain: &D,
|
domain: &D,
|
||||||
ivk: &D::IncomingViewingKey,
|
ivk: &D::IncomingViewingKey,
|
||||||
epk: &D::EphemeralPublicKey,
|
epk: &D::EphemeralPublicKey,
|
||||||
cmstar: &D::ExtractedCommitment,
|
cmstar_bytes: &D::ExtractedCommitmentBytes,
|
||||||
plaintext: &[u8],
|
plaintext: &[u8],
|
||||||
) -> Option<(D::Note, D::Recipient)> {
|
) -> Option<(D::Note, D::Recipient)> {
|
||||||
let (note, to) = domain.parse_note_plaintext_without_memo_ivk(ivk, &plaintext)?;
|
let (note, to) = domain.parse_note_plaintext_without_memo_ivk(ivk, &plaintext)?;
|
||||||
|
|
||||||
if let NoteValidity::Valid = check_note_validity::<D>(¬e, epk, cmstar) {
|
if let NoteValidity::Valid = check_note_validity::<D>(¬e, epk, cmstar_bytes) {
|
||||||
Some((note, to))
|
Some((note, to))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -382,10 +382,10 @@ fn parse_note_plaintext_without_memo_ivk<D: Domain>(
|
||||||
fn check_note_validity<D: Domain>(
|
fn check_note_validity<D: Domain>(
|
||||||
note: &D::Note,
|
note: &D::Note,
|
||||||
epk: &D::EphemeralPublicKey,
|
epk: &D::EphemeralPublicKey,
|
||||||
cmstar: &D::ExtractedCommitment,
|
cmstar_bytes: &D::ExtractedCommitmentBytes,
|
||||||
) -> NoteValidity {
|
) -> NoteValidity {
|
||||||
if D::ExtractedCommitment::try_from(D::note_commitment(¬e))
|
if D::ExtractedCommitmentBytes::try_from(D::cmstar(¬e))
|
||||||
.map_or(false, |cs| &cs == cmstar)
|
.map_or(false, |cs| &cs == cmstar_bytes)
|
||||||
{
|
{
|
||||||
let epk_bytes = D::epk_bytes(epk);
|
let epk_bytes = D::epk_bytes(epk);
|
||||||
D::check_epk_bytes(¬e, |derived_esk| {
|
D::check_epk_bytes(¬e, |derived_esk| {
|
||||||
|
@ -428,7 +428,7 @@ pub fn try_compact_note_decryption<D: Domain, Output: ShieldedOutput<D>>(
|
||||||
plaintext.copy_from_slice(output.enc_ciphertext());
|
plaintext.copy_from_slice(output.enc_ciphertext());
|
||||||
ChaCha20Ietf::xor(key.as_ref(), &[0u8; 12], 1, &mut plaintext);
|
ChaCha20Ietf::xor(key.as_ref(), &[0u8; 12], 1, &mut plaintext);
|
||||||
|
|
||||||
parse_note_plaintext_without_memo_ivk(domain, ivk, output.epk(), &output.cmstar(), &plaintext)
|
parse_note_plaintext_without_memo_ivk(domain, ivk, output.epk(), &output.cmstar_bytes(), &plaintext)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recovery of the full note plaintext by the sender.
|
/// Recovery of the full note plaintext by the sender.
|
||||||
|
@ -484,7 +484,7 @@ pub fn try_output_recovery_with_ock<D: Domain, Output: ShieldedOutput<D>>(
|
||||||
domain.parse_note_plaintext_without_memo_ovk(&pk_d, &esk, output.epk(), &plaintext)?;
|
domain.parse_note_plaintext_without_memo_ovk(&pk_d, &esk, output.epk(), &plaintext)?;
|
||||||
let memo = domain.extract_memo(&plaintext);
|
let memo = domain.extract_memo(&plaintext);
|
||||||
|
|
||||||
if let NoteValidity::Valid = check_note_validity::<D>(¬e, output.epk(), &output.cmstar()) {
|
if let NoteValidity::Valid = check_note_validity::<D>(¬e, output.epk(), &output.cmstar_bytes()) {
|
||||||
Some((note, to, memo))
|
Some((note, to, memo))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -127,8 +127,8 @@ impl<P: consensus::Parameters> Domain for SaplingDomain<P> {
|
||||||
type IncomingViewingKey = SaplingIvk;
|
type IncomingViewingKey = SaplingIvk;
|
||||||
type OutgoingViewingKey = OutgoingViewingKey;
|
type OutgoingViewingKey = OutgoingViewingKey;
|
||||||
type ValueCommitment = jubjub::ExtendedPoint;
|
type ValueCommitment = jubjub::ExtendedPoint;
|
||||||
type NoteCommitment = bls12_381::Scalar;
|
type ExtractedCommitment = bls12_381::Scalar;
|
||||||
type ExtractedCommitment = [u8; 32];
|
type ExtractedCommitmentBytes = [u8; 32];
|
||||||
type Memo = MemoBytes;
|
type Memo = MemoBytes;
|
||||||
|
|
||||||
fn derive_esk(note: &Self::Note) -> Option<Self::EphemeralSecretKey> {
|
fn derive_esk(note: &Self::Note) -> Option<Self::EphemeralSecretKey> {
|
||||||
|
@ -206,7 +206,7 @@ impl<P: consensus::Parameters> Domain for SaplingDomain<P> {
|
||||||
fn derive_ock(
|
fn derive_ock(
|
||||||
ovk: &Self::OutgoingViewingKey,
|
ovk: &Self::OutgoingViewingKey,
|
||||||
cv: &Self::ValueCommitment,
|
cv: &Self::ValueCommitment,
|
||||||
cmu: &Self::NoteCommitment,
|
cmu: &Self::ExtractedCommitment,
|
||||||
epk: &EphemeralKeyBytes,
|
epk: &EphemeralKeyBytes,
|
||||||
) -> OutgoingCipherKey {
|
) -> OutgoingCipherKey {
|
||||||
prf_ock(ovk, cv, cmu, epk)
|
prf_ock(ovk, cv, cmu, epk)
|
||||||
|
@ -265,7 +265,7 @@ impl<P: consensus::Parameters> Domain for SaplingDomain<P> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn note_commitment(note: &Self::Note) -> Self::NoteCommitment {
|
fn cmstar(note: &Self::Note) -> Self::ExtractedCommitment {
|
||||||
note.cmu()
|
note.cmu()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ impl<P: consensus::Parameters> ShieldedOutput<SaplingDomain<P>> for OutputDescri
|
||||||
&self.ephemeral_key
|
&self.ephemeral_key
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cmstar(&self) -> [u8; 32] {
|
fn cmstar_bytes(&self) -> [u8; 32] {
|
||||||
self.cmu.to_repr()
|
self.cmu.to_repr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ impl<P: consensus::Parameters> ShieldedOutput<SaplingDomain<P>> for CompactOutpu
|
||||||
&self.epk
|
&self.epk
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cmstar(&self) -> [u8; 32] {
|
fn cmstar_bytes(&self) -> [u8; 32] {
|
||||||
self.cmu.to_repr()
|
self.cmu.to_repr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue