Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1349447imu; Fri, 11 Jan 2019 21:28:16 -0800 (PST) X-Google-Smtp-Source: ALg8bN7nvqhXTVCSNEF2cfsUL3eTVpaPECTu9GQmDADp0+8FeFeQUiUK2bOVpH6niAplzHWyh6ZN X-Received: by 2002:a65:5a4c:: with SMTP id z12mr15801235pgs.188.1547270896176; Fri, 11 Jan 2019 21:28:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547270896; cv=none; d=google.com; s=arc-20160816; b=NgqwUKSU0dXEr2Nh7sQByI8/aHEDUF6HE30fflgMYcIk+M1HmhdCzf9lCAJEIwcYvu t79odkl1UmsOIMFU3+wFrN7AcW/Ym33jSDxstOGm/yAOKartJpzr1RtHY2nONrmL+3jL NOvZtkUfUiG9Ih3dBJCuZWUEiM700uXVQOtMWUfX+rjY5ULybGJssIJ86zLY8RFixQ/5 Kx77b0DprtanCb0T6AB3tYgO6DkTKc+lafYI0kjZta68SUcW+4WfvLFDvabo7SCGZbG8 eXwRp82j2X+iHnZABOHlWkakeIHRSJ2+s3HTbwe83xAbds/wGY+H7b7dRixnkcSzMg5g A8bQ== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ly/zZ1yXJtGmarhquaLFw/6+JokoChGQgzP0VrxsLuU=; b=g3FtJiHK4j+j43t6jT+7zr2c1M7REtuu/gfF8obbOyEKzCAwsVTWZng3y7PN/DLnze UUME9lQQZiPmBsDJPG7t3ZIDjtbrCnzyTg+gdlI4GZVC7t7Oti4kzeSmhLSRtOwHz6RJ r06hlzjLtnmbhGOKHW1fUesKo+kuVVme7CGBJ4O8PSknxYPH1nfRbtq3HzmYopeFahRK edrfHnJrj6Jhd7bDajkjS9EQ+ebBEHt2CIKZ2N0A4TTpdlwpZlBewT2lo7O+ST6Akmnu Y9N1OjtfOCFB61T2IhlpH23T4zwu4Y11tXsEjWkKNOJ1wUePPeNX5yQ0vSnfPUvHFxGX bvGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sLG53a2O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r8si19074294plo.203.2019.01.11.21.27.57; Fri, 11 Jan 2019 21:28:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sLG53a2O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725834AbfALF0u (ORCPT + 99 others); Sat, 12 Jan 2019 00:26:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:60946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbfALF0t (ORCPT ); Sat, 12 Jan 2019 00:26:49 -0500 Received: from sol.localdomain (c-24-23-143-129.hsd1.ca.comcast.net [24.23.143.129]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7EC742084E; Sat, 12 Jan 2019 05:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547270808; bh=2Q66eYeImLrPy5L7hPfPOW9Wo2sUYqNRiLld3K786cs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sLG53a2OJXWaptFMNZG/5us+oR2pxJUD3XYr7Bc63irnhF+j7nxgj8USm0A4OQVYD tlMUZV9RCtjVVXcy5Se4seLvo6D70tCXJVqIshOHuJYFiOmYMBefA7uDOB3MmHBp5b bjw+aZ2SkUqGF7BoPH2N6/8ygVqSmFSHlvffEoLw= Date: Fri, 11 Jan 2019 21:26:46 -0800 From: Eric Biggers To: Stephan =?iso-8859-1?Q?M=FCller?= Cc: Herbert Xu , James Bottomley , Andy Lutomirski , "Lee, Chun-Yi" , "Rafael J . Wysocki" , Pavel Machek , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, keyrings@vger.kernel.org, "Rafael J. Wysocki" , Chen Yu , Oliver Neukum , Ryan Chen , David Howells , Giovanni Gherdovich , Randy Dunlap , Jann Horn , Andy Lutomirski , linux-crypto@vger.kernel.org Subject: Re: [PATCH 3/6] crypto: kdf - add known answer tests Message-ID: <20190112052645.GC639@sol.localdomain> References: <20190103143227.9138-1-jlee@suse.com> <20190109082103.GA8586@sol.localdomain> <9733066.Vrs4h5eWcW@positron.chronox.de> <8456866.1rT4qWozqf@positron.chronox.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8456866.1rT4qWozqf@positron.chronox.de> User-Agent: Mutt/1.11.2 (2019-01-07) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 11, 2019 at 08:10:22PM +0100, Stephan M?ller wrote: > Add known answer tests to the testmgr for the KDF (SP800-108) cipher. > > Signed-off-by: Stephan Mueller > --- > crypto/testmgr.c | 226 +++++++++++++++++++++++++++++++++++++++++++++++ > crypto/testmgr.h | 110 +++++++++++++++++++++++ > 2 files changed, 336 insertions(+) > > diff --git a/crypto/testmgr.c b/crypto/testmgr.c > index 0f684a414acb..ff9051bffa1f 100644 > --- a/crypto/testmgr.c > +++ b/crypto/testmgr.c > @@ -110,6 +110,11 @@ struct drbg_test_suite { > unsigned int count; > }; > > +struct kdf_test_suite { > + struct kdf_testvec *vecs; > + unsigned int count; > +}; > + > struct akcipher_test_suite { > const struct akcipher_testvec *vecs; > unsigned int count; > @@ -133,6 +138,7 @@ struct alg_test_desc { > struct hash_test_suite hash; > struct cprng_test_suite cprng; > struct drbg_test_suite drbg; > + struct kdf_test_suite kdf; > struct akcipher_test_suite akcipher; > struct kpp_test_suite kpp; > } suite; > @@ -2020,6 +2026,64 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr, > return ret; > } > > +static int kdf_cavs_test(struct kdf_testvec *test, > + const char *driver, u32 type, u32 mask) Why not just "kdf_test()"? > +{ > + int ret = -EAGAIN; > + struct crypto_rng *drng; > + unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL); s/unsigned char/u8 > + > + if (!buf) > + return -ENOMEM; > + > + drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask); > + if (IS_ERR(drng)) { > + printk(KERN_ERR "alg: kdf: could not allocate cipher handle " > + "for %s\n", driver); pr_err > + kzfree(buf); kfree is fine here. > + return -ENOMEM; > + } > + > + ret = crypto_rng_reset(drng, test->K1, test->K1len); > + if (ret) { > + printk(KERN_ERR "alg: kdf: could not set key derivation key\n"); pr_err > + goto err; > + } > + > + ret = crypto_rng_generate(drng, test->context, test->contextlen, > + buf, test->expectedlen); > + if (ret) { > + printk(KERN_ERR "alg: kdf: could not obtain key data\n"); pr_err > + goto err; > + } > + > + ret = memcmp(test->expected, buf, test->expectedlen); Elsewhere this function returns an -errno value but this is different. > + > +err: > + crypto_free_rng(drng); > + kzfree(buf); kfree would be fine here too. > + return ret; > +} > + > +static int alg_test_kdf(const struct alg_test_desc *desc, const char *driver, > + u32 type, u32 mask) > +{ > + int err = 0; > + unsigned int i = 0; > + struct kdf_testvec *template = desc->suite.kdf.vecs; const - Eric