/* SPDX-License-Identifier: GPL-2.0 */1/*2* caam - Freescale FSL CAAM support for Public Key Cryptography descriptors3*4* Copyright 2016 Freescale Semiconductor, Inc.5*6* There is no Shared Descriptor for PKC so that the Job Descriptor must carry7* all the desired key parameters, input and output pointers.8*/910#ifndef _PKC_DESC_H_11#define _PKC_DESC_H_12#include "compat.h"13#include "pdb.h"1415/**16* caam_priv_key_form - CAAM RSA private key representation17* CAAM RSA private key may have either of three forms.18*19* 1. The first representation consists of the pair (n, d), where the20* components have the following meanings:21* n the RSA modulus22* d the RSA private exponent23*24* 2. The second representation consists of the triplet (p, q, d), where the25* components have the following meanings:26* p the first prime factor of the RSA modulus n27* q the second prime factor of the RSA modulus n28* d the RSA private exponent29*30* 3. The third representation consists of the quintuple (p, q, dP, dQ, qInv),31* where the components have the following meanings:32* p the first prime factor of the RSA modulus n33* q the second prime factor of the RSA modulus n34* dP the first factors's CRT exponent35* dQ the second factors's CRT exponent36* qInv the (first) CRT coefficient37*38* The benefit of using the third or the second key form is lower computational39* cost for the decryption and signature operations.40*/41enum caam_priv_key_form {42FORM1,43FORM2,44FORM345};4647/**48* caam_rsa_key - CAAM RSA key structure. Keys are allocated in DMA zone.49* @n : RSA modulus raw byte stream50* @e : RSA public exponent raw byte stream51* @d : RSA private exponent raw byte stream52* @p : RSA prime factor p of RSA modulus n53* @q : RSA prime factor q of RSA modulus n54* @dp : RSA CRT exponent of p55* @dp : RSA CRT exponent of q56* @qinv : RSA CRT coefficient57* @tmp1 : CAAM uses this temporary buffer as internal state buffer.58* It is assumed to be as long as p.59* @tmp2 : CAAM uses this temporary buffer as internal state buffer.60* It is assumed to be as long as q.61* @n_sz : length in bytes of RSA modulus n62* @e_sz : length in bytes of RSA public exponent63* @d_sz : length in bytes of RSA private exponent64* @p_sz : length in bytes of RSA prime factor p of RSA modulus n65* @q_sz : length in bytes of RSA prime factor q of RSA modulus n66* @priv_form : CAAM RSA private key representation67*/68struct caam_rsa_key {69u8 *n;70u8 *e;71u8 *d;72u8 *p;73u8 *q;74u8 *dp;75u8 *dq;76u8 *qinv;77u8 *tmp1;78u8 *tmp2;79size_t n_sz;80size_t e_sz;81size_t d_sz;82size_t p_sz;83size_t q_sz;84enum caam_priv_key_form priv_form;85};8687/**88* caam_rsa_ctx - per session context.89* @key : RSA key in DMA zone90* @dev : device structure91* @padding_dma : dma address of padding, for adding it to the input92*/93struct caam_rsa_ctx {94struct caam_rsa_key key;95struct device *dev;96dma_addr_t padding_dma;9798};99100/**101* caam_rsa_req_ctx - per request context.102* @src : input scatterlist (stripped of leading zeros)103* @fixup_src : input scatterlist (that might be stripped of leading zeros)104* @fixup_src_len : length of the fixup_src input scatterlist105* @edesc : s/w-extended rsa descriptor106* @akcipher_op_done : callback used when operation is done107*/108struct caam_rsa_req_ctx {109struct scatterlist src[2];110struct scatterlist *fixup_src;111unsigned int fixup_src_len;112struct rsa_edesc *edesc;113void (*akcipher_op_done)(struct device *jrdev, u32 *desc, u32 err,114void *context);115};116117/**118* rsa_edesc - s/w-extended rsa descriptor119* @src_nents : number of segments in input s/w scatterlist120* @dst_nents : number of segments in output s/w scatterlist121* @mapped_src_nents: number of segments in input h/w link table122* @mapped_dst_nents: number of segments in output h/w link table123* @sec4_sg_bytes : length of h/w link table124* @bklog : stored to determine if the request needs backlog125* @sec4_sg_dma : dma address of h/w link table126* @sec4_sg : pointer to h/w link table127* @pdb : specific RSA Protocol Data Block (PDB)128* @hw_desc : descriptor followed by link tables if any129*/130struct rsa_edesc {131int src_nents;132int dst_nents;133int mapped_src_nents;134int mapped_dst_nents;135int sec4_sg_bytes;136bool bklog;137dma_addr_t sec4_sg_dma;138struct sec4_sg_entry *sec4_sg;139union {140struct rsa_pub_pdb pub;141struct rsa_priv_f1_pdb priv_f1;142struct rsa_priv_f2_pdb priv_f2;143struct rsa_priv_f3_pdb priv_f3;144} pdb;145u32 hw_desc[];146};147148/* Descriptor construction primitives. */149void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb);150void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb);151void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb);152void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb);153154#endif155156157