Revert SaplingNoteEncryption::new() API to take rng instead of esk
This commit is contained in:
parent
4f22077cf6
commit
c3d89644e2
|
@ -262,13 +262,12 @@ mod tests {
|
||||||
value: value.into(),
|
value: value.into(),
|
||||||
rseed,
|
rseed,
|
||||||
};
|
};
|
||||||
let esk = note.generate_or_derive_esk(&mut rng);
|
|
||||||
let encryptor = SaplingNoteEncryption::new(
|
let encryptor = SaplingNoteEncryption::new(
|
||||||
extfvk.fvk.ovk,
|
extfvk.fvk.ovk,
|
||||||
note.clone(),
|
note.clone(),
|
||||||
to.clone(),
|
to.clone(),
|
||||||
Memo::default(),
|
Memo::default(),
|
||||||
esk,
|
&mut rng,
|
||||||
);
|
);
|
||||||
let cmu = note.cm(&JUBJUB).to_repr().as_ref().to_owned();
|
let cmu = note.cm(&JUBJUB).to_repr().as_ref().to_owned();
|
||||||
let mut epk = vec![];
|
let mut epk = vec![];
|
||||||
|
|
|
@ -133,13 +133,12 @@ mod tests {
|
||||||
value: value.into(),
|
value: value.into(),
|
||||||
rseed,
|
rseed,
|
||||||
};
|
};
|
||||||
let esk = note.generate_or_derive_esk(&mut rng);
|
|
||||||
let encryptor = SaplingNoteEncryption::new(
|
let encryptor = SaplingNoteEncryption::new(
|
||||||
extfvk.fvk.ovk,
|
extfvk.fvk.ovk,
|
||||||
note.clone(),
|
note.clone(),
|
||||||
to.clone(),
|
to.clone(),
|
||||||
Memo::default(),
|
Memo::default(),
|
||||||
esk,
|
&mut rng,
|
||||||
);
|
);
|
||||||
let cmu = note.cm(&JUBJUB).to_repr().as_ref().to_vec();
|
let cmu = note.cm(&JUBJUB).to_repr().as_ref().to_vec();
|
||||||
let mut epk = vec![];
|
let mut epk = vec![];
|
||||||
|
@ -195,9 +194,13 @@ mod tests {
|
||||||
value: value.into(),
|
value: value.into(),
|
||||||
rseed,
|
rseed,
|
||||||
};
|
};
|
||||||
let esk = note.generate_or_derive_esk(&mut rng);
|
let encryptor = SaplingNoteEncryption::new(
|
||||||
let encryptor =
|
extfvk.fvk.ovk,
|
||||||
SaplingNoteEncryption::new(extfvk.fvk.ovk, note.clone(), to, Memo::default(), esk);
|
note.clone(),
|
||||||
|
to,
|
||||||
|
Memo::default(),
|
||||||
|
&mut rng,
|
||||||
|
);
|
||||||
let cmu = note.cm(&JUBJUB).to_repr().as_ref().to_vec();
|
let cmu = note.cm(&JUBJUB).to_repr().as_ref().to_vec();
|
||||||
let mut epk = vec![];
|
let mut epk = vec![];
|
||||||
encryptor.epk().write(&mut epk).unwrap();
|
encryptor.epk().write(&mut epk).unwrap();
|
||||||
|
@ -220,13 +223,12 @@ mod tests {
|
||||||
value: (in_value - value).into(),
|
value: (in_value - value).into(),
|
||||||
rseed,
|
rseed,
|
||||||
};
|
};
|
||||||
let esk = note.generate_or_derive_esk(&mut rng);
|
|
||||||
let encryptor = SaplingNoteEncryption::new(
|
let encryptor = SaplingNoteEncryption::new(
|
||||||
extfvk.fvk.ovk,
|
extfvk.fvk.ovk,
|
||||||
note.clone(),
|
note.clone(),
|
||||||
change_addr,
|
change_addr,
|
||||||
Memo::default(),
|
Memo::default(),
|
||||||
esk,
|
&mut rng,
|
||||||
);
|
);
|
||||||
let cmu = note.cm(&JUBJUB).to_repr().as_ref().to_vec();
|
let cmu = note.cm(&JUBJUB).to_repr().as_ref().to_vec();
|
||||||
let mut epk = vec![];
|
let mut epk = vec![];
|
||||||
|
|
|
@ -15,6 +15,7 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use crypto_api_chachapoly::{ChaCha20Ietf, ChachaPolyIetf};
|
use crypto_api_chachapoly::{ChaCha20Ietf, ChachaPolyIetf};
|
||||||
use ff::PrimeField;
|
use ff::PrimeField;
|
||||||
use pairing::bls12_381::{Bls12, Fr};
|
use pairing::bls12_381::{Bls12, Fr};
|
||||||
|
use rand_core::{CryptoRng, RngCore};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
@ -236,8 +237,7 @@ fn prf_ock(
|
||||||
/// let note = to.create_note(value, Rseed::BeforeZip212(rcm), &JUBJUB).unwrap();
|
/// let note = to.create_note(value, Rseed::BeforeZip212(rcm), &JUBJUB).unwrap();
|
||||||
/// let cmu = note.cm(&JUBJUB);
|
/// let cmu = note.cm(&JUBJUB);
|
||||||
///
|
///
|
||||||
/// let esk = note.generate_or_derive_esk(&mut rng);
|
/// let enc = SaplingNoteEncryption::new(ovk, note, to, Memo::default(), &mut rng);
|
||||||
/// let enc = SaplingNoteEncryption::new(ovk, note, to, Memo::default(), esk);
|
|
||||||
/// let encCiphertext = enc.encrypt_note_plaintext();
|
/// let encCiphertext = enc.encrypt_note_plaintext();
|
||||||
/// let outCiphertext = enc.encrypt_outgoing_plaintext(&cv.cm(&JUBJUB).into(), &cmu);
|
/// let outCiphertext = enc.encrypt_outgoing_plaintext(&cv.cm(&JUBJUB).into(), &cmu);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -252,13 +252,14 @@ pub struct SaplingNoteEncryption {
|
||||||
|
|
||||||
impl SaplingNoteEncryption {
|
impl SaplingNoteEncryption {
|
||||||
/// Creates a new encryption context for the given note.
|
/// Creates a new encryption context for the given note.
|
||||||
pub fn new(
|
pub fn new<R: RngCore + CryptoRng>(
|
||||||
ovk: OutgoingViewingKey,
|
ovk: OutgoingViewingKey,
|
||||||
note: Note<Bls12>,
|
note: Note<Bls12>,
|
||||||
to: PaymentAddress<Bls12>,
|
to: PaymentAddress<Bls12>,
|
||||||
memo: Memo,
|
memo: Memo,
|
||||||
esk: Fs,
|
rng: &mut R,
|
||||||
) -> SaplingNoteEncryption {
|
) -> SaplingNoteEncryption {
|
||||||
|
let esk = note.generate_or_derive_esk(rng);
|
||||||
let epk = note.g_d.mul(esk, &JUBJUB);
|
let epk = note.g_d.mul(esk, &JUBJUB);
|
||||||
|
|
||||||
SaplingNoteEncryption {
|
SaplingNoteEncryption {
|
||||||
|
@ -809,8 +810,7 @@ mod tests {
|
||||||
let cmu = note.cm(&JUBJUB);
|
let cmu = note.cm(&JUBJUB);
|
||||||
|
|
||||||
let ovk = OutgoingViewingKey([0; 32]);
|
let ovk = OutgoingViewingKey([0; 32]);
|
||||||
let esk = note.generate_or_derive_esk(&mut rng);
|
let ne = SaplingNoteEncryption::new(ovk, note, pa, Memo([0; 512]), &mut rng);
|
||||||
let ne = SaplingNoteEncryption::new(ovk, note, pa, Memo([0; 512]), esk);
|
|
||||||
let epk = ne.epk();
|
let epk = ne.epk();
|
||||||
let enc_ciphertext = ne.encrypt_note_plaintext();
|
let enc_ciphertext = ne.encrypt_note_plaintext();
|
||||||
let out_ciphertext = ne.encrypt_outgoing_plaintext(&cv, &cmu);
|
let out_ciphertext = ne.encrypt_outgoing_plaintext(&cv, &cmu);
|
||||||
|
@ -1705,9 +1705,7 @@ mod tests {
|
||||||
// Test encryption
|
// Test encryption
|
||||||
//
|
//
|
||||||
|
|
||||||
let _esk = note.generate_or_derive_esk(&mut OsRng);
|
let mut ne = SaplingNoteEncryption::new(ovk, note, to, Memo(tv.memo), &mut OsRng);
|
||||||
|
|
||||||
let mut ne = SaplingNoteEncryption::new(ovk, note, to, Memo(tv.memo), _esk);
|
|
||||||
// Swap in the ephemeral keypair from the test vectors
|
// Swap in the ephemeral keypair from the test vectors
|
||||||
ne.esk = esk;
|
ne.esk = esk;
|
||||||
ne.epk = epk;
|
ne.epk = epk;
|
||||||
|
|
|
@ -133,7 +133,7 @@ impl SaplingOutput {
|
||||||
self.note.clone(),
|
self.note.clone(),
|
||||||
self.to.clone(),
|
self.to.clone(),
|
||||||
self.memo,
|
self.memo,
|
||||||
self.note.generate_or_derive_esk(rng),
|
rng,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (zkproof, cv) = prover.output_proof(
|
let (zkproof, cv) = prover.output_proof(
|
||||||
|
|
Loading…
Reference in New Issue