The cipher initialization cost has been found to be computationally expensive, especially in the OpenSSL 3.x API.
In order to optimize the cost of using OpenSSL to perform consecutive AES/GCM encryption and decryption operations, two flags are set and passed as parameters.
The first flag indicates whether a different cipher is required for the upcoming operations (i.e., the key size has changed). If that is the case, a cipher is initialized and set to the provided context. If not, those steps are omitted, thus reducing the time required for the operation.
The second flag indicates whether the IV length has changed and is used in a similar way as the first flag.
The rest of the steps required for the operation are performed regardless of the flags.
The handling of freeing arrays that were part of that functionality is, also, updated to comply with the newer approach to cleanup code.
The cipher initialization cost has been found to be computationally expensive, especially in the OpenSSL 3.x API.
In order to optimize the cost of using OpenSSL to perform consecutive AES/GCM encryption and decryption operations, two flags are set and passed as parameters.
The first flag indicates whether a different cipher is required for the upcoming operations (i.e., the key size has changed). If that is the case, a cipher is initialized and set to the provided context. If not, those steps are omitted, thus reducing the time required for the operation.
The second flag indicates whether the IV length has changed and is used in a similar way as the first flag.
The rest of the steps required for the operation are performed regardless of the flags.
The handling of freeing arrays that were part of that functionality is, also, updated to comply with the newer approach to cleanup code.
Back-ported from: https://github.com/ibmruntimes/openj9-openjdk-jdk/pull/655
Signed-off by: Kostas Tsiounis kostas.tsiounis@ibm.com