2016-07-04 17:12:08 +07:00
|
|
|
/*
|
|
|
|
* caam - Freescale FSL CAAM support for Public Key Cryptography descriptors
|
|
|
|
*
|
|
|
|
* Copyright 2016 Freescale Semiconductor, Inc.
|
|
|
|
*
|
|
|
|
* There is no Shared Descriptor for PKC so that the Job Descriptor must carry
|
|
|
|
* all the desired key parameters, input and output pointers.
|
|
|
|
*/
|
|
|
|
#include "caampkc.h"
|
|
|
|
#include "desc_constr.h"
|
|
|
|
|
|
|
|
/* Descriptor for RSA Public operation */
|
|
|
|
void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb)
|
|
|
|
{
|
|
|
|
init_job_desc_pdb(desc, 0, sizeof(*pdb));
|
|
|
|
append_cmd(desc, pdb->sgf);
|
|
|
|
append_ptr(desc, pdb->f_dma);
|
|
|
|
append_ptr(desc, pdb->g_dma);
|
|
|
|
append_ptr(desc, pdb->n_dma);
|
|
|
|
append_ptr(desc, pdb->e_dma);
|
|
|
|
append_cmd(desc, pdb->f_len);
|
|
|
|
append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSAENC_PUBKEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Descriptor for RSA Private operation - Private Key Form #1 */
|
|
|
|
void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb)
|
|
|
|
{
|
|
|
|
init_job_desc_pdb(desc, 0, sizeof(*pdb));
|
|
|
|
append_cmd(desc, pdb->sgf);
|
|
|
|
append_ptr(desc, pdb->g_dma);
|
|
|
|
append_ptr(desc, pdb->f_dma);
|
|
|
|
append_ptr(desc, pdb->n_dma);
|
|
|
|
append_ptr(desc, pdb->d_dma);
|
|
|
|
append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
|
|
|
|
RSA_PRIV_KEY_FRM_1);
|
|
|
|
}
|
crypto: caam - add support for RSA key form 2
CAAM RSA private key may have either of three representations.
1. The first representation consists of the pair (n, d), where the
components have the following meanings:
n the RSA modulus
d the RSA private exponent
2. The second representation consists of the triplet (p, q, d), where
the
components have the following meanings:
p the first prime factor of the RSA modulus n
q the second prime factor of the RSA modulus n
d the RSA private exponent
3. The third representation consists of the quintuple (p, q, dP, dQ,
qInv),
where the components have the following meanings:
p the first prime factor of the RSA modulus n
q the second prime factor of the RSA modulus n
dP the first factors's CRT exponent
dQ the second factors's CRT exponent
qInv the (first) CRT coefficient
The benefit of using the third or the second key form is lower
computational cost for the decryption and signature operations.
This patch adds support for the second RSA private key
representation.
Signed-off-by: Tudor Ambarus <tudor-dan.ambarus@nxp.com>
Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-04-25 20:26:38 +07:00
|
|
|
|
|
|
|
/* Descriptor for RSA Private operation - Private Key Form #2 */
|
|
|
|
void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb)
|
|
|
|
{
|
|
|
|
init_job_desc_pdb(desc, 0, sizeof(*pdb));
|
|
|
|
append_cmd(desc, pdb->sgf);
|
|
|
|
append_ptr(desc, pdb->g_dma);
|
|
|
|
append_ptr(desc, pdb->f_dma);
|
|
|
|
append_ptr(desc, pdb->d_dma);
|
|
|
|
append_ptr(desc, pdb->p_dma);
|
|
|
|
append_ptr(desc, pdb->q_dma);
|
|
|
|
append_ptr(desc, pdb->tmp1_dma);
|
|
|
|
append_ptr(desc, pdb->tmp2_dma);
|
|
|
|
append_cmd(desc, pdb->p_q_len);
|
|
|
|
append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
|
|
|
|
RSA_PRIV_KEY_FRM_2);
|
|
|
|
}
|
crypto: caam - add support for RSA key form 3
CAAM RSA private key may have either of three representations.
1. The first representation consists of the pair (n, d), where the
components have the following meanings:
n the RSA modulus
d the RSA private exponent
2. The second representation consists of the triplet (p, q, d), where
the
components have the following meanings:
p the first prime factor of the RSA modulus n
q the second prime factor of the RSA modulus n
d the RSA private exponent
3. The third representation consists of the quintuple (p, q, dP, dQ,
qInv),
where the components have the following meanings:
p the first prime factor of the RSA modulus n
q the second prime factor of the RSA modulus n
dP the first factors's CRT exponent
dQ the second factors's CRT exponent
qInv the (first) CRT coefficient
The benefit of using the third or the second key form is lower
computational cost for the decryption and signature operations.
This patch adds support for the third RSA private key
representations and extends caampkc to use the fastest key when all
related components are present in the private key.
Signed-off-by: Tudor Ambarus <tudor-dan.ambarus@nxp.com>
Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-04-25 20:26:39 +07:00
|
|
|
|
|
|
|
/* Descriptor for RSA Private operation - Private Key Form #3 */
|
|
|
|
void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb)
|
|
|
|
{
|
|
|
|
init_job_desc_pdb(desc, 0, sizeof(*pdb));
|
|
|
|
append_cmd(desc, pdb->sgf);
|
|
|
|
append_ptr(desc, pdb->g_dma);
|
|
|
|
append_ptr(desc, pdb->f_dma);
|
|
|
|
append_ptr(desc, pdb->c_dma);
|
|
|
|
append_ptr(desc, pdb->p_dma);
|
|
|
|
append_ptr(desc, pdb->q_dma);
|
|
|
|
append_ptr(desc, pdb->dp_dma);
|
|
|
|
append_ptr(desc, pdb->dq_dma);
|
|
|
|
append_ptr(desc, pdb->tmp1_dma);
|
|
|
|
append_ptr(desc, pdb->tmp2_dma);
|
|
|
|
append_cmd(desc, pdb->p_q_len);
|
|
|
|
append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
|
|
|
|
RSA_PRIV_KEY_FRM_3);
|
|
|
|
}
|