From 5091f2e318cced2d5ea871d8552914204b33fdea Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 16 Oct 2025 15:48:06 -0400 Subject: [PATCH] ciphers: Use include file for generated code Signed-off-by: Simo Sorce Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz Reviewed-by: Dmitry Belyavskiy (Merged from https://github.com/openssl/openssl/pull/28838) --- .gitignore | 30 ++--- build.info | 120 +++++++++--------- ...mac_sha.c.in => cipher_aes_cbc_hmac_sha.c} | 38 +----- .../ciphers/cipher_aes_cbc_hmac_sha.inc.in | 45 +++++++ ...etm.c.in => cipher_aes_cbc_hmac_sha_etm.c} | 20 +-- .../cipher_aes_cbc_hmac_sha_etm.inc.in | 26 ++++ ..._aes_gcm_siv.c.in => cipher_aes_gcm_siv.c} | 16 +-- .../ciphers/cipher_aes_gcm_siv.inc.in | 24 ++++ .../{cipher_aes_ocb.c.in => cipher_aes_ocb.c} | 19 +-- .../ciphers/cipher_aes_ocb.inc.in | 27 ++++ .../{cipher_aes_siv.c.in => cipher_aes_siv.c} | 17 +-- .../ciphers/cipher_aes_siv.inc.in | 24 ++++ .../{cipher_aes_wrp.c.in => cipher_aes_wrp.c} | 9 +- .../ciphers/cipher_aes_wrp.inc.in | 16 +++ .../{cipher_aes_xts.c.in => cipher_aes_xts.c} | 8 +- .../ciphers/cipher_aes_xts.inc.in | 16 +++ ...cipher_chacha20.c.in => cipher_chacha20.c} | 16 +-- .../ciphers/cipher_chacha20.inc.in | 23 ++++ ...ly1305.c.in => cipher_chacha20_poly1305.c} | 22 +--- .../ciphers/cipher_chacha20_poly1305.inc.in | 28 ++++ .../{cipher_null.c.in => cipher_null.c} | 15 +-- .../ciphers/cipher_null.inc.in | 22 ++++ ...c4_hmac_md5.c.in => cipher_rc4_hmac_md5.c} | 18 +-- .../ciphers/cipher_rc4_hmac_md5.inc.in | 26 ++++ .../{cipher_sm4_xts.c.in => cipher_sm4_xts.c} | 8 +- .../ciphers/cipher_sm4_xts.inc.in | 16 +++ .../{ciphercommon.c.in => ciphercommon.c} | 54 +------- .../ciphers/ciphercommon.inc.in | 52 ++++++++ ...phercommon_ccm.c.in => ciphercommon_ccm.c} | 21 +-- .../ciphers/ciphercommon_ccm.inc.in | 29 +++++ ...phercommon_gcm.c.in => ciphercommon_gcm.c} | 26 +--- .../ciphers/ciphercommon_gcm.inc.in | 33 +++++ 32 files changed, 506 insertions(+), 358 deletions(-) rename providers/implementations/ciphers/{cipher_aes_cbc_hmac_sha.c.in => cipher_aes_cbc_hmac_sha.c} (85%) create mode 100644 providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.inc.in rename providers/implementations/ciphers/{cipher_aes_cbc_hmac_sha_etm.c.in => cipher_aes_cbc_hmac_sha_etm.c} (93%) create mode 100644 providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.inc.in rename providers/implementations/ciphers/{cipher_aes_gcm_siv.c.in => cipher_aes_gcm_siv.c} (94%) create mode 100644 providers/implementations/ciphers/cipher_aes_gcm_siv.inc.in rename providers/implementations/ciphers/{cipher_aes_ocb.c.in => cipher_aes_ocb.c} (95%) create mode 100644 providers/implementations/ciphers/cipher_aes_ocb.inc.in rename providers/implementations/ciphers/{cipher_aes_siv.c.in => cipher_aes_siv.c} (93%) create mode 100644 providers/implementations/ciphers/cipher_aes_siv.inc.in rename providers/implementations/ciphers/{cipher_aes_wrp.c.in => cipher_aes_wrp.c} (98%) create mode 100644 providers/implementations/ciphers/cipher_aes_wrp.inc.in rename providers/implementations/ciphers/{cipher_aes_xts.c.in => cipher_aes_xts.c} (98%) create mode 100644 providers/implementations/ciphers/cipher_aes_xts.inc.in rename providers/implementations/ciphers/{cipher_chacha20.c.in => cipher_chacha20.c} (93%) create mode 100644 providers/implementations/ciphers/cipher_chacha20.inc.in rename providers/implementations/ciphers/{cipher_chacha20_poly1305.c.in => cipher_chacha20_poly1305.c} (91%) create mode 100644 providers/implementations/ciphers/cipher_chacha20_poly1305.inc.in rename providers/implementations/ciphers/{cipher_null.c.in => cipher_null.c} (91%) create mode 100644 providers/implementations/ciphers/cipher_null.inc.in rename providers/implementations/ciphers/{cipher_rc4_hmac_md5.c.in => cipher_rc4_hmac_md5.c} (90%) create mode 100644 providers/implementations/ciphers/cipher_rc4_hmac_md5.inc.in rename providers/implementations/ciphers/{cipher_sm4_xts.c.in => cipher_sm4_xts.c} (97%) create mode 100644 providers/implementations/ciphers/cipher_sm4_xts.inc.in rename providers/implementations/ciphers/{ciphercommon.c.in => ciphercommon.c} (88%) create mode 100644 providers/implementations/ciphers/ciphercommon.inc.in rename providers/implementations/ciphers/{ciphercommon_ccm.c.in => ciphercommon_ccm.c} (91%) create mode 100644 providers/implementations/ciphers/ciphercommon_ccm.inc.in rename providers/implementations/ciphers/{ciphercommon_gcm.c.in => ciphercommon_gcm.c} (92%) create mode 100644 providers/implementations/ciphers/ciphercommon_gcm.inc.in diff --git a/.gitignore b/.gitignore index 33cb09d9b2d..0932e7780f4 100644 --- a/.gitignore +++ b/.gitignore @@ -140,22 +140,22 @@ providers/implementations/skeymgmt/generic.inc providers/implementations/storemgmt/file_store_any2obj.inc providers/implementations/storemgmt/file_store.inc providers/implementations/storemgmt/winstore_store.inc -providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c -providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c -providers/implementations/ciphers/cipher_aes_gcm_siv.c -providers/implementations/ciphers/cipher_aes_ocb.c -providers/implementations/ciphers/cipher_aes_siv.c -providers/implementations/ciphers/cipher_aes_wrp.c -providers/implementations/ciphers/cipher_aes_xts.c -providers/implementations/ciphers/ciphercommon.c -providers/implementations/ciphers/ciphercommon_ccm.c -providers/implementations/ciphers/ciphercommon_gcm.c -providers/implementations/ciphers/cipher_chacha20.c -providers/implementations/ciphers/cipher_chacha20_poly1305.c -providers/implementations/ciphers/cipher_null.c -providers/implementations/ciphers/cipher_rc4_hmac_md5.c +providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.inc +providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.inc +providers/implementations/ciphers/cipher_aes_gcm_siv.inc +providers/implementations/ciphers/cipher_aes_ocb.inc +providers/implementations/ciphers/cipher_aes_siv.inc +providers/implementations/ciphers/cipher_aes_wrp.inc +providers/implementations/ciphers/cipher_aes_xts.inc +providers/implementations/ciphers/ciphercommon.inc +providers/implementations/ciphers/ciphercommon_ccm.inc +providers/implementations/ciphers/ciphercommon_gcm.inc +providers/implementations/ciphers/cipher_chacha20.inc +providers/implementations/ciphers/cipher_chacha20_poly1305.inc +providers/implementations/ciphers/cipher_null.inc +providers/implementations/ciphers/cipher_rc4_hmac_md5.inc providers/implementations/ciphers/cipher_sm2_xts.c -providers/implementations/ciphers/cipher_sm4_xts.c +providers/implementations/ciphers/cipher_sm4_xts.inc providers/implementations/digests/blake2_prov.c providers/implementations/digests/digestcommon.c providers/implementations/digests/mdc2_prov.c diff --git a/build.info b/build.info index 061598eedd1..c2748d07020 100644 --- a/build.info +++ b/build.info @@ -99,21 +99,21 @@ DEPEND[]=include/openssl/asn1.h \ providers/implementations/storemgmt/file_store_any2obj.inc \ providers/implementations/storemgmt/file_store.inc \ providers/implementations/storemgmt/winstore_store.inc \ - providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c \ - providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c \ - providers/implementations/ciphers/cipher_aes_gcm_siv.c \ - providers/implementations/ciphers/cipher_aes_ocb.c \ - providers/implementations/ciphers/cipher_aes_siv.c \ - providers/implementations/ciphers/cipher_aes_wrp.c \ - providers/implementations/ciphers/cipher_aes_xts.c \ - providers/implementations/ciphers/ciphercommon.c \ - providers/implementations/ciphers/ciphercommon_ccm.c \ - providers/implementations/ciphers/ciphercommon_gcm.c \ - providers/implementations/ciphers/cipher_chacha20.c \ - providers/implementations/ciphers/cipher_chacha20_poly1305.c \ - providers/implementations/ciphers/cipher_null.c \ - providers/implementations/ciphers/cipher_rc4_hmac_md5.c \ - providers/implementations/ciphers/cipher_sm4_xts.c \ + providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.inc \ + providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.inc \ + providers/implementations/ciphers/cipher_aes_gcm_siv.inc \ + providers/implementations/ciphers/cipher_aes_ocb.inc \ + providers/implementations/ciphers/cipher_aes_siv.inc \ + providers/implementations/ciphers/cipher_aes_wrp.inc \ + providers/implementations/ciphers/cipher_aes_xts.inc \ + providers/implementations/ciphers/ciphercommon.inc \ + providers/implementations/ciphers/ciphercommon_ccm.inc \ + providers/implementations/ciphers/ciphercommon_gcm.inc \ + providers/implementations/ciphers/cipher_chacha20.inc \ + providers/implementations/ciphers/cipher_chacha20_poly1305.inc \ + providers/implementations/ciphers/cipher_null.inc \ + providers/implementations/ciphers/cipher_rc4_hmac_md5.inc \ + providers/implementations/ciphers/cipher_sm4_xts.inc \ providers/implementations/digests/blake2_prov.c \ providers/implementations/digests/digestcommon.c \ providers/implementations/digests/mdc2_prov.c \ @@ -217,21 +217,21 @@ DEPEND[providers/implementations/asymciphers/rsa_enc.inc \ providers/implementations/storemgmt/file_store_any2obj.inc \ providers/implementations/storemgmt/file_store.inc \ providers/implementations/storemgmt/winstore_store.inc \ - providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c \ - providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c \ - providers/implementations/ciphers/cipher_aes_gcm_siv.c \ - providers/implementations/ciphers/cipher_aes_ocb.c \ - providers/implementations/ciphers/cipher_aes_siv.c \ - providers/implementations/ciphers/cipher_aes_wrp.c \ - providers/implementations/ciphers/cipher_aes_xts.c \ - providers/implementations/ciphers/ciphercommon.c \ - providers/implementations/ciphers/ciphercommon_ccm.c \ - providers/implementations/ciphers/ciphercommon_gcm.c \ - providers/implementations/ciphers/cipher_chacha20.c \ - providers/implementations/ciphers/cipher_chacha20_poly1305.c \ - providers/implementations/ciphers/cipher_null.c \ - providers/implementations/ciphers/cipher_rc4_hmac_md5.c \ - providers/implementations/ciphers/cipher_sm4_xts.c \ + providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.inc \ + providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.inc \ + providers/implementations/ciphers/cipher_aes_gcm_siv.inc \ + providers/implementations/ciphers/cipher_aes_ocb.inc \ + providers/implementations/ciphers/cipher_aes_siv.inc \ + providers/implementations/ciphers/cipher_aes_wrp.inc \ + providers/implementations/ciphers/cipher_aes_xts.inc \ + providers/implementations/ciphers/ciphercommon.inc \ + providers/implementations/ciphers/ciphercommon_ccm.inc \ + providers/implementations/ciphers/ciphercommon_gcm.inc \ + providers/implementations/ciphers/cipher_chacha20.inc \ + providers/implementations/ciphers/cipher_chacha20_poly1305.inc \ + providers/implementations/ciphers/cipher_null.inc \ + providers/implementations/ciphers/cipher_rc4_hmac_md5.inc \ + providers/implementations/ciphers/cipher_sm4_xts.inc \ providers/implementations/digests/blake2_prov.c \ providers/implementations/digests/digestcommon.c \ providers/implementations/digests/mdc2_prov.c \ @@ -353,36 +353,36 @@ GENERATE[providers/implementations/storemgmt/file_store.inc]=\ providers/implementations/storemgmt/file_store.inc.in GENERATE[providers/implementations/storemgmt/winstore_store.inc]=\ providers/implementations/storemgmt/winstore_store.inc.in -GENERATE[providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c]=\ - providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c.in -GENERATE[providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c]=\ - providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c.in -GENERATE[providers/implementations/ciphers/cipher_aes_gcm_siv.c]=\ - providers/implementations/ciphers/cipher_aes_gcm_siv.c.in -GENERATE[providers/implementations/ciphers/cipher_aes_ocb.c]=\ - providers/implementations/ciphers/cipher_aes_ocb.c.in -GENERATE[providers/implementations/ciphers/cipher_aes_siv.c]=\ - providers/implementations/ciphers/cipher_aes_siv.c.in -GENERATE[providers/implementations/ciphers/cipher_aes_wrp.c]=\ - providers/implementations/ciphers/cipher_aes_wrp.c.in -GENERATE[providers/implementations/ciphers/cipher_aes_xts.c]=\ - providers/implementations/ciphers/cipher_aes_xts.c.in -GENERATE[providers/implementations/ciphers/ciphercommon.c]=\ - providers/implementations/ciphers/ciphercommon.c.in -GENERATE[providers/implementations/ciphers/ciphercommon_ccm.c]=\ - providers/implementations/ciphers/ciphercommon_ccm.c.in -GENERATE[providers/implementations/ciphers/ciphercommon_gcm.c]=\ - providers/implementations/ciphers/ciphercommon_gcm.c.in -GENERATE[providers/implementations/ciphers/cipher_chacha20.c]=\ - providers/implementations/ciphers/cipher_chacha20.c.in -GENERATE[providers/implementations/ciphers/cipher_chacha20_poly1305.c]=\ - providers/implementations/ciphers/cipher_chacha20_poly1305.c.in -GENERATE[providers/implementations/ciphers/cipher_null.c]=\ - providers/implementations/ciphers/cipher_null.c.in -GENERATE[providers/implementations/ciphers/cipher_rc4_hmac_md5.c]=\ - providers/implementations/ciphers/cipher_rc4_hmac_md5.c.in -GENERATE[providers/implementations/ciphers/cipher_sm4_xts.c]=\ - providers/implementations/ciphers/cipher_sm4_xts.c.in +GENERATE[providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.inc]=\ + providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.inc.in +GENERATE[providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.inc]=\ + providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.inc.in +GENERATE[providers/implementations/ciphers/cipher_aes_gcm_siv.inc]=\ + providers/implementations/ciphers/cipher_aes_gcm_siv.inc.in +GENERATE[providers/implementations/ciphers/cipher_aes_ocb.inc]=\ + providers/implementations/ciphers/cipher_aes_ocb.inc.in +GENERATE[providers/implementations/ciphers/cipher_aes_siv.inc]=\ + providers/implementations/ciphers/cipher_aes_siv.inc.in +GENERATE[providers/implementations/ciphers/cipher_aes_wrp.inc]=\ + providers/implementations/ciphers/cipher_aes_wrp.inc.in +GENERATE[providers/implementations/ciphers/cipher_aes_xts.inc]=\ + providers/implementations/ciphers/cipher_aes_xts.inc.in +GENERATE[providers/implementations/ciphers/ciphercommon.inc]=\ + providers/implementations/ciphers/ciphercommon.inc.in +GENERATE[providers/implementations/ciphers/ciphercommon_ccm.inc]=\ + providers/implementations/ciphers/ciphercommon_ccm.inc.in +GENERATE[providers/implementations/ciphers/ciphercommon_gcm.inc]=\ + providers/implementations/ciphers/ciphercommon_gcm.inc.in +GENERATE[providers/implementations/ciphers/cipher_chacha20.inc]=\ + providers/implementations/ciphers/cipher_chacha20.inc.in +GENERATE[providers/implementations/ciphers/cipher_chacha20_poly1305.inc]=\ + providers/implementations/ciphers/cipher_chacha20_poly1305.inc.in +GENERATE[providers/implementations/ciphers/cipher_null.inc]=\ + providers/implementations/ciphers/cipher_null.inc.in +GENERATE[providers/implementations/ciphers/cipher_rc4_hmac_md5.inc]=\ + providers/implementations/ciphers/cipher_rc4_hmac_md5.inc.in +GENERATE[providers/implementations/ciphers/cipher_sm4_xts.inc]=\ + providers/implementations/ciphers/cipher_sm4_xts.inc.in GENERATE[providers/implementations/digests/blake2_prov.c]=\ providers/implementations/digests/blake2_prov.c.in GENERATE[providers/implementations/digests/digestcommon.c]=\ diff --git a/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c.in b/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c similarity index 85% rename from providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c.in rename to providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c index aba2a8a697c..38b2743712c 100644 --- a/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c.in +++ b/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* * AES low level APIs are deprecated for public use, but still ok for internal @@ -33,6 +30,8 @@ const OSSL_DISPATCH ossl_##nm##kbits##sub##_functions[] = { \ }; #else +# include "providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.inc" + # define AES_CBC_HMAC_SHA_FLAGS (PROV_CIPHER_FLAG_AEAD \ | PROV_CIPHER_FLAG_TLS1_MULTIBLOCK) @@ -67,23 +66,6 @@ static int aes_dinit(void *ctx, const unsigned char *key, size_t keylen, return aes_set_ctx_params(ctx, params); } -{- produce_param_decoder('aes_cbc_hmac_sha_set_ctx_params', - (['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_SEND_FRAGMENT', - 'maxfrag', 'size_t', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], - ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD', - 'mb_aad', 'size_t', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], - ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE', - 'ileave', 'uint', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], - ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC', - 'enc', 'octet_string', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], - ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_IN', - 'enc_in', 'octet_string', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], - ['OSSL_CIPHER_PARAM_AEAD_MAC_KEY', 'key', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD', 'tlsaad', 'octet_string'], - ['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_TLS_VERSION', 'tlsver', 'uint' ], - )); -} - const OSSL_PARAM *aes_settable_ctx_params(ossl_unused void *cctx, ossl_unused void *provctx) { @@ -210,22 +192,6 @@ static int aes_set_ctx_params(void *vctx, const OSSL_PARAM params[]) return ret; } -{- produce_param_decoder('aes_cbc_hmac_sha_get_ctx_params', - (['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_BUFSIZE', - 'max', 'size_t', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], - ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE', - 'inter', 'uint', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], - ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD_PACKLEN', - 'packlen', 'uint', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], - ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_LEN', - 'enclen', 'size_t', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD', 'pad', 'size_t'], - ['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string'], - ['OSSL_CIPHER_PARAM_UPDATED_IV', 'upd_iv', 'octet_string'], - )); -} - static int aes_get_ctx_params(void *vctx, OSSL_PARAM params[]) { PROV_AES_HMAC_SHA_CTX *ctx = (PROV_AES_HMAC_SHA_CTX *)vctx; diff --git a/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.inc.in b/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.inc.in new file mode 100644 index 00000000000..53348960703 --- /dev/null +++ b/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.inc.in @@ -0,0 +1,45 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('aes_cbc_hmac_sha_set_ctx_params', + (['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_SEND_FRAGMENT', + 'maxfrag', 'size_t', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], + ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD', + 'mb_aad', 'size_t', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], + ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE', + 'ileave', 'uint', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], + ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC', + 'enc', 'octet_string', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], + ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_IN', + 'enc_in', 'octet_string', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], + ['OSSL_CIPHER_PARAM_AEAD_MAC_KEY', 'key', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD', 'tlsaad', 'octet_string'], + ['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_TLS_VERSION', 'tlsver', 'uint' ], + )); -} + +{- produce_param_decoder('aes_cbc_hmac_sha_get_ctx_params', + (['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_BUFSIZE', + 'max', 'size_t', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], + ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE', + 'inter', 'uint', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], + ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD_PACKLEN', + 'packlen', 'uint', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], + ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_LEN', + 'enclen', 'size_t', "#if !defined(OPENSSL_NO_MULTIBLOCK)"], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD', 'pad', 'size_t'], + ['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string'], + ['OSSL_CIPHER_PARAM_UPDATED_IV', 'upd_iv', 'octet_string'], + )); -} diff --git a/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c.in b/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c similarity index 93% rename from providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c.in rename to providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c index 41299ba16a9..f4e3a9e849f 100644 --- a/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c.in +++ b/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} #include "internal/deprecated.h" @@ -23,6 +20,9 @@ const OSSL_DISPATCH ossl_##nm##kbits##sub##_functions[] = { \ OSSL_DISPATCH_END \ }; #else + +# include "providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.inc" + static OSSL_FUNC_cipher_encrypt_init_fn aes_einit; static OSSL_FUNC_cipher_decrypt_init_fn aes_dinit; static OSSL_FUNC_cipher_gettable_ctx_params_fn aes_gettable_ctx_params; @@ -32,12 +32,6 @@ static OSSL_FUNC_cipher_settable_ctx_params_fn aes_settable_ctx_params; # define aes_final ossl_cipher_generic_stream_final # define aes_cipher ossl_cipher_generic_cipher -{- produce_param_decoder('aes_cbc_hmac_sha_etm_set_ctx_params', - (['OSSL_CIPHER_PARAM_AEAD_MAC_KEY', 'key', 'octet_string'], - ['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_HMAC_PARAM_MAC', 'mac', 'octet_string'], - )); -} - static int aes_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { PROV_AES_HMAC_SHA_ETM_CTX *ctx = (PROV_AES_HMAC_SHA_ETM_CTX *)vctx; @@ -106,14 +100,6 @@ static int aes_dinit(void *ctx, const unsigned char *key, size_t keylen, return aes_set_ctx_params(ctx, params); } -{- produce_param_decoder('aes_cbc_hmac_sha_etm_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string'], - ['OSSL_CIPHER_PARAM_UPDATED_IV', 'upd_iv', 'octet_string'], - ['OSSL_CIPHER_HMAC_PARAM_MAC', 'mac', 'octet_string'], - )); -} - static int aes_get_ctx_params(void *vctx, OSSL_PARAM params[]) { PROV_AES_HMAC_SHA_ETM_CTX *ctx = (PROV_AES_HMAC_SHA_ETM_CTX *)vctx; diff --git a/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.inc.in b/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.inc.in new file mode 100644 index 00000000000..73ea5283197 --- /dev/null +++ b/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha_etm.inc.in @@ -0,0 +1,26 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('aes_cbc_hmac_sha_etm_set_ctx_params', + (['OSSL_CIPHER_PARAM_AEAD_MAC_KEY', 'key', 'octet_string'], + ['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_HMAC_PARAM_MAC', 'mac', 'octet_string'], + )); -} + +{- produce_param_decoder('aes_cbc_hmac_sha_etm_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string'], + ['OSSL_CIPHER_PARAM_UPDATED_IV', 'upd_iv', 'octet_string'], + ['OSSL_CIPHER_HMAC_PARAM_MAC', 'mac', 'octet_string'], + )); -} diff --git a/providers/implementations/ciphers/cipher_aes_gcm_siv.c.in b/providers/implementations/ciphers/cipher_aes_gcm_siv.c similarity index 94% rename from providers/implementations/ciphers/cipher_aes_gcm_siv.c.in rename to providers/implementations/ciphers/cipher_aes_gcm_siv.c index 5c07965242f..cffc08a376b 100644 --- a/providers/implementations/ciphers/cipher_aes_gcm_siv.c.in +++ b/providers/implementations/ciphers/cipher_aes_gcm_siv.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* Dispatch functions for AES SIV mode */ @@ -24,6 +21,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "prov/ciphercommon_aead.h" #include "prov/provider_ctx.h" #include "cipher_aes_gcm_siv.h" +#include "providers/implementations/ciphers/cipher_aes_gcm_siv.inc" static int ossl_aes_gcm_siv_set_ctx_params(void *vctx, const OSSL_PARAM params[]); @@ -175,12 +173,6 @@ static int ossl_aes_gcm_siv_stream_final(void *vctx, unsigned char *out, size_t return !error; } -{- produce_param_decoder('ossl_aes_gcm_siv_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - )); -} - static int ossl_aes_gcm_siv_get_ctx_params(void *vctx, OSSL_PARAM params[]) { PROV_AES_GCM_SIV_CTX *ctx = (PROV_AES_GCM_SIV_CTX *)vctx; @@ -217,12 +209,6 @@ static const OSSL_PARAM *ossl_aes_gcm_siv_gettable_ctx_params(ossl_unused void * return ossl_aes_gcm_siv_get_ctx_params_list; } -{- produce_param_decoder('aes_gcm_siv_set_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_SPEED', 'speed', 'uint'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - )); -} - static int ossl_aes_gcm_siv_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { PROV_AES_GCM_SIV_CTX *ctx = (PROV_AES_GCM_SIV_CTX *)vctx; diff --git a/providers/implementations/ciphers/cipher_aes_gcm_siv.inc.in b/providers/implementations/ciphers/cipher_aes_gcm_siv.inc.in new file mode 100644 index 00000000000..891d3b976d0 --- /dev/null +++ b/providers/implementations/ciphers/cipher_aes_gcm_siv.inc.in @@ -0,0 +1,24 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('ossl_aes_gcm_siv_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + )); -} + +{- produce_param_decoder('aes_gcm_siv_set_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_SPEED', 'speed', 'uint'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + )); -} diff --git a/providers/implementations/ciphers/cipher_aes_ocb.c.in b/providers/implementations/ciphers/cipher_aes_ocb.c similarity index 95% rename from providers/implementations/ciphers/cipher_aes_ocb.c.in rename to providers/implementations/ciphers/cipher_aes_ocb.c index 153c0d8fe8c..fd225c27905 100644 --- a/providers/implementations/ciphers/cipher_aes_ocb.c.in +++ b/providers/implementations/ciphers/cipher_aes_ocb.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* * AES low level APIs are deprecated for public use, but still ok for internal @@ -22,6 +19,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "prov/providercommon.h" #include "prov/ciphercommon_aead.h" #include "prov/implementations.h" +#include "providers/implementations/ciphers/cipher_aes_ocb.inc" #define AES_OCB_FLAGS AEAD_FLAGS @@ -353,12 +351,6 @@ static void *aes_ocb_dupctx(void *vctx) return ret; } -{- produce_param_decoder('aes_ocb_set_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - )); -} - static const OSSL_PARAM *cipher_ocb_settable_ctx_params(ossl_unused void *cctx, ossl_unused void *p_ctx) { @@ -428,15 +420,6 @@ static int aes_ocb_set_ctx_params(void *vctx, const OSSL_PARAM params[]) return 1; } -{- produce_param_decoder('aes_ocb_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], - ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string'], - ['OSSL_CIPHER_PARAM_UPDATED_IV', 'upd_iv', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - )); -} - static const OSSL_PARAM *cipher_ocb_gettable_ctx_params(ossl_unused void *cctx, ossl_unused void *p_ctx) { diff --git a/providers/implementations/ciphers/cipher_aes_ocb.inc.in b/providers/implementations/ciphers/cipher_aes_ocb.inc.in new file mode 100644 index 00000000000..48c46894f0a --- /dev/null +++ b/providers/implementations/ciphers/cipher_aes_ocb.inc.in @@ -0,0 +1,27 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('aes_ocb_set_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + )); -} + +{- produce_param_decoder('aes_ocb_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], + ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string'], + ['OSSL_CIPHER_PARAM_UPDATED_IV', 'upd_iv', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + )); -} diff --git a/providers/implementations/ciphers/cipher_aes_siv.c.in b/providers/implementations/ciphers/cipher_aes_siv.c similarity index 93% rename from providers/implementations/ciphers/cipher_aes_siv.c.in rename to providers/implementations/ciphers/cipher_aes_siv.c index 4ab9a248b06..5166ef74161 100644 --- a/providers/implementations/ciphers/cipher_aes_siv.c.in +++ b/providers/implementations/ciphers/cipher_aes_siv.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* Dispatch functions for AES SIV mode */ @@ -24,6 +21,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "prov/providercommon.h" #include "prov/ciphercommon_aead.h" #include "prov/provider_ctx.h" +#include "providers/implementations/ciphers/cipher_aes_siv.inc" #define siv_stream_update siv_cipher #define SIV_FLAGS AEAD_FLAGS @@ -150,12 +148,6 @@ static int siv_stream_final(void *vctx, unsigned char *out, size_t *outl, return 1; } -{- produce_param_decoder('aes_siv_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - )); -} - static int aes_siv_get_ctx_params(void *vctx, OSSL_PARAM params[]) { PROV_AES_SIV_CTX *ctx = (PROV_AES_SIV_CTX *)vctx; @@ -196,13 +188,6 @@ static const OSSL_PARAM *aes_siv_gettable_ctx_params(ossl_unused void *cctx, return aes_siv_get_ctx_params_list; } - -{- produce_param_decoder('aes_siv_set_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_SPEED', 'speed', 'uint'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - )); -} - static int aes_siv_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { PROV_AES_SIV_CTX *ctx = (PROV_AES_SIV_CTX *)vctx; diff --git a/providers/implementations/ciphers/cipher_aes_siv.inc.in b/providers/implementations/ciphers/cipher_aes_siv.inc.in new file mode 100644 index 00000000000..cdbfd5ef191 --- /dev/null +++ b/providers/implementations/ciphers/cipher_aes_siv.inc.in @@ -0,0 +1,24 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('aes_siv_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + )); -} + +{- produce_param_decoder('aes_siv_set_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_SPEED', 'speed', 'uint'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + )); -} diff --git a/providers/implementations/ciphers/cipher_aes_wrp.c.in b/providers/implementations/ciphers/cipher_aes_wrp.c similarity index 98% rename from providers/implementations/ciphers/cipher_aes_wrp.c.in rename to providers/implementations/ciphers/cipher_aes_wrp.c index fc7d2f5e31f..00c80774a53 100644 --- a/providers/implementations/ciphers/cipher_aes_wrp.c.in +++ b/providers/implementations/ciphers/cipher_aes_wrp.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* * This file uses the low level AES functions (which are deprecated for @@ -20,6 +17,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "cipher_aes.h" #include "prov/providercommon.h" #include "prov/implementations.h" +#include "providers/implementations/ciphers/cipher_aes_wrp.inc" /* AES wrap with padding has IV length of 4, without padding 8 */ #define AES_WRAP_PAD_IVLEN 4 @@ -49,7 +47,6 @@ typedef struct prov_aes_wrap_ctx_st { } PROV_AES_WRAP_CTX; - static void *aes_wrap_newctx(size_t kbits, size_t blkbits, size_t ivbits, unsigned int mode, uint64_t flags) { @@ -263,10 +260,6 @@ static int aes_wrap_cipher(void *vctx, return 1; } -{- produce_param_decoder('aes_wrap_set_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - )); -} - static const OSSL_PARAM *aes_wrap_settable_ctx_params(ossl_unused void *cctx, ossl_unused void *provctx) { diff --git a/providers/implementations/ciphers/cipher_aes_wrp.inc.in b/providers/implementations/ciphers/cipher_aes_wrp.inc.in new file mode 100644 index 00000000000..3d2aa1526e4 --- /dev/null +++ b/providers/implementations/ciphers/cipher_aes_wrp.inc.in @@ -0,0 +1,16 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('aes_wrap_set_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + )); -} diff --git a/providers/implementations/ciphers/cipher_aes_xts.c.in b/providers/implementations/ciphers/cipher_aes_xts.c similarity index 98% rename from providers/implementations/ciphers/cipher_aes_xts.c.in rename to providers/implementations/ciphers/cipher_aes_xts.c index b408aa33ebd..d2845660381 100644 --- a/providers/implementations/ciphers/cipher_aes_xts.c.in +++ b/providers/implementations/ciphers/cipher_aes_xts.c @@ -7,9 +7,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* * AES low level APIs are deprecated for public use, but still ok for internal @@ -22,6 +19,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "cipher_aes_xts.h" #include "prov/implementations.h" #include "prov/providercommon.h" +#include "providers/implementations/ciphers/cipher_aes_xts.inc" #define AES_XTS_FLAGS PROV_CIPHER_FLAG_CUSTOM_IV #define AES_XTS_IV_BITS 128 @@ -244,10 +242,6 @@ static int aes_xts_stream_final(void *vctx, unsigned char *out, size_t *outl, return 1; } -{- produce_param_decoder('aes_xts_set_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - )); -} - static const OSSL_PARAM *aes_xts_settable_ctx_params(ossl_unused void *cctx, ossl_unused void *provctx) { diff --git a/providers/implementations/ciphers/cipher_aes_xts.inc.in b/providers/implementations/ciphers/cipher_aes_xts.inc.in new file mode 100644 index 00000000000..24eb61ed8d3 --- /dev/null +++ b/providers/implementations/ciphers/cipher_aes_xts.inc.in @@ -0,0 +1,16 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('aes_xts_set_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + )); -} diff --git a/providers/implementations/ciphers/cipher_chacha20.c.in b/providers/implementations/ciphers/cipher_chacha20.c similarity index 93% rename from providers/implementations/ciphers/cipher_chacha20.c.in rename to providers/implementations/ciphers/cipher_chacha20.c index 0e9a2d1109a..0dd6f95cbaf 100644 --- a/providers/implementations/ciphers/cipher_chacha20.c.in +++ b/providers/implementations/ciphers/cipher_chacha20.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* Dispatch functions for chacha20 cipher */ @@ -17,6 +14,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "cipher_chacha20.h" #include "prov/implementations.h" #include "prov/providercommon.h" +#include "providers/implementations/ciphers/cipher_chacha20.inc" #define CHACHA20_KEYLEN (CHACHA_KEY_SIZE) #define CHACHA20_BLKLEN (1) @@ -103,12 +101,6 @@ static int chacha20_get_params(OSSL_PARAM params[]) CHACHA20_IVLEN * 8); } -{- produce_param_decoder('chacha20_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_UPDATED_IV', 'upd_iv', 'octet_string'], - )); -} - static int chacha20_get_ctx_params(void *vctx, OSSL_PARAM params[]) { PROV_CHACHA20_CTX *ctx = (PROV_CHACHA20_CTX *)vctx; @@ -147,11 +139,6 @@ const OSSL_PARAM *chacha20_gettable_ctx_params(ossl_unused void *cctx, return chacha20_get_ctx_params_list; } -{- produce_param_decoder('chacha20_set_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - )); -} - static int chacha20_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { PROV_CHACHA20_CTX *ctx = (PROV_CHACHA20_CTX *)vctx; @@ -249,4 +236,3 @@ const OSSL_DISPATCH ossl_chacha20_functions[] = { (void (*)(void))chacha20_settable_ctx_params }, OSSL_DISPATCH_END }; - diff --git a/providers/implementations/ciphers/cipher_chacha20.inc.in b/providers/implementations/ciphers/cipher_chacha20.inc.in new file mode 100644 index 00000000000..aa64e6a44f3 --- /dev/null +++ b/providers/implementations/ciphers/cipher_chacha20.inc.in @@ -0,0 +1,23 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('chacha20_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_UPDATED_IV', 'upd_iv', 'octet_string'], + )); -} + +{- produce_param_decoder('chacha20_set_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + )); -} diff --git a/providers/implementations/ciphers/cipher_chacha20_poly1305.c.in b/providers/implementations/ciphers/cipher_chacha20_poly1305.c similarity index 91% rename from providers/implementations/ciphers/cipher_chacha20_poly1305.c.in rename to providers/implementations/ciphers/cipher_chacha20_poly1305.c index 4ef3ed5e060..a6f88386de4 100644 --- a/providers/implementations/ciphers/cipher_chacha20_poly1305.c.in +++ b/providers/implementations/ciphers/cipher_chacha20_poly1305.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* Dispatch functions for chacha20_poly1305 cipher */ @@ -17,6 +14,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "cipher_chacha20_poly1305.h" #include "prov/implementations.h" #include "prov/providercommon.h" +#include "providers/implementations/ciphers/cipher_chacha20_poly1305.inc" #define CHACHA20_POLY1305_KEYLEN CHACHA_KEY_SIZE #define CHACHA20_POLY1305_BLKLEN 1 @@ -100,14 +98,6 @@ static int chacha20_poly1305_get_params(OSSL_PARAM params[]) CHACHA20_POLY1305_IVLEN * 8); } -{- produce_param_decoder('chacha20_poly1305_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD', 'pad', 'size_t'], - )); -} - static int chacha20_poly1305_get_ctx_params(void *vctx, OSSL_PARAM params[]) { PROV_CHACHA20_POLY1305_CTX *ctx = (PROV_CHACHA20_POLY1305_CTX *)vctx; @@ -164,14 +154,6 @@ static const OSSL_PARAM *chacha20_poly1305_gettable_ctx_params return chacha20_poly1305_get_ctx_params_list; } -{- produce_param_decoder('chacha20_poly1305_set_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD', 'aad', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED', 'fixed', 'octet_string'], - )); -} - static const OSSL_PARAM *chacha20_poly1305_settable_ctx_params( ossl_unused void *cctx, ossl_unused void *provctx ) @@ -191,7 +173,6 @@ static int chacha20_poly1305_set_ctx_params(void *vctx, if (!chacha20_poly1305_set_ctx_params_decoder(params, &p)) return 0; - if (p.keylen != NULL) { if (!OSSL_PARAM_get_size_t(p.keylen, &len)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); @@ -374,4 +355,3 @@ const OSSL_DISPATCH ossl_chacha20_ossl_poly1305_functions[] = { (void (*)(void))chacha20_poly1305_settable_ctx_params }, OSSL_DISPATCH_END }; - diff --git a/providers/implementations/ciphers/cipher_chacha20_poly1305.inc.in b/providers/implementations/ciphers/cipher_chacha20_poly1305.inc.in new file mode 100644 index 00000000000..2a42ca8dd92 --- /dev/null +++ b/providers/implementations/ciphers/cipher_chacha20_poly1305.inc.in @@ -0,0 +1,28 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('chacha20_poly1305_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD', 'pad', 'size_t'], + )); -} + +{- produce_param_decoder('chacha20_poly1305_set_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD', 'aad', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED', 'fixed', 'octet_string'], + )); -} diff --git a/providers/implementations/ciphers/cipher_null.c.in b/providers/implementations/ciphers/cipher_null.c similarity index 91% rename from providers/implementations/ciphers/cipher_null.c.in rename to providers/implementations/ciphers/cipher_null.c index 3a64dfe646b..b9d75a50639 100644 --- a/providers/implementations/ciphers/cipher_null.c.in +++ b/providers/implementations/ciphers/cipher_null.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} #include #include @@ -17,6 +14,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "prov/implementations.h" #include "prov/ciphercommon.h" #include "prov/providercommon.h" +#include "providers/implementations/ciphers/cipher_null.inc" typedef struct prov_cipher_null_ctx_st { int enc; @@ -108,12 +106,6 @@ static int null_get_params(OSSL_PARAM params[]) return ossl_cipher_generic_get_params(params, 0, 0, 0, 8, 0); } -{- produce_param_decoder('null_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_TLS_MAC', 'mac', 'octet_ptr'], - )); -} - static OSSL_FUNC_cipher_gettable_ctx_params_fn null_gettable_ctx_params; static const OSSL_PARAM *null_gettable_ctx_params(ossl_unused void *cctx, ossl_unused void *provctx) @@ -148,10 +140,6 @@ static int null_get_ctx_params(void *vctx, OSSL_PARAM params[]) return 1; } -{- produce_param_decoder('null_set_ctx_params', - (['OSSL_CIPHER_PARAM_TLS_MAC_SIZE', 'macsize', 'size_t'], - )); -} - static OSSL_FUNC_cipher_settable_ctx_params_fn null_settable_ctx_params; static const OSSL_PARAM *null_settable_ctx_params(ossl_unused void *cctx, ossl_unused void *provctx) @@ -159,7 +147,6 @@ static const OSSL_PARAM *null_settable_ctx_params(ossl_unused void *cctx, return null_set_ctx_params_list; } - static OSSL_FUNC_cipher_set_ctx_params_fn null_set_ctx_params; static int null_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { diff --git a/providers/implementations/ciphers/cipher_null.inc.in b/providers/implementations/ciphers/cipher_null.inc.in new file mode 100644 index 00000000000..73ee633c6be --- /dev/null +++ b/providers/implementations/ciphers/cipher_null.inc.in @@ -0,0 +1,22 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('null_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_TLS_MAC', 'mac', 'octet_ptr'], + )); -} + +{- produce_param_decoder('null_set_ctx_params', + (['OSSL_CIPHER_PARAM_TLS_MAC_SIZE', 'macsize', 'size_t'], + )); -} diff --git a/providers/implementations/ciphers/cipher_rc4_hmac_md5.c.in b/providers/implementations/ciphers/cipher_rc4_hmac_md5.c similarity index 90% rename from providers/implementations/ciphers/cipher_rc4_hmac_md5.c.in rename to providers/implementations/ciphers/cipher_rc4_hmac_md5.c index 1685aba7024..a96d3527860 100644 --- a/providers/implementations/ciphers/cipher_rc4_hmac_md5.c.in +++ b/providers/implementations/ciphers/cipher_rc4_hmac_md5.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* Dispatch functions for RC4_HMAC_MD5 cipher */ @@ -22,6 +19,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "cipher_rc4_hmac_md5.h" #include "prov/implementations.h" #include "prov/providercommon.h" +#include "providers/implementations/ciphers/cipher_rc4_hmac_md5.inc" #define RC4_HMAC_MD5_FLAGS (PROV_CIPHER_FLAG_VARIABLE_LENGTH \ | PROV_CIPHER_FLAG_AEAD) @@ -102,12 +100,6 @@ static int rc4_hmac_md5_dinit(void *ctx, const unsigned char *key, return rc4_hmac_md5_set_ctx_params(ctx, params); } -{- produce_param_decoder('rc4_hmac_md5_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD', 'pad', 'size_t'], - )); -} - static const OSSL_PARAM *rc4_hmac_md5_gettable_ctx_params(ossl_unused void *cctx, ossl_unused void *provctx) { @@ -139,14 +131,6 @@ static int rc4_hmac_md5_get_ctx_params(void *vctx, OSSL_PARAM params[]) return 1; } -{- produce_param_decoder('rc4_hmac_md5_set_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD', 'aad', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_MAC_KEY', 'mackey', 'octet_string'], - ['OSSL_CIPHER_PARAM_TLS_VERSION', 'tlsver', 'uint'], - )); -} - static const OSSL_PARAM *rc4_hmac_md5_settable_ctx_params(ossl_unused void *cctx, ossl_unused void *provctx) { diff --git a/providers/implementations/ciphers/cipher_rc4_hmac_md5.inc.in b/providers/implementations/ciphers/cipher_rc4_hmac_md5.inc.in new file mode 100644 index 00000000000..0eef707ffe1 --- /dev/null +++ b/providers/implementations/ciphers/cipher_rc4_hmac_md5.inc.in @@ -0,0 +1,26 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('rc4_hmac_md5_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD', 'pad', 'size_t'], + )); -} + +{- produce_param_decoder('rc4_hmac_md5_set_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD', 'aad', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_MAC_KEY', 'mackey', 'octet_string'], + ['OSSL_CIPHER_PARAM_TLS_VERSION', 'tlsver', 'uint'], + )); -} diff --git a/providers/implementations/ciphers/cipher_sm4_xts.c.in b/providers/implementations/ciphers/cipher_sm4_xts.c similarity index 97% rename from providers/implementations/ciphers/cipher_sm4_xts.c.in rename to providers/implementations/ciphers/cipher_sm4_xts.c index 427e553a4d3..36462623df3 100644 --- a/providers/implementations/ciphers/cipher_sm4_xts.c.in +++ b/providers/implementations/ciphers/cipher_sm4_xts.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* Dispatch functions for SM4 XTS mode */ @@ -16,6 +13,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "cipher_sm4_xts.h" #include "prov/implementations.h" #include "prov/providercommon.h" +#include "providers/implementations/ciphers/cipher_sm4_xts.inc" #define SM4_XTS_FLAGS PROV_CIPHER_FLAG_CUSTOM_IV #define SM4_XTS_IV_BITS 128 @@ -191,10 +189,6 @@ static int sm4_xts_stream_final(void *vctx, unsigned char *out, size_t *outl, return 1; } -{- produce_param_decoder('sm4_xts_set_ctx_params', - (['OSSL_CIPHER_PARAM_XTS_STANDARD', 'std', 'utf8_string'], - )); -} - static const OSSL_PARAM *sm4_xts_settable_ctx_params(ossl_unused void *cctx, ossl_unused void *provctx) { diff --git a/providers/implementations/ciphers/cipher_sm4_xts.inc.in b/providers/implementations/ciphers/cipher_sm4_xts.inc.in new file mode 100644 index 00000000000..b9759ddf812 --- /dev/null +++ b/providers/implementations/ciphers/cipher_sm4_xts.inc.in @@ -0,0 +1,16 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('sm4_xts_set_ctx_params', + (['OSSL_CIPHER_PARAM_XTS_STANDARD', 'std', 'utf8_string'], + )); -} diff --git a/providers/implementations/ciphers/ciphercommon.c.in b/providers/implementations/ciphers/ciphercommon.c similarity index 88% rename from providers/implementations/ciphers/ciphercommon.c.in rename to providers/implementations/ciphers/ciphercommon.c index b0d88f89d8e..f17abf849a8 100644 --- a/providers/implementations/ciphers/ciphercommon.c.in +++ b/providers/implementations/ciphers/ciphercommon.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* * Generic dispatch table functions for ciphers. @@ -25,21 +22,15 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "internal/e_os.h" #include "crypto/types.h" +#define cipher_generic_get_ctx_params_st ossl_cipher_get_ctx_param_list_st +#define cipher_generic_set_ctx_params_st ossl_cipher_set_ctx_param_list_st +#define cipher_var_keylen_set_ctx_params_st ossl_cipher_set_ctx_param_list_st + +#include "providers/implementations/ciphers/ciphercommon.inc" + /*- * Generic cipher functions for OSSL_PARAM gettables and settables */ -{- produce_param_decoder('ossl_cipher_generic_get_params', - (['OSSL_CIPHER_PARAM_MODE', 'mode', 'uint'], - ['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_BLOCK_SIZE', 'bsize', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD', 'aead', 'int' ], - ['OSSL_CIPHER_PARAM_CUSTOM_IV', 'custiv', 'int' ], - ['OSSL_CIPHER_PARAM_CTS', 'cts', 'int' ], - ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK', 'mb', 'int' ], - ['OSSL_CIPHER_PARAM_HAS_RAND_KEY', 'rand', 'int' ], - ['OSSL_CIPHER_PARAM_ENCRYPT_THEN_MAC', 'etm', 'int' ], - )); -} const OSSL_PARAM *ossl_cipher_generic_gettable_params(ossl_unused void *provctx) { @@ -104,34 +95,12 @@ int ossl_cipher_generic_get_params(OSSL_PARAM params[], unsigned int md, return 1; } -#define cipher_generic_get_ctx_params_st ossl_cipher_get_ctx_param_list_st - -{- produce_param_decoder('cipher_generic_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_PADDING', 'pad', 'uint'], - ['OSSL_CIPHER_PARAM_NUM', 'num', 'uint' ], - ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string' ], - ['OSSL_CIPHER_PARAM_UPDATED_IV', 'updiv', 'octet_string' ], - ['OSSL_CIPHER_PARAM_TLS_MAC', 'tlsmac', 'octet_string' ], - )); -} - const OSSL_PARAM *ossl_cipher_generic_gettable_ctx_params (ossl_unused void *cctx, ossl_unused void *provctx) { return cipher_generic_get_ctx_params_list; } -#define cipher_generic_set_ctx_params_st ossl_cipher_set_ctx_param_list_st - -{- produce_param_decoder('cipher_generic_set_ctx_params', - (['OSSL_CIPHER_PARAM_PADDING', 'pad', 'uint'], - ['OSSL_CIPHER_PARAM_NUM', 'num', 'uint'], - ['OSSL_CIPHER_PARAM_USE_BITS', 'bits', 'uint'], - ['OSSL_CIPHER_PARAM_TLS_VERSION', 'tlsvers', 'uint'], - ['OSSL_CIPHER_PARAM_TLS_MAC_SIZE', 'tlsmacsize', 'size_t'], - )); -} - const OSSL_PARAM *ossl_cipher_generic_settable_ctx_params (ossl_unused void *cctx, ossl_unused void *provctx) { @@ -141,16 +110,6 @@ const OSSL_PARAM *ossl_cipher_generic_settable_ctx_params /* * Variable key length cipher functions for OSSL_PARAM settables */ -#define cipher_var_keylen_set_ctx_params_st ossl_cipher_set_ctx_param_list_st - -{- produce_param_decoder('cipher_var_keylen_set_ctx_params', - (['OSSL_CIPHER_PARAM_PADDING', 'pad', 'uint'], - ['OSSL_CIPHER_PARAM_NUM', 'num', 'uint'], - ['OSSL_CIPHER_PARAM_USE_BITS', 'bits', 'uint'], - ['OSSL_CIPHER_PARAM_TLS_VERSION', 'tlsvers', 'uint'], - ['OSSL_CIPHER_PARAM_TLS_MAC_SIZE', 'tlsmacsize', 'size_t'], - ['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - )); -} const OSSL_PARAM *ossl_cipher_var_keylen_settable_ctx_params (ossl_unused void *cctx, ossl_unused void *provctx) @@ -337,7 +296,6 @@ int ossl_cipher_generic_block_update(void *vctx, unsigned char *out, return 0; } - /* Shouldn't normally fail */ if (!ctx->hw->cipher(ctx, out, in, inl)) { ERR_raise(ERR_LIB_PROV, PROV_R_CIPHER_OPERATION_FAILED); diff --git a/providers/implementations/ciphers/ciphercommon.inc.in b/providers/implementations/ciphers/ciphercommon.inc.in new file mode 100644 index 00000000000..997453d24be --- /dev/null +++ b/providers/implementations/ciphers/ciphercommon.inc.in @@ -0,0 +1,52 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('ossl_cipher_generic_get_params', + (['OSSL_CIPHER_PARAM_MODE', 'mode', 'uint'], + ['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_BLOCK_SIZE', 'bsize', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD', 'aead', 'int' ], + ['OSSL_CIPHER_PARAM_CUSTOM_IV', 'custiv', 'int' ], + ['OSSL_CIPHER_PARAM_CTS', 'cts', 'int' ], + ['OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK', 'mb', 'int' ], + ['OSSL_CIPHER_PARAM_HAS_RAND_KEY', 'rand', 'int' ], + ['OSSL_CIPHER_PARAM_ENCRYPT_THEN_MAC', 'etm', 'int' ], + )); -} + +{- produce_param_decoder('cipher_generic_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_PADDING', 'pad', 'uint'], + ['OSSL_CIPHER_PARAM_NUM', 'num', 'uint' ], + ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string' ], + ['OSSL_CIPHER_PARAM_UPDATED_IV', 'updiv', 'octet_string' ], + ['OSSL_CIPHER_PARAM_TLS_MAC', 'tlsmac', 'octet_string' ], + )); -} + +{- produce_param_decoder('cipher_generic_set_ctx_params', + (['OSSL_CIPHER_PARAM_PADDING', 'pad', 'uint'], + ['OSSL_CIPHER_PARAM_NUM', 'num', 'uint'], + ['OSSL_CIPHER_PARAM_USE_BITS', 'bits', 'uint'], + ['OSSL_CIPHER_PARAM_TLS_VERSION', 'tlsvers', 'uint'], + ['OSSL_CIPHER_PARAM_TLS_MAC_SIZE', 'tlsmacsize', 'size_t'], + )); -} + +{- produce_param_decoder('cipher_var_keylen_set_ctx_params', + (['OSSL_CIPHER_PARAM_PADDING', 'pad', 'uint'], + ['OSSL_CIPHER_PARAM_NUM', 'num', 'uint'], + ['OSSL_CIPHER_PARAM_USE_BITS', 'bits', 'uint'], + ['OSSL_CIPHER_PARAM_TLS_VERSION', 'tlsvers', 'uint'], + ['OSSL_CIPHER_PARAM_TLS_MAC_SIZE', 'tlsmacsize', 'size_t'], + ['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + )); -} diff --git a/providers/implementations/ciphers/ciphercommon_ccm.c.in b/providers/implementations/ciphers/ciphercommon_ccm.c similarity index 91% rename from providers/implementations/ciphers/ciphercommon_ccm.c.in rename to providers/implementations/ciphers/ciphercommon_ccm.c index 922312773c5..8089f5306ff 100644 --- a/providers/implementations/ciphers/ciphercommon_ccm.c.in +++ b/providers/implementations/ciphers/ciphercommon_ccm.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* Dispatch functions for ccm mode */ @@ -17,6 +14,7 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "prov/ciphercommon_ccm.h" #include "prov/providercommon.h" +#include "providers/implementations/ciphers/ciphercommon_ccm.inc" static int ccm_cipher_internal(PROV_CCM_CTX *ctx, unsigned char *out, size_t *padlen, const unsigned char *in, @@ -69,13 +67,6 @@ static size_t ccm_get_ivlen(PROV_CCM_CTX *ctx) return 15 - ctx->l; } -{- produce_param_decoder('ossl_cipher_ccm_set_ctx_params', - (['OSSL_CIPHER_PARAM_AEAD_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD', 'aad', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED', 'fixed', 'octet_string'], - )); -} - const OSSL_PARAM *ossl_ccm_settable_ctx_params( ossl_unused void *cctx, ossl_unused void *provctx ) @@ -155,16 +146,6 @@ int ossl_ccm_set_ctx_params(void *vctx, const OSSL_PARAM params[]) return 1; } -{- produce_param_decoder('ossl_cipher_ccm_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], - ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string'], - ['OSSL_CIPHER_PARAM_UPDATED_IV', 'updiv', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD', 'pad', 'size_t'], - )); -} - const OSSL_PARAM *ossl_ccm_gettable_ctx_params( ossl_unused void *cctx, ossl_unused void *provctx ) diff --git a/providers/implementations/ciphers/ciphercommon_ccm.inc.in b/providers/implementations/ciphers/ciphercommon_ccm.inc.in new file mode 100644 index 00000000000..5be0a4c0b03 --- /dev/null +++ b/providers/implementations/ciphers/ciphercommon_ccm.inc.in @@ -0,0 +1,29 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('ossl_cipher_ccm_set_ctx_params', + (['OSSL_CIPHER_PARAM_AEAD_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD', 'aad', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED', 'fixed', 'octet_string'], + )); -} + +{- produce_param_decoder('ossl_cipher_ccm_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], + ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string'], + ['OSSL_CIPHER_PARAM_UPDATED_IV', 'updiv', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD', 'pad', 'size_t'], + )); -} diff --git a/providers/implementations/ciphers/ciphercommon_gcm.c.in b/providers/implementations/ciphers/ciphercommon_gcm.c similarity index 92% rename from providers/implementations/ciphers/ciphercommon_gcm.c.in rename to providers/implementations/ciphers/ciphercommon_gcm.c index 08417687eba..5bad232bfdf 100644 --- a/providers/implementations/ciphers/ciphercommon_gcm.c.in +++ b/providers/implementations/ciphers/ciphercommon_gcm.c @@ -6,9 +6,6 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -{- -use OpenSSL::paramnames qw(produce_param_decoder); --} /* Dispatch functions for gcm mode */ @@ -19,6 +16,8 @@ use OpenSSL::paramnames qw(produce_param_decoder); #include "prov/providercommon.h" #include "prov/provider_ctx.h" +#include "providers/implementations/ciphers/ciphercommon_gcm.inc" + static int gcm_tls_init(PROV_GCM_CTX *dat, unsigned char *aad, size_t aad_len); static int gcm_tls_iv_set_fixed(PROV_GCM_CTX *ctx, unsigned char *iv, size_t len); @@ -143,18 +142,6 @@ static int setivinv(PROV_GCM_CTX *ctx, unsigned char *in, size_t inl) return 1; } -{- produce_param_decoder('ossl_cipher_gcm_get_ctx_params', - (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], - ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], - ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string'], - ['OSSL_CIPHER_PARAM_UPDATED_IV', 'updiv', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD', 'pad', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_GET_IV_GEN', 'ivgen', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_IV_GENERATED', 'gen', 'uint'], - )); -} - const OSSL_PARAM *ossl_gcm_gettable_ctx_params( ossl_unused void *cctx, ossl_unused void *provctx ) @@ -249,15 +236,6 @@ int ossl_gcm_get_ctx_params(void *vctx, OSSL_PARAM params[]) return 1; } -{- produce_param_decoder - ('ossl_cipher_gcm_set_ctx_params', - (['OSSL_CIPHER_PARAM_AEAD_IVLEN', 'ivlen', 'size_t'], - ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD', 'aad', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED', 'fixed', 'octet_string'], - ['OSSL_CIPHER_PARAM_AEAD_TLS1_SET_IV_INV', 'inviv', 'octet_string'], - )); -} - const OSSL_PARAM *ossl_gcm_settable_ctx_params( ossl_unused void *cctx, ossl_unused void *provctx ) diff --git a/providers/implementations/ciphers/ciphercommon_gcm.inc.in b/providers/implementations/ciphers/ciphercommon_gcm.inc.in new file mode 100644 index 00000000000..abee5683a71 --- /dev/null +++ b/providers/implementations/ciphers/ciphercommon_gcm.inc.in @@ -0,0 +1,33 @@ +/* + * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the \"License\"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} + +{- produce_param_decoder('ossl_cipher_gcm_get_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + ['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAGLEN', 'taglen', 'size_t'], + ['OSSL_CIPHER_PARAM_IV', 'iv', 'octet_string'], + ['OSSL_CIPHER_PARAM_UPDATED_IV', 'updiv', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD', 'pad', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_GET_IV_GEN', 'ivgen', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_IV_GENERATED', 'gen', 'uint'], + )); -} + +{- produce_param_decoder + ('ossl_cipher_gcm_set_ctx_params', + (['OSSL_CIPHER_PARAM_AEAD_IVLEN', 'ivlen', 'size_t'], + ['OSSL_CIPHER_PARAM_AEAD_TAG', 'tag', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_AAD', 'aad', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED', 'fixed', 'octet_string'], + ['OSSL_CIPHER_PARAM_AEAD_TLS1_SET_IV_INV', 'inviv', 'octet_string'], + )); -} -- 2.47.3