pub struct SaplingNoteEncryption<R: RngCore> { /* private fields */ }Expand description
An API for encrypting Sapling notes.
This struct provides a safe API for encrypting Sapling notes. In particular, it enforces that fresh ephemeral keys are used for every note, and that the ciphertexts are consistent with each other.
Implements section 4.17.1 of the Zcash Protocol Specification. NB: the example code is only covering the pre-Canopy case.
§Examples
extern crate ff;
extern crate rand_core;
extern crate zcash_primitives;
use ff::Field;
use rand_core::OsRng;
use zcash_primitives::{
keys::{OutgoingViewingKey, prf_expand},
note_encryption::{Memo, SaplingNoteEncryption},
primitives::{Diversifier, PaymentAddress, Rseed, ValueCommitment},
};
let mut rng = OsRng;
let diversifier = Diversifier([0; 11]);
let pk_d = diversifier.g_d().unwrap();
let to = PaymentAddress::from_parts(diversifier, pk_d).unwrap();
let ovk = Some(OutgoingViewingKey([0; 32]));
let value = 1000;
let rcv = jubjub::Fr::random(&mut rng);
let cv = ValueCommitment {
value,
randomness: rcv.clone(),
};
let rcm = jubjub::Fr::random(&mut rng);
let note = to.create_note(value, Rseed::BeforeZip212(rcm)).unwrap();
let cmu = note.cmu();
let mut enc = SaplingNoteEncryption::new(ovk, note, to, Memo::default(), &mut rng);
let encCiphertext = enc.encrypt_note_plaintext();
let outCiphertext = enc.encrypt_outgoing_plaintext(&cv.commitment().into(), &cmu);Implementations§
Source§impl<R: RngCore + CryptoRng> SaplingNoteEncryption<R>
impl<R: RngCore + CryptoRng> SaplingNoteEncryption<R>
Sourcepub fn new(
ovk: Option<OutgoingViewingKey>,
note: Note,
to: PaymentAddress,
memo: Memo,
rng: R,
) -> Self
pub fn new( ovk: Option<OutgoingViewingKey>, note: Note, to: PaymentAddress, memo: Memo, rng: R, ) -> Self
Creates a new encryption context for the given note.
Setting ovk to None represents the ovk = ⊥ case, where the note cannot be
recovered by the sender.
Source§impl<R: RngCore> SaplingNoteEncryption<R>
impl<R: RngCore> SaplingNoteEncryption<R>
Sourcepub fn epk(&self) -> &SubgroupPoint
pub fn epk(&self) -> &SubgroupPoint
Exposes the ephemeral public key being used to encrypt this note.
Sourcepub fn encrypt_note_plaintext(&self) -> [u8; 580]
pub fn encrypt_note_plaintext(&self) -> [u8; 580]
Generates encCiphertext for this note.
Sourcepub fn encrypt_outgoing_plaintext(
&mut self,
cv: &ExtendedPoint,
cmu: &Scalar,
) -> [u8; 80]
pub fn encrypt_outgoing_plaintext( &mut self, cv: &ExtendedPoint, cmu: &Scalar, ) -> [u8; 80]
Generates outCiphertext for this note.
Auto Trait Implementations§
impl<R> Freeze for SaplingNoteEncryption<R>where
R: Freeze,
impl<R> RefUnwindSafe for SaplingNoteEncryption<R>where
R: RefUnwindSafe,
impl<R> Send for SaplingNoteEncryption<R>where
R: Send,
impl<R> Sync for SaplingNoteEncryption<R>where
R: Sync,
impl<R> Unpin for SaplingNoteEncryption<R>where
R: Unpin,
impl<R> UnwindSafe for SaplingNoteEncryption<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> PipeAsRef for T
impl<T> PipeAsRef for T
Source§impl<T> PipeBorrow for T
impl<T> PipeBorrow for T
Source§impl<T> PipeDeref for T
impl<T> PipeDeref for T
Source§impl<T> PipeRef for T
impl<T> PipeRef for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
Provides immutable access for inspection. Read more
Source§fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
Calls
tap in debug builds, and does nothing in release builds.Source§fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
Provides mutable access for modification. Read more
Source§fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
Calls
tap_mut in debug builds, and does nothing in release builds.Source§impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
Source§fn tap_ref<F, R>(self, func: F) -> Self
fn tap_ref<F, R>(self, func: F) -> Self
Provides immutable access to the reference for inspection.
Source§fn tap_ref_dbg<F, R>(self, func: F) -> Self
fn tap_ref_dbg<F, R>(self, func: F) -> Self
Calls
tap_ref in debug builds, and does nothing in release builds.Source§fn tap_ref_mut<F, R>(self, func: F) -> Self
fn tap_ref_mut<F, R>(self, func: F) -> Self
Provides mutable access to the reference for modification.
Source§impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
Source§fn tap_borrow<F, R>(self, func: F) -> Self
fn tap_borrow<F, R>(self, func: F) -> Self
Provides immutable access to the borrow for inspection. Read more
Source§fn tap_borrow_dbg<F, R>(self, func: F) -> Self
fn tap_borrow_dbg<F, R>(self, func: F) -> Self
Calls
tap_borrow in debug builds, and does nothing in release builds.Source§fn tap_borrow_mut<F, R>(self, func: F) -> Self
fn tap_borrow_mut<F, R>(self, func: F) -> Self
Provides mutable access to the borrow for modification.
Source§impl<T> TapDeref for T
impl<T> TapDeref for T
Source§fn tap_deref_dbg<F, R>(self, func: F) -> Self
fn tap_deref_dbg<F, R>(self, func: F) -> Self
Calls
tap_deref in debug builds, and does nothing in release builds.Source§fn tap_deref_mut<F, R>(self, func: F) -> Self
fn tap_deref_mut<F, R>(self, func: F) -> Self
Mutably dereferences
self for modification.