/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright (C) 2020 Pengutronix, Ahmad Fatoum <[email protected]>3*/45#ifndef __CAAM_BLOB_GEN6#define __CAAM_BLOB_GEN78#include <linux/types.h>9#include <linux/errno.h>1011#define CAAM_BLOB_KEYMOD_LENGTH 1612#define CAAM_BLOB_OVERHEAD (32 + 16)13#define CAAM_BLOB_MAX_LEN 40961415struct caam_blob_priv;1617/**18* struct caam_blob_info - information for CAAM blobbing19* @input: pointer to input buffer (must be DMAable)20* @input_len: length of @input buffer in bytes.21* @output: pointer to output buffer (must be DMAable)22* @output_len: length of @output buffer in bytes.23* @key_mod: key modifier24* @key_mod_len: length of @key_mod in bytes.25* May not exceed %CAAM_BLOB_KEYMOD_LENGTH26*/27struct caam_blob_info {28void *input;29size_t input_len;3031void *output;32size_t output_len;3334const void *key_mod;35size_t key_mod_len;36};3738/**39* caam_blob_gen_init - initialize blob generation40* Return: pointer to new &struct caam_blob_priv instance on success41* and ``ERR_PTR(-ENODEV)`` if CAAM has no hardware blobbing support42* or no job ring could be allocated.43*/44struct caam_blob_priv *caam_blob_gen_init(void);4546/**47* caam_blob_gen_exit - free blob generation resources48* @priv: instance returned by caam_blob_gen_init()49*/50void caam_blob_gen_exit(struct caam_blob_priv *priv);5152/**53* caam_process_blob - encapsulate or decapsulate blob54* @priv: instance returned by caam_blob_gen_init()55* @info: pointer to blobbing info describing key, blob and56* key modifier buffers.57* @encap: true for encapsulation, false for decapsulation58*59* Return: %0 and sets ``info->output_len`` on success and a negative60* error code otherwise.61*/62int caam_process_blob(struct caam_blob_priv *priv,63struct caam_blob_info *info, bool encap);6465/**66* caam_encap_blob - encapsulate blob67* @priv: instance returned by caam_blob_gen_init()68* @info: pointer to blobbing info describing input key,69* output blob and key modifier buffers.70*71* Return: %0 and sets ``info->output_len`` on success and72* a negative error code otherwise.73*/74static inline int caam_encap_blob(struct caam_blob_priv *priv,75struct caam_blob_info *info)76{77if (info->output_len < info->input_len + CAAM_BLOB_OVERHEAD)78return -EINVAL;7980return caam_process_blob(priv, info, true);81}8283/**84* caam_decap_blob - decapsulate blob85* @priv: instance returned by caam_blob_gen_init()86* @info: pointer to blobbing info describing output key,87* input blob and key modifier buffers.88*89* Return: %0 and sets ``info->output_len`` on success and90* a negative error code otherwise.91*/92static inline int caam_decap_blob(struct caam_blob_priv *priv,93struct caam_blob_info *info)94{95if (info->input_len < CAAM_BLOB_OVERHEAD ||96info->output_len < info->input_len - CAAM_BLOB_OVERHEAD)97return -EINVAL;9899return caam_process_blob(priv, info, false);100}101102#endif103104105