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

perf: avoid concat in sha1 checksum impl #258

Merged
merged 2 commits into from Dec 9, 2023

Conversation

dadleyy
Copy link
Contributor

@dadleyy dadleyy commented Dec 8, 2023

When decrypting large files, the data used in the sym::SymmetricKeyAlgorithm::decrypt_protected method would be copied via the concat used when taking the checksum.

This change updates the function to avoid the copy, by iterating over the relevant parts of the checksum as immutable references. This should be "transparent" to the overall api of the lib so I thought it might make a nice change.

Use Case

I am using gpg to create large filesystem updates (basically, .ext4.gpg) that can be several hundred MB in size, destined for embedded machines with only several hundred MB of RAM. On those machines, I am using this library in my application to decrypt the updates and apply them. Currently, I am running out of memory during the process.

I did some testing to verify that concat does indeed result in allocations here: gist.github.com/dadleyy/a7f8f01, using the Instruments application on my macOS machine.

When decrypting large files, the `data` used in the
`sym::SymmetricKeyAlgorithm::decrypt_protected` message would be copied
via the `concat` used when taking the checksum.

This change updates the function to avoid the copy, by iterating over
the relevant parts of the checksum as immutable references.
Copy link
Member

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

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

thanks, makes sense 👍

nightly builds are having trouble on `cargo check` - the command warns
against the top level `pub use self::composed::key::*;` entry in
`lib.rs`.

this change disables that check.
@dignifiedquire dignifiedquire merged commit d907163 into rpgp:master Dec 9, 2023
14 of 18 checks passed
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.

None yet

2 participants