}
#endif /* !CONFIG_OPENSSL_3 */
-#ifdef CONFIG_KEYUTILS
static int derive_nvme_keys(const char *hostnqn, const char *subsysnqn,
char *identity, int version,
int hmac, unsigned char *configured,
unsigned char *retained;
int ret = -1;
- if (!hostnqn || !subsysnqn || !identity) {
+ if (!hostnqn || !subsysnqn || !identity || !psk) {
errno = EINVAL;
return -1;
}
return len;
}
+char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn,
+ int version, int hmac,
+ unsigned char *configured_key, int key_len)
+{
+ char *identity;
+ size_t identity_len;
+ unsigned char *psk;
+ int ret = -1;
+
+ identity_len = nvme_identity_len(hmac, version, hostnqn, subsysnqn);
+ if (identity_len < 0)
+ return NULL;
+
+ identity = malloc(identity_len);
+ if (!identity)
+ return NULL;
+
+ psk = malloc(key_len);
+ if (!psk)
+ goto out_free_identity;
+
+ memset(psk, 0, key_len);
+ ret = derive_nvme_keys(hostnqn, subsysnqn, identity, version, hmac,
+ configured_key, psk, key_len);
+ free(psk);
+out_free_identity:
+ if (ret < 0) {
+ free(identity);
+ identity = NULL;
+ }
+ return identity;
+}
+
+#ifdef CONFIG_KEYUTILS
long nvme_lookup_keyring(const char *keyring)
{
key_serial_t keyring_id;
return key;
}
-char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn,
- int version, int hmac,
- unsigned char *configured_key, int key_len)
-{
- char *identity;
- size_t identity_len;
- unsigned char *psk;
- int ret = -1;
-
- identity_len = nvme_identity_len(hmac, version, hostnqn, subsysnqn);
- if (identity_len < 0)
- return NULL;
-
- identity = malloc(identity_len);
- if (!identity)
- return NULL;
-
- psk = malloc(key_len);
- if (!psk)
- goto out_free_identity;
-
- memset(psk, 0, key_len);
- ret = derive_nvme_keys(hostnqn, subsysnqn, identity, version, hmac,
- configured_key, psk, key_len);
- free(psk);
-out_free_identity:
- if (ret < 0) {
- free(identity);
- identity = NULL;
- }
- return identity;
-}
#else
long nvme_lookup_keyring(const char *keyring)
{
errno = ENOTSUP;
return -1;
}
-
-char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn,
- int version, int hmac,
- unsigned char *configured_key, int key_len)
-{
- nvme_msg(NULL, LOG_ERR, "key operations not supported; "
- "recompile with keyutils support.\n");
- errno = ENOTSUP;
- return -1;
-}
#endif
long nvme_insert_tls_key(const char *keyring, const char *key_type,