Re: ssh-ed25519 implementations

Ron Frederick <ronf@timeheart.net> Mon, 15 May 2017 08:47 UTC

Return-Path: <bounces-ietf-ssh-owner-secsh-tyoxbijeg7-archive=lists.ietf.org@NetBSD.org>
X-Original-To: ietfarch-secsh-tyoxbijeg7-archive@ietfa.amsl.com
Delivered-To: ietfarch-secsh-tyoxbijeg7-archive@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 46675129C1E for <ietfarch-secsh-tyoxbijeg7-archive@ietfa.amsl.com>; Mon, 15 May 2017 01:47:20 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -4.09
X-Spam-Level:
X-Spam-Status: No, score=-4.09 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_MED=-2.3, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, T_DKIM_INVALID=0.01] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=fail (1024-bit key) reason="fail (body has been altered)" header.d=timeheart.net
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 mA0DZeu8GX8B for <ietfarch-secsh-tyoxbijeg7-archive@ietfa.amsl.com>; Mon, 15 May 2017 01:47:17 -0700 (PDT)
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id EF038126BF7 for <secsh-tyoxbijeg7-archive@lists.ietf.org>; Mon, 15 May 2017 01:43:42 -0700 (PDT)
Received: by mail.netbsd.org (Postfix, from userid 605) id 818AF85691; Mon, 15 May 2017 08:43:40 +0000 (UTC)
Delivered-To: ietf-ssh@netbsd.org
Received: by mail.netbsd.org (Postfix, from userid 1347) id 1DFB884DED; Mon, 15 May 2017 08:43:40 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id B5ACF84DC2 for <ietf-ssh@netbsd.org>; Sun, 14 May 2017 15:27:20 +0000 (UTC)
X-Virus-Scanned: amavisd-new at netbsd.org
Authentication-Results: mail.netbsd.org (amavisd-new); dkim=pass (1024-bit key) header.d=timeheart.net
Received: from mail.netbsd.org ([127.0.0.1]) by localhost (mail.netbsd.org [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id KcqHdIhZnXLv for <ietf-ssh@netbsd.org>; Sun, 14 May 2017 15:27:19 +0000 (UTC)
Received: from mail-pg0-x235.google.com (mail-pg0-x235.google.com [IPv6:2607:f8b0:400e:c05::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.netbsd.org (Postfix) with ESMTPS id 35C9984CFB for <ietf-ssh@netbsd.org>; Sun, 14 May 2017 15:27:17 +0000 (UTC)
Received: by mail-pg0-x235.google.com with SMTP id q125so29656448pgq.2 for <ietf-ssh@netbsd.org>; Sun, 14 May 2017 08:27:17 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=timeheart.net; s=mail; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=m6rRm15QzwLidRjMCvmY4pK8hiF+yBPYStqSQfgQDK8=; b=Ckmi3gmcXWEaWzpGiH8cKr0BvqR9plR2unjwtoEX07pXx0HgSsoo2UWin3A6M+lHw3 CXXHpwWaB8SukeqdDn4RiLJsRfT5lSprLEEJ1QPRqnn+Wu4/9C1I6qGm4mdkOnugO5Lo L1bDfQgafPJkEDdxM/YL6CSxkJjB576P/9o7U=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=m6rRm15QzwLidRjMCvmY4pK8hiF+yBPYStqSQfgQDK8=; b=T0IhbNjNphPp9Hb9JzfKf3ZlByls963WT2k5VWYwuhmcBYAxBe2fex+17z4gAfJKOz fZ/GYY5jShyQqGWrAH7smggYpCDQAP2nfxgHkruS6nzUN7FN4DTt76/5s6h58wmj8BLr sBjNgcTLX6MSFVO4xcnuTpjE+lYG/5+ilcURr75yp4b7eUkn6qo8OwPmqgmoxjSKNSQ8 4NGJsd9lO98sm6VnbExb2l3M+P+0SG7Bktk2sxkg0j8CPDQSPVOg21UTx+7xPYK1RNnQ ltWdGJu0nU+AFJ/3ly5B+UJKFMezqoauWZTumGEM7vx4E5qhmFYChC37/vkr+ARu6H0t FAIQ==
X-Gm-Message-State: AODbwcBdkTYvEUEgLe6TIZdCvjAdsUv2HZf4BABytaRehHRPFX2qFWiu vciXEEwhbhFwOw==
X-Received: by 10.98.245.155 with SMTP id b27mr1807355pfm.181.1494775637137; Sun, 14 May 2017 08:27:17 -0700 (PDT)
Received: from ?IPv6:2601:647:4282:2200:cfa:5497:d692:7eeb? ([2601:647:4282:2200:cfa:5497:d692:7eeb]) by smtp.gmail.com with ESMTPSA id i68sm14236597pfi.72.2017.05.14.08.27.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 May 2017 08:27:16 -0700 (PDT)
From: Ron Frederick <ronf@timeheart.net>
Message-Id: <BE48CE40-3E26-4F7D-9101-A3D0CC453C17@timeheart.net>
Content-Type: multipart/alternative; boundary="Apple-Mail=_C0F4140A-D4BE-4544-A79C-AAB8E8EEC1A8"
Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\))
Subject: Re: ssh-ed25519 implementations
Date: Sun, 14 May 2017 08:27:14 -0700
In-Reply-To: <74670.1494687062@eng-mail01.juniper.net>
Cc: Eric Rescorla <ekr@rtfm.com>, Brian Smith <brian@briansmith.org>, denis bider <denisbider.ietf@gmail.com>, Simon Tatham <anakin@pobox.com>, "ietf-ssh@NetBSD.org" <ietf-ssh@NetBSD.org>, "curdle@ietf.org" <curdle@ietf.org>
To: "Mark D. Baushke" <mdb@juniper.net>
References: <76FD0F39-1F3D-4476-A3D8-D4C942C2EFD1@juniper.net> <CABcZeBNYUV=-azoZzZjnNtCEu3K0A-THHN2mt02V65oihbbrXw@mail.gmail.com> <36528.1494509552@eng-mail01.juniper.net> <6047C877-67DE-404F-8FBD-5B2C19D16EA6@timeheart.net> <1139.1494566512@eng-mail01.juniper.net> <336063E0-135F-4A75-94E4-71540669E21A@timeheart.net> <74670.1494687062@eng-mail01.juniper.net>
X-Mailer: Apple Mail (2.3273)
Sender: ietf-ssh-owner@NetBSD.org
List-Id: ietf-ssh.NetBSD.org
Precedence: list
List-Unsubscribe: <mailto:majordomo@NetBSD.org?subject=Unsubscribe%20ietf-ssh&body=unsubscribe%20ietf-ssh>

Hi Mark,

On May 13, 2017, at 7:51 AM, Mark D. Baushke <mdb@juniper.net> wrote:
> I have made some adjustments. Here is a unified diff of the relevant
> changes to the .txt form of the draft. If the pseudo-code looks bad,
> let me know if I should just remove it or not.

I would lean toward removing the pseudo-code, and just letting RFC 4251 and the examples provided in section 5 there speak for themselves. If you do that, you probably don’t even need to describe the details of how to encode the length. All I was really looking for here is a mention that the length is present after the conversion, since you had so much detail about the conversion of the integer itself. However, if you just reference this encoding mechanism you may be fine without it. You could replace the second and third paragraphs below with:

The integer K is then encoded as an mpint using the process described in section 5 of [RFC451] and the resulting bytes are fed as described in [RFC4253] to the key exchange method’s hash function to generate encryption keys.


> --- draft-ietf-curdle-ssh-curves-05.txt	2017-05-11 11:58:23.000000000 -0700
> +++ draft-ietf-curdle-ssh-curves-06.txt	2017-05-13 07:46:54.000000000 -0700
> @@ -140,47 +140,64 @@
>    only to be applicable to the scope of the mechanism described in this
>    document.
> 
> -   The shared secret, K, is defined in [RFC4253] as a multiple precision
> -   integer (mpint).  Curve25519/448 outputs a binary string X, which is
> -   the 32 or 56 byte point obtained by scalar multiplication of the
> -   other side's public key and the local private key scalar.  The 32 or
> -   56 bytes of X are converted into K by interpreting the bytes as an
> -   unsigned fixed-length integer encoded in network byte order.  This
> -   conversion follows the normal "mpint" process as described in section
> -   5 of [RFC4251].
> +   The shared secret, K, is defined in [RFC4253] and [RFC5656] as an
> +   integer encoded as a multiple precision integer (mpint).
> +   Curve25519/448 outputs a binary string X, which is the 32 or 56 byte
> +   point obtained by scalar multiplication of the other side's public
> +   key and the local private key scalar.  The 32 or 56 bytes of X are
> +   converted into K by interpreting the octets as an unsigned fixed-
> +   length integer encoded in network byte order.
> +
> +   The fixed-length integer is then minimized into the minimum number of
> +   octets to represent a positve mpint.  This conversion follows the
> +   normal "mpint" process as described in section 5 of [RFC4251] which
> +   requires that unnecessary leading bytes with the value 0 MUST NOT be
> +   included.  The length of the integer is then prepended with a 4 octet
> +   big-endian integer which is the length in octets of the minimized K.
> +
> +   The mpint K is then fed along with other data to the key exchange
> +   method's hash function to generate encryption keys.
> 
>    To clarify a corner-case in this conversion, when X is encoded as an
>    mpint K, in order to calculate the exchange hash, it may vary as
>    follows:
> 
> -   o  Trim all leading zero-bytes of X.  If X is all zero-bytes, then
> -      the key exchange MUST fail.
> -
> -   o  If the high bit of X is set, the mpint format requires a zero byte
> -      to be prepended.
> -
> -   o  The length of the encoded K may not be the same as the original
> -      length of X due to trimming or prepending zero-bytes as needed for
> -      "mpint" format.
> 
> -   Or, as pseudo code:
> +   o  Trim all leading zero-bytes of X, as required in section 5 of
> +      [RFC4251].  If X is all zero-bytes, then the key exchange MUST
> +      fail as required in section 6 of [RFC7748].
> +
> +   o  Given X is a positive, if the MSB of X is set, then the "mpint"
> +      format requires a zero-byte to be prepended.
> +
> +   o  The length of the "mpint" form of K may not be the same as the
> +      original length of X due to trimming or prepending zero-byte
> +      values as needed for "mpint" format. prepend K with the big-endian
> +      number of octets for the length of K.
> +
> +   Or, as pseudo code (without dealing with side-channel issues):
> 
>                  k := x;
> -                 while (k.length() > 0 && k[0] == 0) k = k[1:];
> +                 while (k.length() > 0 && k[0] == 0) k := k[1:];
>                  assert(k.length() > 0);
> -                 if 0 != (k[0] & 0x80) k = '\0' .. k;
> +                 if 0 != (k[0] & 0x80) k := '\0' .. k;
> +                 l[0] := k.lengh() >> 24;
> +                 l[1] := (k.lengh() >> 16) & 0xff;
> +                 l[2] := (k.lengh() >> 8) & 0xff;
> +                 l[3] := k.lengh() & 0xff;
> +                 k := l .. k;
> 
>                                  Figure 1
> 
>    When performing the X25519 or X448 operations, the integer values
> -   there will be encoded into byte strings by doing a fix-length
> +   there will be encoded into byte strings by doing a fixed-length
>    unsigned litle-endian conversion, per [RFC7748].  It is only later
>    when these byte strings are then passed to the ECDH code in SSH that
>    the bytes are re-interpreted as a fixed-length unsigned big-endian

-- 
Ron Frederick
ronf@timeheart.net