Re: [Cfrg] Comments on side channel draft

Watson Ladd <watsonbladd@gmail.com> Wed, 08 January 2014 00:21 UTC

Return-Path: <watsonbladd@gmail.com>
X-Original-To: cfrg@ietfa.amsl.com
Delivered-To: cfrg@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 6FA7C1AE256 for <cfrg@ietfa.amsl.com>; Tue, 7 Jan 2014 16:21:51 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.7
X-Spam-Level:
X-Spam-Status: No, score=-1.7 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, MIME_8BIT_HEADER=0.3, SPF_PASS=-0.001] autolearn=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 qd2d13qbSLMk for <cfrg@ietfa.amsl.com>; Tue, 7 Jan 2014 16:21:49 -0800 (PST)
Received: from mail-wg0-x22d.google.com (mail-wg0-x22d.google.com [IPv6:2a00:1450:400c:c00::22d]) by ietfa.amsl.com (Postfix) with ESMTP id 807481AE257 for <cfrg@irtf.org>; Tue, 7 Jan 2014 16:21:48 -0800 (PST)
Received: by mail-wg0-f45.google.com with SMTP id y10so839409wgg.12 for <cfrg@irtf.org>; Tue, 07 Jan 2014 16:21:39 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=l47Vz+xifZLEZ+zuhcgjaVCsJSbuOyyP7eOoAsrP+FM=; b=tCupSz+sbxANQ8ltx599RsWM2nhkIW7Bjes/gq+TrTIRIl0VYnoRe9hlqj21Fcrmgf niBQ4nBxJX6yV8iBgi3cNG+QgFvbsD4wAAVqw6sG+WlEQc+DvPkH934DSXKiYn8ROlgP GK6u2LnvCfhCVAMvySFKMq94QyJLtXq9hImLJobUHoezpiobRPmU12QIMI9lB/qZcoId TeY62apb0OqgCAVSJMbOPJJMhyFpsVYH0SCoGb1Hb9AetZYEW2FkO7JFBguDZdFS/zOP r4DbSSz3Fcftk/Y4ZQ9utGrJWSwt7v62hljcffuxQyg6tTKMWjPTnUotaz338sR2TQgk tUIw==
MIME-Version: 1.0
X-Received: by 10.194.175.66 with SMTP id by2mr8434252wjc.59.1389140499146; Tue, 07 Jan 2014 16:21:39 -0800 (PST)
Received: by 10.194.242.131 with HTTP; Tue, 7 Jan 2014 16:21:39 -0800 (PST)
In-Reply-To: <52CC82A6.5010806@elzevir.fr>
References: <52CBFBFF.5090602@elzevir.fr> <52CC82A6.5010806@elzevir.fr>
Date: Tue, 7 Jan 2014 16:21:39 -0800
Message-ID: <CACsn0cmt3EOiJp4Hmqp6SC+Fj1ZJ-WtmjBJn0apOpVv+RpNu6w@mail.gmail.com>
From: Watson Ladd <watsonbladd@gmail.com>
To: =?UTF-8?Q?Manuel_P=C3=A9gouri=C3=A9=2DGonnard?= <mpg@elzevir.fr>, "cfrg@irtf.org" <cfrg@irtf.org>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Subject: Re: [Cfrg] Comments on side channel draft
X-BeenThere: cfrg@irtf.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Crypto Forum Research Group <cfrg.irtf.org>
List-Unsubscribe: <http://www.irtf.org/mailman/options/cfrg>, <mailto:cfrg-request@irtf.org?subject=unsubscribe>
List-Archive: <http://www.irtf.org/mail-archive/web/cfrg/>
List-Post: <mailto:cfrg@irtf.org>
List-Help: <mailto:cfrg-request@irtf.org?subject=help>
List-Subscribe: <http://www.irtf.org/mailman/listinfo/cfrg>, <mailto:cfrg-request@irtf.org?subject=subscribe>
X-List-Received-Date: Wed, 08 Jan 2014 00:21:51 -0000

On Tue, Jan 7, 2014 at 2:41 PM, Manuel Pégourié-Gonnard <mpg@elzevir.fr> wrote:
> Hi,
>
> Since I received a notification from gmail that my email was rejected due to
> being considered spam, and I know mailman is sometimes configured to avoid
> sending copies of messages when people are cc'ed, I'm now re-sending this (using
> a different SMTP server) in case you didn't receive the first copy.
>
> If this is a duplicate, please ignore it.
>
> Manuel.

Sorry to everyone whose threading gets busted because of this gmail issue.

>
>
> -------- Original Message --------
> Subject: Re: [Cfrg] Comments on side channel draft
> Date: Tue, 07 Jan 2014 14:07:11 +0100
> From: Manuel Pégourié-Gonnard <mpg@elzevir.fr>
> To: Watson Ladd <watsonbladd@gmail.com>om>, "cfrg@irtf.org" <cfrg@irtf.org>
>
> Hi Watson,
>
> On 06/01/2014 22:03, Watson Ladd wrote:
>> http://datatracker.ietf.org/doc/draft-ladd-sidechannel/
>>
> A few comments:
>
> 1. Concerning the attack model:
>
>    In certain scenarios the power generated by individual operations can
>    be effectively measured. This is a very difficult setting to work in,
>    and will not be considered further in this document. But if someone
>    leaves a multimeter in your machine room, watch out!
>
> I think the draft might mention that sometimes (smartcards, etc.) the
> attacker may also be able to inject faults at specific times, which is
> also a very difficult setting to work in, and will not be considered
> further in this document. For example, the counter-measure you mention
> later:

Good idea!

>
>            Alternatively one uses a standard radix-k multiplication, but
>    to load an entry from the table one reads through the entire table,
>    using the following conditional load code:
>
>       c=c*bit+a*(1-bit)
>
>    or some varation thereof.
>
> is susceptible to a fault attack: if the attacker causes a corruption
> when we're reading one entry, the result of the operation will be
> incorrect if and only if it was the entry we're actually using, which
> reveals bits of the exponents. Of course, in most circumstances the
> attackers doesn't have this level of physical access, so this
> counter-measure is indeed useful as it protects against attacks that
> require a lesser level of access.
>
> 2. Concerning modular inverses:
>
>                                       Modular inverses should always be
>    computed through exponentiation: if this is not possible the binary
>    Euclidean algorithm should be run for a constant number of steps,
>    calculated as the number for the worst case. (For reference, the
>    worst case is two consecutive Fibonacci numbers)
>
> Do you mean to imply that blinding isn't an option here? I may be
> mistaken, but I think the following should be OK for computing x^{-1}
> mod n:
>
>     r = random(1.. n-1);
>     xb = x * r;
>     xib = inv_mov(xb, n); // using non-constant time Euclidean algorithm
>     xi = xib * r;
>
> (Well, that's assuming n is prime. Otherwise the first line should be
> replaced with "pick r uniformly at random in (Z/nZ)*" obviously.) This
> is particularly convenient if x happens to be already randomized.

Blinding is my second choice compared to constant time. The reason is
that blinding might not work perfectly, whereas circuit-like programs have
no timing sidechannels by definition.

>
> 3. Concerning ladders, it might seem obvious, but it is probably useful
> to mention explicitly that the number of iterations must be fixed
> (that is, it must not depend on the most significant bit of the scalar).

Another good point.
>
> 4. A totally minor point:
>
>                              Freely usable implementations taking these
>    precautions exist for P224, P256, Curve25519, Curve3617, and some
>    GLS/GLV curves with endomorphisms.
>
> I didn't look at it very closely, but it seems to me that the 64-bits
> implementation of P521 in Openssl (crypto/ec/ecp_nistp521.c) qualifies
> too.

Thanks for the pointer.

>
> 5. A more general question: I wonder if it could be appropriate to add,
> in an appendix, examples of real code in C and/or other languages for
> a reliable constant-time way to implement some common operations, as it
> is not always clear what is constant-time.
>
> For example, see the discussion in section 4 of this blog article [1].
> The author basically argues that C code such as 'a = (b == c);' hides a
> branch. According to my experiments, this is not true with recent
> compilers for the x86 plaftorm (they will use the SETcc instruction
> rather than a conditional jump, probably because conditional jumps are
> bad for performance, but in this case it happens to be good for us).
>
> [1]: http://rdist.root.org/2010/01/07/timing-independent-array-comparison/
>
> I did not test (yet) on other platforms and/or with other compilers, so it
> might indeed be true that 'a = (b == c);' hides a branch on some
> platforms with some compilers. It would be great for developpers to have
> a central, reliable source of information about such things, rather than
> having to test themselves, and maybe an appendix in this draft could be
> a good place for that.

The problem is that one really cannot tell what does and does not
contain jumps without looking
at the assembler output. Mix in the different compilers,
architectures, and compiler options, and this
is far, far too much work for me to reasonably do.

Even integer division is not constant time on some CPU families.

I'll wait two weeks for more comments, and then post an updated draft.
Sincerely,
Watson Ladd
>
> Manuel.
> _______________________________________________
> Cfrg mailing list
> Cfrg@irtf.org
> http://www.irtf.org/mailman/listinfo/cfrg
>
>



-- 
"Those who would give up Essential Liberty to purchase a little
Temporary Safety deserve neither  Liberty nor Safety."
-- Benjamin Franklin