Skip to content
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

test partial decryption #4200

Closed
wants to merge 1 commit into from
Closed

Conversation

jowparks
Copy link
Contributor

@jowparks jowparks commented Aug 10, 2023

Decrypting notes runtime, decrypting the first 32 bytes vs whole note:

tl;dr:
decrypt note for spender ~ 40% reduction in time
Full note vs first 32 bytes: 300 us vs 173 us

decrypt note for owner ~75% reduction in time
Full note vs first 32 bytes: 270 us vs 73 us

Test:
To just decrypt first 32 bytes in rust instead of full note we can change:
let note = Note::from_spender_encrypted(transmission_key, &shared_key, &self.encrypted_note).unwrap();
to

let mut truncated_encrypted_text = [0u8; 32];
truncated_encrypted_text.copy_from_slice(&self.encrypted_note[..32]);
let partial: [u8; 32] = aead::decrypt_partial(&shared_key, &truncated_encrypted_text.to_vec()).try_into().unwrap();
jubjub::Fr::from_bytes(&partial).unwrap();

@jowparks jowparks changed the base branch from master to staging August 10, 2023 17:38
@jowparks jowparks changed the title Joe/test partial decryption test partial decryption Aug 10, 2023
@@ -28,7 +28,7 @@ pub fn decrypt_note_for_spender(c: &mut Criterion) {
},
// Benchmark
|(ovk, merkle_note)| {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done to avoid having to modify return types

@jowparks jowparks force-pushed the joe/test-partial-decryption branch 2 times, most recently from 6ae1f3f to 5c7fe94 Compare August 10, 2023 17:51
truncated_encrypted_text.copy_from_slice(&truncated_ciphertext[..]);

let mut keystream = ChaCha20::new(key.as_ref().into(), [0u8; 12][..].into());
keystream.seek(64);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seek value needs to change based on the position of the plaintext (for example if you want to decrypt bytes 32-64 instead of 0-32, this would need to seek to 96. Hardcoded here for test

@jowparks jowparks force-pushed the joe/test-partial-decryption branch from 5c7fe94 to b3d529f Compare November 2, 2023 20:57
@jowparks jowparks closed this Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant