Commit 2f4332f5 authored by Jacek Kalwas's avatar Jacek Kalwas Committed by Jim Harris
Browse files

accel: move aes xts validation from accel modules to generic layer



This allows to leverage these checks on different accel modules and
not duplicate the code.

Signed-off-by: default avatarJacek Kalwas <jacek.kalwas@intel.com>
Change-Id: Ia8e7a4d6caac49bfa8fe65d57b398137f1225a53
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17529


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Mellanox Build Bot
parent d63aa0d5
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -2090,6 +2090,13 @@ spdk_accel_crypto_key_create(const struct spdk_accel_crypto_key_create_param *pa
		rc = -EINVAL;
		goto error;
	}

	if (hex_key_size == 0) {
		SPDK_ERRLOG("key1 size cannot be 0\n");
		rc = -EINVAL;
		goto error;
	}

	key->param.hex_key = strdup(param->hex_key);
	if (!key->param.hex_key) {
		rc = -ENOMEM;
@@ -2111,6 +2118,13 @@ spdk_accel_crypto_key_create(const struct spdk_accel_crypto_key_create_param *pa
			rc = -EINVAL;
			goto error;
		}

		if (hex_key2_size == 0) {
			SPDK_ERRLOG("key2 size cannot be 0\n");
			rc = -EINVAL;
			goto error;
		}

		key->param.hex_key2 = strdup(param->hex_key2);
		if (!key->param.hex_key2) {
			rc = -ENOMEM;
@@ -2126,7 +2140,7 @@ spdk_accel_crypto_key_create(const struct spdk_accel_crypto_key_create_param *pa
		}

		if (accel_aes_xts_keys_equal(key->key, key->key_size, key->key2, key->key2_size)) {
			SPDK_ERRLOG("Identical keys are not secure\n");
			SPDK_ERRLOG("%s identical keys are not secure\n", ACCEL_AES_XTS);
			rc = -EINVAL;
			goto error;
		}
@@ -2168,6 +2182,21 @@ spdk_accel_crypto_key_create(const struct spdk_accel_crypto_key_create_param *pa
		goto error;
	}

	if (strcmp(key->param.cipher, ACCEL_AES_XTS) == 0) {
		if (!key->key2) {
			SPDK_ERRLOG("%s key2 is missing\n", ACCEL_AES_XTS);
			rc = -EINVAL;
			goto error;
		}

		if (key->key_size != key->key2_size) {
			SPDK_ERRLOG("%s key size %zu is not equal to key2 size %zu\n", ACCEL_AES_XTS, key->key_size,
				    key->key2_size);
			rc = -EINVAL;
			goto error;
		}
	}

	key->module_if = module;

	spdk_spin_lock(&g_keyring_spin);
+2 −0
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@
#include "spdk/queue.h"
#include "spdk/config.h"

#define ACCEL_AES_XTS "AES_XTS"

struct module_info {
	struct spdk_json_write_ctx *w;
	const char *name;
+1 −15
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@

#define ACCEL_AES_XTS_128_KEY_SIZE 16
#define ACCEL_AES_XTS_256_KEY_SIZE 32
#define ACCEL_AES_XTS "AES_XTS"

/* Per the AES-XTS spec, the size of data unit cannot be bigger than 2^20 blocks, 128b each block */
#define ACCEL_AES_XTS_MAX_BLOCK_SIZE (1 << 24)

@@ -620,17 +620,6 @@ sw_accel_create_aes_xts(struct spdk_accel_crypto_key *key)
#ifdef SPDK_CONFIG_ISAL_CRYPTO
	struct sw_accel_crypto_key_data *key_data;

	if (!key->key || !key->key2) {
		SPDK_ERRLOG("key or key2 are missing\n");
		return -EINVAL;
	}

	if (!key->key_size || key->key_size != key->key2_size) {
		SPDK_ERRLOG("key size %zu is not equal to key2 size %zu or is 0\n", key->key_size,
			    key->key2_size);
		return -EINVAL;
	}

	key_data = calloc(1, sizeof(*key_data));
	if (!key_data) {
		return -ENOMEM;
@@ -663,9 +652,6 @@ sw_accel_create_aes_xts(struct spdk_accel_crypto_key *key)
static int
sw_accel_crypto_key_init(struct spdk_accel_crypto_key *key)
{
	if (!key || !key->param.cipher) {
		return -EINVAL;
	}
	if (strcmp(key->param.cipher, ACCEL_AES_XTS) == 0) {
		return sw_accel_create_aes_xts(key);
	} else {
+0 −13
Original line number Diff line number Diff line
@@ -1394,10 +1394,6 @@ accel_dpdk_cryptodev_validate_parameters(enum accel_dpdk_cryptodev_driver_type d
		}
		break;
	case ACCEL_DPDK_CRYPTODEV_CIPHER_AES_XTS:
		if (!key->key || !key->key_size || !key->key2 || !key->key2_size) {
			SPDK_ERRLOG("ACCEL_DPDK_CRYPTODEV_AES_XTS requires both key and key2\n");
			return -1;
		}
		break;
	default:
		return -1;
@@ -1419,10 +1415,6 @@ accel_dpdk_cryptodev_validate_parameters(enum accel_dpdk_cryptodev_driver_type d
		}
		break;
	case ACCEL_DPDK_CRYPTODEV_CIPHER_AES_XTS:
		if (key->key_size != key->key2_size) {
			SPDK_ERRLOG("Cipher %s requires equal key and key2 sizes\n", g_cipher_names[driver]);
			return -1;
		}
		switch (driver) {
		case ACCEL_DPDK_CRYPTODEV_DRIVER_MLX5_PCI:
			if (key->key_size != ACCEL_DPDK_CRYPTODEV_AES_XTS_128_BLOCK_KEY_LENGTH &&
@@ -1485,11 +1477,6 @@ accel_dpdk_cryptodev_key_init(struct spdk_accel_crypto_key *key)
	enum accel_dpdk_crypto_dev_cipher_type cipher;
	int rc;

	if (!key->param.cipher) {
		SPDK_ERRLOG("Cipher is missing\n");
		return -EINVAL;
	}

	if (strcmp(key->param.cipher, ACCEL_DPDK_CRYPTODEV_AES_CBC) == 0) {
		cipher = ACCEL_DPDK_CRYPTODEV_CIPHER_AES_CBC;
	} else if (strcmp(key->param.cipher, ACCEL_DPDK_CRYPTODEV_AES_XTS) == 0) {