Re: [PATCH] crypto: talitos - fix ahash algorithms registration

2016-04-25 Thread Herbert Xu
On Thu, Apr 21, 2016 at 07:24:55PM +0300, Horia Geantă wrote:
> Provide hardware state import/export functionality, as mandated by
> commit 8996eafdcbad ("crypto: ahash - ensure statesize is non-zero")
> 
> Cc:  # 4.3+
> Reported-by: Jonas Eymann 
> Signed-off-by: Horia Geantă 

Applied to cryptodev.  As with other statesize fixes, I'd like
this to go into the next merge window.

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: talitos - fix ahash algorithms registration

2016-04-21 Thread Horia Geantă
Provide hardware state import/export functionality, as mandated by
commit 8996eafdcbad ("crypto: ahash - ensure statesize is non-zero")

Cc:  # 4.3+
Reported-by: Jonas Eymann 
Signed-off-by: Horia Geantă 
---
 drivers/crypto/talitos.c | 64 
 1 file changed, 64 insertions(+)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index aae05547b924..b7ee8d30147d 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -835,6 +835,16 @@ struct talitos_ahash_req_ctx {
struct scatterlist *psrc;
 };
 
+struct talitos_export_state {
+   u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE / sizeof(u32)];
+   u8 buf[HASH_MAX_BLOCK_SIZE];
+   unsigned int swinit;
+   unsigned int first;
+   unsigned int last;
+   unsigned int to_hash_later;
+   unsigned int nbuf;
+};
+
 static int aead_setkey(struct crypto_aead *authenc,
   const u8 *key, unsigned int keylen)
 {
@@ -1981,6 +1991,46 @@ static int ahash_digest(struct ahash_request *areq)
return ahash_process_req(areq, areq->nbytes);
 }
 
+static int ahash_export(struct ahash_request *areq, void *out)
+{
+   struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
+   struct talitos_export_state *export = out;
+
+   memcpy(export->hw_context, req_ctx->hw_context,
+  req_ctx->hw_context_size);
+   memcpy(export->buf, req_ctx->buf, req_ctx->nbuf);
+   export->swinit = req_ctx->swinit;
+   export->first = req_ctx->first;
+   export->last = req_ctx->last;
+   export->to_hash_later = req_ctx->to_hash_later;
+   export->nbuf = req_ctx->nbuf;
+
+   return 0;
+}
+
+static int ahash_import(struct ahash_request *areq, const void *in)
+{
+   struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
+   struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
+   const struct talitos_export_state *export = in;
+
+   memset(req_ctx, 0, sizeof(*req_ctx));
+   req_ctx->hw_context_size =
+   (crypto_ahash_digestsize(tfm) <= SHA256_DIGEST_SIZE)
+   ? TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256
+   : TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512;
+   memcpy(req_ctx->hw_context, export->hw_context,
+  req_ctx->hw_context_size);
+   memcpy(req_ctx->buf, export->buf, export->nbuf);
+   req_ctx->swinit = export->swinit;
+   req_ctx->first = export->first;
+   req_ctx->last = export->last;
+   req_ctx->to_hash_later = export->to_hash_later;
+   req_ctx->nbuf = export->nbuf;
+
+   return 0;
+}
+
 struct keyhash_result {
struct completion completion;
int err;
@@ -2458,6 +2508,7 @@ static struct talitos_alg_template driver_algs[] = {
{   .type = CRYPTO_ALG_TYPE_AHASH,
.alg.hash = {
.halg.digestsize = MD5_DIGEST_SIZE,
+   .halg.statesize = sizeof(struct talitos_export_state),
.halg.base = {
.cra_name = "md5",
.cra_driver_name = "md5-talitos",
@@ -2473,6 +2524,7 @@ static struct talitos_alg_template driver_algs[] = {
{   .type = CRYPTO_ALG_TYPE_AHASH,
.alg.hash = {
.halg.digestsize = SHA1_DIGEST_SIZE,
+   .halg.statesize = sizeof(struct talitos_export_state),
.halg.base = {
.cra_name = "sha1",
.cra_driver_name = "sha1-talitos",
@@ -2488,6 +2540,7 @@ static struct talitos_alg_template driver_algs[] = {
{   .type = CRYPTO_ALG_TYPE_AHASH,
.alg.hash = {
.halg.digestsize = SHA224_DIGEST_SIZE,
+   .halg.statesize = sizeof(struct talitos_export_state),
.halg.base = {
.cra_name = "sha224",
.cra_driver_name = "sha224-talitos",
@@ -2503,6 +2556,7 @@ static struct talitos_alg_template driver_algs[] = {
{   .type = CRYPTO_ALG_TYPE_AHASH,
.alg.hash = {
.halg.digestsize = SHA256_DIGEST_SIZE,
+   .halg.statesize = sizeof(struct talitos_export_state),
.halg.base = {
.cra_name = "sha256",
.cra_driver_name = "sha256-talitos",
@@ -2518,6 +2572,7 @@ static struct talitos_alg_template driver_algs[] = {
{   .type = CRYPTO_ALG_TYPE_AHASH,
.alg.hash = {
.halg.digestsize = SHA384_DIGEST_SIZE,
+   .halg.statesize = sizeof(struct talitos_export_state),
.halg.base = {
.cra_name = "sha384",