-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor enc_ciphertext to return reference instead of copy #13
Changes from 6 commits
3a54c72
606c82c
e0cfd5b
445d109
b7221e5
c66c8a2
ded868d
6c1f21b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[toolchain] | ||
channel = "1.56.1" | ||
components = [ "clippy", "rustfmt" ] | ||
components = ["clippy", "rustfmt"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,28 +44,22 @@ pub mod note_bytes; | |
|
||
use note_bytes::NoteBytes; | ||
|
||
/// The size of a compact note for Sapling and Orchard Vanilla. | ||
/// The size of a compact note for Sapling and pre-ZSA Orchard. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't want new term There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done (removed unused constants COMPACT_NOTE_SIZE, NOTE_PLAINTEXT_SIZE, ENC_CIPHERTEXT_SIZE with those comments). |
||
pub const COMPACT_NOTE_SIZE: usize = 1 + // version | ||
11 + // diversifier | ||
8 + // value | ||
32; // rseed (or rcm prior to ZIP 212) | ||
/// The size of `NotePlaintextBytes` for Sapling and Orchard Vanilla. | ||
/// The size of [`Domain::NotePlaintextBytes`] for Sapling and pre-ZSA Orchard. | ||
pub const NOTE_PLAINTEXT_SIZE: usize = COMPACT_NOTE_SIZE + 512; | ||
|
||
/// The size of the memo. | ||
pub const MEMO_SIZE: usize = 512; | ||
/// The size of the authentication tag used for note encryption. | ||
pub const AEAD_TAG_SIZE: usize = 16; | ||
|
||
/// The size of [`OutPlaintextBytes`]. | ||
pub const OUT_PLAINTEXT_SIZE: usize = 32 + // pk_d | ||
32; // esk | ||
const AEAD_TAG_SIZE: usize = 16; | ||
/// The size of an encrypted note plaintext for Sapling and pre-ZSA Orchard. | ||
pub const ENC_CIPHERTEXT_SIZE: usize = NOTE_PLAINTEXT_SIZE + AEAD_TAG_SIZE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
/// The size of an encrypted outgoing plaintext. | ||
pub const OUT_CIPHERTEXT_SIZE: usize = OUT_PLAINTEXT_SIZE + AEAD_TAG_SIZE; | ||
|
||
/// The size of an encrypted note plaintext for Sapling and Orchard Vanilla. | ||
pub const ENC_CIPHERTEXT_SIZE: usize = NOTE_PLAINTEXT_SIZE + AEAD_TAG_SIZE; | ||
|
||
/// A symmetric key that can be used to recover a single Sapling or Orchard output. | ||
pub struct OutgoingCipherKey(pub [u8; 32]); | ||
|
||
|
@@ -270,7 +264,8 @@ pub trait Domain { | |
plaintext: &Self::CompactNotePlaintextBytes, | ||
) -> Option<(Self::Note, Self::Recipient)>; | ||
|
||
/// Splits the memo field from the given note plaintext. | ||
/// Splits the given note plaintext into the compact part (containing the note) and | ||
/// the memo field. | ||
/// | ||
/// # Compatibility | ||
/// | ||
|
@@ -374,7 +369,7 @@ pub trait ShieldedOutput<D: Domain> { | |
fn cmstar_bytes(&self) -> D::ExtractedCommitmentBytes; | ||
|
||
/// Exposes the note ciphertext of the output. Returns `None` if the output is compact. | ||
fn enc_ciphertext(&self) -> Option<D::NoteCiphertextBytes>; | ||
fn enc_ciphertext(&self) -> Option<&D::NoteCiphertextBytes>; | ||
|
||
// FIXME: Should we return `Option<D::CompactNoteCiphertextBytes>` or | ||
// `&D::CompactNoteCiphertextBytes` instead? (complexity)? | ||
|
@@ -383,8 +378,7 @@ pub trait ShieldedOutput<D: Domain> { | |
|
||
//// Splits the AEAD tag from the ciphertext. | ||
fn split_ciphertext_at_tag(&self) -> Option<(D::NotePlaintextBytes, [u8; AEAD_TAG_SIZE])> { | ||
let enc_ciphertext = self.enc_ciphertext()?; | ||
let enc_ciphertext_bytes = enc_ciphertext.as_ref(); | ||
let enc_ciphertext_bytes = self.enc_ciphertext()?.as_ref(); | ||
|
||
let (plaintext, tail) = enc_ciphertext_bytes | ||
.len() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should keep the original constants. this might create confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (removed the constants and updated CHANGELOG accordingly).