From patchwork Mon Feb 8 15:26:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyrille Pitchen X-Patchwork-Id: 8251171 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C79B4BEEE5 for ; Mon, 8 Feb 2016 15:29:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C956F2039E for ; Mon, 8 Feb 2016 15:29:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E19D1203B7 for ; Mon, 8 Feb 2016 15:29:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aSnj8-00083q-FL; Mon, 08 Feb 2016 15:27:46 +0000 Received: from eusmtp01.atmel.com ([212.144.249.242]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aSni4-0007Ad-C1 for linux-arm-kernel@lists.infradead.org; Mon, 08 Feb 2016 15:26:43 +0000 Received: from tenerife.corp.atmel.com (10.161.101.13) by eusmtp01.atmel.com (10.161.101.30) with Microsoft SMTP Server id 14.3.235.1; Mon, 8 Feb 2016 16:26:34 +0100 From: Cyrille Pitchen To: , , Subject: [PATCH 1/2] crypto: atmel-sha - fix .import()/.export() implementation Date: Mon, 8 Feb 2016 16:26:48 +0100 Message-ID: X-Mailer: git-send-email 1.8.2.2 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160208_072640_962009_63ED00A8 X-CRM114-Status: GOOD ( 11.02 ) X-Spam-Score: -4.5 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cyrille Pitchen , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using only the digest, digcnt[], bufcnt and buffer[] fields of the struct atmel_sha_reqctx was not enough to import/export the request state, so now we use the whole structure. Signed-off-by: Cyrille Pitchen --- drivers/crypto/atmel-sha.c | 44 ++++++++++---------------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c index f8407dc7dd38..7d27f96cdf02 100644 --- a/drivers/crypto/atmel-sha.c +++ b/drivers/crypto/atmel-sha.c @@ -81,16 +81,9 @@ struct atmel_sha_caps { struct atmel_sha_dev; /* - * .statesize = sizeof(struct atmel_sha_state) must be <= PAGE_SIZE / 8 as + * .statesize = sizeof(struct atmel_sha_reqctx) must be <= PAGE_SIZE / 8 as * tested by the ahash_prepare_alg() function. */ -struct atmel_sha_state { - u8 digest[SHA512_DIGEST_SIZE]; - u8 buffer[SHA_BUFFER_LEN]; - u64 digcnt[2]; - size_t bufcnt; -}; - struct atmel_sha_reqctx { struct atmel_sha_dev *dd; unsigned long flags; @@ -109,7 +102,7 @@ struct atmel_sha_reqctx { size_t block_size; - u8 buffer[0] __aligned(sizeof(u32)); + u8 buffer[SHA_BUFFER_LEN + SHA512_BLOCK_SIZE] __aligned(sizeof(u32)); }; struct atmel_sha_ctx { @@ -1048,40 +1041,23 @@ static int atmel_sha_digest(struct ahash_request *req) static int atmel_sha_export(struct ahash_request *req, void *out) { const struct atmel_sha_reqctx *ctx = ahash_request_ctx(req); - struct atmel_sha_state state; - - memcpy(state.digest, ctx->digest, SHA512_DIGEST_SIZE); - memcpy(state.buffer, ctx->buffer, ctx->bufcnt); - state.bufcnt = ctx->bufcnt; - state.digcnt[0] = ctx->digcnt[0]; - state.digcnt[1] = ctx->digcnt[1]; - /* out might be unaligned. */ - memcpy(out, &state, sizeof(state)); + memcpy(out, ctx, sizeof(*ctx)); return 0; } static int atmel_sha_import(struct ahash_request *req, const void *in) { struct atmel_sha_reqctx *ctx = ahash_request_ctx(req); - struct atmel_sha_state state; - - /* in might be unaligned. */ - memcpy(&state, in, sizeof(state)); - memcpy(ctx->digest, state.digest, SHA512_DIGEST_SIZE); - memcpy(ctx->buffer, state.buffer, state.bufcnt); - ctx->bufcnt = state.bufcnt; - ctx->digcnt[0] = state.digcnt[0]; - ctx->digcnt[1] = state.digcnt[1]; + memcpy(ctx, in, sizeof(*ctx)); return 0; } static int atmel_sha_cra_init(struct crypto_tfm *tfm) { crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), - sizeof(struct atmel_sha_reqctx) + - SHA_BUFFER_LEN + SHA512_BLOCK_SIZE); + sizeof(struct atmel_sha_reqctx)); return 0; } @@ -1097,7 +1073,7 @@ static struct ahash_alg sha_1_256_algs[] = { .import = atmel_sha_import, .halg = { .digestsize = SHA1_DIGEST_SIZE, - .statesize = sizeof(struct atmel_sha_state), + .statesize = sizeof(struct atmel_sha_reqctx), .base = { .cra_name = "sha1", .cra_driver_name = "atmel-sha1", @@ -1121,7 +1097,7 @@ static struct ahash_alg sha_1_256_algs[] = { .import = atmel_sha_import, .halg = { .digestsize = SHA256_DIGEST_SIZE, - .statesize = sizeof(struct atmel_sha_state), + .statesize = sizeof(struct atmel_sha_reqctx), .base = { .cra_name = "sha256", .cra_driver_name = "atmel-sha256", @@ -1147,7 +1123,7 @@ static struct ahash_alg sha_224_alg = { .import = atmel_sha_import, .halg = { .digestsize = SHA224_DIGEST_SIZE, - .statesize = sizeof(struct atmel_sha_state), + .statesize = sizeof(struct atmel_sha_reqctx), .base = { .cra_name = "sha224", .cra_driver_name = "atmel-sha224", @@ -1173,7 +1149,7 @@ static struct ahash_alg sha_384_512_algs[] = { .import = atmel_sha_import, .halg = { .digestsize = SHA384_DIGEST_SIZE, - .statesize = sizeof(struct atmel_sha_state), + .statesize = sizeof(struct atmel_sha_reqctx), .base = { .cra_name = "sha384", .cra_driver_name = "atmel-sha384", @@ -1197,7 +1173,7 @@ static struct ahash_alg sha_384_512_algs[] = { .import = atmel_sha_import, .halg = { .digestsize = SHA512_DIGEST_SIZE, - .statesize = sizeof(struct atmel_sha_state), + .statesize = sizeof(struct atmel_sha_reqctx), .base = { .cra_name = "sha512", .cra_driver_name = "atmel-sha512",