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

Crypto Module #276

Merged
merged 14 commits into from
Sep 6, 2023
Merged

Crypto Module #276

merged 14 commits into from
Sep 6, 2023

Conversation

jabbate19
Copy link
Collaborator

What type of PR is this?

/kind documentation
/kind feature
/kind api-change
/kind eldritch-function

What this PR does / why we need it:

Adds the crypto module with methods to encrypt and hash files.
Starts framework for future cryptography-based methods.

Which issue(s) this PR fixes:

Fixes #67
Fixes #68
Fixes #275

@jabbate19 jabbate19 requested a review from hulto August 15, 2023 22:57
let f = File::open(src)?;
let mut reader = BufReader::new(f);
let mut buffer: Vec<u8> = Vec::new();
reader.read_to_end(&mut buffer)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may want to switch to a streaming encryption for better performance with large files.
I've seen a few c2s crash trying to encrypt Medium to large files especially on low powered VMs in competitions.

Copy link
Collaborator

@hulto hulto left a comment

Choose a reason for hiding this comment

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

Few thoughts but other wise look good to me.

The <b>crypto.aes_encrypt_file</b> method encrypts and decrypts the given src file, encrypts it using the given key, and writes it to disk at the dst location.

This uses the AES CTR algorithm, and the key parameter will be used for the key and IV.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add the docs for aes_decrypt_file

@codecov
Copy link

codecov bot commented Sep 6, 2023

Codecov Report

Merging #276 (117cd2d) into main (01532c1) will increase coverage by 2.84%.
The diff coverage is 87.55%.

@@            Coverage Diff             @@
##             main     #276      +/-   ##
==========================================
+ Coverage   71.91%   74.75%   +2.84%     
==========================================
  Files          90       94       +4     
  Lines        5739     6088     +349     
==========================================
+ Hits         4127     4551     +424     
+ Misses       1526     1451      -75     
  Partials       86       86              
Files Changed Coverage Δ
implants/lib/eldritch/src/crypto.rs 38.46% <38.46%> (ø)
...s/lib/eldritch/src/crypto/aes_decrypt_file_impl.rs 93.24% <93.24%> (ø)
...s/lib/eldritch/src/crypto/aes_encrypt_file_impl.rs 100.00% <100.00%> (ø)
implants/lib/eldritch/src/crypto/hash_file_impl.rs 100.00% <100.00%> (ø)
implants/lib/eldritch/src/lib.rs 92.75% <100.00%> (+0.07%) ⬆️

... and 14 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jabbate19 jabbate19 requested a review from hulto September 6, 2023 02:39
@hulto
Copy link
Collaborator

hulto commented Sep 6, 2023

Testing memory consumption
Encrypting an 8GB file on a system with 7.8Gb of memory.
Usage stays steady around 3.7Gb.
Took about 21 minutes in my container.

image
image

image

image

image

@hulto
Copy link
Collaborator

hulto commented Sep 6, 2023

Seems like 16 bytes might be getting truncated on large (1GB) files.
image

Could be because the files are all 0s.

@hulto
Copy link
Collaborator

hulto commented Sep 6, 2023

image
image

@jabbate19
Copy link
Collaborator Author

Found what was causing last 2 bytes to get cut. Pushing fix soon.

@hulto
Copy link
Collaborator

hulto commented Sep 6, 2023

LGTM 🏎️

@jabbate19 jabbate19 merged commit 483225e into main Sep 6, 2023
6 checks passed
@jabbate19 jabbate19 deleted the crypto_encrypt_file branch September 6, 2023 15:15
hulto pushed a commit that referenced this pull request Sep 30, 2023
* Add Grounds for Crypto

* Add crypto docs

* Implement crypto.aes_encrypt_file() and crypto.hash_file()

* Fix Newlines

* Fix Tests for AES Encrypt

* Debug

* Everything Works Now

* Allow Support for Encrpyting File in Place

* It Needed a Check for Destination File Existing

* Remove Redundant File Creation

* Fix Perfect Block Size Files

* Docs and Tests

* Windows Fix
hulto pushed a commit that referenced this pull request Sep 30, 2023
* Add Grounds for Crypto

* Add crypto docs

* Implement crypto.aes_encrypt_file() and crypto.hash_file()

* Fix Newlines

* Fix Tests for AES Encrypt

* Debug

* Everything Works Now

* Allow Support for Encrpyting File in Place

* It Needed a Check for Destination File Existing

* Remove Redundant File Creation

* Fix Perfect Block Size Files

* Docs and Tests

* Windows Fix
hulto pushed a commit that referenced this pull request Oct 5, 2023
* Add Grounds for Crypto

* Add crypto docs

* Implement crypto.aes_encrypt_file() and crypto.hash_file()

* Fix Newlines

* Fix Tests for AES Encrypt

* Debug

* Everything Works Now

* Allow Support for Encrpyting File in Place

* It Needed a Check for Destination File Existing

* Remove Redundant File Creation

* Fix Perfect Block Size Files

* Docs and Tests

* Windows Fix
KCarretto pushed a commit that referenced this pull request Feb 1, 2024
 
Crypto Module (#276)

* Add Grounds for Crypto

* Add crypto docs

* Implement crypto.aes_encrypt_file() and crypto.hash_file()

* Fix Newlines

* Fix Tests for AES Encrypt

* Debug

* Everything Works Now

* Allow Support for Encrpyting File in Place

* It Needed a Check for Destination File Existing

* Remove Redundant File Creation

* Fix Perfect Block Size Files

* Docs and Tests

* Windows Fix
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.

[feature] crypto.hash_file Implement crypto.decrypt_file Implement crypto.encrypt_file
2 participants