1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 2 /* 3 * Copyright (C) 2020 Pengutronix, Ahmad Fatou 4 */ 5 6 #ifndef __CAAM_BLOB_GEN 7 #define __CAAM_BLOB_GEN 8 9 #include <linux/types.h> 10 #include <linux/errno.h> 11 12 #define CAAM_BLOB_KEYMOD_LENGTH 16 13 #define CAAM_BLOB_OVERHEAD (32 + 14 #define CAAM_BLOB_MAX_LEN 4096 15 16 struct caam_blob_priv; 17 18 /** 19 * struct caam_blob_info - information for CAA 20 * @input: pointer to input buffer (must 21 * @input_len: length of @input buffer in by 22 * @output: pointer to output buffer (mus 23 * @output_len: length of @output buffer in b 24 * @key_mod: key modifier 25 * @key_mod_len: length of @key_mod in bytes. 26 * May not exceed %CAAM_BLOB_KEY 27 */ 28 struct caam_blob_info { 29 void *input; 30 size_t input_len; 31 32 void *output; 33 size_t output_len; 34 35 const void *key_mod; 36 size_t key_mod_len; 37 }; 38 39 /** 40 * caam_blob_gen_init - initialize blob genera 41 * Return: pointer to new &struct caam_blob_pr 42 * and ``ERR_PTR(-ENODEV)`` if CAAM has no har 43 * or no job ring could be allocated. 44 */ 45 struct caam_blob_priv *caam_blob_gen_init(void 46 47 /** 48 * caam_blob_gen_exit - free blob generation r 49 * @priv: instance returned by caam_blob_gen_i 50 */ 51 void caam_blob_gen_exit(struct caam_blob_priv 52 53 /** 54 * caam_process_blob - encapsulate or decapsul 55 * @priv: instance returned by caam_blob_gen 56 * @info: pointer to blobbing info describin 57 * key modifier buffers. 58 * @encap: true for encapsulation, false for 59 * 60 * Return: %0 and sets ``info->output_len`` on 61 * error code otherwise. 62 */ 63 int caam_process_blob(struct caam_blob_priv *p 64 struct caam_blob_info *i 65 66 /** 67 * caam_encap_blob - encapsulate blob 68 * @priv: instance returned by caam_blob_gen 69 * @info: pointer to blobbing info describin 70 * output blob and key modifier buffe 71 * 72 * Return: %0 and sets ``info->output_len`` on 73 * a negative error code otherwise. 74 */ 75 static inline int caam_encap_blob(struct caam_ 76 struct caam_ 77 { 78 if (info->output_len < info->input_len 79 return -EINVAL; 80 81 return caam_process_blob(priv, info, t 82 } 83 84 /** 85 * caam_decap_blob - decapsulate blob 86 * @priv: instance returned by caam_blob_gen 87 * @info: pointer to blobbing info describin 88 * input blob and key modifier buffer 89 * 90 * Return: %0 and sets ``info->output_len`` on 91 * a negative error code otherwise. 92 */ 93 static inline int caam_decap_blob(struct caam_ 94 struct caam_ 95 { 96 if (info->input_len < CAAM_BLOB_OVERHE 97 info->output_len < info->input_len 98 return -EINVAL; 99 100 return caam_process_blob(priv, info, f 101 } 102 103 #endif 104
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.