diff options
Diffstat (limited to 'drivers/crypto/ccp/ccp-ops.c')
-rw-r--r-- | drivers/crypto/ccp/ccp-ops.c | 108 |
1 files changed, 69 insertions, 39 deletions
diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c index d09c6c4af4aa..c6e883b296a9 100644 --- a/drivers/crypto/ccp/ccp-ops.c +++ b/drivers/crypto/ccp/ccp-ops.c | |||
@@ -611,15 +611,16 @@ static void ccp_get_dm_area(struct ccp_dm_workarea *wa, unsigned int wa_offset, | |||
611 | 1); | 611 | 1); |
612 | } | 612 | } |
613 | 613 | ||
614 | static void ccp_reverse_set_dm_area(struct ccp_dm_workarea *wa, | 614 | static int ccp_reverse_set_dm_area(struct ccp_dm_workarea *wa, |
615 | struct scatterlist *sg, | 615 | struct scatterlist *sg, |
616 | unsigned int len, unsigned int se_len, | 616 | unsigned int len, unsigned int se_len, |
617 | bool sign_extend) | 617 | bool sign_extend) |
618 | { | 618 | { |
619 | unsigned int nbytes, sg_offset, dm_offset, ksb_len, i; | 619 | unsigned int nbytes, sg_offset, dm_offset, ksb_len, i; |
620 | u8 buffer[CCP_REVERSE_BUF_SIZE]; | 620 | u8 buffer[CCP_REVERSE_BUF_SIZE]; |
621 | 621 | ||
622 | BUG_ON(se_len > sizeof(buffer)); | 622 | if (WARN_ON(se_len > sizeof(buffer))) |
623 | return -EINVAL; | ||
623 | 624 | ||
624 | sg_offset = len; | 625 | sg_offset = len; |
625 | dm_offset = 0; | 626 | dm_offset = 0; |
@@ -642,6 +643,8 @@ static void ccp_reverse_set_dm_area(struct ccp_dm_workarea *wa, | |||
642 | se_len - ksb_len); | 643 | se_len - ksb_len); |
643 | } | 644 | } |
644 | } | 645 | } |
646 | |||
647 | return 0; | ||
645 | } | 648 | } |
646 | 649 | ||
647 | static void ccp_reverse_get_dm_area(struct ccp_dm_workarea *wa, | 650 | static void ccp_reverse_get_dm_area(struct ccp_dm_workarea *wa, |
@@ -1606,8 +1609,10 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1606 | if (ret) | 1609 | if (ret) |
1607 | goto e_ksb; | 1610 | goto e_ksb; |
1608 | 1611 | ||
1609 | ccp_reverse_set_dm_area(&exp, rsa->exp, rsa->exp_len, CCP_KSB_BYTES, | 1612 | ret = ccp_reverse_set_dm_area(&exp, rsa->exp, rsa->exp_len, |
1610 | false); | 1613 | CCP_KSB_BYTES, false); |
1614 | if (ret) | ||
1615 | goto e_exp; | ||
1611 | ret = ccp_copy_to_ksb(cmd_q, &exp, op.jobid, op.ksb_key, | 1616 | ret = ccp_copy_to_ksb(cmd_q, &exp, op.jobid, op.ksb_key, |
1612 | CCP_PASSTHRU_BYTESWAP_NOOP); | 1617 | CCP_PASSTHRU_BYTESWAP_NOOP); |
1613 | if (ret) { | 1618 | if (ret) { |
@@ -1623,11 +1628,15 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1623 | if (ret) | 1628 | if (ret) |
1624 | goto e_exp; | 1629 | goto e_exp; |
1625 | 1630 | ||
1626 | ccp_reverse_set_dm_area(&src, rsa->mod, rsa->mod_len, CCP_KSB_BYTES, | 1631 | ret = ccp_reverse_set_dm_area(&src, rsa->mod, rsa->mod_len, |
1627 | false); | 1632 | CCP_KSB_BYTES, false); |
1633 | if (ret) | ||
1634 | goto e_src; | ||
1628 | src.address += o_len; /* Adjust the address for the copy operation */ | 1635 | src.address += o_len; /* Adjust the address for the copy operation */ |
1629 | ccp_reverse_set_dm_area(&src, rsa->src, rsa->src_len, CCP_KSB_BYTES, | 1636 | ret = ccp_reverse_set_dm_area(&src, rsa->src, rsa->src_len, |
1630 | false); | 1637 | CCP_KSB_BYTES, false); |
1638 | if (ret) | ||
1639 | goto e_src; | ||
1631 | src.address -= o_len; /* Reset the address to original value */ | 1640 | src.address -= o_len; /* Reset the address to original value */ |
1632 | 1641 | ||
1633 | /* Prepare the output area for the operation */ | 1642 | /* Prepare the output area for the operation */ |
@@ -1841,21 +1850,27 @@ static int ccp_run_ecc_mm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1841 | save = src.address; | 1850 | save = src.address; |
1842 | 1851 | ||
1843 | /* Copy the ECC modulus */ | 1852 | /* Copy the ECC modulus */ |
1844 | ccp_reverse_set_dm_area(&src, ecc->mod, ecc->mod_len, | 1853 | ret = ccp_reverse_set_dm_area(&src, ecc->mod, ecc->mod_len, |
1845 | CCP_ECC_OPERAND_SIZE, false); | 1854 | CCP_ECC_OPERAND_SIZE, false); |
1855 | if (ret) | ||
1856 | goto e_src; | ||
1846 | src.address += CCP_ECC_OPERAND_SIZE; | 1857 | src.address += CCP_ECC_OPERAND_SIZE; |
1847 | 1858 | ||
1848 | /* Copy the first operand */ | 1859 | /* Copy the first operand */ |
1849 | ccp_reverse_set_dm_area(&src, ecc->u.mm.operand_1, | 1860 | ret = ccp_reverse_set_dm_area(&src, ecc->u.mm.operand_1, |
1850 | ecc->u.mm.operand_1_len, | 1861 | ecc->u.mm.operand_1_len, |
1851 | CCP_ECC_OPERAND_SIZE, false); | 1862 | CCP_ECC_OPERAND_SIZE, false); |
1863 | if (ret) | ||
1864 | goto e_src; | ||
1852 | src.address += CCP_ECC_OPERAND_SIZE; | 1865 | src.address += CCP_ECC_OPERAND_SIZE; |
1853 | 1866 | ||
1854 | if (ecc->function != CCP_ECC_FUNCTION_MINV_384BIT) { | 1867 | if (ecc->function != CCP_ECC_FUNCTION_MINV_384BIT) { |
1855 | /* Copy the second operand */ | 1868 | /* Copy the second operand */ |
1856 | ccp_reverse_set_dm_area(&src, ecc->u.mm.operand_2, | 1869 | ret = ccp_reverse_set_dm_area(&src, ecc->u.mm.operand_2, |
1857 | ecc->u.mm.operand_2_len, | 1870 | ecc->u.mm.operand_2_len, |
1858 | CCP_ECC_OPERAND_SIZE, false); | 1871 | CCP_ECC_OPERAND_SIZE, false); |
1872 | if (ret) | ||
1873 | goto e_src; | ||
1859 | src.address += CCP_ECC_OPERAND_SIZE; | 1874 | src.address += CCP_ECC_OPERAND_SIZE; |
1860 | } | 1875 | } |
1861 | 1876 | ||
@@ -1960,18 +1975,24 @@ static int ccp_run_ecc_pm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1960 | save = src.address; | 1975 | save = src.address; |
1961 | 1976 | ||
1962 | /* Copy the ECC modulus */ | 1977 | /* Copy the ECC modulus */ |
1963 | ccp_reverse_set_dm_area(&src, ecc->mod, ecc->mod_len, | 1978 | ret = ccp_reverse_set_dm_area(&src, ecc->mod, ecc->mod_len, |
1964 | CCP_ECC_OPERAND_SIZE, false); | 1979 | CCP_ECC_OPERAND_SIZE, false); |
1980 | if (ret) | ||
1981 | goto e_src; | ||
1965 | src.address += CCP_ECC_OPERAND_SIZE; | 1982 | src.address += CCP_ECC_OPERAND_SIZE; |
1966 | 1983 | ||
1967 | /* Copy the first point X and Y coordinate */ | 1984 | /* Copy the first point X and Y coordinate */ |
1968 | ccp_reverse_set_dm_area(&src, ecc->u.pm.point_1.x, | 1985 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.point_1.x, |
1969 | ecc->u.pm.point_1.x_len, | 1986 | ecc->u.pm.point_1.x_len, |
1970 | CCP_ECC_OPERAND_SIZE, false); | 1987 | CCP_ECC_OPERAND_SIZE, false); |
1988 | if (ret) | ||
1989 | goto e_src; | ||
1971 | src.address += CCP_ECC_OPERAND_SIZE; | 1990 | src.address += CCP_ECC_OPERAND_SIZE; |
1972 | ccp_reverse_set_dm_area(&src, ecc->u.pm.point_1.y, | 1991 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.point_1.y, |
1973 | ecc->u.pm.point_1.y_len, | 1992 | ecc->u.pm.point_1.y_len, |
1974 | CCP_ECC_OPERAND_SIZE, false); | 1993 | CCP_ECC_OPERAND_SIZE, false); |
1994 | if (ret) | ||
1995 | goto e_src; | ||
1975 | src.address += CCP_ECC_OPERAND_SIZE; | 1996 | src.address += CCP_ECC_OPERAND_SIZE; |
1976 | 1997 | ||
1977 | /* Set the first point Z coordianate to 1 */ | 1998 | /* Set the first point Z coordianate to 1 */ |
@@ -1980,13 +2001,17 @@ static int ccp_run_ecc_pm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1980 | 2001 | ||
1981 | if (ecc->function == CCP_ECC_FUNCTION_PADD_384BIT) { | 2002 | if (ecc->function == CCP_ECC_FUNCTION_PADD_384BIT) { |
1982 | /* Copy the second point X and Y coordinate */ | 2003 | /* Copy the second point X and Y coordinate */ |
1983 | ccp_reverse_set_dm_area(&src, ecc->u.pm.point_2.x, | 2004 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.point_2.x, |
1984 | ecc->u.pm.point_2.x_len, | 2005 | ecc->u.pm.point_2.x_len, |
1985 | CCP_ECC_OPERAND_SIZE, false); | 2006 | CCP_ECC_OPERAND_SIZE, false); |
2007 | if (ret) | ||
2008 | goto e_src; | ||
1986 | src.address += CCP_ECC_OPERAND_SIZE; | 2009 | src.address += CCP_ECC_OPERAND_SIZE; |
1987 | ccp_reverse_set_dm_area(&src, ecc->u.pm.point_2.y, | 2010 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.point_2.y, |
1988 | ecc->u.pm.point_2.y_len, | 2011 | ecc->u.pm.point_2.y_len, |
1989 | CCP_ECC_OPERAND_SIZE, false); | 2012 | CCP_ECC_OPERAND_SIZE, false); |
2013 | if (ret) | ||
2014 | goto e_src; | ||
1990 | src.address += CCP_ECC_OPERAND_SIZE; | 2015 | src.address += CCP_ECC_OPERAND_SIZE; |
1991 | 2016 | ||
1992 | /* Set the second point Z coordianate to 1 */ | 2017 | /* Set the second point Z coordianate to 1 */ |
@@ -1994,16 +2019,21 @@ static int ccp_run_ecc_pm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) | |||
1994 | src.address += CCP_ECC_OPERAND_SIZE; | 2019 | src.address += CCP_ECC_OPERAND_SIZE; |
1995 | } else { | 2020 | } else { |
1996 | /* Copy the Domain "a" parameter */ | 2021 | /* Copy the Domain "a" parameter */ |
1997 | ccp_reverse_set_dm_area(&src, ecc->u.pm.domain_a, | 2022 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.domain_a, |
1998 | ecc->u.pm.domain_a_len, | 2023 | ecc->u.pm.domain_a_len, |
1999 | CCP_ECC_OPERAND_SIZE, false); | 2024 | CCP_ECC_OPERAND_SIZE, false); |
2025 | if (ret) | ||
2026 | goto e_src; | ||
2000 | src.address += CCP_ECC_OPERAND_SIZE; | 2027 | src.address += CCP_ECC_OPERAND_SIZE; |
2001 | 2028 | ||
2002 | if (ecc->function == CCP_ECC_FUNCTION_PMUL_384BIT) { | 2029 | if (ecc->function == CCP_ECC_FUNCTION_PMUL_384BIT) { |
2003 | /* Copy the scalar value */ | 2030 | /* Copy the scalar value */ |
2004 | ccp_reverse_set_dm_area(&src, ecc->u.pm.scalar, | 2031 | ret = ccp_reverse_set_dm_area(&src, ecc->u.pm.scalar, |
2005 | ecc->u.pm.scalar_len, | 2032 | ecc->u.pm.scalar_len, |
2006 | CCP_ECC_OPERAND_SIZE, false); | 2033 | CCP_ECC_OPERAND_SIZE, |
2034 | false); | ||
2035 | if (ret) | ||
2036 | goto e_src; | ||
2007 | src.address += CCP_ECC_OPERAND_SIZE; | 2037 | src.address += CCP_ECC_OPERAND_SIZE; |
2008 | } | 2038 | } |
2009 | } | 2039 | } |