aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2015-10-18 12:51:25 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-10-20 10:11:11 -0400
commit5ec908319ab53072d3a2188e62ed2e5d7b846951 (patch)
tree62a518ca85620fce86224cbd434edff17cb079b1
parentc7556ff7e3e4f2747583bcc787f12ec9460ec3a6 (diff)
crypto: caam - only export the state we really need to export
Avoid exporting lots of state by only exporting what we really require, which is the buffer containing the set of pending bytes to be hashed, number of pending bytes, the context buffer, and the function pointer state. This reduces down the exported state size to 216 bytes from 576 bytes. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/caam/caamhash.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index cafc0018dca1..0f8fbdfad0b7 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -134,6 +134,15 @@ struct caam_hash_state {
134 int current_buf; 134 int current_buf;
135}; 135};
136 136
137struct caam_export_state {
138 u8 buf[CAAM_MAX_HASH_BLOCK_SIZE];
139 u8 caam_ctx[MAX_CTX_LEN];
140 int buflen;
141 int (*update)(struct ahash_request *req);
142 int (*final)(struct ahash_request *req);
143 int (*finup)(struct ahash_request *req);
144};
145
137/* Common job descriptor seq in/out ptr routines */ 146/* Common job descriptor seq in/out ptr routines */
138 147
139/* Map state->caam_ctx, and append seq_out_ptr command that points to it */ 148/* Map state->caam_ctx, and append seq_out_ptr command that points to it */
@@ -1553,20 +1562,41 @@ static int ahash_final(struct ahash_request *req)
1553 1562
1554static int ahash_export(struct ahash_request *req, void *out) 1563static int ahash_export(struct ahash_request *req, void *out)
1555{ 1564{
1556 struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
1557 struct caam_hash_state *state = ahash_request_ctx(req); 1565 struct caam_hash_state *state = ahash_request_ctx(req);
1566 struct caam_export_state *export = out;
1567 int len;
1568 u8 *buf;
1558 1569
1559 memcpy(out, state, sizeof(struct caam_hash_state)); 1570 if (state->current_buf) {
1571 buf = state->buf_1;
1572 len = state->buflen_1;
1573 } else {
1574 buf = state->buf_0;
1575 len = state->buflen_1;
1576 }
1577
1578 memcpy(export->buf, buf, len);
1579 memcpy(export->caam_ctx, state->caam_ctx, sizeof(export->caam_ctx));
1580 export->buflen = len;
1581 export->update = state->update;
1582 export->final = state->final;
1583 export->finup = state->finup;
1560 1584
1561 return 0; 1585 return 0;
1562} 1586}
1563 1587
1564static int ahash_import(struct ahash_request *req, const void *in) 1588static int ahash_import(struct ahash_request *req, const void *in)
1565{ 1589{
1566 struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
1567 struct caam_hash_state *state = ahash_request_ctx(req); 1590 struct caam_hash_state *state = ahash_request_ctx(req);
1591 const struct caam_export_state *export = in;
1568 1592
1569 memcpy(state, in, sizeof(struct caam_hash_state)); 1593 memset(state, 0, sizeof(*state));
1594 memcpy(state->buf_0, export->buf, export->buflen);
1595 memcpy(state->caam_ctx, export->caam_ctx, sizeof(state->caam_ctx));
1596 state->buflen_0 = export->buflen;
1597 state->update = export->update;
1598 state->final = export->final;
1599 state->finup = export->finup;
1570 1600
1571 return 0; 1601 return 0;
1572} 1602}
@@ -1601,6 +1631,7 @@ static struct caam_hash_template driver_hash[] = {
1601 .setkey = ahash_setkey, 1631 .setkey = ahash_setkey,
1602 .halg = { 1632 .halg = {
1603 .digestsize = SHA1_DIGEST_SIZE, 1633 .digestsize = SHA1_DIGEST_SIZE,
1634 .statesize = sizeof(struct caam_export_state),
1604 }, 1635 },
1605 }, 1636 },
1606 .alg_type = OP_ALG_ALGSEL_SHA1, 1637 .alg_type = OP_ALG_ALGSEL_SHA1,
@@ -1622,6 +1653,7 @@ static struct caam_hash_template driver_hash[] = {
1622 .setkey = ahash_setkey, 1653 .setkey = ahash_setkey,
1623 .halg = { 1654 .halg = {
1624 .digestsize = SHA224_DIGEST_SIZE, 1655 .digestsize = SHA224_DIGEST_SIZE,
1656 .statesize = sizeof(struct caam_export_state),
1625 }, 1657 },
1626 }, 1658 },
1627 .alg_type = OP_ALG_ALGSEL_SHA224, 1659 .alg_type = OP_ALG_ALGSEL_SHA224,
@@ -1643,6 +1675,7 @@ static struct caam_hash_template driver_hash[] = {
1643 .setkey = ahash_setkey, 1675 .setkey = ahash_setkey,
1644 .halg = { 1676 .halg = {
1645 .digestsize = SHA256_DIGEST_SIZE, 1677 .digestsize = SHA256_DIGEST_SIZE,
1678 .statesize = sizeof(struct caam_export_state),
1646 }, 1679 },
1647 }, 1680 },
1648 .alg_type = OP_ALG_ALGSEL_SHA256, 1681 .alg_type = OP_ALG_ALGSEL_SHA256,
@@ -1664,6 +1697,7 @@ static struct caam_hash_template driver_hash[] = {
1664 .setkey = ahash_setkey, 1697 .setkey = ahash_setkey,
1665 .halg = { 1698 .halg = {
1666 .digestsize = SHA384_DIGEST_SIZE, 1699 .digestsize = SHA384_DIGEST_SIZE,
1700 .statesize = sizeof(struct caam_export_state),
1667 }, 1701 },
1668 }, 1702 },
1669 .alg_type = OP_ALG_ALGSEL_SHA384, 1703 .alg_type = OP_ALG_ALGSEL_SHA384,
@@ -1685,6 +1719,7 @@ static struct caam_hash_template driver_hash[] = {
1685 .setkey = ahash_setkey, 1719 .setkey = ahash_setkey,
1686 .halg = { 1720 .halg = {
1687 .digestsize = SHA512_DIGEST_SIZE, 1721 .digestsize = SHA512_DIGEST_SIZE,
1722 .statesize = sizeof(struct caam_export_state),
1688 }, 1723 },
1689 }, 1724 },
1690 .alg_type = OP_ALG_ALGSEL_SHA512, 1725 .alg_type = OP_ALG_ALGSEL_SHA512,
@@ -1706,6 +1741,7 @@ static struct caam_hash_template driver_hash[] = {
1706 .setkey = ahash_setkey, 1741 .setkey = ahash_setkey,
1707 .halg = { 1742 .halg = {
1708 .digestsize = MD5_DIGEST_SIZE, 1743 .digestsize = MD5_DIGEST_SIZE,
1744 .statesize = sizeof(struct caam_export_state),
1709 }, 1745 },
1710 }, 1746 },
1711 .alg_type = OP_ALG_ALGSEL_MD5, 1747 .alg_type = OP_ALG_ALGSEL_MD5,