module: icp: spi: flatten struct crypto_ops, crypto_provider_info

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12901
This commit is contained in:
наб 2021-12-22 22:09:28 +01:00 committed by Brian Behlendorf
parent 959b9d6392
commit f5896e2bdf
6 changed files with 19 additions and 108 deletions

View File

@ -205,7 +205,7 @@ kcf_prov_tab_lookup(crypto_provider_id_t prov_id)
} }
static void 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) uint_t *mech_list_count)
{ {
if (src->co_digest_ops != NULL) 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) if (src->co_ctx_ops != NULL)
dst->co_ctx_ops = kmem_alloc(sizeof (crypto_ctx_ops_t), dst->co_ctx_ops = kmem_alloc(sizeof (crypto_ctx_ops_t),
KM_SLEEP); KM_SLEEP);
}
static void
allocate_ops_v2(const crypto_ops_t *src, crypto_ops_t *dst)
{
if (src->co_mech_ops != NULL) if (src->co_mech_ops != NULL)
dst->co_mech_ops = kmem_alloc(sizeof (crypto_mech_ops_t), dst->co_mech_ops = kmem_alloc(sizeof (crypto_mech_ops_t),
KM_SLEEP); KM_SLEEP);
}
static void
allocate_ops_v3(const crypto_ops_t *src, crypto_ops_t *dst)
{
if (src->co_nostore_key_ops != NULL) if (src->co_nostore_key_ops != NULL)
dst->co_nostore_key_ops = dst->co_nostore_key_ops =
kmem_alloc(sizeof (crypto_nostore_key_ops_t), KM_SLEEP); 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); crypto_ops_t *opvec = kmem_zalloc(sizeof (crypto_ops_t), KM_SLEEP);
if (info->pi_provider_type != CRYPTO_LOGICAL_PROVIDER) { if (info->pi_provider_type != CRYPTO_LOGICAL_PROVIDER) {
allocate_ops_v1(src_ops, opvec, &mech_list_count); allocate_ops(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);
} }
desc->pd_ops_vector = opvec; desc->pd_ops_vector = opvec;

View File

@ -487,7 +487,7 @@ typedef struct crypto_nostore_key_ops {
* supplied by a provider when it registers with the kernel * supplied by a provider when it registers with the kernel
* by calling crypto_register_provider(9F). * 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_digest_ops_t *co_digest_ops;
const crypto_cipher_ops_t *co_cipher_ops; const crypto_cipher_ops_t *co_cipher_ops;
const crypto_mac_ops_t *co_mac_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_key_ops_t *co_key_ops;
crypto_provider_management_ops_t *co_provider_ops; crypto_provider_management_ops_t *co_provider_ops;
const crypto_ctx_ops_t *co_ctx_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_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_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; } 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 * 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, * 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 * register for the same device instance. In this case, the same
* pi_provider_dev must be specified with a different pi_provider_handle. * pi_provider_dev must be specified with a different pi_provider_handle.
*/ */
typedef struct crypto_provider_info_v1 { typedef struct crypto_provider_info {
uint_t pi_interface_version;
char *pi_provider_description; char *pi_provider_description;
crypto_provider_type_t pi_provider_type; crypto_provider_type_t pi_provider_type;
crypto_provider_handle_t pi_provider_handle; crypto_provider_handle_t pi_provider_handle;
@ -646,31 +613,9 @@ typedef struct crypto_provider_info_v1 {
const crypto_mech_info_t *pi_mechanisms; const crypto_mech_info_t *pi_mechanisms;
uint_t pi_logical_provider_count; uint_t pi_logical_provider_count;
crypto_kcf_provider_handle_t *pi_logical_providers; 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; 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; } 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 */ /* hidden providers can only be accessed via a logical provider */
#define CRYPTO_HIDE_PROVIDER 0x00000001 #define CRYPTO_HIDE_PROVIDER 0x00000001
/* /*

View File

@ -143,7 +143,7 @@ static const crypto_ctx_ops_t aes_ctx_ops = {
.free_context = aes_free_context .free_context = aes_free_context
}; };
static const crypto_ops_t aes_crypto_ops = {{{{{ static const crypto_ops_t aes_crypto_ops = {
NULL, NULL,
&aes_cipher_ops, &aes_cipher_ops,
&aes_mac_ops, &aes_mac_ops,
@ -157,17 +157,16 @@ static const crypto_ops_t aes_crypto_ops = {{{{{
NULL, NULL,
NULL, NULL,
&aes_ctx_ops &aes_ctx_ops
}}}}}; };
static const crypto_provider_info_t aes_prov_info = {{{{ static const crypto_provider_info_t aes_prov_info = {
CRYPTO_SPI_VERSION_1,
"AES Software Provider", "AES Software Provider",
CRYPTO_SW_PROVIDER, CRYPTO_SW_PROVIDER,
NULL, NULL,
&aes_crypto_ops, &aes_crypto_ops,
sizeof (aes_mech_info_tab) / sizeof (crypto_mech_info_t), sizeof (aes_mech_info_tab) / sizeof (crypto_mech_info_t),
aes_mech_info_tab aes_mech_info_tab
}}}}; };
static crypto_kcf_provider_handle_t aes_prov_handle = 0; static crypto_kcf_provider_handle_t aes_prov_handle = 0;
static crypto_data_t null_crypto_data = { CRYPTO_DATA_RAW }; static crypto_data_t null_crypto_data = { CRYPTO_DATA_RAW };

View File

@ -157,7 +157,7 @@ static const crypto_ctx_ops_t sha2_ctx_ops = {
.free_context = sha2_free_context .free_context = sha2_free_context
}; };
static const crypto_ops_t sha2_crypto_ops = {{{{{ static const crypto_ops_t sha2_crypto_ops = {
&sha2_digest_ops, &sha2_digest_ops,
NULL, NULL,
&sha2_mac_ops, &sha2_mac_ops,
@ -171,17 +171,16 @@ static const crypto_ops_t sha2_crypto_ops = {{{{{
NULL, NULL,
NULL, NULL,
&sha2_ctx_ops &sha2_ctx_ops
}}}}}; };
static const crypto_provider_info_t sha2_prov_info = {{{{ static const crypto_provider_info_t sha2_prov_info = {
CRYPTO_SPI_VERSION_1,
"SHA2 Software Provider", "SHA2 Software Provider",
CRYPTO_SW_PROVIDER, CRYPTO_SW_PROVIDER,
NULL, NULL,
&sha2_crypto_ops, &sha2_crypto_ops,
sizeof (sha2_mech_info_tab) / sizeof (crypto_mech_info_t), sizeof (sha2_mech_info_tab) / sizeof (crypto_mech_info_t),
sha2_mech_info_tab sha2_mech_info_tab
}}}}; };
static crypto_kcf_provider_handle_t sha2_prov_handle = 0; static crypto_kcf_provider_handle_t sha2_prov_handle = 0;

View File

@ -95,7 +95,7 @@ static const crypto_ctx_ops_t skein_ctx_ops = {
.free_context = skein_free_context .free_context = skein_free_context
}; };
static const crypto_ops_t skein_crypto_ops = {{{{{ static const crypto_ops_t skein_crypto_ops = {
&skein_digest_ops, &skein_digest_ops,
NULL, NULL,
&skein_mac_ops, &skein_mac_ops,
@ -109,17 +109,16 @@ static const crypto_ops_t skein_crypto_ops = {{{{{
NULL, NULL,
NULL, NULL,
&skein_ctx_ops, &skein_ctx_ops,
}}}}}; };
static const crypto_provider_info_t skein_prov_info = {{{{ static const crypto_provider_info_t skein_prov_info = {
CRYPTO_SPI_VERSION_1,
"Skein Software Provider", "Skein Software Provider",
CRYPTO_SW_PROVIDER, CRYPTO_SW_PROVIDER,
NULL, NULL,
&skein_crypto_ops, &skein_crypto_ops,
sizeof (skein_mech_info_tab) / sizeof (crypto_mech_info_t), sizeof (skein_mech_info_tab) / sizeof (crypto_mech_info_t),
skein_mech_info_tab skein_mech_info_tab
}}}}; };
static crypto_kcf_provider_handle_t skein_prov_handle = 0; static crypto_kcf_provider_handle_t skein_prov_handle = 0;

View File

@ -70,7 +70,7 @@ static const kcf_prov_stats_t kcf_stats_ks_data_template = {
* persistent. * persistent.
*/ */
static void 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_digest_ops);
KCF_SPI_COPY_OPS(src_ops, dst_ops, co_cipher_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_key_ops);
KCF_SPI_COPY_OPS(src_ops, dst_ops, co_provider_ops); KCF_SPI_COPY_OPS(src_ops, dst_ops, co_provider_ops);
KCF_SPI_COPY_OPS(src_ops, dst_ops, co_ctx_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); 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); 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; kcf_provider_desc_t *prov_desc = NULL;
int ret = CRYPTO_ARGUMENTS_BAD; 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. * Check provider type, must be software, hardware, or logical.
*/ */
@ -159,14 +146,8 @@ crypto_register_provider(const crypto_provider_info_t *info,
goto bail; goto bail;
} }
crypto_ops_t *pvec = (crypto_ops_t *)prov_desc->pd_ops_vector; crypto_ops_t *pvec = (crypto_ops_t *)prov_desc->pd_ops_vector;
copy_ops_vector_v1(info->pi_ops_vector, pvec); copy_ops_vector(info->pi_ops_vector, pvec);
if (info->pi_interface_version >= CRYPTO_SPI_VERSION_2) { prov_desc->pd_flags = info->pi_flags;
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);
}
} }
/* object_ops and nostore_key_ops are mutually exclusive */ /* object_ops and nostore_key_ops are mutually exclusive */