@@ -1092,7 +1092,6 @@ static int gen_tls_identity(const char *hostnqn, const char *subsysnqn,
10921092}
10931093#endif /* !CONFIG_OPENSSL_3 */
10941094
1095- #ifdef CONFIG_KEYUTILS
10961095static int derive_nvme_keys (const char * hostnqn , const char * subsysnqn ,
10971096 char * identity , int version ,
10981097 int hmac , unsigned char * configured ,
@@ -1101,7 +1100,7 @@ static int derive_nvme_keys(const char *hostnqn, const char *subsysnqn,
11011100 unsigned char * retained ;
11021101 int ret = -1 ;
11031102
1104- if (!hostnqn || !subsysnqn || !identity ) {
1103+ if (!hostnqn || !subsysnqn || !identity || ! psk ) {
11051104 errno = EINVAL ;
11061105 return -1 ;
11071106 }
@@ -1141,6 +1140,40 @@ static size_t nvme_identity_len(int hmac, int version, const char *hostnqn,
11411140 return len ;
11421141}
11431142
1143+ char * nvme_generate_tls_key_identity (const char * hostnqn , const char * subsysnqn ,
1144+ int version , int hmac ,
1145+ unsigned char * configured_key , int key_len )
1146+ {
1147+ char * identity ;
1148+ size_t identity_len ;
1149+ unsigned char * psk ;
1150+ int ret = -1 ;
1151+
1152+ identity_len = nvme_identity_len (hmac , version , hostnqn , subsysnqn );
1153+ if (identity_len < 0 )
1154+ return NULL ;
1155+
1156+ identity = malloc (identity_len );
1157+ if (!identity )
1158+ return NULL ;
1159+
1160+ psk = malloc (key_len );
1161+ if (!psk )
1162+ goto out_free_identity ;
1163+
1164+ memset (psk , 0 , key_len );
1165+ ret = derive_nvme_keys (hostnqn , subsysnqn , identity , version , hmac ,
1166+ configured_key , psk , key_len );
1167+ free (psk );
1168+ out_free_identity :
1169+ if (ret < 0 ) {
1170+ free (identity );
1171+ identity = NULL ;
1172+ }
1173+ return identity ;
1174+ }
1175+
1176+ #ifdef CONFIG_KEYUTILS
11441177long nvme_lookup_keyring (const char * keyring )
11451178{
11461179 key_serial_t keyring_id ;
@@ -1233,38 +1266,6 @@ long nvme_insert_tls_key_versioned(const char *keyring, const char *key_type,
12331266 return key ;
12341267}
12351268
1236- char * nvme_generate_tls_key_identity (const char * hostnqn , const char * subsysnqn ,
1237- int version , int hmac ,
1238- unsigned char * configured_key , int key_len )
1239- {
1240- char * identity ;
1241- size_t identity_len ;
1242- unsigned char * psk ;
1243- int ret = -1 ;
1244-
1245- identity_len = nvme_identity_len (hmac , version , hostnqn , subsysnqn );
1246- if (identity_len < 0 )
1247- return NULL ;
1248-
1249- identity = malloc (identity_len );
1250- if (!identity )
1251- return NULL ;
1252-
1253- psk = malloc (key_len );
1254- if (!psk )
1255- goto out_free_identity ;
1256-
1257- memset (psk , 0 , key_len );
1258- ret = derive_nvme_keys (hostnqn , subsysnqn , identity , version , hmac ,
1259- configured_key , psk , key_len );
1260- free (psk );
1261- out_free_identity :
1262- if (ret < 0 ) {
1263- free (identity );
1264- identity = NULL ;
1265- }
1266- return identity ;
1267- }
12681269#else
12691270long nvme_lookup_keyring (const char * keyring )
12701271{
@@ -1308,16 +1309,6 @@ long nvme_insert_tls_key_versioned(const char *keyring, const char *key_type,
13081309 errno = ENOTSUP ;
13091310 return -1 ;
13101311}
1311-
1312- char * nvme_generate_tls_key_identity (const char * hostnqn , const char * subsysnqn ,
1313- int version , int hmac ,
1314- unsigned char * configured_key , int key_len )
1315- {
1316- nvme_msg (NULL , LOG_ERR , "key operations not supported; "
1317- "recompile with keyutils support.\n" );
1318- errno = ENOTSUP ;
1319- return -1 ;
1320- }
13211312#endif
13221313
13231314long nvme_insert_tls_key (const char * keyring , const char * key_type ,
0 commit comments