-/* $OpenBSD: e_aes.c,v 1.53 2023/07/07 19:37:53 beck Exp $ */
+/* $OpenBSD: e_aes.c,v 1.54 2023/09/28 11:29:10 tb Exp $ */
/* ====================================================================
* Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved.
*
gctx->tls_aad_len = -1;
return 1;
- case EVP_CTRL_GCM_SET_IVLEN:
+ case EVP_CTRL_AEAD_GET_IVLEN:
+ *(int *)ptr = gctx->ivlen;
+ return 1;
+
+ case EVP_CTRL_AEAD_SET_IVLEN:
if (arg <= 0)
return 0;
/* Allocate memory for IV if needed */
#define CUSTOM_FLAGS \
( EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CUSTOM_IV | \
+ EVP_CIPH_FLAG_CUSTOM_IV_LENGTH | \
EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT | \
EVP_CIPH_CTRL_INIT | EVP_CIPH_CUSTOM_COPY )
cctx->len_set = 0;
return 1;
- case EVP_CTRL_CCM_SET_IVLEN:
+ case EVP_CTRL_AEAD_GET_IVLEN:
+ *(int *)ptr = 15 - cctx->L;
+ return 1;
+
+ case EVP_CTRL_AEAD_SET_IVLEN:
arg = 15 - arg;
case EVP_CTRL_CCM_SET_L:
-/* $OpenBSD: e_chacha20poly1305.c,v 1.31 2023/08/24 04:33:08 tb Exp $ */
+/* $OpenBSD: e_chacha20poly1305.c,v 1.32 2023/09/28 11:29:10 tb Exp $ */
/*
* Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <limits.h>
#include <stdint.h>
#include <string.h>
cpx->nonce_len = sizeof(cpx->nonce);
return 1;
+ case EVP_CTRL_AEAD_GET_IVLEN:
+ if (cpx->nonce_len > INT_MAX)
+ return 0;
+ *(int *)ptr = (int)cpx->nonce_len;
+ return 1;
+
case EVP_CTRL_AEAD_SET_IVLEN:
if (arg <= 0 || arg > sizeof(cpx->nonce))
return 0;
.key_len = 32,
.iv_len = 12,
.flags = EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT |
- EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_AEAD_CIPHER |
- EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_FLAG_DEFAULT_ASN1,
+ EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_IV_LENGTH |
+ EVP_CIPH_FLAG_AEAD_CIPHER | EVP_CIPH_FLAG_CUSTOM_CIPHER |
+ EVP_CIPH_FLAG_DEFAULT_ASN1,
.init = chacha20_poly1305_init,
.do_cipher = chacha20_poly1305_cipher,
.cleanup = chacha20_poly1305_cleanup,
-/* $OpenBSD: evp_lib.c,v 1.27 2023/07/07 19:37:53 beck Exp $ */
+/* $OpenBSD: evp_lib.c,v 1.28 2023/09/28 11:29:10 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
int
EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
{
- return ctx->cipher->iv_len;
+ int iv_length = 0;
+
+ if ((ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_IV_LENGTH) == 0)
+ return ctx->cipher->iv_len;
+
+ /*
+ * XXX - sanity would suggest to pass the size of the pointer along,
+ * but unfortunately we have to match the other crowd.
+ */
+ if (EVP_CIPHER_CTX_ctrl((EVP_CIPHER_CTX *)ctx, EVP_CTRL_GET_IVLEN, 0,
+ &iv_length) != 1)
+ return -1;
+
+ return iv_length;
}
unsigned char *
-/* $OpenBSD: evp_local.h,v 1.4 2023/08/11 05:10:35 tb Exp $ */
+/* $OpenBSD: evp_local.h,v 1.5 2023/09/28 11:29:10 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
__BEGIN_HIDDEN_DECLS
+/* XXX - move these to evp.h after unlock. */
+#define EVP_CTRL_GET_IVLEN 0x25
+#define EVP_CIPH_FLAG_CUSTOM_IV_LENGTH 0x400000
+
+#define EVP_CTRL_AEAD_GET_IVLEN EVP_CTRL_GET_IVLEN
+
/*
* Don't free md_ctx->pctx in EVP_MD_CTX_cleanup(). Needed for ownership
* handling in EVP_MD_CTX_set_pkey_ctx().