In EMA, the byte block comprises a byte array that stores data for encryption and decryption. To enhance efficiency, the byte block may hold some or all input data bytes, particularly when the volume of data is high. The size of the byte block varies, depending on the available hardware capacity and ranges from 64KB (minimum) to 1GB (maximum). For a byte array data source, the default encryption size is 64KB, while for a file data source, the default size is 2MB.
The choice of the byte block size is crucial only in the encryption stage, with the option of either using the default size or manually setting it. During decryption, the byte block size is determined alongside other data, decrypting only the initial portion (header) of the encrypted information. After encryption, it becomes impossible to determine the length of the header due to the mixing up of data positions. Nonetheless, we can determine the minimum and maximum range of the header’s size. However, since we do not consider this factor to be significant, we will employ a large byte block to read the header. After examining the header and establishing the byte block size, the decryption process may begin.
For both byte arrays and files we consider using the default byte block size for reading the header, 64KB and 2MB respectively.
It does not matter if we read a part of the encrypted data beyond the header that is not relevant to us at the moment, as it will have to be read again later when reading the first byte block.
Regarding the encryption of files, to set a different size of the byte block than default you can use the method
- setByteBlockSize(bytes number);
- setByteBlockSize(821_437); // means the new byte-block size will be 821_437 byte long and will work in file mode only
2024.03.03 16:38:05.837 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2024.03.03 16:38:05.837 RUNNING setByteBlockSize() :: 2024.03.03 16:38:05.837 SETTING the new byte block size to 821.437-byte
Valid sizes are greater or equal to minimum byte block size and less or equal to maximum byte block size.
If the settings do not meet the above requirements, the byte block size will remain as default.
If the new byte block size is larger than the combined size of the file to be encrypted and the header, the byte block size will automatically scale to the size of the source file plus the header. Therefore, encryption will only use one block.
The bigger the byte block, the fewer cycles required for reading, processing, and writing, albeit with a larger amount of data.
Therefore, depending on the computing power (CPU and memory I/O) of the machine being used, it may be appropriate to set a smaller or larger byte block size.
Encryption of a large file using byte blocks of different sizes
Using the minimum byte block size (65,536-byte) the encryption takes 28302 cycles
2024.04.04 08:54:07.120 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.04 08:54:07.120 RUNNING setEncryptionChecksumAlgorithm() ::
2024.04.04 08:54:07.121 SETTING checksum algorithm to 'SHA-1' for encryption
2024.04.04 08:54:07.121
2024.04.04 08:54:07.121 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.04 08:54:07.121 RUNNING fileEncryption() ::
2024.04.04 08:54:07.122 FILE TO ENCRYPT
2024.04.04 08:54:07.122 C:\Users\guest\ema\src\movie.mkv
2024.04.04 08:54:07.122 Size = 1.854.694.887-byte
2024.04.04 08:54:07.123 ..................................................................................................
2024.04.04 08:54:07.123 ENCRYPTION KEY
2024.04.04 08:54:07.124 C:\Users\guest\ema\key\1712213110928004300_a7721cd837e1de1e5c0daec15bf4c13fca340142.key
2024.04.04 08:54:07.125 Size = 55.556-byte
2024.04.04 08:54:07.125 sub-key_1: from index '0' to index '2.097.151'
2024.04.04 08:54:07.125 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.04 08:54:07.126
2024.04.04 08:54:07.126 This key adds 10297 random bytes to the top of pre-encryption data if origin data is a file
2024.04.04 08:54:07.126 and 321 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.04 08:54:07.127 ..................................................................................................
2024.04.04 08:54:07.166 ENCRYPTION SETTINGS
2024.04.04 08:54:07.167 Encryption execution core: ENABLED
2024.04.04 08:54:07.167 Checksum calculation: ENABLED with SHA-1 algorithm
2024.04.04 08:54:07.168 Encryption details: ENABLED
2024.04.04 08:54:07.168 Use a random name to save the encrypted file: ENABLED
2024.04.04 08:54:07.169 ..................................................................................................
2024.04.04 08:54:07.169 STARTING THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.04 08:54:07.171 Reading the prepared byte block 0000000001 00001255µs 65.536-byte
2024.04.04 08:54:07.172 Calculating SHA-1 checksum 00000469µs
2024.04.04 08:54:07.175 Encrypting the byte block 0000000001 00002750µs
2024.04.04 08:54:07.175 Writing the encrypted byte block 0000000001 00000235µs 65.536-byte
2024.04.04 08:54:07.176 ....
2024.04.04 08:54:07.177 ....
2024.04.04 08:54:07.177 ....
2024.04.04 08:54:07.177 ....
2024.04.04 08:54:18.085 Reading the prepared byte block 0000028301 00000020µs 37.326-byte
2024.04.04 08:54:18.086 Calculating SHA-1 checksum 00000323µs
2024.04.04 08:54:18.086 Encrypting the byte block 0000028301 00000174µs
2024.04.04 08:54:18.087 Writing the encrypted byte block 0000028301 00000048µs 37.326-byte
2024.04.04 08:54:18.087 FINISHED THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.04 08:54:18.088 ..................................................................................................
2024.04.04 08:54:18.088 OVERALL TIMES
2024.04.04 08:54:18.089 Time to read 0000028301 byte blocks 00000943ms
2024.04.04 08:54:18.089 Time to calculate the SHA-1 checksum 00004643ms
2024.04.04 08:54:18.089 Time to complete the encryption 00003885ms
2024.04.04 08:54:18.090 Time to write 0000028301 byte blocks 00001104ms
2024.04.04 08:54:18.090 Total time 00010577ms
2024.04.04 08:54:18.090 ..................................................................................................
2024.04.04 08:54:18.090 SAVING THE ENCRYPTED FILE
2024.04.04 08:54:18.091 C:\Users\guest\ema\msk\1712213647213664700_475CkopjDFKQyeqIAi1AC1AnxND2pfnc.msk 1.854.706.126-byte
2024.04.04 08:54:18.091 ..................................................................................................
2024.04.04 08:54:18.091 The checksum SHA-1 was calculated
2024.04.04 08:54:18.091 Encryption performed successfully
2024.04.04 08:54:18.091
2024.04.04 08:54:18.091 FINISHED fileEncryption() ::
Using the default block size (2,097,152-byte) the encryption takes 885 cycles
2024.04.04 08:55:40.071 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.04 08:55:40.071 RUNNING fileEncryption() ::
2024.04.04 08:55:40.072 FILE TO ENCRYPT
2024.04.04 08:55:40.072 C:\Users\guest\ema\src\movie.mkv
2024.04.04 08:55:40.073 Size = 1.854.694.887-byte
2024.04.04 08:55:40.073 ..................................................................................................
2024.04.04 08:55:40.073 ENCRYPTION KEY
2024.04.04 08:55:40.073 C:\Users\guest\ema\key\1712213110928004300_a7721cd837e1de1e5c0daec15bf4c13fca340142.key
2024.04.04 08:55:40.075 Size = 55.556-byte
2024.04.04 08:55:40.075 sub-key_1: from index '0' to index '2.097.151'
2024.04.04 08:55:40.075 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.04 08:55:40.075
2024.04.04 08:55:40.076 This key adds 10297 random bytes to the top of pre-encryption data if origin data is a file
2024.04.04 08:55:40.076 and 321 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.04 08:55:40.076 ..................................................................................................
2024.04.04 08:55:40.111 ENCRYPTION SETTINGS
2024.04.04 08:55:40.111 Encryption execution core: ENABLED
2024.04.04 08:55:40.111 Checksum calculation: ENABLED with SHA-1 algorithm
2024.04.04 08:55:40.112 Encryption details: ENABLED
2024.04.04 08:55:40.112 Use a random name to save the encrypted file: ENABLED
2024.04.04 08:55:40.112 ..................................................................................................
2024.04.04 08:55:40.113 STARTING THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.04 08:55:40.127 Reading the prepared byte block 0000000001 00002317µs 2.097.152-byte
2024.04.04 08:55:40.128 Calculating SHA-1 checksum 00011382µs
2024.04.04 08:55:40.138 Encrypting the byte block 0000000001 00009131µs
2024.04.04 08:55:40.140 Writing the encrypted byte block 0000000001 00001525µs 2.097.152-byte
2024.04.04 08:55:40.141 ....
2024.04.04 08:55:40.141 ....
2024.04.04 08:55:40.141 ....
2024.04.04 08:55:40.142 ....
2024.04.04 08:55:50.504 Reading the prepared byte block 0000000885 00000460µs 823.758-byte
2024.04.04 08:55:50.505 Calculating SHA-1 checksum 00002214µs
2024.04.04 08:55:50.507 Encrypting the byte block 0000000885 00001862µs
2024.04.04 08:55:50.508 Writing the encrypted byte block 0000000885 00000643µs 823.758-byte
2024.04.04 08:55:50.509 FINISHED THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.04 08:55:50.509 ..................................................................................................
2024.04.04 08:55:50.510 OVERALL TIMES
2024.04.04 08:55:50.510 Time to read 0000000885 byte blocks 00000714ms
2024.04.04 08:55:50.511 Time to calculate the SHA-1 checksum 00004647ms
2024.04.04 08:55:50.511 Time to complete the encryption 00004007ms
2024.04.04 08:55:50.512 Time to write 0000000885 byte blocks 00000795ms
2024.04.04 08:55:50.512 Total time 00010164ms
2024.04.04 08:55:50.512 ..................................................................................................
2024.04.04 08:55:50.513 SAVING THE ENCRYPTED FILE
2024.04.04 08:55:50.513 C:\Users\guest\ema\msk\1712213740111318600_YIXH4owc71SQuRX5FxT6CCJial293nBO.msk 1.854.706.126-byte
2024.04.04 08:55:50.513 ..................................................................................................
2024.04.04 08:55:50.513 The checksum SHA-1 was calculated
2024.04.04 08:55:50.514 Encryption performed successfully
2024.04.04 08:55:50.514
2024.04.04 08:55:50.514 FINISHED fileEncryption() ::
Using a large block size (909,715,200-byte) the encryption takes 3 cycles
2024.04.04 08:56:43.967 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2024.04.04 08:56:43.967 RUNNING fileEncryption() ::
2024.04.04 08:56:43.968 FILE TO ENCRYPT
2024.04.04 08:56:43.968 C:\Users\guest\ema\src\movie.mkv
2024.04.04 08:56:43.968 Size = 1.854.694.887-byte
2024.04.04 08:56:43.969 ..................................................................................................
2024.04.04 08:56:43.969 ENCRYPTION KEY
2024.04.04 08:56:43.969 C:\Users\guest\ema\key\1712213110928004300_a7721cd837e1de1e5c0daec15bf4c13fca340142.key
2024.04.04 08:56:43.970 Size = 55.556-byte
2024.04.04 08:56:43.970 sub-key_1: from index '0' to index '2.097.151'
2024.04.04 08:56:43.970 sub-key_2: from index '2.097.152' to index '4.194.304'
2024.04.04 08:56:43.970
2024.04.04 08:56:43.970 This key adds 10297 random bytes to the top of pre-encryption data if origin data is a file
2024.04.04 08:56:43.972 and 321 random bytes to the top of pre-encryption data if origin data is a byte array
2024.04.04 08:56:43.972 ..................................................................................................
2024.04.04 08:56:44.004 ENCRYPTION SETTINGS
2024.04.04 08:56:44.005 Encryption execution core: ENABLED
2024.04.04 08:56:44.005 Checksum calculation: ENABLED with SHA-1 algorithm
2024.04.04 08:56:44.006 Encryption details: ENABLED
2024.04.04 08:56:44.006 Use a random name to save the encrypted file: ENABLED
2024.04.04 08:56:44.006 ..................................................................................................
2024.04.04 08:56:44.006 STARTING THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.04 08:56:47.313 Reading the prepared byte block 0000000001 00585045µs 909.715.200-byte
2024.04.04 08:56:47.314 Calculating SHA-1 checksum 02280724µs
2024.04.04 08:56:49.092 Encrypting the byte block 0000000001 01777072µs
2024.04.04 08:56:50.481 Writing the encrypted byte block 0000000001 01388396µs 909.715.200-byte
2024.04.04 08:56:50.482 ....
2024.04.04 08:56:50.483 ....
2024.04.04 08:56:50.483 ....
2024.04.04 08:56:50.483 ....
2024.04.04 08:56:56.654 Reading the prepared byte block 0000000003 00014506µs 35.275.726-byte
2024.04.04 08:56:56.655 Calculating SHA-1 checksum 00086739µs
2024.04.04 08:56:56.726 Encrypting the byte block 0000000003 00070344µs
2024.04.04 08:56:56.755 Writing the encrypted byte block 0000000003 00029230µs 35.275.726-byte
2024.04.04 08:56:56.756 FINISHED THE CORE EXECUTION IN ENCRYPTION MODE
2024.04.04 08:56:56.756 ..................................................................................................
2024.04.04 08:56:56.757 OVERALL TIMES
2024.04.04 08:56:56.757 Time to read 0000000003 byte blocks 00000990ms
2024.04.04 08:56:56.758 Time to calculate the SHA-1 checksum 00004641ms
2024.04.04 08:56:56.758 Time to complete the encryption 00003783ms
2024.04.04 08:56:56.758 Time to write 0000000003 byte blocks 00002301ms
2024.04.04 08:56:56.759 Total time 00011716ms
2024.04.04 08:56:56.759 ..................................................................................................
2024.04.04 08:56:56.759 SAVING THE ENCRYPTED FILE
2024.04.04 08:56:56.760 C:\Users\guest\ema\msk\1712213804099898100_PYB7mqtlzaQKN1cuCk6QLhCelo45I5hP.msk 1.854.706.126-byte
2024.04.04 08:56:56.760 ..................................................................................................
2024.04.04 08:56:56.761 The checksum SHA-1 was calculated
2024.04.04 08:56:56.761 Encryption performed successfully
2024.04.04 08:56:56.761
2024.04.04 08:56:56.763 FINISHED fileEncryption() ::
It is evident that a large byte block size results in fewer cycles. It is always possible to optimise performance a little by adjusting the size of the byte block, although the examples above show that by changing the block size, performance does not change much.
The performance of hardware and software systems can vary depending on the architecture and computing power. Some systems achieve greater performance by using large byte blocks, which require few calculation cycles, while others use small byte blocks and require more calculation cycles.