Re: [Cfrg] Poly1305 and timing attacks

Watson Ladd <watsonbladd@gmail.com> Mon, 10 March 2014 15:44 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 2889F1A049E for <cfrg@ietfa.amsl.com>; Mon, 10 Mar 2014 08:44:15 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2
X-Spam-Level:
X-Spam-Status: No, score=-2 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, SPF_PASS=-0.001] autolearn=ham
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 eNUB04boZzoh for <cfrg@ietfa.amsl.com>; Mon, 10 Mar 2014 08:44:13 -0700 (PDT)
Received: from mail-yk0-x230.google.com (mail-yk0-x230.google.com [IPv6:2607:f8b0:4002:c07::230]) by ietfa.amsl.com (Postfix) with ESMTP id CE0661A049C for <cfrg@irtf.org>; Mon, 10 Mar 2014 08:44:12 -0700 (PDT)
Received: by mail-yk0-f176.google.com with SMTP id 19so19576580ykq.7 for <cfrg@irtf.org>; Mon, 10 Mar 2014 08:44:07 -0700 (PDT)
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 :cc:content-type:content-transfer-encoding; bh=z5kWXCTQCUoLFgXxwh469+NcnzaP/egSZ4Xhka/cGJI=; b=p0DzOpeijPwKl/5zjVxZnx+Fig9iDa6PmRbHbrV/ZptrevDSAtatiUr6G6iPInJ4IL BjlN9qVdPyDdqSCpLy6244Oo0Xz8cFH5ttKgooAul3cyRtAQQebFhj6p46VneJ1XOjvM ItOBxzK0oz3nDXZ8PCejO0rFvEEtgQUr1i5PIkBn3avcFq+YKtk1fRWvKIFGUEN9w0AN H/5Obbk3o2Qj0tiJtj7Idxc0GTUR9CEFT6BhJPpQW5xXpspLrEjRXx5tYhzhgMp3EHyn b2MCciDS4/DfKXN9GQo31437ZBiQa1n4juuu9Ta4acEXNUr4oh8S8kaTo3LiYryglURD +gvQ==
MIME-Version: 1.0
X-Received: by 10.236.90.12 with SMTP id d12mr2676489yhf.120.1394466247265; Mon, 10 Mar 2014 08:44:07 -0700 (PDT)
Received: by 10.170.80.214 with HTTP; Mon, 10 Mar 2014 08:44:07 -0700 (PDT)
In-Reply-To: <CAGvU-a4m+ZVw6Gsq-_hPX_aLTajKkHD31G++otx5B-xu1vJ78g@mail.gmail.com>
References: <CAGvU-a7Mpn9Wrie=QEftsZrojQAcwysnQgNt5BOjdr8ZRY08Zg@mail.gmail.com> <CACsn0ckrTB37jB4Apj7GxAZUjou_=RUj7j4dgFeWpqxS4HKq6Q@mail.gmail.com> <CA0A4F63-89AB-4AC2-8955-E3C575E3B01C@gmail.com> <CACsn0cmNA15ZM9S2s73oTtKGH5SujSef9_3ez12jzg934HW9ow@mail.gmail.com> <CAGvU-a4m+ZVw6Gsq-_hPX_aLTajKkHD31G++otx5B-xu1vJ78g@mail.gmail.com>
Date: Mon, 10 Mar 2014 08:44:07 -0700
Message-ID: <CACsn0cm+Ab5tzEt5zHKmypCa9rH0WD36jp5yaEaNC2asEYnQsg@mail.gmail.com>
From: Watson Ladd <watsonbladd@gmail.com>
To: Yoav Nir <ynir.ietf@gmail.com>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Archived-At: http://mailarchive.ietf.org/arch/msg/cfrg/sE3gEK0Fyrow84oV2WZiUQCClOo
Cc: "cfrg@irtf.org" <cfrg@irtf.org>
Subject: Re: [Cfrg] Poly1305 and timing attacks
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: Mon, 10 Mar 2014 15:44:15 -0000

On Mon, Mar 10, 2014 at 6:19 AM, Yoav Nir <ynir.ietf@gmail.com> wrote:
>
>
>
> On Mon, Mar 10, 2014 at 12:48 AM, Watson Ladd <watsonbladd@gmail.com> wrote:
>>
>> On Sun, Mar 9, 2014 at 3:00 PM, Yoav Nir <ynir.ietf@gmail.com> wrote:
>> >
>> > On Mar 9, 2014, at 6:45 PM, Watson Ladd <watsonbladd@gmail.com> wrote:
>> <snipped agreement>
>> >
>> >> For Poly1305 as used in this draft, I am very, very hesitant about
>> >> approving any draft that says not-constant time is okay. However, if
>> >> the entire keys are being generated pseudorandomly, then I think, if
>> >> the side channel isn't gratuitously large, it's possibly safe. Saying
>> >> anything more concrete would require a lot of painful analysis of what
>> >> is leaked and how it can be used.
>> >>
>> >> Personally, I don't understand why making the crypto not constant
>> >> time, and thus open to attacks, simplifies the security
>> >> considerations. It might make the job of the implementor easier, but
>> >> it makes the job of the person who builds on top harder.
>> >
>> > It makes the security considerations simpler because it makes all the
>> > talk about constant time implementations go away and eliminates the need for
>> > pointing people at how to accomplish this. I agree I probably can’t do this,
>> > as this implementation might later be used as part of a library for other
>> > things. It’s not generally good to instruct people on how to make an
>> > implementation with a warning label (that they will later ignore).
>>
>> Well, I have to fundamentally disagree with this. A constant-time,
>> constant-memory access, constant-control flow implementation is far
>> more reassuring than one which doesn't have these properties.
>
>
> Hey, no need to pile it on. You've already convinced me that the text needs
> to stay.

Ah, I was disagreeing with the claim that this makes "security
considerations simpler". But yes, I think we are in agreement.

>
> Do you have a reference I can point to on how to make the Poly1305
> calculations constant-time?

Yes, DJB's Poly1305-AES paper. But that uses the FPU heavily: It uses
2^26 as a base, taking advantage of the mantissa being 2^53 bits, and
uses special rounding instructions for carries. This is because the
integer multiplier on 32 bit Intels had issues.

In assembler one can use saturated word arithmetic, taking care to
avoid data dependent loops. Barrett reduction always involves a
maximum of three reductions, so you write a constant time
reduce_if_necessary function, and apply to the product during the
cleanup. But this isn't the fastest. It's a small modification to the
usual method.

On a 64-bit machine 5 limbs of 26 bits, base 2^26 works fine. One does
the addition, with no need to reduce as the limbs grow to only 27
bits, then does the multiplication, getting 10 44 bit limbs. These
represent a number at most 2^262, so after carrying the top limb is a
maximum of 28 bits. Using the fact that we are modulo 2^130-5, limb 6
is multiplied by 5 and added to limb 1 and so on. Finally a carry
chain is used, and some analysis has to be done to see if you reduce
back to something you can add again. This still might not be optimal:
I've skimmed over the multiplication, and the carry chain can be
tricky.

On a 32-bit machine I'm not sure what one does. There are a lot of
options, but I don't know which is best.

As a sidenote blinding is just too slow: it doubles the number of
multiplications that have to be done. It's also not clear that it can
eliminate the side channel because you need to operate on two values,
not just one.

Sincerely,
Watson Ladd