#include "internal/provider_algs.h"
#include "ciphers_locl.h"
+static OSSL_OP_cipher_encrypt_init_fn aes_einit;
+static OSSL_OP_cipher_decrypt_init_fn aes_dinit;
+static OSSL_OP_cipher_update_fn aes_block_update;
+static OSSL_OP_cipher_final_fn aes_block_final;
+static OSSL_OP_cipher_update_fn aes_stream_update;
+static OSSL_OP_cipher_final_fn aes_stream_final;
+static OSSL_OP_cipher_cipher_fn aes_cipher;
+static OSSL_OP_cipher_freectx_fn aes_freectx;
+static OSSL_OP_cipher_dupctx_fn aes_dupctx;
+static OSSL_OP_cipher_key_length_fn key_length_256;
+static OSSL_OP_cipher_key_length_fn key_length_192;
+static OSSL_OP_cipher_key_length_fn key_length_128;
+static OSSL_OP_cipher_iv_length_fn iv_length_16;
+static OSSL_OP_cipher_iv_length_fn iv_length_0;
+static OSSL_OP_cipher_block_size_fn block_size_16;
+static OSSL_OP_cipher_block_size_fn block_size_1;
+static OSSL_OP_cipher_ctx_get_params_fn aes_ctx_get_params;
+static OSSL_OP_cipher_ctx_set_params_fn aes_ctx_set_params;
+
static int PROV_AES_KEY_generic_init(PROV_AES_KEY *ctx,
const unsigned char *iv,
size_t ivlen,
}
static int aes_block_update(void *vctx, unsigned char *out, size_t *outl,
- const unsigned char *in, size_t inl)
+ size_t outsize, const unsigned char *in, size_t inl)
{
PROV_AES_KEY *ctx = (PROV_AES_KEY *)vctx;
size_t nextblocks = fillblock(ctx->buf, &ctx->bufsz, AES_BLOCK_SIZE, &in,
*/
if (ctx->bufsz == AES_BLOCK_SIZE
&& (ctx->enc || inl > 0 || !ctx->pad)) {
+ if (outsize < AES_BLOCK_SIZE)
+ return 0;
if (!ctx->ciph->cipher(ctx, out, ctx->buf, AES_BLOCK_SIZE))
return 0;
ctx->bufsz = 0;
return 0;
nextblocks -= AES_BLOCK_SIZE;
}
+ outlint += nextblocks;
+ if (outsize < outlint)
+ return 0;
if (!ctx->ciph->cipher(ctx, out, in, nextblocks))
return 0;
in += nextblocks;
inl -= nextblocks;
- outlint += nextblocks;
}
if (!trailingdata(ctx->buf, &ctx->bufsz, AES_BLOCK_SIZE, &in, &inl))
return 0;
return inl == 0;
}
-static int aes_block_final(void *vctx, unsigned char *out, size_t *outl)
+static int aes_block_final(void *vctx, unsigned char *out, size_t *outl,
+ size_t outsize)
{
PROV_AES_KEY *ctx = (PROV_AES_KEY *)vctx;
return 0;
}
+ if (outsize < AES_BLOCK_SIZE)
+ return 0;
if (!ctx->ciph->cipher(ctx, out, ctx->buf, AES_BLOCK_SIZE))
return 0;
ctx->bufsz = 0;
if (ctx->pad && !unpadblock(ctx->buf, &ctx->bufsz, AES_BLOCK_SIZE))
return 0;
+ if (outsize < ctx->bufsz)
+ return 0;
memcpy(out, ctx->buf, ctx->bufsz);
*outl = ctx->bufsz;
ctx->bufsz = 0;
}
static int aes_stream_update(void *vctx, unsigned char *out, size_t *outl,
- const unsigned char *in, size_t inl)
+ size_t outsize, const unsigned char *in,
+ size_t inl)
{
PROV_AES_KEY *ctx = (PROV_AES_KEY *)vctx;
+ if (outsize < inl)
+ return 0;
+
if (!ctx->ciph->cipher(ctx, out, in, inl))
return 0;
*outl = inl;
return 1;
}
-static int aes_stream_final(void *vctx, unsigned char *out, size_t *outl)
+static int aes_stream_final(void *vctx, unsigned char *out, size_t *outl,
+ size_t outsize)
{
*outl = 0;
return 1;
}
#define IMPLEMENT_new_params(lcmode, UCMODE) \
+ static OSSL_OP_cipher_get_params_fn aes_##lcmode##_get_params; \
static int aes_##lcmode##_get_params(const OSSL_PARAM params[]) \
{ \
const OSSL_PARAM *p; \
}
#define IMPLEMENT_new_ctx(lcmode, UCMODE, len) \
+ static OSSL_OP_cipher_newctx_fn aes_##len##_##lcmode##_newctx; \
static void *aes_##len##_##lcmode##_newctx(void) \
{ \
PROV_AES_KEY *ctx = OPENSSL_zalloc(sizeof(*ctx)); \
\
ctx->pad = 1; \
ctx->keylen = (len / 8); \
- ctx->ciph = PROV_AES_CIPHER_##lcmode(); \
+ ctx->ciph = PROV_AES_CIPHER_##lcmode(ctx->keylen); \
ctx->mode = EVP_CIPH_##UCMODE##_MODE; \
return ctx; \
}