Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752195AbdHBODW (ORCPT ); Wed, 2 Aug 2017 10:03:22 -0400 Received: from mail-ve1eur01on0049.outbound.protection.outlook.com ([104.47.1.49]:49424 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752006AbdHBODT (ORCPT ); Wed, 2 Aug 2017 10:03:19 -0400 From: =?iso-8859-2?Q?Horia_Geant=E3?= To: Harald Freudenberger , Oleksij Rempel CC: Herbert Xu , "linux-kernel@vger.kernel.org" , Oleksij Rempel , "Dan Douglass" , "linux-crypto@vger.kernel.org" , "kernel@pengutronix.de" , Martin Schwidefsky , "David S. Miller" Subject: Re: [PATCH v1] crypto: caam - set hwrng quality level Thread-Topic: [PATCH v1] crypto: caam - set hwrng quality level Thread-Index: AQHTAGL5pmG33iaaT0uDieR7tYnZTg== Date: Wed, 2 Aug 2017 14:03:14 +0000 Message-ID: References: <20170719074458.9247-1-o.rempel@pengutronix.de> <20170719163248.sn7mvnq2s3fm2hvh@pengutronix.de> <20170719181303.rj4fyjj7qplatrzk@pengutronix.de> <4e42d639-9f83-dcbb-9a2a-91686656c7dd@linux.vnet.ibm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=horia.geanta@nxp.com; x-originating-ip: [192.88.146.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR0401MB2624;7:x3px2KpU0I5uj/yd2pXaL9PhhuYQ3N4HO4kjY5twdzPjI5UUy34/Z1RIRB+Npm931aZyqPI3kCon6LLIHPvLPFWDS74BZxh/beh2ynGoouTqctWbGV0wRSU5AYvRO6C9KD3iLejF28HWi81eYJMb9v30yCDFdPawnt7pMnqxgZKaUzGfrQ9L0FItDOYn3jpvcXI2WrSbam8mYUQxPVVnjFnNnB8xxuqvLb3e0EOW4nQgZXjo7vZeM1qs8IE2iBeIpzr7tF65HspupGeOfQ55yvEHNytfrswtjOWHZFuXeIZ3fM5iRSaVsmNVmPVArQu6yV1kJjJZ+u7K32eGE9tuizv1QIuEsBVnMwO/X9y9InFVaBM8foZgjDtzZjtDqstzM5GK/KD83ayIk4MKfQMdcOM0wkg4iwX2g1oUZ1A4Yb2BSri1GfF+++9G3wqa9DXDiyR9ohH05OzkY65luytELPGZzdviH0NmfD8fuBMeetVND8KvRhbXbMFMEOe6QhxNd0bpFHBu/R0zy2zYuIZhNm1Duh9Q+r3fvY/dCmA45zjpS7c33iOUGBynVT6elY/Wk+j9+FXwzs9/9qBRcTRa3pbaZitQptQz5bWUYBZR/KcvScldOhwtmC2IMYTCmElyRGYANTxX6CHASBlj9FyKHMY1s3Va6ZkocM7XZY9AkOKT5iCp8y201cRmhjgs9TfJ2CAEoKrxEAkUDzDa/4ZOaDejfIXwywF6o2OO3k67Rqf5E/kx2ZBOPRDgkuFDOcolvpXog5S2Yx+H93kqc+WonR7C/XwIjiRICUDd2hWFthU= x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10009020)(6009001)(39860400002)(39450400003)(39840400002)(39400400002)(39850400002)(39410400002)(199003)(377454003)(189002)(24454002)(9686003)(6436002)(6246003)(81166006)(81156014)(3660700001)(4326008)(6506006)(5250100002)(74316002)(33656002)(2900100001)(3280700002)(68736007)(7736002)(229853002)(189998001)(8936002)(53546010)(305945005)(105586002)(93886004)(5660300001)(102836003)(3846002)(38730400002)(478600001)(76176999)(50986999)(54906002)(54356999)(14454004)(6306002)(25786009)(66066001)(53936002)(97736004)(106356001)(6116002)(2906002)(7696004)(101416001)(55016002)(966005)(8676002)(99286003)(575784001)(86362001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0401MB2624;H:VI1PR0401MB2591.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; x-ms-office365-filtering-correlation-id: 69ee15d0-51cd-45c7-dfba-08d4d9af37f9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:VI1PR0401MB2624; x-ms-traffictypediagnostic: VI1PR0401MB2624: x-exchange-antispam-report-test: UriScan:; x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123558100)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:VI1PR0401MB2624;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:VI1PR0401MB2624; x-forefront-prvs: 0387D64A71 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-2" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Aug 2017 14:03:14.5990 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2624 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v72E3SVS026080 Content-Length: 4542 Lines: 106 On 7/20/2017 4:08 PM, Harald Freudenberger wrote: > On 07/19/2017 08:13 PM, Oleksij Rempel wrote: >> On Wed, Jul 19, 2017 at 04:53:21PM +0000, Horia Geant? wrote: >>> On 7/19/2017 7:32 PM, Oleksij Rempel wrote: >>>> On Wed, Jul 19, 2017 at 12:49:47PM +0000, Horia Geant? wrote: >>>>> On 7/19/2017 10:45 AM, Oleksij Rempel wrote: >>>>>> According documentation, it is NIST certified TRNG. >>>>>> So, set high quality to let the HWRNG framework automatically use it. >>>>>> >>>>>> Signed-off-by: Oleksij Rempel >>>>>> --- >>>>>> drivers/crypto/caam/caamrng.c | 6 ++++++ >>>>>> 1 file changed, 6 insertions(+) >>>>>> >>>>>> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c >>>>>> index 41398da3edf4..684c0bc88dfd 100644 >>>>>> --- a/drivers/crypto/caam/caamrng.c >>>>>> +++ b/drivers/crypto/caam/caamrng.c >>>>>> @@ -292,10 +292,16 @@ static int caam_init_rng(struct caam_rng_ctx *ctx, struct device *jrdev) >>>>>> return 0; >>>>>> } >>>>>> >>>>>> +/* >>>>>> + * hwrng register struct >>>>>> + * The trng is suppost to have 100% entropy, and thus >>>>>> + * we register with a very high quality value. >>>>>> + */ >>>>>> static struct hwrng caam_rng = { >>>>>> .name = "rng-caam", >>>>>> .cleanup = caam_cleanup, >>>>>> .read = caam_read, >>>>>> + .quality = 999, >>>>> Why not 1024, i.e. where is 999 coming from? >>>> It comes from s390-trng.c driver. >>>> Should I use 1024 instead? >>>> >>> AFAICT the range for quality is from 0 to 1024 (no entropy -> perfect >>> entropy). >>> >>> 1024 should be used since I'd expect a HW TRNG to provide perfect >>> entropy unless otherwise stated. >> I assume 1024 can be given only on verified HW with accessible verilog >> files and compared with resulting chip :) >> May be this would be a good example https://www.sifive.com/ >> > Well, the header file says: > ... > /** > * struct hwrng - Hardware Random Number Generator driver > * @name: Unique RNG name. > * @init: Initialization callback (can be NULL). > * @cleanup: Cleanup callback (can be NULL). > * @data_present: Callback to determine if data is available > * on the RNG. If NULL, it is assumed that > * there is always data available. *OBSOLETE* > * @data_read: Read data from the RNG device. > * Returns the number of lower random bytes in "data". > * Must not be NULL. *OBSOLETE* > * @read: New API. drivers can fill up to max bytes of data > * into the buffer. The buffer is aligned for any type > * and max is a multiple of 4 and >= 32 bytes. > * @priv: Private data, for use by the RNG driver. > * @quality: Estimation of true entropy in RNG's bitstream > * (per mill). > */ > ... > quality = estimation of true entropy per mill. "per mill as in https://en.wikipedia.org/wiki/Mill_(currency) ? I consider it rather unfortunate, as already noticed here: https://lkml.org/lkml/2014/3/27/210 And isn't this inaccurate, since the (de)rating factor is quality/1024, not quality/1000? > I understand this as quality=1000 meaning 100% entropy. > However, the core code currently does not really check this value. > When more than one hwrng sources do register, simple the one with > the higher quality value wins :-) The value is not even checked > to be in a given range. > > I searched through some device drivers which do register at > the hwrng and it looks like most of the drivers do not even > set this value. My feeling is, you should use 999 when your Maybe this is because it's not clear how to determine quality's value? Take CAAM's engine HWRNG: it can work both as a TRNG and as a TRNG-seeded DRBG (that's how it's currently configured). IIUC, both setups are fit as source for the entropy pool. Do I have to set quality value comparing the two cases? (It's a bit like comparing the quality of entropy offered by RDSEED vs. RDRAND.) Meaning: give full credit - maximum quality - for the TRNG setup, and provide a lower value for quality in the case of TRNG-seeded DRBG? > hardware provides 'perfect' random. So there is a chance for > an even 'more perfect' hardware coming up later to overrule > your 'perfect' hardware. I am not sure why the hwrng with the best quality wins, instead of using all available resources, as suggested here: https://lkml.org/lkml/2014/3/27/210 Thanks, Horia