Commit 9cd94384 authored by Jacek Kalwas's avatar Jacek Kalwas Committed by Tomasz Zawadzki
Browse files

accel: introduce cipher enum



Enum is introduced so accel crypto modules doesn't need to define
such on its own, moreover logic is simplified as module doesn't
need to operate on c-string but simple enum type.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 8072cbc2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -44,6 +44,11 @@ enum accel_opcode {
	ACCEL_OPC_LAST			= 11,
};

enum spdk_accel_cipher {
	SPDK_ACCEL_CIPHER_AES_CBC,
	SPDK_ACCEL_CIPHER_AES_XTS,
};

/**
 * Acceleration operation callback.
 *
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ struct spdk_accel_crypto_key {
	size_t key_size;				/**< Key size in bytes */
	char *key2;					/**< Key2 in binary form */
	size_t key2_size;				/**< Key2 size in bytes */
	enum spdk_accel_cipher cipher;
	enum spdk_accel_crypto_tweak_mode tweak_mode;
	struct spdk_accel_module_if *module_if;			/**< Accel module the key belongs to */
	struct spdk_accel_crypto_key_create_param param;	/**< User input parameters */
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 12
SO_VER := 13
SO_MINOR := 0
SO_SUFFIX := $(SO_VER).$(SO_MINOR)

+29 −5
Original line number Diff line number Diff line
@@ -2040,12 +2040,19 @@ static const char *g_tweak_modes[SPDK_ACCEL_CRYPTO_TWEAK_MODE_MAX] = {
	[SPDK_ACCEL_CRYPTO_TWEAK_MODE_INCR_512_UPPER_LBA] = "INCR_512_UPPER_LBA",
};

static const char *g_ciphers[] = {
	[SPDK_ACCEL_CIPHER_AES_CBC] = "AES_CBC",
	[SPDK_ACCEL_CIPHER_AES_XTS] = "AES_XTS",
};

int
spdk_accel_crypto_key_create(const struct spdk_accel_crypto_key_create_param *param)
{
	struct spdk_accel_module_if *module;
	struct spdk_accel_crypto_key *key;
	size_t hex_key_size, hex_key2_size;
	bool found = false;
	size_t i;
	int rc;

	if (!param || !param->hex_key || !param->cipher || !param->key_name) {
@@ -2078,6 +2085,22 @@ spdk_accel_crypto_key_create(const struct spdk_accel_crypto_key_create_param *pa
		goto error;
	}

	for (i = 0; i < SPDK_COUNTOF(g_ciphers); ++i) {
		assert(g_ciphers[i]);

		if (strncmp(param->cipher, g_ciphers[i], strlen(g_ciphers[i])) == 0) {
			key->cipher = i;
			found = true;
			break;
		}
	}

	if (!found) {
		SPDK_ERRLOG("Failed to parse cipher\n");
		rc = -EINVAL;
		goto error;
	}

	key->param.cipher = strdup(param->cipher);
	if (!key->param.cipher) {
		rc = -ENOMEM;
@@ -2142,7 +2165,7 @@ spdk_accel_crypto_key_create(const struct spdk_accel_crypto_key_create_param *pa

	key->tweak_mode = ACCEL_CRYPTO_TWEAK_MODE_DEFAULT;
	if (param->tweak_mode) {
		bool found = false;
		found = false;

		key->param.tweak_mode = strdup(param->tweak_mode);
		if (!key->param.tweak_mode) {
@@ -2175,22 +2198,23 @@ 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->cipher == SPDK_ACCEL_CIPHER_AES_XTS) {
		if (!key->key2) {
			SPDK_ERRLOG("%s key2 is missing\n", ACCEL_AES_XTS);
			SPDK_ERRLOG("%s key2 is missing\n", g_ciphers[key->cipher]);
			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,
			SPDK_ERRLOG("%s key size %zu is not equal to key2 size %zu\n", g_ciphers[key->cipher],
				    key->key_size,
				    key->key2_size);
			rc = -EINVAL;
			goto error;
		}

		if (accel_aes_xts_keys_equal(key->key, key->key_size, key->key2, key->key2_size)) {
			SPDK_ERRLOG("%s identical keys are not secure\n", ACCEL_AES_XTS);
			SPDK_ERRLOG("%s identical keys are not secure\n", g_ciphers[key->cipher]);
			rc = -EINVAL;
			goto error;
		}
+3 −3
Original line number Diff line number Diff line
@@ -652,12 +652,12 @@ 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 (strcmp(key->param.cipher, ACCEL_AES_XTS) == 0) {
		return sw_accel_create_aes_xts(key);
	} else {
	if (key->cipher != SPDK_ACCEL_CIPHER_AES_XTS) {
		SPDK_ERRLOG("Only %s cipher is supported\n", ACCEL_AES_XTS);
		return -EINVAL;
	}

	return sw_accel_create_aes_xts(key);
}

static void
Loading