From patchwork Fri Sep 5 23:02:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 36907 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f72.google.com (mail-qg0-f72.google.com [209.85.192.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CCC2A202E4 for ; Fri, 5 Sep 2014 23:02:54 +0000 (UTC) Received: by mail-qg0-f72.google.com with SMTP id f51sf2734437qge.11 for ; Fri, 05 Sep 2014 16:02:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :mime-version:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=LzYQPl5tse51N1CMt3LvJltzJxQEp6Amy0ea3l3QF00=; b=P9brgDtAl9h48ivjuKN7age82qmvpT9rUnb5GTlU9bJ2UhuPxXU3uAOtAwn2mHIO/8 Ja8YeJarnP/95/heb4tuvTJ+d5Ea2Ry7HSFlELfhBwubXtkKa7XuGVCsK9Lu9SUU5W3M r36IaA/8mG2swktSpil79w82D/UHCvCFoeq+okiJUeBzVkrbYRHlK5wHNKSf8/WUNBmi HMoneieCOmPUfmF1vRKoYn1lL/y73BtATNgnzmASHMohvoD5whxSDsQEmgOkOR0PZYLf nskOJ+slmn9uiE6Fc1vYJmgmQFxdqsCOjDv2QiCUpFYG2JIAIxpDi4d+1sjC44b2SLtj ucgQ== X-Gm-Message-State: ALoCoQkIsIqoa1lP784wcUfUayQ+fAed9SafiqF8Pj9ob9wgVgII29iUeu+CTMCxAKRbKu/mmQQl X-Received: by 10.236.23.230 with SMTP id v66mr8790711yhv.53.1409958174681; Fri, 05 Sep 2014 16:02:54 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.100.229 with SMTP id s92ls272671qge.65.gmail; Fri, 05 Sep 2014 16:02:54 -0700 (PDT) X-Received: by 10.220.172.8 with SMTP id j8mr4050858vcz.32.1409958174618; Fri, 05 Sep 2014 16:02:54 -0700 (PDT) Received: from mail-vc0-x22b.google.com (mail-vc0-x22b.google.com [2607:f8b0:400c:c03::22b]) by mx.google.com with ESMTPS id 9si1518504vcq.96.2014.09.05.16.02.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 16:02:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22b as permitted sender) client-ip=2607:f8b0:400c:c03::22b; Received: by mail-vc0-f171.google.com with SMTP id id10so13036187vcb.2 for ; Fri, 05 Sep 2014 16:02:54 -0700 (PDT) X-Received: by 10.220.97.138 with SMTP id l10mr12810772vcn.25.1409958174527; Fri, 05 Sep 2014 16:02:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp148481vcb; Fri, 5 Sep 2014 16:02:54 -0700 (PDT) X-Received: by 10.66.220.230 with SMTP id pz6mr25772412pac.145.1409958173370; Fri, 05 Sep 2014 16:02:53 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id du1si6167959pdb.189.2014.09.05.16.02.53 for ; Fri, 05 Sep 2014 16:02:53 -0700 (PDT) Received-SPF: none (google.com: linux-crypto-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752934AbaIEXCu (ORCPT ); Fri, 5 Sep 2014 19:02:50 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:55038 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753928AbaIEXCt (ORCPT ); Fri, 5 Sep 2014 19:02:49 -0400 Received: by mail-pd0-f179.google.com with SMTP id g10so4083463pdj.38 for ; Fri, 05 Sep 2014 16:02:49 -0700 (PDT) X-Received: by 10.68.68.134 with SMTP id w6mr158339pbt.110.1409958169116; Fri, 05 Sep 2014 16:02:49 -0700 (PDT) Received: from galdor.websterwood.com (S0106dc9fdb80cffd.gv.shawcable.net. [96.50.97.138]) by mx.google.com with ESMTPSA id qc3sm2778502pab.48.2014.09.05.16.02.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Sep 2014 16:02:47 -0700 (PDT) From: behanw@converseincode.com To: davem@davemloft.net, herbert@gondor.apana.org.au Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= , Behan Webster , pageexec@freemail.hu Subject: [PATCH v2] crypto: LLVMLinux: Remove VLAIS usage from crypto/hmac.c Date: Fri, 5 Sep 2014 16:02:43 -0700 Message-Id: <1409958163-3730-1-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Original-Sender: behanw@converseincode.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22b as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@ Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Jan-Simon Möller The use of variable length arrays in structs (VLAIS) in the Linux Kernel code precludes the use of compilers which don't implement VLAIS (for instance the Clang compiler). This patch instead allocates the appropriate amount of memory using an char array. struct shash_desc contains a flexible array member member ctx declared with CRYPTO_MINALIGN_ATTR, so sizeof(struct shash_desc) aligns the beginning of the array declared after struct shash_desc with long long. No trailing padding is required because it is not a struct type that can be used in an array. The CRYPTO_MINALIGN_ATTR is required so that desc is aligned with long long as would be the case for a struct containing a member with CRYPTO_MINALIGN_ATTR. Signed-off-by: Jan-Simon Möller Signed-off-by: Behan Webster Cc: pageexec@freemail.hu --- crypto/hmac.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/crypto/hmac.c b/crypto/hmac.c index 8d9544c..f2da806 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c @@ -52,20 +52,19 @@ static int hmac_setkey(struct crypto_shash *parent, struct hmac_ctx *ctx = align_ptr(opad + ss, crypto_tfm_ctx_alignment()); struct crypto_shash *hash = ctx->hash; - struct { - struct shash_desc shash; - char ctx[crypto_shash_descsize(hash)]; - } desc; + char desc[sizeof(struct shash_desc) + + crypto_shash_descsize(hash)] CRYPTO_MINALIGN_ATTR; + struct shash_desc *shash = (struct shash_desc *)desc; unsigned int i; - desc.shash.tfm = hash; - desc.shash.flags = crypto_shash_get_flags(parent) & - CRYPTO_TFM_REQ_MAY_SLEEP; + shash->tfm = hash; + shash->flags = crypto_shash_get_flags(parent) + & CRYPTO_TFM_REQ_MAY_SLEEP; if (keylen > bs) { int err; - err = crypto_shash_digest(&desc.shash, inkey, keylen, ipad); + err = crypto_shash_digest(shash, inkey, keylen, ipad); if (err) return err; @@ -81,12 +80,12 @@ static int hmac_setkey(struct crypto_shash *parent, opad[i] ^= 0x5c; } - return crypto_shash_init(&desc.shash) ?: - crypto_shash_update(&desc.shash, ipad, bs) ?: - crypto_shash_export(&desc.shash, ipad) ?: - crypto_shash_init(&desc.shash) ?: - crypto_shash_update(&desc.shash, opad, bs) ?: - crypto_shash_export(&desc.shash, opad); + return crypto_shash_init(shash) ?: + crypto_shash_update(shash, ipad, bs) ?: + crypto_shash_export(shash, ipad) ?: + crypto_shash_init(shash) ?: + crypto_shash_update(shash, opad, bs) ?: + crypto_shash_export(shash, opad); } static int hmac_export(struct shash_desc *pdesc, void *out)