![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-only */ 0002 /* 0003 * Copyright (C) 2020 Pengutronix, Ahmad Fatoum <kernel@pengutronix.de> 0004 */ 0005 0006 #ifndef __CAAM_BLOB_GEN 0007 #define __CAAM_BLOB_GEN 0008 0009 #include <linux/types.h> 0010 #include <linux/errno.h> 0011 0012 #define CAAM_BLOB_KEYMOD_LENGTH 16 0013 #define CAAM_BLOB_OVERHEAD (32 + 16) 0014 #define CAAM_BLOB_MAX_LEN 4096 0015 0016 struct caam_blob_priv; 0017 0018 /** 0019 * struct caam_blob_info - information for CAAM blobbing 0020 * @input: pointer to input buffer (must be DMAable) 0021 * @input_len: length of @input buffer in bytes. 0022 * @output: pointer to output buffer (must be DMAable) 0023 * @output_len: length of @output buffer in bytes. 0024 * @key_mod: key modifier 0025 * @key_mod_len: length of @key_mod in bytes. 0026 * May not exceed %CAAM_BLOB_KEYMOD_LENGTH 0027 */ 0028 struct caam_blob_info { 0029 void *input; 0030 size_t input_len; 0031 0032 void *output; 0033 size_t output_len; 0034 0035 const void *key_mod; 0036 size_t key_mod_len; 0037 }; 0038 0039 /** 0040 * caam_blob_gen_init - initialize blob generation 0041 * Return: pointer to new &struct caam_blob_priv instance on success 0042 * and ``ERR_PTR(-ENODEV)`` if CAAM has no hardware blobbing support 0043 * or no job ring could be allocated. 0044 */ 0045 struct caam_blob_priv *caam_blob_gen_init(void); 0046 0047 /** 0048 * caam_blob_gen_exit - free blob generation resources 0049 * @priv: instance returned by caam_blob_gen_init() 0050 */ 0051 void caam_blob_gen_exit(struct caam_blob_priv *priv); 0052 0053 /** 0054 * caam_process_blob - encapsulate or decapsulate blob 0055 * @priv: instance returned by caam_blob_gen_init() 0056 * @info: pointer to blobbing info describing key, blob and 0057 * key modifier buffers. 0058 * @encap: true for encapsulation, false for decapsulation 0059 * 0060 * Return: %0 and sets ``info->output_len`` on success and a negative 0061 * error code otherwise. 0062 */ 0063 int caam_process_blob(struct caam_blob_priv *priv, 0064 struct caam_blob_info *info, bool encap); 0065 0066 /** 0067 * caam_encap_blob - encapsulate blob 0068 * @priv: instance returned by caam_blob_gen_init() 0069 * @info: pointer to blobbing info describing input key, 0070 * output blob and key modifier buffers. 0071 * 0072 * Return: %0 and sets ``info->output_len`` on success and 0073 * a negative error code otherwise. 0074 */ 0075 static inline int caam_encap_blob(struct caam_blob_priv *priv, 0076 struct caam_blob_info *info) 0077 { 0078 if (info->output_len < info->input_len + CAAM_BLOB_OVERHEAD) 0079 return -EINVAL; 0080 0081 return caam_process_blob(priv, info, true); 0082 } 0083 0084 /** 0085 * caam_decap_blob - decapsulate blob 0086 * @priv: instance returned by caam_blob_gen_init() 0087 * @info: pointer to blobbing info describing output key, 0088 * input blob and key modifier buffers. 0089 * 0090 * Return: %0 and sets ``info->output_len`` on success and 0091 * a negative error code otherwise. 0092 */ 0093 static inline int caam_decap_blob(struct caam_blob_priv *priv, 0094 struct caam_blob_info *info) 0095 { 0096 if (info->input_len < CAAM_BLOB_OVERHEAD || 0097 info->output_len < info->input_len - CAAM_BLOB_OVERHEAD) 0098 return -EINVAL; 0099 0100 return caam_process_blob(priv, info, false); 0101 } 0102 0103 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |