Re: [Cfrg] Building a vector-input MAC by chained construction

Scott Arciszewski <scott@paragonie.com> Tue, 18 December 2018 18:57 UTC

Return-Path: <scott@paragonie.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 422E0130F33 for <cfrg@ietfa.amsl.com>; Tue, 18 Dec 2018 10:57:36 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.9
X-Spam-Level:
X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=paragonie-com.20150623.gappssmtp.com
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 aWY2NzNDU_Mw for <cfrg@ietfa.amsl.com>; Tue, 18 Dec 2018 10:57:33 -0800 (PST)
Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id A7042130F04 for <cfrg@ietf.org>; Tue, 18 Dec 2018 10:57:32 -0800 (PST)
Received: by mail-lf1-x12a.google.com with SMTP id c16so13088952lfj.8 for <cfrg@ietf.org>; Tue, 18 Dec 2018 10:57:32 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragonie-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=bemxXqBuvUzIsD9IJwIIGvG8vVVb3quodtiUXIQIn1E=; b=2NysSBqOxv6pSBZ98xUaw4w7UZWsOY5s10zqZJlCZQ+3u4iLZeiLBMsvNFIatf9fMb CwIZJ4EseNiTMUicl6sMUhegxbTBipOXYIwbidi6FBsRL5t8VKeTWAqh2JehlsgE35lt kn/L64/P466aq4HjgslG9nwTZ+8vK5b0vNICttFIrQ3U4lHXX5Ym7ASQwZJog59Rr3++ c5Xe4og5GuV8v/Ns9gj/nkWwEUEhMuTsOyN2iM6B30UFC7qKmFmM3ZdtLnNlFk3Be02R X7Ak3DPWisN3p54fQ/X0d5AIt7ueXYqxubxeEddF6PI4G01VwXWLBJr+5dFtakizDwI1 q58A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=bemxXqBuvUzIsD9IJwIIGvG8vVVb3quodtiUXIQIn1E=; b=iLHIvdWXp5ykLpflUnr1LHEt5rxaomEsYQnESoD0p0tvWISuye6u2nyMfdF7gWUV7o uqm91vcpK6tFnmNSlA/mjFQYq3pVBOeDtwswA92fv2FENyVLzUar4UFZy2yhSnyaKhuj J1QrWLkws69nqGPn5tHLJS0NDOY1bylUd3FG0IaUrurojpRJ2NtxDp6IX/BEzrXBWsLI Q+iHg0P31IDh598dCNSithH2nQsiRCufgIGtQNxme+mJr3BI9lz8YpD6W11/5fLZQmMG xYvwizjlvQzUx7Uvvxp4NHf7Tkddn/8W+gICKYA0V3wAmIT5z+Emu8hx5UdjK5G5tOKh 95bg==
X-Gm-Message-State: AA+aEWb+BvD6UQTlPfCpntlM3dU5UaruSUe57Ziyt2POb9j+QX/3Vqts 8nCXX1hEDTPgv0rW3DFmIwN1W+8uYMryNbXjBzounQ==
X-Google-Smtp-Source: AFSGD/VR8CE1Zfwan43Npg/ficXzXcppjBm3JuGhI27QMIAzi0tTJWqoFvrd8BPCdHvzNEaRlfTxki1RPjMiHu7sRv0=
X-Received: by 2002:a19:3809:: with SMTP id f9mr203774lfa.148.1545159450726; Tue, 18 Dec 2018 10:57:30 -0800 (PST)
MIME-Version: 1.0
References: <A44A80BE-030B-4D1E-9889-F727EB0BF142@gmail.com> <CACEhwkQKHkHEyLbmZ6oeDtvuvmwgifyuTUsb6Xy1CDR+4RE9PA@mail.gmail.com> <F9E1D18B-2C9E-4ED1-8F23-C25A0A8AF2C6@gmail.com>
In-Reply-To: <F9E1D18B-2C9E-4ED1-8F23-C25A0A8AF2C6@gmail.com>
From: Scott Arciszewski <scott@paragonie.com>
Date: Tue, 18 Dec 2018 13:57:17 -0500
Message-ID: <CAKws9z0qXuAqtNEMYXEbrNkXUb20pQok3jQcG90B=hxjhvxWQQ@mail.gmail.com>
To: Neil Madden <neil.e.madden@gmail.com>, cfrg@ietf.org
Content-Type: multipart/alternative; boundary="0000000000002ea837057d507816"
Archived-At: <https://mailarchive.ietf.org/arch/msg/cfrg/adn7oUW9eJgNI44Y5iMh2fv-TLA>
Subject: Re: [Cfrg] Building a vector-input MAC by chained construction
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: Tue, 18 Dec 2018 18:57:36 -0000

When designing PASETO, I specifically did something like this for feeding
data into the MAC:

function LE64(n) {
    var str = '';
    for (var i = 0; i < 8; ++i) {
        if (i === 7) {
            // Clear the MSB for interoperability
            n &= 127;
        }
        str += String.fromCharCode(n & 255);
        n = n >>> 8;
    }
    return str;
}function PAE(pieces) {
    if (!Array.isArray(pieces)) {
        throw TypeError('Expected an array.');
    }
    var count = pieces.length;
    var output = LE64(count);
    for (var i = 0; i < count; i++) {
        output += LE64(pieces[i].length);
        output += pieces[i];
    }
    return output;
}

Or, in human terms:

First, you feed in the number of pieces (little-endian, unsigned
64-bit integer).

Then, for each piece, you prefix the piece with the length of the
piece (little-endian, 64-bit integer) followed by the data.

Adopting a similar strategy may be advantageous here. (I don't think
we'll have to worry about 64-bit integer overflows in the real world
today, due to bandwidth limitations.)

Scott Arciszewski
Chief Development Officer
Paragon Initiative Enterprises <https://paragonie.com>


On Tue, Dec 18, 2018 at 1:52 PM Neil Madden <neil.e.madden@gmail.com> wrote:

> In the context of SIV, encrypting the last input prevents any further
> extension, as any extension will destroy the SIV rendering the plaintext
> undecryptable and the tag then unverifiable. You’re right that as a general
> purpose MAC it would either need to have a fixed number of inputs or else
> encode the length into the first input.
>
> — Neil
>
> On 18 Dec 2018, at 18:29, Mihir Bellare <mihir@eng.ucsd.edu> wrote:
>
> I may be missing something but this does not seem secure. Given the tag
> tag1 = MAC(key,x1) of a length-1 vector x1, we can compute the tag of the
> length-2 vector (x1,x2) as tag = MAC(tag1,x2).
>
> Mihir
>
> On Tue, Dec 18, 2018 at 8:55 AM Neil Madden <neil.e.madden@gmail.com>
> wrote:
>
>> While mulling over some ways to improve JOSE [1], I was looking at the
>> Macaroons paper [2] and realised that the chained-MAC construction they use
>> to allow new caveats to be appended to a Macaroon also serves as a way to
>> convert a normal string-input MAC into one that takes a vector of strings
>> as input instead. This is exactly what the S2V construction in AES-SIV
>> does, and most of the detail in the SIV RFC (and my internet draft
>> extending it to non-AES ciphers) is around S2V.
>>
>> The chained-MAC construction used in Macaroons is basically the
>> following. If you want to authenticate a vector of strings s[0]…s[n] with a
>> key k, you do the following:
>>
>> key = k
>> tag = null
>> for i = 0 to n:
>>     tag = MAC(key, s[i])
>>     key = tag
>> end
>>
>> That is, on each iteration you simply use the tag from the last iteration
>> as the MAC key.
>>
>> Compared to S2V, this is very easy to implement and naturally generalises
>> to different MACs (so long as the tag size is the same as the key size),
>> however it would be costly if MAC has an expensive key setup.
>>
>> Based on this observation I mocked up a variant of SIV that uses this
>> instead of S2V. The code is almost comically simple - you just perform the
>> above MAC calculation and then encrypt (in-place) the final element s[n]
>> using a stream cipher (e.g. AES-CTR or XChaCha20) using the tag as the SIV.
>>
>> The paper [3] has security proofs for this construction based on the
>> assumption that the MAC is a secure PRF (Construction 1 in section 3.1.1).
>> Based on this, my plan is to include this construction as an alternative to
>> S2V in the generalised SIV draft, unless there are strong objections.
>>
>> [1] https://neilmadden.blog/2018/12/16/simplifying-jose/
>> [2] https://ai.google/research/pubs/pub41892
>> [3] https://cs.nyu.edu/media/publications/TR2013-962.pdf
>>
>> Kind regards,
>>
>> Neil
>> _______________________________________________
>> Cfrg mailing list
>> Cfrg@irtf.org
>> https://www.irtf.org/mailman/listinfo/cfrg
>>
> _______________________________________________
> Cfrg mailing list
> Cfrg@irtf.org
> https://www.irtf.org/mailman/listinfo/cfrg
>