From f5896e2bdf9d8824befe8660c7fe1f77ff773e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Wed, 22 Dec 2021 22:09:28 +0100 Subject: [PATCH] module: icp: spi: flatten struct crypto_ops, crypto_provider_info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #12901 --- module/icp/core/kcf_prov_tabs.c | 16 +------- module/icp/include/sys/crypto/spi.h | 59 +---------------------------- module/icp/io/aes.c | 9 ++--- module/icp/io/sha2_mod.c | 9 ++--- module/icp/io/skein_mod.c | 9 ++--- module/icp/spi/kcf_spi.c | 25 ++---------- 6 files changed, 19 insertions(+), 108 deletions(-) diff --git a/module/icp/core/kcf_prov_tabs.c b/module/icp/core/kcf_prov_tabs.c index 59ff071337..734bf457c3 100644 --- a/module/icp/core/kcf_prov_tabs.c +++ b/module/icp/core/kcf_prov_tabs.c @@ -205,7 +205,7 @@ kcf_prov_tab_lookup(crypto_provider_id_t prov_id) } static void -allocate_ops_v1(const crypto_ops_t *src, crypto_ops_t *dst, +allocate_ops(const crypto_ops_t *src, crypto_ops_t *dst, uint_t *mech_list_count) { if (src->co_digest_ops != NULL) @@ -268,19 +268,11 @@ allocate_ops_v1(const crypto_ops_t *src, crypto_ops_t *dst, if (src->co_ctx_ops != NULL) dst->co_ctx_ops = kmem_alloc(sizeof (crypto_ctx_ops_t), KM_SLEEP); -} -static void -allocate_ops_v2(const crypto_ops_t *src, crypto_ops_t *dst) -{ if (src->co_mech_ops != NULL) dst->co_mech_ops = kmem_alloc(sizeof (crypto_mech_ops_t), KM_SLEEP); -} -static void -allocate_ops_v3(const crypto_ops_t *src, crypto_ops_t *dst) -{ if (src->co_nostore_key_ops != NULL) dst->co_nostore_key_ops = kmem_alloc(sizeof (crypto_nostore_key_ops_t), KM_SLEEP); @@ -329,11 +321,7 @@ kcf_alloc_provider_desc(const crypto_provider_info_t *info) crypto_ops_t *opvec = kmem_zalloc(sizeof (crypto_ops_t), KM_SLEEP); if (info->pi_provider_type != CRYPTO_LOGICAL_PROVIDER) { - allocate_ops_v1(src_ops, opvec, &mech_list_count); - if (info->pi_interface_version >= CRYPTO_SPI_VERSION_2) - allocate_ops_v2(src_ops, opvec); - if (info->pi_interface_version == CRYPTO_SPI_VERSION_3) - allocate_ops_v3(src_ops, opvec); + allocate_ops(src_ops, opvec, &mech_list_count); } desc->pd_ops_vector = opvec; diff --git a/module/icp/include/sys/crypto/spi.h b/module/icp/include/sys/crypto/spi.h index 4a4909544d..7e265d3a90 100644 --- a/module/icp/include/sys/crypto/spi.h +++ b/module/icp/include/sys/crypto/spi.h @@ -487,7 +487,7 @@ typedef struct crypto_nostore_key_ops { * supplied by a provider when it registers with the kernel * by calling crypto_register_provider(9F). */ -typedef struct crypto_ops_v1 { +typedef struct crypto_ops { const crypto_digest_ops_t *co_digest_ops; const crypto_cipher_ops_t *co_cipher_ops; const crypto_mac_ops_t *co_mac_ops; @@ -501,42 +501,10 @@ typedef struct crypto_ops_v1 { crypto_key_ops_t *co_key_ops; crypto_provider_management_ops_t *co_provider_ops; const crypto_ctx_ops_t *co_ctx_ops; -} crypto_ops_v1_t; - -typedef struct crypto_ops_v2 { - crypto_ops_v1_t v1_ops; crypto_mech_ops_t *co_mech_ops; -} crypto_ops_v2_t; - -typedef struct crypto_ops_v3 { - crypto_ops_v2_t v2_ops; crypto_nostore_key_ops_t *co_nostore_key_ops; -} crypto_ops_v3_t; - -typedef struct crypto_ops { - union { - crypto_ops_v3_t cou_v3; - crypto_ops_v2_t cou_v2; - crypto_ops_v1_t cou_v1; - } cou; } crypto_ops_t; -#define co_digest_ops cou.cou_v1.co_digest_ops -#define co_cipher_ops cou.cou_v1.co_cipher_ops -#define co_mac_ops cou.cou_v1.co_mac_ops -#define co_sign_ops cou.cou_v1.co_sign_ops -#define co_verify_ops cou.cou_v1.co_verify_ops -#define co_dual_ops cou.cou_v1.co_dual_ops -#define co_dual_cipher_mac_ops cou.cou_v1.co_dual_cipher_mac_ops -#define co_random_ops cou.cou_v1.co_random_ops -#define co_session_ops cou.cou_v1.co_session_ops -#define co_object_ops cou.cou_v1.co_object_ops -#define co_key_ops cou.cou_v1.co_key_ops -#define co_provider_ops cou.cou_v1.co_provider_ops -#define co_ctx_ops cou.cou_v1.co_ctx_ops -#define co_mech_ops cou.cou_v2.co_mech_ops -#define co_nostore_key_ops cou.cou_v3.co_nostore_key_ops - /* * The mechanism info structure crypto_mech_info_t contains a function group * bit mask cm_func_group_mask. This field, of type crypto_func_group_t, @@ -636,8 +604,7 @@ typedef uint_t crypto_kcf_provider_handle_t; * register for the same device instance. In this case, the same * pi_provider_dev must be specified with a different pi_provider_handle. */ -typedef struct crypto_provider_info_v1 { - uint_t pi_interface_version; +typedef struct crypto_provider_info { char *pi_provider_description; crypto_provider_type_t pi_provider_type; crypto_provider_handle_t pi_provider_handle; @@ -646,31 +613,9 @@ typedef struct crypto_provider_info_v1 { const crypto_mech_info_t *pi_mechanisms; uint_t pi_logical_provider_count; crypto_kcf_provider_handle_t *pi_logical_providers; -} crypto_provider_info_v1_t; - -typedef struct crypto_provider_info_v2 { - crypto_provider_info_v1_t v1_info; uint_t pi_flags; -} crypto_provider_info_v2_t; - -typedef struct crypto_provider_info { - union { - crypto_provider_info_v2_t piu_v2; - crypto_provider_info_v1_t piu_v1; - } piu; } crypto_provider_info_t; -#define pi_interface_version piu.piu_v1.pi_interface_version -#define pi_provider_description piu.piu_v1.pi_provider_description -#define pi_provider_type piu.piu_v1.pi_provider_type -#define pi_provider_handle piu.piu_v1.pi_provider_handle -#define pi_ops_vector piu.piu_v1.pi_ops_vector -#define pi_mech_list_count piu.piu_v1.pi_mech_list_count -#define pi_mechanisms piu.piu_v1.pi_mechanisms -#define pi_logical_provider_count piu.piu_v1.pi_logical_provider_count -#define pi_logical_providers piu.piu_v1.pi_logical_providers -#define pi_flags piu.piu_v2.pi_flags - /* hidden providers can only be accessed via a logical provider */ #define CRYPTO_HIDE_PROVIDER 0x00000001 /* diff --git a/module/icp/io/aes.c b/module/icp/io/aes.c index 510764e7b8..27930ed00d 100644 --- a/module/icp/io/aes.c +++ b/module/icp/io/aes.c @@ -143,7 +143,7 @@ static const crypto_ctx_ops_t aes_ctx_ops = { .free_context = aes_free_context }; -static const crypto_ops_t aes_crypto_ops = {{{{{ +static const crypto_ops_t aes_crypto_ops = { NULL, &aes_cipher_ops, &aes_mac_ops, @@ -157,17 +157,16 @@ static const crypto_ops_t aes_crypto_ops = {{{{{ NULL, NULL, &aes_ctx_ops -}}}}}; +}; -static const crypto_provider_info_t aes_prov_info = {{{{ - CRYPTO_SPI_VERSION_1, +static const crypto_provider_info_t aes_prov_info = { "AES Software Provider", CRYPTO_SW_PROVIDER, NULL, &aes_crypto_ops, sizeof (aes_mech_info_tab) / sizeof (crypto_mech_info_t), aes_mech_info_tab -}}}}; +}; static crypto_kcf_provider_handle_t aes_prov_handle = 0; static crypto_data_t null_crypto_data = { CRYPTO_DATA_RAW }; diff --git a/module/icp/io/sha2_mod.c b/module/icp/io/sha2_mod.c index df25d1544b..0c7f8a73d3 100644 --- a/module/icp/io/sha2_mod.c +++ b/module/icp/io/sha2_mod.c @@ -157,7 +157,7 @@ static const crypto_ctx_ops_t sha2_ctx_ops = { .free_context = sha2_free_context }; -static const crypto_ops_t sha2_crypto_ops = {{{{{ +static const crypto_ops_t sha2_crypto_ops = { &sha2_digest_ops, NULL, &sha2_mac_ops, @@ -171,17 +171,16 @@ static const crypto_ops_t sha2_crypto_ops = {{{{{ NULL, NULL, &sha2_ctx_ops -}}}}}; +}; -static const crypto_provider_info_t sha2_prov_info = {{{{ - CRYPTO_SPI_VERSION_1, +static const crypto_provider_info_t sha2_prov_info = { "SHA2 Software Provider", CRYPTO_SW_PROVIDER, NULL, &sha2_crypto_ops, sizeof (sha2_mech_info_tab) / sizeof (crypto_mech_info_t), sha2_mech_info_tab -}}}}; +}; static crypto_kcf_provider_handle_t sha2_prov_handle = 0; diff --git a/module/icp/io/skein_mod.c b/module/icp/io/skein_mod.c index b54685873f..cceea29d4f 100644 --- a/module/icp/io/skein_mod.c +++ b/module/icp/io/skein_mod.c @@ -95,7 +95,7 @@ static const crypto_ctx_ops_t skein_ctx_ops = { .free_context = skein_free_context }; -static const crypto_ops_t skein_crypto_ops = {{{{{ +static const crypto_ops_t skein_crypto_ops = { &skein_digest_ops, NULL, &skein_mac_ops, @@ -109,17 +109,16 @@ static const crypto_ops_t skein_crypto_ops = {{{{{ NULL, NULL, &skein_ctx_ops, -}}}}}; +}; -static const crypto_provider_info_t skein_prov_info = {{{{ - CRYPTO_SPI_VERSION_1, +static const crypto_provider_info_t skein_prov_info = { "Skein Software Provider", CRYPTO_SW_PROVIDER, NULL, &skein_crypto_ops, sizeof (skein_mech_info_tab) / sizeof (crypto_mech_info_t), skein_mech_info_tab -}}}}; +}; static crypto_kcf_provider_handle_t skein_prov_handle = 0; diff --git a/module/icp/spi/kcf_spi.c b/module/icp/spi/kcf_spi.c index 7e7487912b..51670d5b98 100644 --- a/module/icp/spi/kcf_spi.c +++ b/module/icp/spi/kcf_spi.c @@ -70,7 +70,7 @@ static const kcf_prov_stats_t kcf_stats_ks_data_template = { * persistent. */ static void -copy_ops_vector_v1(const crypto_ops_t *src_ops, crypto_ops_t *dst_ops) +copy_ops_vector(const crypto_ops_t *src_ops, crypto_ops_t *dst_ops) { KCF_SPI_COPY_OPS(src_ops, dst_ops, co_digest_ops); KCF_SPI_COPY_OPS(src_ops, dst_ops, co_cipher_ops); @@ -85,17 +85,7 @@ copy_ops_vector_v1(const crypto_ops_t *src_ops, crypto_ops_t *dst_ops) KCF_SPI_COPY_OPS(src_ops, dst_ops, co_key_ops); KCF_SPI_COPY_OPS(src_ops, dst_ops, co_provider_ops); KCF_SPI_COPY_OPS(src_ops, dst_ops, co_ctx_ops); -} - -static void -copy_ops_vector_v2(const crypto_ops_t *src_ops, crypto_ops_t *dst_ops) -{ KCF_SPI_COPY_OPS(src_ops, dst_ops, co_mech_ops); -} - -static void -copy_ops_vector_v3(const crypto_ops_t *src_ops, crypto_ops_t *dst_ops) -{ KCF_SPI_COPY_OPS(src_ops, dst_ops, co_nostore_key_ops); } @@ -116,9 +106,6 @@ crypto_register_provider(const crypto_provider_info_t *info, kcf_provider_desc_t *prov_desc = NULL; int ret = CRYPTO_ARGUMENTS_BAD; - if (info->pi_interface_version > CRYPTO_SPI_VERSION_3) - return (CRYPTO_VERSION_MISMATCH); - /* * Check provider type, must be software, hardware, or logical. */ @@ -159,14 +146,8 @@ crypto_register_provider(const crypto_provider_info_t *info, goto bail; } crypto_ops_t *pvec = (crypto_ops_t *)prov_desc->pd_ops_vector; - copy_ops_vector_v1(info->pi_ops_vector, pvec); - if (info->pi_interface_version >= CRYPTO_SPI_VERSION_2) { - copy_ops_vector_v2(info->pi_ops_vector, pvec); - prov_desc->pd_flags = info->pi_flags; - } - if (info->pi_interface_version == CRYPTO_SPI_VERSION_3) { - copy_ops_vector_v3(info->pi_ops_vector, pvec); - } + copy_ops_vector(info->pi_ops_vector, pvec); + prov_desc->pd_flags = info->pi_flags; } /* object_ops and nostore_key_ops are mutually exclusive */