1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2018 Intel Corporation. 3 * All rights reserved. 4 * Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. 5 * All rights reserved. 6 */ 7 8 #ifndef SPDK_VBDEV_CRYPTO_H 9 #define SPDK_VBDEV_CRYPTO_H 10 11 #include "spdk/rpc.h" 12 #include "spdk/util.h" 13 #include "spdk/string.h" 14 #include "spdk/log.h" 15 16 #include "spdk/bdev.h" 17 18 #define AESNI_MB "crypto_aesni_mb" 19 #define QAT "crypto_qat" 20 #define QAT_ASYM "crypto_qat_asym" 21 #define MLX5 "mlx5_pci" 22 23 /* Supported ciphers */ 24 #define AES_CBC "AES_CBC" /* QAT and AESNI_MB */ 25 #define AES_XTS "AES_XTS" /* QAT and MLX5 */ 26 27 /* Specific to AES_CBC. */ 28 #define AES_CBC_KEY_LENGTH 16 29 30 #define AES_XTS_128_BLOCK_KEY_LENGTH 16 /* AES-XTS-128 block key size. */ 31 #define AES_XTS_256_BLOCK_KEY_LENGTH 32 /* AES-XTS-256 block key size. */ 32 #define AES_XTS_512_BLOCK_KEY_LENGTH 64 /* AES-XTS-512 block key size. */ 33 34 #define AES_XTS_TWEAK_KEY_LENGTH 16 /* XTS part key size is always 128 bit. */ 35 36 /* Structure to hold crypto options for crypto pmd setup. */ 37 struct vbdev_crypto_opts { 38 char *vbdev_name; /* name of the vbdev to create */ 39 char *bdev_name; /* base bdev name */ 40 41 char *drv_name; /* name of the crypto device driver */ 42 char *cipher; /* AES_CBC or AES_XTS */ 43 44 /* Note, for dev/test we allow use of key in the config file, for production 45 * use, you must use an RPC to specify the key for security reasons. 46 */ 47 uint8_t *key; /* key per bdev */ 48 uint8_t key_size; /* key size */ 49 uint8_t *key2; /* key #2 for AES_XTS, per bdev */ 50 uint8_t key2_size; /* key #2 size */ 51 uint8_t *xts_key; /* key + key 2 */ 52 }; 53 54 typedef void (*spdk_delete_crypto_complete)(void *cb_arg, int bdeverrno); 55 56 /** 57 * Create new crypto bdev. 58 * 59 * \param opts Crypto options populated by create_crypto_opts() 60 * \return 0 on success, other on failure. 61 */ 62 int create_crypto_disk(struct vbdev_crypto_opts *opts); 63 64 /** 65 * Delete crypto bdev. 66 * 67 * \param bdev_name Crypto bdev name. 68 * \param cb_fn Function to call after deletion. 69 * \param cb_arg Argument to pass to cb_fn. 70 */ 71 void delete_crypto_disk(const char *bdev_name, spdk_delete_crypto_complete cb_fn, 72 void *cb_arg); 73 74 /** 75 * Release crypto opts created with create_crypto_opts() 76 * 77 * \param opts Crypto opts to release 78 */ 79 void free_crypto_opts(struct vbdev_crypto_opts *opts); 80 81 #endif /* SPDK_VBDEV_CRYPTO_H */ 82