40 #include "../common.h"
79 for (i = 0; i < hex_str_size; i++) {
81 if (
'0' <= hex_str[i] && hex_str[i] <=
'9')
82 digit = hex_str[i] -
'0';
83 else if (
'a' <= tolower(hex_str[i]) && tolower(hex_str[i]) <=
'f')
84 digit = tolower(hex_str[i]) -
'a' + 10;
86 DOCA_LOG_ERR(
"Wrong format for input (%s) - need to be in hex format (1-9) or (a-f) values",
91 bytes_arr[i / 2] = (bytes_arr[i / 2] << 4) + digit;
111 DOCA_LOG_ERR(
"Entered device PCI address exceeding the maximum size of %d",
129 char *file = (
char *)param;
151 char *file = (
char *)param;
180 "Invalid string length %d to represent a key, string length should be %d or %d characters long",
203 char *
iv = (
char *)param;
210 "Invalid string length %d to represent the initialization vector, max string length should be %d",
232 uint32_t
tag_size = *(uint32_t *)param;
235 DOCA_LOG_ERR(
"Invalid authentication tag size %d, tag size can be %d bytes or %d bytes",
270 const int *num = (
int *)param;
273 DOCA_LOG_ERR(
"Entered number of source doca_buf: %d, valid value must be >= 1", *num);
292 const int *num = (
int *)param;
295 DOCA_LOG_ERR(
"Entered number of destination doca_buf: %d, valid value must be >= 1", *num);
312 struct doca_argp_param *pci_param, *file_param, *output_param, *raw_key_param, *iv_param, *tag_size_param,
314 struct doca_argp_param *num_src_buf_param, *num_dst_buf_param;
374 "Raw key to encrypt/decrypt with, represented in hex format (32 characters for 128-bit key, and 64 for 256-bit key) - default: 256-bit key, equals to zero");
392 "Initialization vector, represented in hex format (0-24 characters for 0-96-bit IV) - default: 96-bit IV, equals to zero");
410 "Authentication tag size. Tag size is in bytes and can be 12B or 16B - default: 12");
481 struct doca_ctx *
ctx,
490 switch (next_state) {
500 DOCA_LOG_ERR(
"AES-GCM context entered into starting state. Unexpected transition");
513 DOCA_LOG_INFO(
"AES-GCM context entered into stopping state. Any inflight tasks will be flushed");
525 uint32_t max_buf_list_len = 0;
538 if (pci_addr !=
NULL) {
568 if (max_bufs > max_buf_list_len) {
570 DOCA_LOG_ERR(
"Number of doca_buf [%d] exceed the limitation [%u]: %s",
588 goto destroy_aes_gcm;
683 struct doca_buf *src_buf,
684 struct doca_buf *dst_buf,
685 struct doca_aes_gcm_key *key,
691 struct doca_aes_gcm_task_encrypt *encrypt_task;
693 struct doca_task *task;
695 struct timespec ts = {
702 task_user_data.
ptr = &task_result;
742 struct doca_buf *src_buf,
743 struct doca_buf *dst_buf,
744 struct doca_aes_gcm_key *key,
750 struct doca_aes_gcm_task_decrypt *decrypt_task;
752 struct doca_task *task;
754 struct timespec ts = {
761 task_user_data.
ptr = &task_result;
static void aes_gcm_state_changed_callback(const union doca_data user_data, struct doca_ctx *ctx, enum doca_ctx_states prev_state, enum doca_ctx_states next_state)
static doca_error_t raw_key_callback(void *param, void *config)
doca_error_t submit_aes_gcm_decrypt_task(struct aes_gcm_resources *resources, struct doca_buf *src_buf, struct doca_buf *dst_buf, struct doca_aes_gcm_key *key, const uint8_t *iv, uint32_t iv_length, uint32_t tag_size, uint32_t aad_size)
static doca_error_t pci_address_callback(void *param, void *config)
doca_error_t aes_gcm_task_decrypt_is_supported(struct doca_devinfo *devinfo)
DOCA_LOG_REGISTER(AES_GCM::COMMON)
doca_error_t submit_aes_gcm_encrypt_task(struct aes_gcm_resources *resources, struct doca_buf *src_buf, struct doca_buf *dst_buf, struct doca_aes_gcm_key *key, const uint8_t *iv, uint32_t iv_length, uint32_t tag_size, uint32_t aad_size)
doca_error_t destroy_aes_gcm_resources(struct aes_gcm_resources *resources)
static doca_error_t aad_callback(void *param, void *config)
void init_aes_gcm_params(struct aes_gcm_cfg *aes_gcm_cfg)
doca_error_t register_aes_gcm_params(void)
void decrypt_error_callback(struct doca_aes_gcm_task_decrypt *decrypt_task, union doca_data task_user_data, union doca_data ctx_user_data)
void encrypt_completed_callback(struct doca_aes_gcm_task_encrypt *encrypt_task, union doca_data task_user_data, union doca_data ctx_user_data)
doca_error_t allocate_aes_gcm_resources(const char *pci_addr, uint32_t max_bufs, struct aes_gcm_resources *resources)
static doca_error_t iv_callback(void *param, void *config)
void encrypt_error_callback(struct doca_aes_gcm_task_encrypt *encrypt_task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t num_dst_buf_callback(void *param, void *config)
static doca_error_t output_callback(void *param, void *config)
static doca_error_t tag_callback(void *param, void *config)
static doca_error_t parse_hex_to_bytes(const char *hex_str, size_t hex_str_size, uint8_t *bytes_arr)
static doca_error_t num_src_buf_callback(void *param, void *config)
doca_error_t aes_gcm_task_encrypt_is_supported(struct doca_devinfo *devinfo)
static doca_error_t file_callback(void *param, void *config)
void decrypt_completed_callback(struct doca_aes_gcm_task_decrypt *decrypt_task, union doca_data task_user_data, union doca_data ctx_user_data)
#define AES_GCM_KEY_256_STR_SIZE
#define NUM_AES_GCM_TASKS
#define AES_GCM_AUTH_TAG_96_SIZE_IN_BYTES
#define MAX_AES_GCM_KEY_STR_SIZE
#define AES_GCM_KEY_128_STR_SIZE
#define MAX_AES_GCM_KEY_SIZE
#define AES_GCM_AUTH_TAG_128_SIZE_IN_BYTES
#define USER_MAX_FILE_NAME
#define MAX_AES_GCM_IV_LENGTH
#define MAX_AES_GCM_IV_STR_LENGTH
doca_error_t destroy_core_objects(struct program_core_objects *state)
doca_error_t create_core_objects(struct program_core_objects *state, uint32_t max_bufs)
doca_error_t open_doca_device_with_capabilities(tasks_check func, struct doca_dev **retval)
static doca_error_t open_doca_device_with_pci(const char *pcie_value, struct doca_dev **retval)
struct rdma_resources resources
DOCA_EXPERIMENTAL doca_error_t doca_aes_gcm_task_decrypt_alloc_init(struct doca_aes_gcm *aes_gcm, struct doca_buf const *src_buff, struct doca_buf *dst_buff, struct doca_aes_gcm_key *key, const uint8_t *iv, uint32_t iv_length, uint32_t tag_size, uint32_t aad_size, union doca_data user_data, struct doca_aes_gcm_task_decrypt **task)
Allocate aes_gcm decrypt task.
DOCA_EXPERIMENTAL doca_error_t doca_aes_gcm_cap_task_decrypt_get_max_list_buf_num_elem(const struct doca_devinfo *devinfo, uint32_t *max_list_num_elem)
DOCA_EXPERIMENTAL doca_error_t doca_aes_gcm_cap_task_encrypt_get_max_list_buf_num_elem(const struct doca_devinfo *devinfo, uint32_t *max_list_num_elem)
DOCA_EXPERIMENTAL doca_error_t doca_aes_gcm_task_encrypt_alloc_init(struct doca_aes_gcm *aes_gcm, struct doca_buf const *src_buff, struct doca_buf *dst_buff, struct doca_aes_gcm_key *key, const uint8_t *iv, uint32_t iv_length, uint32_t tag_size, uint32_t aad_size, union doca_data user_data, struct doca_aes_gcm_task_encrypt **task)
Allocate aes_gcm encrypt task.
DOCA_EXPERIMENTAL struct doca_task * doca_aes_gcm_task_encrypt_as_task(struct doca_aes_gcm_task_encrypt *task)
convert aes_gcm encrypt task to doca_task
DOCA_EXPERIMENTAL struct doca_ctx * doca_aes_gcm_as_ctx(struct doca_aes_gcm *aes_gcm)
DOCA_EXPERIMENTAL doca_error_t doca_aes_gcm_task_encrypt_set_conf(struct doca_aes_gcm *aes_gcm, doca_aes_gcm_task_encrypt_completion_cb_t task_completion_cb, doca_aes_gcm_task_encrypt_completion_cb_t task_error_cb, uint32_t num_tasks)
This method sets the aes_gcm encrypt task configuration.
DOCA_EXPERIMENTAL doca_error_t doca_aes_gcm_cap_task_encrypt_is_supported(const struct doca_devinfo *devinfo)
Check if a aes_gcm encrypt task is supported by a device.
DOCA_EXPERIMENTAL struct doca_task * doca_aes_gcm_task_decrypt_as_task(struct doca_aes_gcm_task_decrypt *task)
convert aes_gcm decrypt task to doca_task
DOCA_EXPERIMENTAL doca_error_t doca_aes_gcm_create(struct doca_dev *dev, struct doca_aes_gcm **aes_gcm)
DOCA_EXPERIMENTAL doca_error_t doca_aes_gcm_task_decrypt_set_conf(struct doca_aes_gcm *aes_gcm, doca_aes_gcm_task_decrypt_completion_cb_t task_completion_cb, doca_aes_gcm_task_decrypt_completion_cb_t task_error_cb, uint32_t num_tasks)
This method sets the aes_gcm decrypt task configuration.
DOCA_EXPERIMENTAL doca_error_t doca_aes_gcm_cap_task_decrypt_is_supported(const struct doca_devinfo *devinfo)
Check if a aes_gcm decrypt task is supported by a device.
DOCA_EXPERIMENTAL doca_error_t doca_aes_gcm_destroy(struct doca_aes_gcm *aes_gcm)
DOCA_EXPERIMENTAL void doca_argp_param_set_description(struct doca_argp_param *param, const char *description)
Set the description of the program param, used during program usage.
DOCA_EXPERIMENTAL void doca_argp_param_set_long_name(struct doca_argp_param *param, const char *name)
Set the long name of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_callback(struct doca_argp_param *param, doca_argp_param_cb_t callback)
Set the callback function of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_mandatory(struct doca_argp_param *param)
Mark the program param as mandatory.
DOCA_EXPERIMENTAL doca_error_t doca_argp_param_create(struct doca_argp_param **param)
Create new program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_type(struct doca_argp_param *param, enum doca_argp_type type)
Set the type of the param arguments.
DOCA_EXPERIMENTAL void doca_argp_param_set_short_name(struct doca_argp_param *param, const char *name)
Set the short name of the program param.
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_param(struct doca_argp_param *input_param)
Register a program flag.
DOCA_STABLE doca_error_t doca_ctx_set_state_changed_cb(struct doca_ctx *ctx, doca_ctx_state_changed_callback_t cb)
Set state changed callback.
DOCA_STABLE doca_error_t doca_ctx_set_user_data(struct doca_ctx *ctx, union doca_data user_data)
set user data to context
DOCA_STABLE doca_error_t doca_ctx_stop(struct doca_ctx *ctx)
Stops the context allowing reconfiguration.
doca_ctx_states
This enum defines the states of a context.
@ DOCA_CTX_STATE_STARTING
@ DOCA_CTX_STATE_STOPPING
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
DOCA_STABLE struct doca_devinfo * doca_dev_as_devinfo(const struct doca_dev *dev)
Get local device info from device. This should be useful when wanting to query information about devi...
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_INVALID_VALUE
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
DOCA_STABLE doca_error_t doca_task_get_status(const struct doca_task *task)
Get task status.
DOCA_STABLE doca_error_t doca_pe_connect_ctx(struct doca_pe *pe, struct doca_ctx *ctx)
This method connects a context to a progress engine.
DOCA_STABLE doca_error_t doca_task_submit(struct doca_task *task)
Submit a task to a progress engine.
DOCA_STABLE uint8_t doca_pe_progress(struct doca_pe *pe)
Run the progress engine.
DOCA_STABLE void doca_task_free(struct doca_task *task)
Free a task back to where it was allocated from.
char pci_address[DOCA_DEVINFO_PCI_ADDR_SIZE]
uint8_t iv[MAX_AES_GCM_IV_LENGTH]
uint8_t raw_key[MAX_AES_GCM_KEY_SIZE]
char file_path[MAX_FILE_NAME]
enum doca_aes_gcm_key_type raw_key_type
char output_path[MAX_FILE_NAME]
size_t num_remaining_tasks
Convenience type for representing opaque data.
struct upf_accel_ctx * ctx