xref: /linux/drivers/crypto/caam/pkc_desc.c (revision 976e3645923bdd2fe7893aae33fd7a21098bfb28)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
28c419778STudor Ambarus /*
38c419778STudor Ambarus  * caam - Freescale FSL CAAM support for Public Key Cryptography descriptors
48c419778STudor Ambarus  *
58c419778STudor Ambarus  * Copyright 2016 Freescale Semiconductor, Inc.
68c419778STudor Ambarus  *
78c419778STudor Ambarus  * There is no Shared Descriptor for PKC so that the Job Descriptor must carry
88c419778STudor Ambarus  * all the desired key parameters, input and output pointers.
98c419778STudor Ambarus  */
108c419778STudor Ambarus #include "caampkc.h"
118c419778STudor Ambarus #include "desc_constr.h"
128c419778STudor Ambarus 
138c419778STudor Ambarus /* Descriptor for RSA Public operation */
init_rsa_pub_desc(u32 * desc,struct rsa_pub_pdb * pdb)148c419778STudor Ambarus void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb)
158c419778STudor Ambarus {
16*a1cf573eSAndrey Smirnov 	init_job_desc_pdb(desc, 0, SIZEOF_RSA_PUB_PDB);
178c419778STudor Ambarus 	append_cmd(desc, pdb->sgf);
188c419778STudor Ambarus 	append_ptr(desc, pdb->f_dma);
198c419778STudor Ambarus 	append_ptr(desc, pdb->g_dma);
208c419778STudor Ambarus 	append_ptr(desc, pdb->n_dma);
218c419778STudor Ambarus 	append_ptr(desc, pdb->e_dma);
228c419778STudor Ambarus 	append_cmd(desc, pdb->f_len);
238c419778STudor Ambarus 	append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSAENC_PUBKEY);
248c419778STudor Ambarus }
258c419778STudor Ambarus 
268c419778STudor Ambarus /* Descriptor for RSA Private operation - Private Key Form #1 */
init_rsa_priv_f1_desc(u32 * desc,struct rsa_priv_f1_pdb * pdb)278c419778STudor Ambarus void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb)
288c419778STudor Ambarus {
29*a1cf573eSAndrey Smirnov 	init_job_desc_pdb(desc, 0, SIZEOF_RSA_PRIV_F1_PDB);
308c419778STudor Ambarus 	append_cmd(desc, pdb->sgf);
318c419778STudor Ambarus 	append_ptr(desc, pdb->g_dma);
328c419778STudor Ambarus 	append_ptr(desc, pdb->f_dma);
338c419778STudor Ambarus 	append_ptr(desc, pdb->n_dma);
348c419778STudor Ambarus 	append_ptr(desc, pdb->d_dma);
358c419778STudor Ambarus 	append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
368c419778STudor Ambarus 			 RSA_PRIV_KEY_FRM_1);
378c419778STudor Ambarus }
3852e26d77SRadu Alexe 
3952e26d77SRadu Alexe /* Descriptor for RSA Private operation - Private Key Form #2 */
init_rsa_priv_f2_desc(u32 * desc,struct rsa_priv_f2_pdb * pdb)4052e26d77SRadu Alexe void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb)
4152e26d77SRadu Alexe {
42*a1cf573eSAndrey Smirnov 	init_job_desc_pdb(desc, 0, SIZEOF_RSA_PRIV_F2_PDB);
4352e26d77SRadu Alexe 	append_cmd(desc, pdb->sgf);
4452e26d77SRadu Alexe 	append_ptr(desc, pdb->g_dma);
4552e26d77SRadu Alexe 	append_ptr(desc, pdb->f_dma);
4652e26d77SRadu Alexe 	append_ptr(desc, pdb->d_dma);
4752e26d77SRadu Alexe 	append_ptr(desc, pdb->p_dma);
4852e26d77SRadu Alexe 	append_ptr(desc, pdb->q_dma);
4952e26d77SRadu Alexe 	append_ptr(desc, pdb->tmp1_dma);
5052e26d77SRadu Alexe 	append_ptr(desc, pdb->tmp2_dma);
5152e26d77SRadu Alexe 	append_cmd(desc, pdb->p_q_len);
5252e26d77SRadu Alexe 	append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
5352e26d77SRadu Alexe 			 RSA_PRIV_KEY_FRM_2);
5452e26d77SRadu Alexe }
554a651b12SRadu Alexe 
564a651b12SRadu Alexe /* Descriptor for RSA Private operation - Private Key Form #3 */
init_rsa_priv_f3_desc(u32 * desc,struct rsa_priv_f3_pdb * pdb)574a651b12SRadu Alexe void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb)
584a651b12SRadu Alexe {
59*a1cf573eSAndrey Smirnov 	init_job_desc_pdb(desc, 0, SIZEOF_RSA_PRIV_F3_PDB);
604a651b12SRadu Alexe 	append_cmd(desc, pdb->sgf);
614a651b12SRadu Alexe 	append_ptr(desc, pdb->g_dma);
624a651b12SRadu Alexe 	append_ptr(desc, pdb->f_dma);
634a651b12SRadu Alexe 	append_ptr(desc, pdb->c_dma);
644a651b12SRadu Alexe 	append_ptr(desc, pdb->p_dma);
654a651b12SRadu Alexe 	append_ptr(desc, pdb->q_dma);
664a651b12SRadu Alexe 	append_ptr(desc, pdb->dp_dma);
674a651b12SRadu Alexe 	append_ptr(desc, pdb->dq_dma);
684a651b12SRadu Alexe 	append_ptr(desc, pdb->tmp1_dma);
694a651b12SRadu Alexe 	append_ptr(desc, pdb->tmp2_dma);
704a651b12SRadu Alexe 	append_cmd(desc, pdb->p_q_len);
714a651b12SRadu Alexe 	append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
724a651b12SRadu Alexe 			 RSA_PRIV_KEY_FRM_3);
734a651b12SRadu Alexe }
74