1 /* 2 * caam - Freescale FSL CAAM support for Public Key Cryptography descriptors 3 * 4 * Copyright 2016 Freescale Semiconductor, Inc. 5 * 6 * There is no Shared Descriptor for PKC so that the Job Descriptor must carry 7 * all the desired key parameters, input and output pointers. 8 */ 9 10 #ifndef _PKC_DESC_H_ 11 #define _PKC_DESC_H_ 12 #include "compat.h" 13 #include "pdb.h" 14 15 /** 16 * caam_priv_key_form - CAAM RSA private key representation 17 * CAAM RSA private key may have either of two forms. 18 * 19 * 1. The first representation consists of the pair (n, d), where the 20 * components have the following meanings: 21 * n the RSA modulus 22 * d the RSA private exponent 23 * 24 * 2. The second representation consists of the triplet (p, q, d), where the 25 * components have the following meanings: 26 * p the first prime factor of the RSA modulus n 27 * q the second prime factor of the RSA modulus n 28 * d the RSA private exponent 29 */ 30 enum caam_priv_key_form { 31 FORM1, 32 FORM2, 33 }; 34 35 /** 36 * caam_rsa_key - CAAM RSA key structure. Keys are allocated in DMA zone. 37 * @n : RSA modulus raw byte stream 38 * @e : RSA public exponent raw byte stream 39 * @d : RSA private exponent raw byte stream 40 * @p : RSA prime factor p of RSA modulus n 41 * @q : RSA prime factor q of RSA modulus n 42 * @tmp1 : CAAM uses this temporary buffer as internal state buffer. 43 * It is assumed to be as long as p. 44 * @tmp2 : CAAM uses this temporary buffer as internal state buffer. 45 * It is assumed to be as long as q. 46 * @n_sz : length in bytes of RSA modulus n 47 * @e_sz : length in bytes of RSA public exponent 48 * @d_sz : length in bytes of RSA private exponent 49 * @p_sz : length in bytes of RSA prime factor p of RSA modulus n 50 * @q_sz : length in bytes of RSA prime factor q of RSA modulus n 51 * @priv_form : CAAM RSA private key representation 52 */ 53 struct caam_rsa_key { 54 u8 *n; 55 u8 *e; 56 u8 *d; 57 u8 *p; 58 u8 *q; 59 u8 *tmp1; 60 u8 *tmp2; 61 size_t n_sz; 62 size_t e_sz; 63 size_t d_sz; 64 size_t p_sz; 65 size_t q_sz; 66 enum caam_priv_key_form priv_form; 67 }; 68 69 /** 70 * caam_rsa_ctx - per session context. 71 * @key : RSA key in DMA zone 72 * @dev : device structure 73 */ 74 struct caam_rsa_ctx { 75 struct caam_rsa_key key; 76 struct device *dev; 77 }; 78 79 /** 80 * rsa_edesc - s/w-extended rsa descriptor 81 * @src_nents : number of segments in input scatterlist 82 * @dst_nents : number of segments in output scatterlist 83 * @sec4_sg_bytes : length of h/w link table 84 * @sec4_sg_dma : dma address of h/w link table 85 * @sec4_sg : pointer to h/w link table 86 * @pdb : specific RSA Protocol Data Block (PDB) 87 * @hw_desc : descriptor followed by link tables if any 88 */ 89 struct rsa_edesc { 90 int src_nents; 91 int dst_nents; 92 int sec4_sg_bytes; 93 dma_addr_t sec4_sg_dma; 94 struct sec4_sg_entry *sec4_sg; 95 union { 96 struct rsa_pub_pdb pub; 97 struct rsa_priv_f1_pdb priv_f1; 98 struct rsa_priv_f2_pdb priv_f2; 99 } pdb; 100 u32 hw_desc[]; 101 }; 102 103 /* Descriptor construction primitives. */ 104 void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb); 105 void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb); 106 void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb); 107 108 #endif 109