diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2010-05-22 02:36:56 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-05-22 02:36:56 -0400 |
commit | cf9b59e9d3e008591d1f54830f570982bb307a0d (patch) | |
tree | 113478ce8fd8c832ba726ffdf59b82cb46356476 /drivers/crypto/talitos.c | |
parent | 44504b2bebf8b5823c59484e73096a7d6574471d (diff) | |
parent | f4b87dee923342505e1ddba8d34ce9de33e75050 (diff) |
Merge remote branch 'origin' into secretlab/next-devicetree
Merging in current state of Linus' tree to deal with merge conflicts and
build failures in vio.c after merge.
Conflicts:
drivers/i2c/busses/i2c-cpm.c
drivers/i2c/busses/i2c-mpc.c
drivers/net/gianfar.c
Also fixed up one line in arch/powerpc/kernel/vio.c to use the
correct node pointer.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/crypto/talitos.c')
-rw-r--r-- | drivers/crypto/talitos.c | 699 |
1 files changed, 652 insertions, 47 deletions
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 7e4e42d85fe4..637c105f53d2 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * talitos - Freescale Integrated Security Engine (SEC) device driver | 2 | * talitos - Freescale Integrated Security Engine (SEC) device driver |
3 | * | 3 | * |
4 | * Copyright (c) 2008 Freescale Semiconductor, Inc. | 4 | * Copyright (c) 2008-2010 Freescale Semiconductor, Inc. |
5 | * | 5 | * |
6 | * Scatterlist Crypto API glue code copied from files with the following: | 6 | * Scatterlist Crypto API glue code copied from files with the following: |
7 | * Copyright (c) 2006-2007 Herbert Xu <herbert@gondor.apana.org.au> | 7 | * Copyright (c) 2006-2007 Herbert Xu <herbert@gondor.apana.org.au> |
@@ -43,9 +43,12 @@ | |||
43 | #include <crypto/aes.h> | 43 | #include <crypto/aes.h> |
44 | #include <crypto/des.h> | 44 | #include <crypto/des.h> |
45 | #include <crypto/sha.h> | 45 | #include <crypto/sha.h> |
46 | #include <crypto/md5.h> | ||
46 | #include <crypto/aead.h> | 47 | #include <crypto/aead.h> |
47 | #include <crypto/authenc.h> | 48 | #include <crypto/authenc.h> |
48 | #include <crypto/skcipher.h> | 49 | #include <crypto/skcipher.h> |
50 | #include <crypto/hash.h> | ||
51 | #include <crypto/internal/hash.h> | ||
49 | #include <crypto/scatterwalk.h> | 52 | #include <crypto/scatterwalk.h> |
50 | 53 | ||
51 | #include "talitos.h" | 54 | #include "talitos.h" |
@@ -65,6 +68,13 @@ struct talitos_ptr { | |||
65 | __be32 ptr; /* address */ | 68 | __be32 ptr; /* address */ |
66 | }; | 69 | }; |
67 | 70 | ||
71 | static const struct talitos_ptr zero_entry = { | ||
72 | .len = 0, | ||
73 | .j_extent = 0, | ||
74 | .eptr = 0, | ||
75 | .ptr = 0 | ||
76 | }; | ||
77 | |||
68 | /* descriptor */ | 78 | /* descriptor */ |
69 | struct talitos_desc { | 79 | struct talitos_desc { |
70 | __be32 hdr; /* header high bits */ | 80 | __be32 hdr; /* header high bits */ |
@@ -146,6 +156,7 @@ struct talitos_private { | |||
146 | /* .features flag */ | 156 | /* .features flag */ |
147 | #define TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT 0x00000001 | 157 | #define TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT 0x00000001 |
148 | #define TALITOS_FTR_HW_AUTH_CHECK 0x00000002 | 158 | #define TALITOS_FTR_HW_AUTH_CHECK 0x00000002 |
159 | #define TALITOS_FTR_SHA224_HWINIT 0x00000004 | ||
149 | 160 | ||
150 | static void to_talitos_ptr(struct talitos_ptr *talitos_ptr, dma_addr_t dma_addr) | 161 | static void to_talitos_ptr(struct talitos_ptr *talitos_ptr, dma_addr_t dma_addr) |
151 | { | 162 | { |
@@ -692,7 +703,7 @@ static void talitos_unregister_rng(struct device *dev) | |||
692 | #define TALITOS_MAX_KEY_SIZE 64 | 703 | #define TALITOS_MAX_KEY_SIZE 64 |
693 | #define TALITOS_MAX_IV_LENGTH 16 /* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */ | 704 | #define TALITOS_MAX_IV_LENGTH 16 /* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */ |
694 | 705 | ||
695 | #define MD5_DIGEST_SIZE 16 | 706 | #define MD5_BLOCK_SIZE 64 |
696 | 707 | ||
697 | struct talitos_ctx { | 708 | struct talitos_ctx { |
698 | struct device *dev; | 709 | struct device *dev; |
@@ -705,6 +716,23 @@ struct talitos_ctx { | |||
705 | unsigned int authsize; | 716 | unsigned int authsize; |
706 | }; | 717 | }; |
707 | 718 | ||
719 | #define HASH_MAX_BLOCK_SIZE SHA512_BLOCK_SIZE | ||
720 | #define TALITOS_MDEU_MAX_CONTEXT_SIZE TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 | ||
721 | |||
722 | struct talitos_ahash_req_ctx { | ||
723 | u64 count; | ||
724 | u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE / sizeof(u32)]; | ||
725 | unsigned int hw_context_size; | ||
726 | u8 buf[HASH_MAX_BLOCK_SIZE]; | ||
727 | u8 bufnext[HASH_MAX_BLOCK_SIZE]; | ||
728 | unsigned int swinit; | ||
729 | unsigned int first; | ||
730 | unsigned int last; | ||
731 | unsigned int to_hash_later; | ||
732 | struct scatterlist bufsl[2]; | ||
733 | struct scatterlist *psrc; | ||
734 | }; | ||
735 | |||
708 | static int aead_setauthsize(struct crypto_aead *authenc, | 736 | static int aead_setauthsize(struct crypto_aead *authenc, |
709 | unsigned int authsize) | 737 | unsigned int authsize) |
710 | { | 738 | { |
@@ -821,10 +849,14 @@ static void talitos_sg_unmap(struct device *dev, | |||
821 | else | 849 | else |
822 | dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE); | 850 | dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE); |
823 | 851 | ||
824 | if (edesc->dst_is_chained) | 852 | if (dst) { |
825 | talitos_unmap_sg_chain(dev, dst, DMA_FROM_DEVICE); | 853 | if (edesc->dst_is_chained) |
826 | else | 854 | talitos_unmap_sg_chain(dev, dst, |
827 | dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE); | 855 | DMA_FROM_DEVICE); |
856 | else | ||
857 | dma_unmap_sg(dev, dst, dst_nents, | ||
858 | DMA_FROM_DEVICE); | ||
859 | } | ||
828 | } else | 860 | } else |
829 | if (edesc->src_is_chained) | 861 | if (edesc->src_is_chained) |
830 | talitos_unmap_sg_chain(dev, src, DMA_BIDIRECTIONAL); | 862 | talitos_unmap_sg_chain(dev, src, DMA_BIDIRECTIONAL); |
@@ -1114,12 +1146,67 @@ static int sg_count(struct scatterlist *sg_list, int nbytes, int *chained) | |||
1114 | return sg_nents; | 1146 | return sg_nents; |
1115 | } | 1147 | } |
1116 | 1148 | ||
1149 | /** | ||
1150 | * sg_copy_end_to_buffer - Copy end data from SG list to a linear buffer | ||
1151 | * @sgl: The SG list | ||
1152 | * @nents: Number of SG entries | ||
1153 | * @buf: Where to copy to | ||
1154 | * @buflen: The number of bytes to copy | ||
1155 | * @skip: The number of bytes to skip before copying. | ||
1156 | * Note: skip + buflen should equal SG total size. | ||
1157 | * | ||
1158 | * Returns the number of copied bytes. | ||
1159 | * | ||
1160 | **/ | ||
1161 | static size_t sg_copy_end_to_buffer(struct scatterlist *sgl, unsigned int nents, | ||
1162 | void *buf, size_t buflen, unsigned int skip) | ||
1163 | { | ||
1164 | unsigned int offset = 0; | ||
1165 | unsigned int boffset = 0; | ||
1166 | struct sg_mapping_iter miter; | ||
1167 | unsigned long flags; | ||
1168 | unsigned int sg_flags = SG_MITER_ATOMIC; | ||
1169 | size_t total_buffer = buflen + skip; | ||
1170 | |||
1171 | sg_flags |= SG_MITER_FROM_SG; | ||
1172 | |||
1173 | sg_miter_start(&miter, sgl, nents, sg_flags); | ||
1174 | |||
1175 | local_irq_save(flags); | ||
1176 | |||
1177 | while (sg_miter_next(&miter) && offset < total_buffer) { | ||
1178 | unsigned int len; | ||
1179 | unsigned int ignore; | ||
1180 | |||
1181 | if ((offset + miter.length) > skip) { | ||
1182 | if (offset < skip) { | ||
1183 | /* Copy part of this segment */ | ||
1184 | ignore = skip - offset; | ||
1185 | len = miter.length - ignore; | ||
1186 | memcpy(buf + boffset, miter.addr + ignore, len); | ||
1187 | } else { | ||
1188 | /* Copy all of this segment */ | ||
1189 | len = miter.length; | ||
1190 | memcpy(buf + boffset, miter.addr, len); | ||
1191 | } | ||
1192 | boffset += len; | ||
1193 | } | ||
1194 | offset += miter.length; | ||
1195 | } | ||
1196 | |||
1197 | sg_miter_stop(&miter); | ||
1198 | |||
1199 | local_irq_restore(flags); | ||
1200 | return boffset; | ||
1201 | } | ||
1202 | |||
1117 | /* | 1203 | /* |
1118 | * allocate and map the extended descriptor | 1204 | * allocate and map the extended descriptor |
1119 | */ | 1205 | */ |
1120 | static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, | 1206 | static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, |
1121 | struct scatterlist *src, | 1207 | struct scatterlist *src, |
1122 | struct scatterlist *dst, | 1208 | struct scatterlist *dst, |
1209 | int hash_result, | ||
1123 | unsigned int cryptlen, | 1210 | unsigned int cryptlen, |
1124 | unsigned int authsize, | 1211 | unsigned int authsize, |
1125 | int icv_stashing, | 1212 | int icv_stashing, |
@@ -1139,11 +1226,16 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, | |||
1139 | src_nents = sg_count(src, cryptlen + authsize, &src_chained); | 1226 | src_nents = sg_count(src, cryptlen + authsize, &src_chained); |
1140 | src_nents = (src_nents == 1) ? 0 : src_nents; | 1227 | src_nents = (src_nents == 1) ? 0 : src_nents; |
1141 | 1228 | ||
1142 | if (dst == src) { | 1229 | if (hash_result) { |
1143 | dst_nents = src_nents; | 1230 | dst_nents = 0; |
1144 | } else { | 1231 | } else { |
1145 | dst_nents = sg_count(dst, cryptlen + authsize, &dst_chained); | 1232 | if (dst == src) { |
1146 | dst_nents = (dst_nents == 1) ? 0 : dst_nents; | 1233 | dst_nents = src_nents; |
1234 | } else { | ||
1235 | dst_nents = sg_count(dst, cryptlen + authsize, | ||
1236 | &dst_chained); | ||
1237 | dst_nents = (dst_nents == 1) ? 0 : dst_nents; | ||
1238 | } | ||
1147 | } | 1239 | } |
1148 | 1240 | ||
1149 | /* | 1241 | /* |
@@ -1172,8 +1264,10 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, | |||
1172 | edesc->src_is_chained = src_chained; | 1264 | edesc->src_is_chained = src_chained; |
1173 | edesc->dst_is_chained = dst_chained; | 1265 | edesc->dst_is_chained = dst_chained; |
1174 | edesc->dma_len = dma_len; | 1266 | edesc->dma_len = dma_len; |
1175 | edesc->dma_link_tbl = dma_map_single(dev, &edesc->link_tbl[0], | 1267 | if (dma_len) |
1176 | edesc->dma_len, DMA_BIDIRECTIONAL); | 1268 | edesc->dma_link_tbl = dma_map_single(dev, &edesc->link_tbl[0], |
1269 | edesc->dma_len, | ||
1270 | DMA_BIDIRECTIONAL); | ||
1177 | 1271 | ||
1178 | return edesc; | 1272 | return edesc; |
1179 | } | 1273 | } |
@@ -1184,7 +1278,7 @@ static struct talitos_edesc *aead_edesc_alloc(struct aead_request *areq, | |||
1184 | struct crypto_aead *authenc = crypto_aead_reqtfm(areq); | 1278 | struct crypto_aead *authenc = crypto_aead_reqtfm(areq); |
1185 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); | 1279 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
1186 | 1280 | ||
1187 | return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst, | 1281 | return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst, 0, |
1188 | areq->cryptlen, ctx->authsize, icv_stashing, | 1282 | areq->cryptlen, ctx->authsize, icv_stashing, |
1189 | areq->base.flags); | 1283 | areq->base.flags); |
1190 | } | 1284 | } |
@@ -1441,8 +1535,8 @@ static struct talitos_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request * | |||
1441 | struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); | 1535 | struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); |
1442 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); | 1536 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
1443 | 1537 | ||
1444 | return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst, areq->nbytes, | 1538 | return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst, 0, |
1445 | 0, 0, areq->base.flags); | 1539 | areq->nbytes, 0, 0, areq->base.flags); |
1446 | } | 1540 | } |
1447 | 1541 | ||
1448 | static int ablkcipher_encrypt(struct ablkcipher_request *areq) | 1542 | static int ablkcipher_encrypt(struct ablkcipher_request *areq) |
@@ -1478,15 +1572,329 @@ static int ablkcipher_decrypt(struct ablkcipher_request *areq) | |||
1478 | return common_nonsnoop(edesc, areq, NULL, ablkcipher_done); | 1572 | return common_nonsnoop(edesc, areq, NULL, ablkcipher_done); |
1479 | } | 1573 | } |
1480 | 1574 | ||
1575 | static void common_nonsnoop_hash_unmap(struct device *dev, | ||
1576 | struct talitos_edesc *edesc, | ||
1577 | struct ahash_request *areq) | ||
1578 | { | ||
1579 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1580 | |||
1581 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[5], DMA_FROM_DEVICE); | ||
1582 | |||
1583 | /* When using hashctx-in, must unmap it. */ | ||
1584 | if (edesc->desc.ptr[1].len) | ||
1585 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[1], | ||
1586 | DMA_TO_DEVICE); | ||
1587 | |||
1588 | if (edesc->desc.ptr[2].len) | ||
1589 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2], | ||
1590 | DMA_TO_DEVICE); | ||
1591 | |||
1592 | talitos_sg_unmap(dev, edesc, req_ctx->psrc, NULL); | ||
1593 | |||
1594 | if (edesc->dma_len) | ||
1595 | dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len, | ||
1596 | DMA_BIDIRECTIONAL); | ||
1597 | |||
1598 | } | ||
1599 | |||
1600 | static void ahash_done(struct device *dev, | ||
1601 | struct talitos_desc *desc, void *context, | ||
1602 | int err) | ||
1603 | { | ||
1604 | struct ahash_request *areq = context; | ||
1605 | struct talitos_edesc *edesc = | ||
1606 | container_of(desc, struct talitos_edesc, desc); | ||
1607 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1608 | |||
1609 | if (!req_ctx->last && req_ctx->to_hash_later) { | ||
1610 | /* Position any partial block for next update/final/finup */ | ||
1611 | memcpy(req_ctx->buf, req_ctx->bufnext, req_ctx->to_hash_later); | ||
1612 | } | ||
1613 | common_nonsnoop_hash_unmap(dev, edesc, areq); | ||
1614 | |||
1615 | kfree(edesc); | ||
1616 | |||
1617 | areq->base.complete(&areq->base, err); | ||
1618 | } | ||
1619 | |||
1620 | static int common_nonsnoop_hash(struct talitos_edesc *edesc, | ||
1621 | struct ahash_request *areq, unsigned int length, | ||
1622 | void (*callback) (struct device *dev, | ||
1623 | struct talitos_desc *desc, | ||
1624 | void *context, int error)) | ||
1625 | { | ||
1626 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); | ||
1627 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); | ||
1628 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1629 | struct device *dev = ctx->dev; | ||
1630 | struct talitos_desc *desc = &edesc->desc; | ||
1631 | int sg_count, ret; | ||
1632 | |||
1633 | /* first DWORD empty */ | ||
1634 | desc->ptr[0] = zero_entry; | ||
1635 | |||
1636 | /* hash context in */ | ||
1637 | if (!req_ctx->first || req_ctx->swinit) { | ||
1638 | map_single_talitos_ptr(dev, &desc->ptr[1], | ||
1639 | req_ctx->hw_context_size, | ||
1640 | (char *)req_ctx->hw_context, 0, | ||
1641 | DMA_TO_DEVICE); | ||
1642 | req_ctx->swinit = 0; | ||
1643 | } else { | ||
1644 | desc->ptr[1] = zero_entry; | ||
1645 | /* Indicate next op is not the first. */ | ||
1646 | req_ctx->first = 0; | ||
1647 | } | ||
1648 | |||
1649 | /* HMAC key */ | ||
1650 | if (ctx->keylen) | ||
1651 | map_single_talitos_ptr(dev, &desc->ptr[2], ctx->keylen, | ||
1652 | (char *)&ctx->key, 0, DMA_TO_DEVICE); | ||
1653 | else | ||
1654 | desc->ptr[2] = zero_entry; | ||
1655 | |||
1656 | /* | ||
1657 | * data in | ||
1658 | */ | ||
1659 | desc->ptr[3].len = cpu_to_be16(length); | ||
1660 | desc->ptr[3].j_extent = 0; | ||
1661 | |||
1662 | sg_count = talitos_map_sg(dev, req_ctx->psrc, | ||
1663 | edesc->src_nents ? : 1, | ||
1664 | DMA_TO_DEVICE, | ||
1665 | edesc->src_is_chained); | ||
1666 | |||
1667 | if (sg_count == 1) { | ||
1668 | to_talitos_ptr(&desc->ptr[3], sg_dma_address(req_ctx->psrc)); | ||
1669 | } else { | ||
1670 | sg_count = sg_to_link_tbl(req_ctx->psrc, sg_count, length, | ||
1671 | &edesc->link_tbl[0]); | ||
1672 | if (sg_count > 1) { | ||
1673 | desc->ptr[3].j_extent |= DESC_PTR_LNKTBL_JUMP; | ||
1674 | to_talitos_ptr(&desc->ptr[3], edesc->dma_link_tbl); | ||
1675 | dma_sync_single_for_device(ctx->dev, | ||
1676 | edesc->dma_link_tbl, | ||
1677 | edesc->dma_len, | ||
1678 | DMA_BIDIRECTIONAL); | ||
1679 | } else { | ||
1680 | /* Only one segment now, so no link tbl needed */ | ||
1681 | to_talitos_ptr(&desc->ptr[3], | ||
1682 | sg_dma_address(req_ctx->psrc)); | ||
1683 | } | ||
1684 | } | ||
1685 | |||
1686 | /* fifth DWORD empty */ | ||
1687 | desc->ptr[4] = zero_entry; | ||
1688 | |||
1689 | /* hash/HMAC out -or- hash context out */ | ||
1690 | if (req_ctx->last) | ||
1691 | map_single_talitos_ptr(dev, &desc->ptr[5], | ||
1692 | crypto_ahash_digestsize(tfm), | ||
1693 | areq->result, 0, DMA_FROM_DEVICE); | ||
1694 | else | ||
1695 | map_single_talitos_ptr(dev, &desc->ptr[5], | ||
1696 | req_ctx->hw_context_size, | ||
1697 | req_ctx->hw_context, 0, DMA_FROM_DEVICE); | ||
1698 | |||
1699 | /* last DWORD empty */ | ||
1700 | desc->ptr[6] = zero_entry; | ||
1701 | |||
1702 | ret = talitos_submit(dev, desc, callback, areq); | ||
1703 | if (ret != -EINPROGRESS) { | ||
1704 | common_nonsnoop_hash_unmap(dev, edesc, areq); | ||
1705 | kfree(edesc); | ||
1706 | } | ||
1707 | return ret; | ||
1708 | } | ||
1709 | |||
1710 | static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, | ||
1711 | unsigned int nbytes) | ||
1712 | { | ||
1713 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); | ||
1714 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); | ||
1715 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1716 | |||
1717 | return talitos_edesc_alloc(ctx->dev, req_ctx->psrc, NULL, 1, | ||
1718 | nbytes, 0, 0, areq->base.flags); | ||
1719 | } | ||
1720 | |||
1721 | static int ahash_init(struct ahash_request *areq) | ||
1722 | { | ||
1723 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); | ||
1724 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1725 | |||
1726 | /* Initialize the context */ | ||
1727 | req_ctx->count = 0; | ||
1728 | req_ctx->first = 1; /* first indicates h/w must init its context */ | ||
1729 | req_ctx->swinit = 0; /* assume h/w init of context */ | ||
1730 | req_ctx->hw_context_size = | ||
1731 | (crypto_ahash_digestsize(tfm) <= SHA256_DIGEST_SIZE) | ||
1732 | ? TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 | ||
1733 | : TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512; | ||
1734 | |||
1735 | return 0; | ||
1736 | } | ||
1737 | |||
1738 | /* | ||
1739 | * on h/w without explicit sha224 support, we initialize h/w context | ||
1740 | * manually with sha224 constants, and tell it to run sha256. | ||
1741 | */ | ||
1742 | static int ahash_init_sha224_swinit(struct ahash_request *areq) | ||
1743 | { | ||
1744 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1745 | |||
1746 | ahash_init(areq); | ||
1747 | req_ctx->swinit = 1;/* prevent h/w initting context with sha256 values*/ | ||
1748 | |||
1749 | req_ctx->hw_context[0] = cpu_to_be32(SHA224_H0); | ||
1750 | req_ctx->hw_context[1] = cpu_to_be32(SHA224_H1); | ||
1751 | req_ctx->hw_context[2] = cpu_to_be32(SHA224_H2); | ||
1752 | req_ctx->hw_context[3] = cpu_to_be32(SHA224_H3); | ||
1753 | req_ctx->hw_context[4] = cpu_to_be32(SHA224_H4); | ||
1754 | req_ctx->hw_context[5] = cpu_to_be32(SHA224_H5); | ||
1755 | req_ctx->hw_context[6] = cpu_to_be32(SHA224_H6); | ||
1756 | req_ctx->hw_context[7] = cpu_to_be32(SHA224_H7); | ||
1757 | |||
1758 | /* init 64-bit count */ | ||
1759 | req_ctx->hw_context[8] = 0; | ||
1760 | req_ctx->hw_context[9] = 0; | ||
1761 | |||
1762 | return 0; | ||
1763 | } | ||
1764 | |||
1765 | static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) | ||
1766 | { | ||
1767 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); | ||
1768 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); | ||
1769 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1770 | struct talitos_edesc *edesc; | ||
1771 | unsigned int blocksize = | ||
1772 | crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm)); | ||
1773 | unsigned int nbytes_to_hash; | ||
1774 | unsigned int to_hash_later; | ||
1775 | unsigned int index; | ||
1776 | int chained; | ||
1777 | |||
1778 | index = req_ctx->count & (blocksize - 1); | ||
1779 | req_ctx->count += nbytes; | ||
1780 | |||
1781 | if (!req_ctx->last && (index + nbytes) < blocksize) { | ||
1782 | /* Buffer the partial block */ | ||
1783 | sg_copy_to_buffer(areq->src, | ||
1784 | sg_count(areq->src, nbytes, &chained), | ||
1785 | req_ctx->buf + index, nbytes); | ||
1786 | return 0; | ||
1787 | } | ||
1788 | |||
1789 | if (index) { | ||
1790 | /* partial block from previous update; chain it in. */ | ||
1791 | sg_init_table(req_ctx->bufsl, (nbytes) ? 2 : 1); | ||
1792 | sg_set_buf(req_ctx->bufsl, req_ctx->buf, index); | ||
1793 | if (nbytes) | ||
1794 | scatterwalk_sg_chain(req_ctx->bufsl, 2, | ||
1795 | areq->src); | ||
1796 | req_ctx->psrc = req_ctx->bufsl; | ||
1797 | } else { | ||
1798 | req_ctx->psrc = areq->src; | ||
1799 | } | ||
1800 | nbytes_to_hash = index + nbytes; | ||
1801 | if (!req_ctx->last) { | ||
1802 | to_hash_later = (nbytes_to_hash & (blocksize - 1)); | ||
1803 | if (to_hash_later) { | ||
1804 | int nents; | ||
1805 | /* Must copy to_hash_later bytes from the end | ||
1806 | * to bufnext (a partial block) for later. | ||
1807 | */ | ||
1808 | nents = sg_count(areq->src, nbytes, &chained); | ||
1809 | sg_copy_end_to_buffer(areq->src, nents, | ||
1810 | req_ctx->bufnext, | ||
1811 | to_hash_later, | ||
1812 | nbytes - to_hash_later); | ||
1813 | |||
1814 | /* Adjust count for what will be hashed now */ | ||
1815 | nbytes_to_hash -= to_hash_later; | ||
1816 | } | ||
1817 | req_ctx->to_hash_later = to_hash_later; | ||
1818 | } | ||
1819 | |||
1820 | /* allocate extended descriptor */ | ||
1821 | edesc = ahash_edesc_alloc(areq, nbytes_to_hash); | ||
1822 | if (IS_ERR(edesc)) | ||
1823 | return PTR_ERR(edesc); | ||
1824 | |||
1825 | edesc->desc.hdr = ctx->desc_hdr_template; | ||
1826 | |||
1827 | /* On last one, request SEC to pad; otherwise continue */ | ||
1828 | if (req_ctx->last) | ||
1829 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_PAD; | ||
1830 | else | ||
1831 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_CONT; | ||
1832 | |||
1833 | /* request SEC to INIT hash. */ | ||
1834 | if (req_ctx->first && !req_ctx->swinit) | ||
1835 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_INIT; | ||
1836 | |||
1837 | /* When the tfm context has a keylen, it's an HMAC. | ||
1838 | * A first or last (ie. not middle) descriptor must request HMAC. | ||
1839 | */ | ||
1840 | if (ctx->keylen && (req_ctx->first || req_ctx->last)) | ||
1841 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_HMAC; | ||
1842 | |||
1843 | return common_nonsnoop_hash(edesc, areq, nbytes_to_hash, | ||
1844 | ahash_done); | ||
1845 | } | ||
1846 | |||
1847 | static int ahash_update(struct ahash_request *areq) | ||
1848 | { | ||
1849 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1850 | |||
1851 | req_ctx->last = 0; | ||
1852 | |||
1853 | return ahash_process_req(areq, areq->nbytes); | ||
1854 | } | ||
1855 | |||
1856 | static int ahash_final(struct ahash_request *areq) | ||
1857 | { | ||
1858 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1859 | |||
1860 | req_ctx->last = 1; | ||
1861 | |||
1862 | return ahash_process_req(areq, 0); | ||
1863 | } | ||
1864 | |||
1865 | static int ahash_finup(struct ahash_request *areq) | ||
1866 | { | ||
1867 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1868 | |||
1869 | req_ctx->last = 1; | ||
1870 | |||
1871 | return ahash_process_req(areq, areq->nbytes); | ||
1872 | } | ||
1873 | |||
1874 | static int ahash_digest(struct ahash_request *areq) | ||
1875 | { | ||
1876 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | ||
1877 | struct crypto_ahash *ahash = crypto_ahash_reqtfm(areq); | ||
1878 | |||
1879 | ahash->init(areq); | ||
1880 | req_ctx->last = 1; | ||
1881 | |||
1882 | return ahash_process_req(areq, areq->nbytes); | ||
1883 | } | ||
1884 | |||
1481 | struct talitos_alg_template { | 1885 | struct talitos_alg_template { |
1482 | struct crypto_alg alg; | 1886 | u32 type; |
1887 | union { | ||
1888 | struct crypto_alg crypto; | ||
1889 | struct ahash_alg hash; | ||
1890 | } alg; | ||
1483 | __be32 desc_hdr_template; | 1891 | __be32 desc_hdr_template; |
1484 | }; | 1892 | }; |
1485 | 1893 | ||
1486 | static struct talitos_alg_template driver_algs[] = { | 1894 | static struct talitos_alg_template driver_algs[] = { |
1487 | /* AEAD algorithms. These use a single-pass ipsec_esp descriptor */ | 1895 | /* AEAD algorithms. These use a single-pass ipsec_esp descriptor */ |
1488 | { | 1896 | { .type = CRYPTO_ALG_TYPE_AEAD, |
1489 | .alg = { | 1897 | .alg.crypto = { |
1490 | .cra_name = "authenc(hmac(sha1),cbc(aes))", | 1898 | .cra_name = "authenc(hmac(sha1),cbc(aes))", |
1491 | .cra_driver_name = "authenc-hmac-sha1-cbc-aes-talitos", | 1899 | .cra_driver_name = "authenc-hmac-sha1-cbc-aes-talitos", |
1492 | .cra_blocksize = AES_BLOCK_SIZE, | 1900 | .cra_blocksize = AES_BLOCK_SIZE, |
@@ -1511,8 +1919,8 @@ static struct talitos_alg_template driver_algs[] = { | |||
1511 | DESC_HDR_MODE1_MDEU_PAD | | 1919 | DESC_HDR_MODE1_MDEU_PAD | |
1512 | DESC_HDR_MODE1_MDEU_SHA1_HMAC, | 1920 | DESC_HDR_MODE1_MDEU_SHA1_HMAC, |
1513 | }, | 1921 | }, |
1514 | { | 1922 | { .type = CRYPTO_ALG_TYPE_AEAD, |
1515 | .alg = { | 1923 | .alg.crypto = { |
1516 | .cra_name = "authenc(hmac(sha1),cbc(des3_ede))", | 1924 | .cra_name = "authenc(hmac(sha1),cbc(des3_ede))", |
1517 | .cra_driver_name = "authenc-hmac-sha1-cbc-3des-talitos", | 1925 | .cra_driver_name = "authenc-hmac-sha1-cbc-3des-talitos", |
1518 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, | 1926 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
@@ -1538,8 +1946,8 @@ static struct talitos_alg_template driver_algs[] = { | |||
1538 | DESC_HDR_MODE1_MDEU_PAD | | 1946 | DESC_HDR_MODE1_MDEU_PAD | |
1539 | DESC_HDR_MODE1_MDEU_SHA1_HMAC, | 1947 | DESC_HDR_MODE1_MDEU_SHA1_HMAC, |
1540 | }, | 1948 | }, |
1541 | { | 1949 | { .type = CRYPTO_ALG_TYPE_AEAD, |
1542 | .alg = { | 1950 | .alg.crypto = { |
1543 | .cra_name = "authenc(hmac(sha256),cbc(aes))", | 1951 | .cra_name = "authenc(hmac(sha256),cbc(aes))", |
1544 | .cra_driver_name = "authenc-hmac-sha256-cbc-aes-talitos", | 1952 | .cra_driver_name = "authenc-hmac-sha256-cbc-aes-talitos", |
1545 | .cra_blocksize = AES_BLOCK_SIZE, | 1953 | .cra_blocksize = AES_BLOCK_SIZE, |
@@ -1564,8 +1972,8 @@ static struct talitos_alg_template driver_algs[] = { | |||
1564 | DESC_HDR_MODE1_MDEU_PAD | | 1972 | DESC_HDR_MODE1_MDEU_PAD | |
1565 | DESC_HDR_MODE1_MDEU_SHA256_HMAC, | 1973 | DESC_HDR_MODE1_MDEU_SHA256_HMAC, |
1566 | }, | 1974 | }, |
1567 | { | 1975 | { .type = CRYPTO_ALG_TYPE_AEAD, |
1568 | .alg = { | 1976 | .alg.crypto = { |
1569 | .cra_name = "authenc(hmac(sha256),cbc(des3_ede))", | 1977 | .cra_name = "authenc(hmac(sha256),cbc(des3_ede))", |
1570 | .cra_driver_name = "authenc-hmac-sha256-cbc-3des-talitos", | 1978 | .cra_driver_name = "authenc-hmac-sha256-cbc-3des-talitos", |
1571 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, | 1979 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
@@ -1591,8 +1999,8 @@ static struct talitos_alg_template driver_algs[] = { | |||
1591 | DESC_HDR_MODE1_MDEU_PAD | | 1999 | DESC_HDR_MODE1_MDEU_PAD | |
1592 | DESC_HDR_MODE1_MDEU_SHA256_HMAC, | 2000 | DESC_HDR_MODE1_MDEU_SHA256_HMAC, |
1593 | }, | 2001 | }, |
1594 | { | 2002 | { .type = CRYPTO_ALG_TYPE_AEAD, |
1595 | .alg = { | 2003 | .alg.crypto = { |
1596 | .cra_name = "authenc(hmac(md5),cbc(aes))", | 2004 | .cra_name = "authenc(hmac(md5),cbc(aes))", |
1597 | .cra_driver_name = "authenc-hmac-md5-cbc-aes-talitos", | 2005 | .cra_driver_name = "authenc-hmac-md5-cbc-aes-talitos", |
1598 | .cra_blocksize = AES_BLOCK_SIZE, | 2006 | .cra_blocksize = AES_BLOCK_SIZE, |
@@ -1617,8 +2025,8 @@ static struct talitos_alg_template driver_algs[] = { | |||
1617 | DESC_HDR_MODE1_MDEU_PAD | | 2025 | DESC_HDR_MODE1_MDEU_PAD | |
1618 | DESC_HDR_MODE1_MDEU_MD5_HMAC, | 2026 | DESC_HDR_MODE1_MDEU_MD5_HMAC, |
1619 | }, | 2027 | }, |
1620 | { | 2028 | { .type = CRYPTO_ALG_TYPE_AEAD, |
1621 | .alg = { | 2029 | .alg.crypto = { |
1622 | .cra_name = "authenc(hmac(md5),cbc(des3_ede))", | 2030 | .cra_name = "authenc(hmac(md5),cbc(des3_ede))", |
1623 | .cra_driver_name = "authenc-hmac-md5-cbc-3des-talitos", | 2031 | .cra_driver_name = "authenc-hmac-md5-cbc-3des-talitos", |
1624 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, | 2032 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
@@ -1645,8 +2053,8 @@ static struct talitos_alg_template driver_algs[] = { | |||
1645 | DESC_HDR_MODE1_MDEU_MD5_HMAC, | 2053 | DESC_HDR_MODE1_MDEU_MD5_HMAC, |
1646 | }, | 2054 | }, |
1647 | /* ABLKCIPHER algorithms. */ | 2055 | /* ABLKCIPHER algorithms. */ |
1648 | { | 2056 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
1649 | .alg = { | 2057 | .alg.crypto = { |
1650 | .cra_name = "cbc(aes)", | 2058 | .cra_name = "cbc(aes)", |
1651 | .cra_driver_name = "cbc-aes-talitos", | 2059 | .cra_driver_name = "cbc-aes-talitos", |
1652 | .cra_blocksize = AES_BLOCK_SIZE, | 2060 | .cra_blocksize = AES_BLOCK_SIZE, |
@@ -1667,8 +2075,8 @@ static struct talitos_alg_template driver_algs[] = { | |||
1667 | DESC_HDR_SEL0_AESU | | 2075 | DESC_HDR_SEL0_AESU | |
1668 | DESC_HDR_MODE0_AESU_CBC, | 2076 | DESC_HDR_MODE0_AESU_CBC, |
1669 | }, | 2077 | }, |
1670 | { | 2078 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
1671 | .alg = { | 2079 | .alg.crypto = { |
1672 | .cra_name = "cbc(des3_ede)", | 2080 | .cra_name = "cbc(des3_ede)", |
1673 | .cra_driver_name = "cbc-3des-talitos", | 2081 | .cra_driver_name = "cbc-3des-talitos", |
1674 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, | 2082 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
@@ -1689,14 +2097,140 @@ static struct talitos_alg_template driver_algs[] = { | |||
1689 | DESC_HDR_SEL0_DEU | | 2097 | DESC_HDR_SEL0_DEU | |
1690 | DESC_HDR_MODE0_DEU_CBC | | 2098 | DESC_HDR_MODE0_DEU_CBC | |
1691 | DESC_HDR_MODE0_DEU_3DES, | 2099 | DESC_HDR_MODE0_DEU_3DES, |
1692 | } | 2100 | }, |
2101 | /* AHASH algorithms. */ | ||
2102 | { .type = CRYPTO_ALG_TYPE_AHASH, | ||
2103 | .alg.hash = { | ||
2104 | .init = ahash_init, | ||
2105 | .update = ahash_update, | ||
2106 | .final = ahash_final, | ||
2107 | .finup = ahash_finup, | ||
2108 | .digest = ahash_digest, | ||
2109 | .halg.digestsize = MD5_DIGEST_SIZE, | ||
2110 | .halg.base = { | ||
2111 | .cra_name = "md5", | ||
2112 | .cra_driver_name = "md5-talitos", | ||
2113 | .cra_blocksize = MD5_BLOCK_SIZE, | ||
2114 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | | ||
2115 | CRYPTO_ALG_ASYNC, | ||
2116 | .cra_type = &crypto_ahash_type | ||
2117 | } | ||
2118 | }, | ||
2119 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | | ||
2120 | DESC_HDR_SEL0_MDEUA | | ||
2121 | DESC_HDR_MODE0_MDEU_MD5, | ||
2122 | }, | ||
2123 | { .type = CRYPTO_ALG_TYPE_AHASH, | ||
2124 | .alg.hash = { | ||
2125 | .init = ahash_init, | ||
2126 | .update = ahash_update, | ||
2127 | .final = ahash_final, | ||
2128 | .finup = ahash_finup, | ||
2129 | .digest = ahash_digest, | ||
2130 | .halg.digestsize = SHA1_DIGEST_SIZE, | ||
2131 | .halg.base = { | ||
2132 | .cra_name = "sha1", | ||
2133 | .cra_driver_name = "sha1-talitos", | ||
2134 | .cra_blocksize = SHA1_BLOCK_SIZE, | ||
2135 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | | ||
2136 | CRYPTO_ALG_ASYNC, | ||
2137 | .cra_type = &crypto_ahash_type | ||
2138 | } | ||
2139 | }, | ||
2140 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | | ||
2141 | DESC_HDR_SEL0_MDEUA | | ||
2142 | DESC_HDR_MODE0_MDEU_SHA1, | ||
2143 | }, | ||
2144 | { .type = CRYPTO_ALG_TYPE_AHASH, | ||
2145 | .alg.hash = { | ||
2146 | .init = ahash_init, | ||
2147 | .update = ahash_update, | ||
2148 | .final = ahash_final, | ||
2149 | .finup = ahash_finup, | ||
2150 | .digest = ahash_digest, | ||
2151 | .halg.digestsize = SHA224_DIGEST_SIZE, | ||
2152 | .halg.base = { | ||
2153 | .cra_name = "sha224", | ||
2154 | .cra_driver_name = "sha224-talitos", | ||
2155 | .cra_blocksize = SHA224_BLOCK_SIZE, | ||
2156 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | | ||
2157 | CRYPTO_ALG_ASYNC, | ||
2158 | .cra_type = &crypto_ahash_type | ||
2159 | } | ||
2160 | }, | ||
2161 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | | ||
2162 | DESC_HDR_SEL0_MDEUA | | ||
2163 | DESC_HDR_MODE0_MDEU_SHA224, | ||
2164 | }, | ||
2165 | { .type = CRYPTO_ALG_TYPE_AHASH, | ||
2166 | .alg.hash = { | ||
2167 | .init = ahash_init, | ||
2168 | .update = ahash_update, | ||
2169 | .final = ahash_final, | ||
2170 | .finup = ahash_finup, | ||
2171 | .digest = ahash_digest, | ||
2172 | .halg.digestsize = SHA256_DIGEST_SIZE, | ||
2173 | .halg.base = { | ||
2174 | .cra_name = "sha256", | ||
2175 | .cra_driver_name = "sha256-talitos", | ||
2176 | .cra_blocksize = SHA256_BLOCK_SIZE, | ||
2177 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | | ||
2178 | CRYPTO_ALG_ASYNC, | ||
2179 | .cra_type = &crypto_ahash_type | ||
2180 | } | ||
2181 | }, | ||
2182 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | | ||
2183 | DESC_HDR_SEL0_MDEUA | | ||
2184 | DESC_HDR_MODE0_MDEU_SHA256, | ||
2185 | }, | ||
2186 | { .type = CRYPTO_ALG_TYPE_AHASH, | ||
2187 | .alg.hash = { | ||
2188 | .init = ahash_init, | ||
2189 | .update = ahash_update, | ||
2190 | .final = ahash_final, | ||
2191 | .finup = ahash_finup, | ||
2192 | .digest = ahash_digest, | ||
2193 | .halg.digestsize = SHA384_DIGEST_SIZE, | ||
2194 | .halg.base = { | ||
2195 | .cra_name = "sha384", | ||
2196 | .cra_driver_name = "sha384-talitos", | ||
2197 | .cra_blocksize = SHA384_BLOCK_SIZE, | ||
2198 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | | ||
2199 | CRYPTO_ALG_ASYNC, | ||
2200 | .cra_type = &crypto_ahash_type | ||
2201 | } | ||
2202 | }, | ||
2203 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | | ||
2204 | DESC_HDR_SEL0_MDEUB | | ||
2205 | DESC_HDR_MODE0_MDEUB_SHA384, | ||
2206 | }, | ||
2207 | { .type = CRYPTO_ALG_TYPE_AHASH, | ||
2208 | .alg.hash = { | ||
2209 | .init = ahash_init, | ||
2210 | .update = ahash_update, | ||
2211 | .final = ahash_final, | ||
2212 | .finup = ahash_finup, | ||
2213 | .digest = ahash_digest, | ||
2214 | .halg.digestsize = SHA512_DIGEST_SIZE, | ||
2215 | .halg.base = { | ||
2216 | .cra_name = "sha512", | ||
2217 | .cra_driver_name = "sha512-talitos", | ||
2218 | .cra_blocksize = SHA512_BLOCK_SIZE, | ||
2219 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | | ||
2220 | CRYPTO_ALG_ASYNC, | ||
2221 | .cra_type = &crypto_ahash_type | ||
2222 | } | ||
2223 | }, | ||
2224 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | | ||
2225 | DESC_HDR_SEL0_MDEUB | | ||
2226 | DESC_HDR_MODE0_MDEUB_SHA512, | ||
2227 | }, | ||
1693 | }; | 2228 | }; |
1694 | 2229 | ||
1695 | struct talitos_crypto_alg { | 2230 | struct talitos_crypto_alg { |
1696 | struct list_head entry; | 2231 | struct list_head entry; |
1697 | struct device *dev; | 2232 | struct device *dev; |
1698 | __be32 desc_hdr_template; | 2233 | struct talitos_alg_template algt; |
1699 | struct crypto_alg crypto_alg; | ||
1700 | }; | 2234 | }; |
1701 | 2235 | ||
1702 | static int talitos_cra_init(struct crypto_tfm *tfm) | 2236 | static int talitos_cra_init(struct crypto_tfm *tfm) |
@@ -1705,13 +2239,28 @@ static int talitos_cra_init(struct crypto_tfm *tfm) | |||
1705 | struct talitos_crypto_alg *talitos_alg; | 2239 | struct talitos_crypto_alg *talitos_alg; |
1706 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); | 2240 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); |
1707 | 2241 | ||
1708 | talitos_alg = container_of(alg, struct talitos_crypto_alg, crypto_alg); | 2242 | if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_AHASH) |
2243 | talitos_alg = container_of(__crypto_ahash_alg(alg), | ||
2244 | struct talitos_crypto_alg, | ||
2245 | algt.alg.hash); | ||
2246 | else | ||
2247 | talitos_alg = container_of(alg, struct talitos_crypto_alg, | ||
2248 | algt.alg.crypto); | ||
1709 | 2249 | ||
1710 | /* update context with ptr to dev */ | 2250 | /* update context with ptr to dev */ |
1711 | ctx->dev = talitos_alg->dev; | 2251 | ctx->dev = talitos_alg->dev; |
1712 | 2252 | ||
1713 | /* copy descriptor header template value */ | 2253 | /* copy descriptor header template value */ |
1714 | ctx->desc_hdr_template = talitos_alg->desc_hdr_template; | 2254 | ctx->desc_hdr_template = talitos_alg->algt.desc_hdr_template; |
2255 | |||
2256 | return 0; | ||
2257 | } | ||
2258 | |||
2259 | static int talitos_cra_init_aead(struct crypto_tfm *tfm) | ||
2260 | { | ||
2261 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); | ||
2262 | |||
2263 | talitos_cra_init(tfm); | ||
1715 | 2264 | ||
1716 | /* random first IV */ | 2265 | /* random first IV */ |
1717 | get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH); | 2266 | get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH); |
@@ -1719,6 +2268,19 @@ static int talitos_cra_init(struct crypto_tfm *tfm) | |||
1719 | return 0; | 2268 | return 0; |
1720 | } | 2269 | } |
1721 | 2270 | ||
2271 | static int talitos_cra_init_ahash(struct crypto_tfm *tfm) | ||
2272 | { | ||
2273 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); | ||
2274 | |||
2275 | talitos_cra_init(tfm); | ||
2276 | |||
2277 | ctx->keylen = 0; | ||
2278 | crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), | ||
2279 | sizeof(struct talitos_ahash_req_ctx)); | ||
2280 | |||
2281 | return 0; | ||
2282 | } | ||
2283 | |||
1722 | /* | 2284 | /* |
1723 | * given the alg's descriptor header template, determine whether descriptor | 2285 | * given the alg's descriptor header template, determine whether descriptor |
1724 | * type and primary/secondary execution units required match the hw | 2286 | * type and primary/secondary execution units required match the hw |
@@ -1747,7 +2309,15 @@ static int talitos_remove(struct of_device *ofdev) | |||
1747 | int i; | 2309 | int i; |
1748 | 2310 | ||
1749 | list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) { | 2311 | list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) { |
1750 | crypto_unregister_alg(&t_alg->crypto_alg); | 2312 | switch (t_alg->algt.type) { |
2313 | case CRYPTO_ALG_TYPE_ABLKCIPHER: | ||
2314 | case CRYPTO_ALG_TYPE_AEAD: | ||
2315 | crypto_unregister_alg(&t_alg->algt.alg.crypto); | ||
2316 | break; | ||
2317 | case CRYPTO_ALG_TYPE_AHASH: | ||
2318 | crypto_unregister_ahash(&t_alg->algt.alg.hash); | ||
2319 | break; | ||
2320 | } | ||
1751 | list_del(&t_alg->entry); | 2321 | list_del(&t_alg->entry); |
1752 | kfree(t_alg); | 2322 | kfree(t_alg); |
1753 | } | 2323 | } |
@@ -1781,6 +2351,7 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, | |||
1781 | struct talitos_alg_template | 2351 | struct talitos_alg_template |
1782 | *template) | 2352 | *template) |
1783 | { | 2353 | { |
2354 | struct talitos_private *priv = dev_get_drvdata(dev); | ||
1784 | struct talitos_crypto_alg *t_alg; | 2355 | struct talitos_crypto_alg *t_alg; |
1785 | struct crypto_alg *alg; | 2356 | struct crypto_alg *alg; |
1786 | 2357 | ||
@@ -1788,16 +2359,36 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, | |||
1788 | if (!t_alg) | 2359 | if (!t_alg) |
1789 | return ERR_PTR(-ENOMEM); | 2360 | return ERR_PTR(-ENOMEM); |
1790 | 2361 | ||
1791 | alg = &t_alg->crypto_alg; | 2362 | t_alg->algt = *template; |
1792 | *alg = template->alg; | 2363 | |
2364 | switch (t_alg->algt.type) { | ||
2365 | case CRYPTO_ALG_TYPE_ABLKCIPHER: | ||
2366 | alg = &t_alg->algt.alg.crypto; | ||
2367 | alg->cra_init = talitos_cra_init; | ||
2368 | break; | ||
2369 | case CRYPTO_ALG_TYPE_AEAD: | ||
2370 | alg = &t_alg->algt.alg.crypto; | ||
2371 | alg->cra_init = talitos_cra_init_aead; | ||
2372 | break; | ||
2373 | case CRYPTO_ALG_TYPE_AHASH: | ||
2374 | alg = &t_alg->algt.alg.hash.halg.base; | ||
2375 | alg->cra_init = talitos_cra_init_ahash; | ||
2376 | if (!(priv->features & TALITOS_FTR_SHA224_HWINIT) && | ||
2377 | !strcmp(alg->cra_name, "sha224")) { | ||
2378 | t_alg->algt.alg.hash.init = ahash_init_sha224_swinit; | ||
2379 | t_alg->algt.desc_hdr_template = | ||
2380 | DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | | ||
2381 | DESC_HDR_SEL0_MDEUA | | ||
2382 | DESC_HDR_MODE0_MDEU_SHA256; | ||
2383 | } | ||
2384 | break; | ||
2385 | } | ||
1793 | 2386 | ||
1794 | alg->cra_module = THIS_MODULE; | 2387 | alg->cra_module = THIS_MODULE; |
1795 | alg->cra_init = talitos_cra_init; | ||
1796 | alg->cra_priority = TALITOS_CRA_PRIORITY; | 2388 | alg->cra_priority = TALITOS_CRA_PRIORITY; |
1797 | alg->cra_alignmask = 0; | 2389 | alg->cra_alignmask = 0; |
1798 | alg->cra_ctxsize = sizeof(struct talitos_ctx); | 2390 | alg->cra_ctxsize = sizeof(struct talitos_ctx); |
1799 | 2391 | ||
1800 | t_alg->desc_hdr_template = template->desc_hdr_template; | ||
1801 | t_alg->dev = dev; | 2392 | t_alg->dev = dev; |
1802 | 2393 | ||
1803 | return t_alg; | 2394 | return t_alg; |
@@ -1877,7 +2468,8 @@ static int talitos_probe(struct of_device *ofdev, | |||
1877 | priv->features |= TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT; | 2468 | priv->features |= TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT; |
1878 | 2469 | ||
1879 | if (of_device_is_compatible(np, "fsl,sec2.1")) | 2470 | if (of_device_is_compatible(np, "fsl,sec2.1")) |
1880 | priv->features |= TALITOS_FTR_HW_AUTH_CHECK; | 2471 | priv->features |= TALITOS_FTR_HW_AUTH_CHECK | |
2472 | TALITOS_FTR_SHA224_HWINIT; | ||
1881 | 2473 | ||
1882 | priv->chan = kzalloc(sizeof(struct talitos_channel) * | 2474 | priv->chan = kzalloc(sizeof(struct talitos_channel) * |
1883 | priv->num_channels, GFP_KERNEL); | 2475 | priv->num_channels, GFP_KERNEL); |
@@ -1931,6 +2523,7 @@ static int talitos_probe(struct of_device *ofdev, | |||
1931 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { | 2523 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { |
1932 | if (hw_supports(dev, driver_algs[i].desc_hdr_template)) { | 2524 | if (hw_supports(dev, driver_algs[i].desc_hdr_template)) { |
1933 | struct talitos_crypto_alg *t_alg; | 2525 | struct talitos_crypto_alg *t_alg; |
2526 | char *name = NULL; | ||
1934 | 2527 | ||
1935 | t_alg = talitos_alg_alloc(dev, &driver_algs[i]); | 2528 | t_alg = talitos_alg_alloc(dev, &driver_algs[i]); |
1936 | if (IS_ERR(t_alg)) { | 2529 | if (IS_ERR(t_alg)) { |
@@ -1938,15 +2531,27 @@ static int talitos_probe(struct of_device *ofdev, | |||
1938 | goto err_out; | 2531 | goto err_out; |
1939 | } | 2532 | } |
1940 | 2533 | ||
1941 | err = crypto_register_alg(&t_alg->crypto_alg); | 2534 | switch (t_alg->algt.type) { |
2535 | case CRYPTO_ALG_TYPE_ABLKCIPHER: | ||
2536 | case CRYPTO_ALG_TYPE_AEAD: | ||
2537 | err = crypto_register_alg( | ||
2538 | &t_alg->algt.alg.crypto); | ||
2539 | name = t_alg->algt.alg.crypto.cra_driver_name; | ||
2540 | break; | ||
2541 | case CRYPTO_ALG_TYPE_AHASH: | ||
2542 | err = crypto_register_ahash( | ||
2543 | &t_alg->algt.alg.hash); | ||
2544 | name = | ||
2545 | t_alg->algt.alg.hash.halg.base.cra_driver_name; | ||
2546 | break; | ||
2547 | } | ||
1942 | if (err) { | 2548 | if (err) { |
1943 | dev_err(dev, "%s alg registration failed\n", | 2549 | dev_err(dev, "%s alg registration failed\n", |
1944 | t_alg->crypto_alg.cra_driver_name); | 2550 | name); |
1945 | kfree(t_alg); | 2551 | kfree(t_alg); |
1946 | } else { | 2552 | } else { |
1947 | list_add_tail(&t_alg->entry, &priv->alg_list); | 2553 | list_add_tail(&t_alg->entry, &priv->alg_list); |
1948 | dev_info(dev, "%s\n", | 2554 | dev_info(dev, "%s\n", name); |
1949 | t_alg->crypto_alg.cra_driver_name); | ||
1950 | } | 2555 | } |
1951 | } | 2556 | } |
1952 | } | 2557 | } |