Re: [Cfrg] Recommended bit length before truncating a hash mod p

Ilari Liusvaara <ilariliusvaara@welho.com> Sat, 06 April 2019 17:47 UTC

Return-Path: <ilariliusvaara@welho.com>
X-Original-To: cfrg@ietfa.amsl.com
Delivered-To: cfrg@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id EBA771201E7 for <cfrg@ietfa.amsl.com>; Sat, 6 Apr 2019 10:47:31 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.6
X-Spam-Level:
X-Spam-Status: No, score=-2.6 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c0V_p7l-NijW for <cfrg@ietfa.amsl.com>; Sat, 6 Apr 2019 10:47:29 -0700 (PDT)
Received: from welho-filter3.welho.com (welho-filter3.welho.com [83.102.41.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 539FF1201A9 for <cfrg@irtf.org>; Sat, 6 Apr 2019 10:47:28 -0700 (PDT)
Received: from localhost (localhost [127.0.0.1]) by welho-filter3.welho.com (Postfix) with ESMTP id 11A2AB903; Sat, 6 Apr 2019 20:47:26 +0300 (EEST)
X-Virus-Scanned: Debian amavisd-new at pp.htv.fi
Received: from welho-smtp1.welho.com ([IPv6:::ffff:83.102.41.84]) by localhost (welho-filter3.welho.com [::ffff:83.102.41.25]) (amavisd-new, port 10024) with ESMTP id FdiMCUVmwpA1; Sat, 6 Apr 2019 20:47:25 +0300 (EEST)
Received: from LK-Perkele-VII (87-92-19-27.bb.dnainternet.fi [87.92.19.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by welho-smtp1.welho.com (Postfix) with ESMTPSA id 0EE8A292; Sat, 6 Apr 2019 20:47:21 +0300 (EEST)
Date: Sat, 06 Apr 2019 20:47:21 +0300
From: Ilari Liusvaara <ilariliusvaara@welho.com>
To: Michele Orrù <lists@tumbolandia.net>
Cc: cfrg@irtf.org, Anita DURR <anita.durr@psl.eu>
Message-ID: <20190406174721.GA108882@LK-Perkele-VII>
References: <1853a156-df76-7999-df2b-1ea120a85b40@tumbolandia.net>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <1853a156-df76-7999-df2b-1ea120a85b40@tumbolandia.net>
User-Agent: Mutt/1.10.1 (2018-07-13)
Sender: ilariliusvaara@welho.com
Archived-At: <https://mailarchive.ietf.org/arch/msg/cfrg/YZBusc2PngCg2XfzJKXEVFzGNIA>
Subject: Re: [Cfrg] Recommended bit length before truncating a hash mod p
X-BeenThere: cfrg@irtf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Crypto Forum Research Group <cfrg.irtf.org>
List-Unsubscribe: <https://www.irtf.org/mailman/options/cfrg>, <mailto:cfrg-request@irtf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cfrg/>
List-Post: <mailto:cfrg@irtf.org>
List-Help: <mailto:cfrg-request@irtf.org?subject=help>
List-Subscribe: <https://www.irtf.org/mailman/listinfo/cfrg>, <mailto:cfrg-request@irtf.org?subject=subscribe>
X-List-Received-Date: Sat, 06 Apr 2019 17:47:32 -0000

On Tue, Apr 02, 2019 at 10:07:13AM +0200, Michele Orrù wrote:
> 
> Together with Anita (in Cc.) we independently thought that the draft could
> be a bit more precise about how many bits to take before reducing mod p.
> More specifically, the sentence:
> 
> ```
> To address this, our hash2base algorithm greedily takes as many bits as
> possible before reducing mod p, in order to smooth out this bias. This is
> preferable to an iterated procedure, such as rejection sampling, since this
> can be hard to reliably implement in constant time.
> ```
> 
> is imprecise: a developer should know exactly how many bits to add (for the
> current security level) in order to have a distribution indistinguishable
> from uniformly random mod p. Taking into account what has been said so far,
> we would like to change the above sentence to:
> 
> ```
> In order to smooth out this bias, our hash2base algorithm takes 64 +
> floor(log2(p)) + 1 bits in order to smooth out this bias. This is preferable
> to an iterated procedure, such as rejection sampling, since this can be hard
> to reliably implement in constant time.
> ```
> 
> This should at least give an intuition that adding 64 bits makes the
> difference of the two distributions statistically negligible.
> What do you think? Is this relevant?

In fact, the uniformity can heavily depend on p. Any p very close to
power of two gives very uniform results. And one needs lots of extra
bits to increase the uniformity further.

Looking at Curve25519, Curve448 and NIST P-384, the SD is <2^-200 and
that won't bulge with 64 extra bits.

NIST P-256 has much bigger base SD (~2^-32), and that starts to move
with ~30 extra bits. 64 extra bits seems to decrease SD by factor of
~2^64.



-Ilari