Re: [Cfrg] draft-irtf-cfrg-eddsa - more implementation questions

Mike Hamburg <mike@shiftleft.org> Mon, 11 July 2016 19:25 UTC

Return-Path: <mike@shiftleft.org>
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 30DF512D1A6 for <cfrg@ietfa.amsl.com>; Mon, 11 Jul 2016 12:25:47 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -3.288
X-Spam-Level:
X-Spam-Status: No, score=-3.288 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=0.001, RP_MATCHES_RCVD=-1.287, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=shiftleft.org
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 BjhMfNtBSPOx for <cfrg@ietfa.amsl.com>; Mon, 11 Jul 2016 12:25:45 -0700 (PDT)
Received: from astral.shiftleft.org (vpn.shiftleft.org [52.40.228.30]) by ietfa.amsl.com (Postfix) with ESMTP id 86CC112D099 for <cfrg@ietf.org>; Mon, 11 Jul 2016 12:25:45 -0700 (PDT)
Received: from [10.184.148.249] (unknown [209.36.6.242]) (Authenticated sender: mike) by astral.shiftleft.org (Postfix) with ESMTPSA id 66599A418A; Mon, 11 Jul 2016 12:25:43 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shiftleft.org; s=sldo; t=1468265143; bh=57XDU9979fPK1ta4Tczb42v3YZ0t3RwdkqCx1P5nkGo=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=MQ0dTWrt8XsRA/1mrmTzTZygtFamY+qH+WL7wERgVvA7RKzstGnzE1XnaMkbRzWPU QVrCHG3pvBBlr7p1ByhxSSyFrIn3YWFtIpFyBY7fwupc2dQWCUAkMvmHM5FLD1cJNT b8f/rIVuwTLTnPfFrMbttWbVfS4NyuU0gX8MXsdQ=
Content-Type: multipart/alternative; boundary="Apple-Mail=_25B696BD-6A18-42E3-8810-6ED244579B8C"
Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\))
From: Mike Hamburg <mike@shiftleft.org>
In-Reply-To: <011701d1dba4$242c0840$6c8418c0$@augustcellars.com>
Date: Mon, 11 Jul 2016 12:25:43 -0700
Message-Id: <34FC4763-3995-490C-9842-3A7B4B97A2A5@shiftleft.org>
References: <008901d1db7b$ab86bed0$02943c70$@augustcellars.com> <84618BCB-35C7-4978-8F75-7FEE4B137A9F@shiftleft.org> <011701d1dba4$242c0840$6c8418c0$@augustcellars.com>
To: Jim Schaad <ietf@augustcellars.com>
X-Mailer: Apple Mail (2.3124)
X-Virus-Scanned: clamav-milter 0.99 at astral
X-Virus-Status: Clean
Archived-At: <https://mailarchive.ietf.org/arch/msg/cfrg/uIHY4VTojO3ONzabxPkzWj1tyWE>
Resent-From: alias-bounces@ietf.org
Resent-To: <>
Cc: cfrg@ietf.org
Subject: Re: [Cfrg] draft-irtf-cfrg-eddsa - more implementation questions
X-BeenThere: cfrg@irtf.org
X-Mailman-Version: 2.1.17
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: Mon, 11 Jul 2016 19:25:47 -0000

> On Jul 11, 2016, at 11:43 AM, Jim Schaad <ietf@augustcellars.com> wrote:
> 
> 
> 
>> -----Original Message-----
>> From: Cfrg [mailto:cfrg-bounces@irtf.org] On Behalf Of Mike Hamburg
>> Sent: Monday, July 11, 2016 11:14 AM
>> To: Jim Schaad <ietf@augustcellars.com>
>> Cc: cfrg@ietf.org; draft-irtf-cfrg-eddsa@tools.ietf.org
>> Subject: Re: [Cfrg] draft-irtf-cfrg-eddsa - more implementation questions
>> 
>> 
>>> On Jul 11, 2016, at 6:53 AM, Jim Schaad <ietf@augustcellars.com> wrote:
>>> 
>>> In step #3 of the verify function, I assume that I can reduce k mod p
>>> without any problems.   Can I reduce it mod L or not?  It would be useful to
>>> have the hint in the text since it is all over the Sign algorithm.
>> 
>> Good idea; we should add that hint to the spec.
>> 
>> You can’t reduce it mod p.  You can and should reduce it mod L (aka q), at least
>> for the non-strict verification formula.
>> 
>> For the strict verification formula, it may be better to reduce mod hL, where h=8
>> or 4 for ed25519 and ed448 respectively.  This doesn’t affect the usual notion of
>> security, but reducing mod hL will give you the same answer as not reducing,
>> and reducing mod L will sometimes change whether a maliciously-crafted
>> signature validates or not.
>> Since the spec doesn’t say you may reduce mod L, you probably shouldn’t.  But
>> the easier solution is not to use the strict formula.
>> 
>>> I have been using the python program to help debug my quick
>>> implementation of the signature algorithm.  This has worked up to the
>>> point of trying to decode points as the python code does not use the
>>> suggested formula in section 5.1.3 (use this trick) but instead just
>>> directly computes a square root on the base formula.
>>> 
>>> I am therefore unable to determine where my bug is:  In my code, in
>>> the formula, or in how I read the formula.  It might be worthwhile to
>>> actually implement this algorithm for computing square roots if that
>>> is what is suggested.
>> 
>> How are you implementing the division and square root?  The code for square
>> root looks almost the same as the trick anyway, so you could just switch it over.
> 
> Probably because the document implies that one should in order to avoid the double modular exponentiation.

I agree that the python code could stand some improvement.  It should probably also use pow() instead of implementing exponentiation itself.

I believe that the formula given for sqrt(u/v) is correct, but it really should be given as x = u * (uv)^((p-5)/8) and then the same adjustment stpes, because that’s simpler and also correct.  Also, it should be implemented in the Python code.

Likewise, the formula for ed448 in 5.2.3 is correct, but should be replaced by x = u * (uv)^((p-3)/4) with the same adjustment steps.

> 
>> 
>>> By the way, I finally found were the neutral point was defined.  You
>>> still might want to highlight it as part of the point addition sections.
>>> 
>>> Looking at the python code, I think I see the trick you are using to
>>> deal with step 1 in the decoding code for removing the x_0 bit but it
>>> could be highlighted that it is being done in the field parsing
>>> function rather than the decoding function.
>> 
>> It’s being done in decode_base, right?
> 
> No 
>        xs=s[(b-1)//8]>>((b-1)&7)
> 
> obtains the value of x_0, however it does not remove it from the array s, that is being done in frombytes (I think).
> 
> jim

Ah, OK.  Another place where the python should be simplified.

— Mike