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 three 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 * 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 n 33 * q the second prime factor of the RSA modulus n 34 * dP the first factors's CRT exponent 35 * dQ the second factors's CRT exponent 36 * qInv the (first) CRT coefficient 37 * 38 * The benefit of using the third or the second key form is lower computational 39 * cost for the decryption and signature operations. 40 */ 41 enum caam_priv_key_form { 42 FORM1, 43 FORM2, 44 FORM3 45 }; 46 47 /** 48 * caam_rsa_key - CAAM RSA key structure. Keys are allocated in DMA zone. 49 * @n : RSA modulus raw byte stream 50 * @e : RSA public exponent raw byte stream 51 * @d : RSA private exponent raw byte stream 52 * @p : RSA prime factor p of RSA modulus n 53 * @q : RSA prime factor q of RSA modulus n 54 * @dp : RSA CRT exponent of p 55 * @dp : RSA CRT exponent of q 56 * @qinv : RSA CRT coefficient 57 * @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 n 62 * @e_sz : length in bytes of RSA public exponent 63 * @d_sz : length in bytes of RSA private exponent 64 * @p_sz : length in bytes of RSA prime factor p of RSA modulus n 65 * @q_sz : length in bytes of RSA prime factor q of RSA modulus n 66 * @priv_form : CAAM RSA private key representation 67 */ 68 struct caam_rsa_key { 69 u8 *n; 70 u8 *e; 71 u8 *d; 72 u8 *p; 73 u8 *q; 74 u8 *dp; 75 u8 *dq; 76 u8 *qinv; 77 u8 *tmp1; 78 u8 *tmp2; 79 size_t n_sz; 80 size_t e_sz; 81 size_t d_sz; 82 size_t p_sz; 83 size_t q_sz; 84 enum caam_priv_key_form priv_form; 85 }; 86 87 /** 88 * caam_rsa_ctx - per session context. 89 * @key : RSA key in DMA zone 90 * @dev : device structure 91 */ 92 struct caam_rsa_ctx { 93 struct caam_rsa_key key; 94 struct device *dev; 95 }; 96 97 /** 98 * rsa_edesc - s/w-extended rsa descriptor 99 * @src_nents : number of segments in input scatterlist 100 * @dst_nents : number of segments in output scatterlist 101 * @sec4_sg_bytes : length of h/w link table 102 * @sec4_sg_dma : dma address of h/w link table 103 * @sec4_sg : pointer to h/w link table 104 * @pdb : specific RSA Protocol Data Block (PDB) 105 * @hw_desc : descriptor followed by link tables if any 106 */ 107 struct rsa_edesc { 108 int src_nents; 109 int dst_nents; 110 int sec4_sg_bytes; 111 dma_addr_t sec4_sg_dma; 112 struct sec4_sg_entry *sec4_sg; 113 union { 114 struct rsa_pub_pdb pub; 115 struct rsa_priv_f1_pdb priv_f1; 116 struct rsa_priv_f2_pdb priv_f2; 117 struct rsa_priv_f3_pdb priv_f3; 118 } pdb; 119 u32 hw_desc[]; 120 }; 121 122 /* Descriptor construction primitives. */ 123 void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb); 124 void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb); 125 void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb); 126 void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb); 127 128 #endif 129