Skip to content

Commit

Permalink
Make IV/buf in prov_cipher_ctx_st aligned
Browse files Browse the repository at this point in the history
Make IV/buf aligned will drastically improve performance
as some architecture performs badly on misaligned memory
access.

Ref to
https://gist.github.com/ZenithalHourlyRate/7b5175734f87acb73d0bbc53391d7140#file-2-openssl-long-md
Ref to
#18197

Signed-off-by: Hongren (Zenithal) Zheng <i@zenithal.me>

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #18267)

(cherry picked from commit 2787a70)
  • Loading branch information
ZenithalHourlyRate authored and t8m committed Nov 21, 2022
1 parent 5c03d5d commit e12f0f1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions providers/implementations/include/prov/ciphercommon.h
Expand Up @@ -42,6 +42,13 @@ typedef int (PROV_CIPHER_HW_FN)(PROV_CIPHER_CTX *dat, unsigned char *out,
#define PROV_CIPHER_FLAG_INVERSE_CIPHER 0x0200

struct prov_cipher_ctx_st {
/* place buffer at the beginning for memory alignment */
/* The original value of the iv */
unsigned char oiv[GENERIC_BLOCK_SIZE];
/* Buffer of partial blocks processed via update calls */
unsigned char buf[GENERIC_BLOCK_SIZE];
unsigned char iv[GENERIC_BLOCK_SIZE];

block128_f block;
union {
cbc128_f cbc;
Expand Down Expand Up @@ -82,12 +89,6 @@ struct prov_cipher_ctx_st {
* manage partial blocks themselves.
*/
unsigned int num;

/* The original value of the iv */
unsigned char oiv[GENERIC_BLOCK_SIZE];
/* Buffer of partial blocks processed via update calls */
unsigned char buf[GENERIC_BLOCK_SIZE];
unsigned char iv[GENERIC_BLOCK_SIZE];
const PROV_CIPHER_HW *hw; /* hardware specific functions */
const void *ks; /* Pointer to algorithm specific key data */
OSSL_LIB_CTX *libctx;
Expand Down

0 comments on commit e12f0f1

Please sign in to comment.