Add AES GCM file encryptions#371
Merged
dgarske merged 4 commits intowolfSSL:masterfrom May 3, 2023
Merged
Conversation
… struct stat). Allow building aesgcm-file-encrypt even if AES GCM streaming is not enabled, but show message on run.
dgarske
approved these changes
May 3, 2023
yota22721
pushed a commit
to yota22721/wolfssl-examples
that referenced
this pull request
Jan 25, 2025
Add AES GCM file encryptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds file encryption/decryption using AES GCM.
The code uses POSIX APIs, 32 Bytes key size, and an IV length of 16 Bytes. The code is optimized to use a large buffer size of up to 1G of RAM or input file size to minimize file I/O overhead.
The encrypt_file_AesGCM() API will encrypt a given file and write it to the supplied cipher output file.
The cipher output file will contain a header at the beginning:
WOLFSSL (7 Bytes) magic/identifier | TAG (16Bytes) | IV (16Bytes) | cipher data (= size of the plane file) ...
decrypt_file_AesGCM() API extracts/uses the header and decrypts the cipher data.
When encrypting a file, read and write buffers are used to read data from the file, encrypt it, and then place it into a buffer before writing it to another file. The buffer size is crucial for determining the speed of the encryption process as it significantly impacts performance. You can change the default value of MIN_BUFFER_SIZE and MAX_BUFFER_SIZE.
make CPPFLAGS="-DMAX_BUFFER_SIZE=1073741824 -DMIN_BUFFER_SIZE=1024"Tested with the following: