diff options
author | Yashpal Dutta <yashpal.dutta@freescale.com> | 2014-03-22 22:59:34 (GMT) |
---|---|---|
committer | Jose Rivera <German.Rivera@freescale.com> | 2014-03-24 16:09:35 (GMT) |
commit | fc281aa59e4c6f2e1574d4a6812438a6e06be0a9 (patch) | |
tree | fa46b059eae0492f4a78bf3d65bc04560f9397c2 /drivers/crypto/caam/pkc_desc.c | |
parent | 67659d841becfc172216df76f058db25588f87cf (diff) | |
download | linux-fsl-qoriq-fc281aa59e4c6f2e1574d4a6812438a6e06be0a9.tar.xz |
added support for PKC keygen
As a part of PKC support, RSA, DSA DH, ECDH, ECDSA requires key
generation. The patch adds support for key generation support
for DSA, ECDSA, DH, ECDH.
The patch adds DH operation support too
Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com>
Change-Id: I0dc9c144a23e2248bf8974a1615363341dc4886e
Reviewed-on: http://git.am.freescale.net:8181/5867
Tested-by: Review Code-CDREVIEW <CDREVIEW@freescale.com>
Reviewed-by: Geanta Neag Horia Ioan-B05471 <horia.geanta@freescale.com>
Reviewed-by: Rivera Jose-B46482 <German.Rivera@freescale.com>
Reviewed-on: http://git.am.freescale.net:8181/9551
Reviewed-by: Ruchika Gupta <ruchika.gupta@freescale.com>
Reviewed-by: Jose Rivera <German.Rivera@freescale.com>
Diffstat (limited to 'drivers/crypto/caam/pkc_desc.c')
-rw-r--r-- | drivers/crypto/caam/pkc_desc.c | 132 |
1 files changed, 131 insertions, 1 deletions
diff --git a/drivers/crypto/caam/pkc_desc.c b/drivers/crypto/caam/pkc_desc.c index a607dd4..5bcf5d3 100644 --- a/drivers/crypto/caam/pkc_desc.c +++ b/drivers/crypto/caam/pkc_desc.c @@ -142,11 +142,56 @@ void *caam_rsa_priv_f3_desc(struct rsa_edesc *edesc) return rsa_priv_desc; } +/* DH sign CAAM descriptor */ +void *caam_dh_key_desc(struct dh_edesc_s *edesc) +{ + u32 start_idx, desc_size; + void *desc; +#ifdef CAAM_DEBUG + uint32_t i; + uint32_t *buf; +#endif + struct dh_key_desc_s *dh_desc = + (struct dh_key_desc_s *)edesc->hw_desc; + desc_size = sizeof(struct dh_key_desc_s) / sizeof(u32); + start_idx = desc_size - 1; + start_idx &= HDR_START_IDX_MASK; + init_job_desc(edesc->hw_desc, (start_idx << HDR_START_IDX_SHIFT) | + (start_idx & HDR_DESCLEN_MASK) | HDR_ONE); + dh_desc->sgf_ln = (edesc->l_len << DH_PDB_L_SHIFT) | + ((edesc->n_len & DH_PDB_N_MASK)); + dh_desc->q_dma = edesc->q_dma; + dh_desc->w_dma = edesc->w_dma; + dh_desc->s_dma = edesc->s_dma; + dh_desc->z_dma = edesc->z_dma; + dh_desc->op = CMD_OPERATION | OP_TYPE_UNI_PROTOCOL | + OP_PCLID_DH; + if (edesc->req_type == ECDH_COMPUTE_KEY) { + dh_desc->ab_dma = edesc->ab_dma; + dh_desc->op |= OP_PCL_PKPROT_ECC; + if (edesc->curve_type == ECC_BINARY) + dh_desc->op |= OP_PCL_PKPROT_F2M; + } + + desc = dh_desc; +#ifdef CAAM_DEBUG + buf = desc; + pr_debug("%d DH Descriptor is:\n", desc_size); + for (i = 0; i < desc_size; i++) + pr_debug("[%d] %x\n", i, buf[i]); +#endif + return desc; +} + /* DSA sign CAAM descriptor */ void *caam_dsa_sign_desc(struct dsa_edesc_s *edesc) { u32 start_idx, desc_size; void *desc; +#ifdef CAAM_DEBUG + uint32_t i; + uint32_t *buf; +#endif if (edesc->req_type == ECDSA_SIGN) { struct ecdsa_sign_desc_s *ecdsa_desc = @@ -169,6 +214,9 @@ void *caam_dsa_sign_desc(struct dsa_edesc_s *edesc) ecdsa_desc->ab_dma = edesc->ab_dma; ecdsa_desc->op = CMD_OPERATION | OP_TYPE_UNI_PROTOCOL | OP_PCLID_DSASIGN | OP_PCL_PKPROT_ECC; + if (edesc->curve_type == ECC_BINARY) + ecdsa_desc->op |= OP_PCL_PKPROT_F2M; + desc = ecdsa_desc; } else { struct dsa_sign_desc_s *dsa_desc = @@ -192,6 +240,77 @@ void *caam_dsa_sign_desc(struct dsa_edesc_s *edesc) OP_PCLID_DSASIGN; desc = dsa_desc; } +#ifdef CAAM_DEBUG + buf = desc; + pr_debug("DSA Descriptor is:"); + for (i = 0; i < desc_size; i++) + pr_debug("[%d] %x ", i, buf[i]); + pr_debug("\n"); +#endif + + return desc; +} + +/* DSA/ECDSA/DH/ECDH keygen CAAM descriptor */ +void *caam_keygen_desc(struct dsa_edesc_s *edesc) +{ + u32 start_idx, desc_size; + void *desc; +#ifdef CAAM_DEBUG + uint32_t i; + uint32_t *buf; +#endif + + if (edesc->req_type == ECC_KEYGEN) { + struct ecc_keygen_desc_s *ecc_desc = + (struct ecc_keygen_desc_s *)edesc->hw_desc; + desc_size = sizeof(struct ecc_keygen_desc_s) / sizeof(u32); + start_idx = desc_size - 1; + start_idx &= HDR_START_IDX_MASK; + init_job_desc(edesc->hw_desc, + (start_idx << HDR_START_IDX_SHIFT) | + (start_idx & HDR_DESCLEN_MASK) | HDR_ONE); + ecc_desc->sgf_ln = (edesc->l_len << DSA_PDB_L_SHIFT) | + ((edesc->n_len & DSA_PDB_N_MASK)); + ecc_desc->q_dma = edesc->q_dma; + ecc_desc->r_dma = edesc->r_dma; + ecc_desc->g_dma = edesc->g_dma; + ecc_desc->s_dma = edesc->s_dma; + ecc_desc->w_dma = edesc->key_dma; + ecc_desc->ab_dma = edesc->ab_dma; + ecc_desc->op = CMD_OPERATION | OP_TYPE_UNI_PROTOCOL | + OP_PCLID_PUBLICKEYPAIR | OP_PCL_PKPROT_ECC; + if (edesc->curve_type == ECC_BINARY) + ecc_desc->op |= OP_PCL_PKPROT_F2M; + + desc = ecc_desc; + } else { + struct dlc_keygen_desc_s *key_desc = + (struct dlc_keygen_desc_s *)edesc->hw_desc; + desc_size = sizeof(struct dlc_keygen_desc_s) / sizeof(u32); + start_idx = desc_size - 1; + start_idx &= HDR_START_IDX_MASK; + init_job_desc(edesc->hw_desc, + (start_idx << HDR_START_IDX_SHIFT) | + (start_idx & HDR_DESCLEN_MASK) | HDR_ONE); + key_desc->sgf_ln = (edesc->l_len << DSA_PDB_L_SHIFT) | + ((edesc->n_len & DSA_PDB_N_MASK)); + key_desc->q_dma = edesc->q_dma; + key_desc->r_dma = edesc->r_dma; + key_desc->g_dma = edesc->g_dma; + key_desc->s_dma = edesc->s_dma; + key_desc->w_dma = edesc->key_dma; + key_desc->op = CMD_OPERATION | OP_TYPE_UNI_PROTOCOL | + OP_PCLID_PUBLICKEYPAIR; + desc = key_desc; + } +#ifdef CAAM_DEBUG + buf = desc; + pr_debug("DSA Keygen Descriptor is:"); + for (i = 0; i < desc_size; i++) + pr_debug("[%d] %x ", i, buf[i]); + pr_debug("\n"); +#endif return desc; } @@ -201,6 +320,10 @@ void *caam_dsa_verify_desc(struct dsa_edesc_s *edesc) { u32 start_idx, desc_size; void *desc; +#ifdef CAAM_DEBUG + uint32_t i; + uint32_t *buf; +#endif if (edesc->req_type == ECDSA_VERIFY) { struct ecdsa_verify_desc_s *ecdsa_desc = @@ -224,8 +347,9 @@ void *caam_dsa_verify_desc(struct dsa_edesc_s *edesc) ecdsa_desc->ab_dma = edesc->ab_dma; ecdsa_desc->op = CMD_OPERATION | OP_TYPE_UNI_PROTOCOL | OP_PCLID_DSAVERIFY | OP_PCL_PKPROT_ECC; + if (edesc->curve_type == ECC_BINARY) + ecdsa_desc->op |= OP_PCL_PKPROT_F2M; desc = ecdsa_desc; - } else { struct dsa_verify_desc_s *dsa_desc = (struct dsa_verify_desc_s *)edesc->hw_desc; @@ -249,5 +373,11 @@ void *caam_dsa_verify_desc(struct dsa_edesc_s *edesc) OP_PCLID_DSAVERIFY; desc = dsa_desc; } +#ifdef CAAM_DEBUG + buf = desc; + pr_debug("DSA Descriptor is:\n"); + for (i = 0; i < desc_size; i++) + pr_debug("[%d] %x\n", i, buf[i]); +#endif return desc; } |