Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp939958ybi; Wed, 3 Jul 2019 06:58:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqKTv49gh9oGOIjOi3cm/ENOIARE57eWrm08V993ixI2ThbdHucR9DkJEz3PeJ7+388CMj X-Received: by 2002:a17:90a:9a8d:: with SMTP id e13mr13172248pjp.77.1562162306238; Wed, 03 Jul 2019 06:58:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562162306; cv=none; d=google.com; s=arc-20160816; b=pSFo9qUheHMrjjjJVWRUhaY1zHYWsKsSC4dkgFu0XPjZoWthme1G7CJNfonyCXR8G3 rTlk80TRG2nuTcGWMr09G27aJwC1wL33+nPn2crYdsVT7+US+5tMvFQtrqv6Il26MEUV +/ZI+BL7B/3rsDJX+nxPGSujL6K/kFZL1EqIS3Jj5Qps5DbhGCAYRDaMYSkdA2K8Gad1 rLJo9NBJnCwS1XvDkWs3CxQXkJ1HN8M4cbIl1y4qKf38IBCppzqCn+hUjRIxx4x4Fpy+ 9lPMR5hmw7VUzuhHgAkchhfsbK2C9qfWf0MEhwtCisSFo3Ui+VQN90Lsi8orWNSFvnPW m48Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=lHUQHLvcL/C/Rdmf6+uHKZX7Xh9HWGoiUmm5Y+xDAyc=; b=YWZxO6bPKX+e7eqDNNw14wB1ZAx1tqGNBr60D8GIQqUz/K0pQcWEP7nsKYmgV9ihjL /RN05l7PQWS4icLsHsJDHFVIYiVYzu/Q9+02bT/eJHQohYPmAKRsyevudQoN/tvjkCeY nGreSUuWAssvYyKp4aaTL+Me8bOZjFRY2VXq12mUVAfwQpIx4UR1qFU86qiq+FsyTNzX btpPX6ePNqqHAdtLY9nSCWsaInL4Tll0HSOPskfEvk/IgcKf96JcCt/Q5oPztDGStaVF B5q/NXZQEfRGTM0oMZecU1pSC51ZW+wc04KueG2aL1RQ1zVznRZs1EmaThMnPzhck8Yo rcXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i95si2236070plb.106.2019.07.03.06.58.11; Wed, 03 Jul 2019 06:58:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725944AbfGCN4h (ORCPT + 99 others); Wed, 3 Jul 2019 09:56:37 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:50868 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725830AbfGCN4h (ORCPT ); Wed, 3 Jul 2019 09:56:37 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1hifkR-0008Bz-RW; Wed, 03 Jul 2019 21:56:35 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1hifkO-0003w3-IT; Wed, 03 Jul 2019 21:56:32 +0800 Date: Wed, 3 Jul 2019 21:56:32 +0800 From: Herbert Xu To: Ard Biesheuvel Cc: linux-crypto@vger.kernel.org, ebiggers@kernel.org, horia.geanta@nxp.com Subject: Re: [PATCH v3 27/30] crypto: des - split off DES library from generic DES cipher driver Message-ID: <20190703135632.cizz77mr7ur3tii7@gondor.apana.org.au> References: <20190628093529.12281-1-ard.biesheuvel@linaro.org> <20190628093529.12281-28-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190628093529.12281-28-ard.biesheuvel@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Jun 28, 2019 at 11:35:26AM +0200, Ard Biesheuvel wrote: > > static int des_setkey(struct crypto_tfm *tfm, const u8 *key, > unsigned int keylen) > { > struct des_ctx *dctx = crypto_tfm_ctx(tfm); > - u32 *flags = &tfm->crt_flags; > - u32 tmp[DES_EXPKEY_WORDS]; > - int ret; > - > - /* Expand to tmp */ > - ret = des_ekey(tmp, key); > + int err; > > - if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { > - *flags |= CRYPTO_TFM_RES_WEAK_KEY; > - return -EINVAL; > + err = des_expand_key(dctx, key, keylen); > + if (err == -ENOKEY) { > + if (crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) > + err = -EINVAL; > + else > + err = 0; > } > > - /* Copy to output */ > - memcpy(dctx->expkey, tmp, sizeof(dctx->expkey)); > - > - return 0; > + if (err) { > + memzero_explicit(dctx, sizeof(*dctx)); This should use memset as it's not a stack location. Ditto with the 3DES version below. It may not look like a big deal but we sometimes get bogus patches that convert such memsets to memzeros and being consistent with our own usage might discourage them. Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt