Skip to content

Commit

Permalink
Fix partial block encryption in cfb and ofb for s390x (legacy)
Browse files Browse the repository at this point in the history
Use the number of processed bytes information (num) from the generic
cipher context for the partial block handling in cfb and ofb also in
s390x-legacy code. For more details see 4df92c1 ("Fix partial block
encryption in cfb and ofb for s390x").

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #23201)

(cherry picked from commit f9ccd20)
  • Loading branch information
holger-dengler authored and t8m committed Jan 12, 2024
1 parent 8e60b9d commit b1b3e6b
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions crypto/evp/e_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,6 @@ typedef struct {
/* KMO-AES parameter block - end */
} kmo;
unsigned int fc;

int res;
} S390X_AES_OFB_CTX;

typedef struct {
Expand All @@ -849,8 +847,6 @@ typedef struct {
/* KMF-AES parameter block - end */
} kmf;
unsigned int fc;

int res;
} S390X_AES_CFB_CTX;

typedef struct {
Expand Down Expand Up @@ -1002,7 +998,6 @@ static int s390x_aes_ofb_init_key(EVP_CIPHER_CTX *ctx,
memcpy(cctx->kmo.param.cv, iv, ivlen);
memcpy(cctx->kmo.param.k, key, keylen);
cctx->fc = S390X_AES_FC(keylen);
cctx->res = 0;
return 1;
}

Expand All @@ -1012,7 +1007,7 @@ static int s390x_aes_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
S390X_AES_OFB_CTX *cctx = EVP_C_DATA(S390X_AES_OFB_CTX, ctx);
const int ivlen = EVP_CIPHER_CTX_get_iv_length(ctx);
unsigned char *iv = EVP_CIPHER_CTX_iv_noconst(ctx);
int n = cctx->res;
int n = ctx->num;
int rem;

memcpy(cctx->kmo.param.cv, iv, ivlen);
Expand Down Expand Up @@ -1045,7 +1040,7 @@ static int s390x_aes_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
}

memcpy(iv, cctx->kmo.param.cv, ivlen);
cctx->res = n;
ctx->num = n;
return 1;
}

Expand All @@ -1063,7 +1058,6 @@ static int s390x_aes_cfb_init_key(EVP_CIPHER_CTX *ctx,
if (!enc)
cctx->fc |= S390X_DECRYPT;

cctx->res = 0;
memcpy(cctx->kmf.param.cv, iv, ivlen);
memcpy(cctx->kmf.param.k, key, keylen);
return 1;
Expand All @@ -1077,7 +1071,7 @@ static int s390x_aes_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
const int enc = EVP_CIPHER_CTX_is_encrypting(ctx);
const int ivlen = EVP_CIPHER_CTX_get_iv_length(ctx);
unsigned char *iv = EVP_CIPHER_CTX_iv_noconst(ctx);
int n = cctx->res;
int n = ctx->num;
int rem;
unsigned char tmp;

Expand Down Expand Up @@ -1115,7 +1109,7 @@ static int s390x_aes_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
}

memcpy(iv, cctx->kmf.param.cv, ivlen);
cctx->res = n;
ctx->num = n;
return 1;
}

Expand Down

0 comments on commit b1b3e6b

Please sign in to comment.