aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/mediatek/mtk-sha.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2020-08-28crypto: mediatek - Fix endianness bugs and sparse warningsHerbert Xu1-1/+1
This patch squashes all the sparse warnings in mediatek, some of which appear to be genuine bugs. In particular, previously on BE the keys and IVs all get 32-bit swabbed which can't be right because they don't get swabbed on LE. I presume LE is the one that actually works. Another funky thing is that the GHASH key gets swabbed on LE. This makes no sense but I'm presuming someone actually tested this on LE so I'm preserving the swabbing. Someone needs to test this though as it is entirely possible that GCM is the only thing that worked on BE but not LE. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-05-08crypto: mediatek - use crypto_shash_tfm_digest()Eric Biggers1-5/+2
Instead of manually allocating a 'struct shash_desc' on the stack and calling crypto_shash_digest(), switch to using the new helper function crypto_shash_tfm_digest() which does this for us. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-03-06crypto: Replace zero-length array with flexible-array memberGustavo A. R. Silva1-1/+1
The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] https://github.com/KSPP/linux/issues/21 [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2019-09-05crypto: mediatek - only treat EBUSY as transient if backlogRyder Lee1-1/+3
The driver was treating -EBUSY as indication of queueing to backlog without checking that backlog is enabled for the request. Fix it by checking request flags. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Vic Wu <vic.wu@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2019-06-19treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500Thomas Gleixner1-4/+1
Based on 2 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license version 2 as published by the free software foundation this program is free software you can redistribute it and or modify it under the terms of the gnu general public license version 2 as published by the free software foundation # extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 4122 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Enrico Weigelt <info@metux.net> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Allison Randal <allison@lohutok.net> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-25crypto: shash - remove shash_desc::flagsEric Biggers1-3/+0
The flags field in 'struct shash_desc' never actually does anything. The only ostensibly supported flag is CRYPTO_TFM_REQ_MAY_SLEEP. However, no shash algorithm ever sleeps, making this flag a no-op. With this being the case, inevitably some users who can't sleep wrongly pass MAY_SLEEP. These would all need to be fixed if any shash algorithm actually started sleeping. For example, the shash_ahash_*() functions, which wrap a shash algorithm with the ahash API, pass through MAY_SLEEP from the ahash API to the shash API. However, the shash functions are called under kmap_atomic(), so actually they're assumed to never sleep. Even if it turns out that some users do need preemption points while hashing large buffers, we could easily provide a helper function crypto_shash_update_large() which divides the data into smaller chunks and calls crypto_shash_update() and cond_resched() for each chunk. It's not necessary to have a flag in 'struct shash_desc', nor is it necessary to make individual shash algorithms aware of this at all. Therefore, remove shash_desc::flags, and document that the crypto_shash_*() functions can be called from any context. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-05-23crypto: mediatek - Use IPAD/OPAD constantCorentin LABBE1-2/+3
This patch simply replace all occurrence of HMAC IPAD/OPAD value by their define. Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-03-16crypto: mediatek - make hardware operation flow more efficientRyder Lee1-52/+38
This patch refines data structures, which are used to control engine's data path, to make it more efficient. Hence current change are: - gathers the broken pieces of structures 'mtk_aes_ct''mtk_aes_tfm' into struct mtk_aes_info hence avoiding additional DMA-mapping. - adds 'keymode' in struct mtk_aes_base_ctx. When .setkey() callback is called, we store keybit setting in keymode. Doing so, there is no need to check keylen second time in mtk_aes_info_init() / mtk_aes_gcm_info_init(). Besides, this patch also removes unused macro definitions and adds helper inline function to write security information(key, IV,...) to info->state. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-03-16crypto: mediatek - add queue_task taskletRyder Lee1-4/+15
This patch adds 'queue_task' to dequeue crypto requset. This will help to avoid directly calling mtk_aes_handle_queue() / mtk_sha_handle_queue() from done tasklet or error handler. In order to avoid confusion, the new code properly renames DMA completion "task" to "done_task". Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-03-16crypto: mediatek - simplify descriptor ring managementRyder Lee1-16/+19
This patch replaces cmd_pos/res_pos with pointer cmd_next/res_next. In old code, we must to add one to shift ring to the next segment, and then use this value to caculate current offset from ring base for each DMA operation. Now these pointers helps us to simplify flow, so we just need to move pointers and check the boundaries of ring. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-03-16crypto: mediatek - make mtk_sha_xmit() more genericRyder Lee1-82/+34
This is a transitional patch. It merges mtk_sha_xmit() and mtk_sha_xmit2() to make transmit function more generic. In addition, res->buf and cryp->tmp_dma in mtk_sha_xmit() are useless, since crypto engine writes the result digests into ctx->tfm.digest instead of res->buf. It's better to remove it. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-03-16crypto: mediatek - add MTK_* prefix and correct annotations.Ryder Lee1-7/+7
Dummy patch to add MTK_* prefix to ring enum and fix incorrect annotations. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-03-16crypto: mediatek - rework interrupt handlerRyder Lee1-51/+22
This patch removes redundant task that used to handle interrupt from ring manager, so that the same task/handler can be shared. It also uses aes->id and sha-id to distinguish interrupt sources. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-23crypto: mediatek - fix typo and indentationRyder Lee1-23/+17
Dummy patch to fix typo and indentation. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-23crypto: mediatek - fix incorrect data transfer resultRyder Lee1-12/+17
This patch fixes mtk_aes_xmit() data transfer bug. The original function uses the same loop and ring->pos to handle both command and result descriptors. But this produces incomplete results when src.sg_len != dst.sg_len. To solve the problem, we splits the descriptors into different loops and uses cmd_pos and res_pos to record them respectively. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-23crypto: mediatek - move HW control data to transformation contextRyder Lee1-51/+50
This patch moves hardware control block members from mtk_*_rec to transformation context and refines related definition. This makes operational context to manage its own control information easily for each DMA transfer. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-13crypto: mediatek - fix format string for 64-bit buildsArnd Bergmann1-2/+2
After I enabled COMPILE_TEST for non-ARM targets, I ran into these warnings: crypto/mediatek/mtk-aes.c: In function 'mtk_aes_info_map': crypto/mediatek/mtk-aes.c:224:28: error: format '%d' expects argument of type 'int', but argument 3 has type 'long unsigned int' [-Werror=format=] dev_err(cryp->dev, "dma %d bytes error\n", sizeof(*info)); crypto/mediatek/mtk-sha.c:344:28: error: format '%d' expects argument of type 'int', but argument 3 has type 'long unsigned int' [-Werror=format=] crypto/mediatek/mtk-sha.c:550:21: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'size_t {aka long unsigned int}' [-Werror=format=] The correct format for size_t is %zu, so use that in all three cases. Fixes: 785e5c616c84 ("crypto: mediatek - Add crypto driver support for some MediaTek chips") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-13crypto: mediatek - don't return garbage err on successful returnColin Ian King1-1/+1
In the case where keylen <= bs mtk_sha_setkey returns an uninitialized return value in err. Fix this by returning 0 instead of err. Issue detected by static analysis with cppcheck. Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2016-12-27crypto: mediatek - Add crypto driver support for some MediaTek chipsRyder Lee1-0/+1437
This adds support for the MediaTek hardware accelerator on mt7623/mt2701/mt8521p SoC. This driver currently implement: - SHA1 and SHA2 family(HMAC) hash algorithms. - AES block cipher in CBC/ECB mode with 128/196/256 bits keys. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>