-/* $OpenBSD: evp_enc.c,v 1.68 2023/12/20 11:33:52 tb Exp $ */
+/* $OpenBSD: evp_enc.c,v 1.69 2023/12/20 14:10:03 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
EVPerror(EVP_R_NO_CIPHER_SET);
return 0;
}
- /* we assume block size is a power of 2 in *cryptUpdate */
+
+ /* Block sizes must be a power of 2 due to the use of block_mask. */
if (ctx->cipher->block_size != 1 &&
ctx->cipher->block_size != 8 &&
ctx->cipher->block_size != 16) {
if (!ctx->cipher->init(ctx, key, iv, enc))
return 0;
}
+
ctx->partial_len = 0;
ctx->final_used = 0;
- ctx->block_mask = ctx->cipher->block_size - 1;
+
return 1;
}
const unsigned char *in, int inl)
{
const int block_size = ctx->cipher->block_size;
- const int block_mask = ctx->block_mask;
+ const int block_mask = block_size - 1;
int partial_len = ctx->partial_len;
int len = 0, total_len = 0;
*outl = 0;
+ if ((block_size & block_mask) != 0)
+ return 0;
+
if (inl < 0)
return 0;
const unsigned char *in, int inl)
{
const int block_size = ctx->cipher->block_size;
+ const int block_mask = block_size - 1;
int len = 0, total_len = 0;
*outl = 0;
+ if ((block_size & block_mask) != 0)
+ return 0;
+
if (inl < 0)
return 0;
* length output from EVP_EncryptUpdate() is inl & ~block_mask.
* Ensure (inl & ~block_mask) + block_size doesn't overflow.
*/
- if ((inl & ~ctx->block_mask) > INT_MAX - block_size) {
+ if ((inl & ~block_mask) > INT_MAX - block_size) {
EVPerror(EVP_R_TOO_LARGE);
return 0;
}
-/* $OpenBSD: evp_local.h,v 1.7 2023/12/20 11:31:17 tb Exp $ */
+/* $OpenBSD: evp_local.h,v 1.8 2023/12/20 14:10:03 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
unsigned long flags; /* Various flags */
void *cipher_data; /* per EVP data */
int final_used;
- int block_mask;
unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */
} /* EVP_CIPHER_CTX */;