Re: [Cbor] draft-ietf-cbor-network-addresses: tag validity; deterministic encoding

Brian E Carpenter <brian.e.carpenter@gmail.com> Fri, 15 October 2021 04:35 UTC

Return-Path: <brian.e.carpenter@gmail.com>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id A73043A184D for <cbor@ietfa.amsl.com>; Thu, 14 Oct 2021 21:35:15 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.099
X-Spam-Level:
X-Spam-Status: No, score=-2.099 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, SPF_HELO_NONE=0.001, 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=gmail.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 eGLk4tvRwFzy for <cbor@ietfa.amsl.com>; Thu, 14 Oct 2021 21:35:10 -0700 (PDT)
Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (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 7CBB23A17B9 for <cbor@ietf.org>; Thu, 14 Oct 2021 21:35:10 -0700 (PDT)
Received: by mail-pg1-x535.google.com with SMTP id c4so445700pgv.11 for <cbor@ietf.org>; Thu, 14 Oct 2021 21:35:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=tP89SmXfrViX0+4ChqNkTb0E/+rMvkpGsWNdh0oCAhI=; b=DVthgVEWrN04OG5Q29OoBpn5kH0772y2NYmCsFapnPNN/xI4cBV+2wMAKLRRsgvp3H 98khx8bFFtxpRuEXyxHSNKwM282YmNqXrMzynK1yc59eNQDCMeXhalMUp557VzoCqXiF ycDT0InfxS/pjMcDoe69kJ/EqOdpeFXe0NujoMkDwMHJ0hOKR6CfuIV1c296xTzBLTsK J1JOecffJ7tofM1mpQZyLNmLRwC6kjgkrAp8exNBVNj0S/TkUeFiYn2ffv4M7YmTVYag Xet7N/QI6aDs+3qV/ZxMOnyMsO9od8uSQVvS5EMLgPX9CMzSv6FxDWouOv9rKCiEOcH6 rtyg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=tP89SmXfrViX0+4ChqNkTb0E/+rMvkpGsWNdh0oCAhI=; b=0PYpaEFlPJ43bmeCa0XnJmaQ50LnkX93chxExJPK3OAMbw2wv8mDVBOojHy0WQf0Of wx3UWHjuoB6ZJ6g9+pzefh1WNH71UrtVVpfYuY1XVRjJgslCV6yMkzfcLrXT0nPwejMd h8KB0PgSYdZNFS8uV94CtIfA2eLGdosPwgyuFlYx00OVhdyygnDfjFcmelyeFt62HhgI cnk4B5y8U0TbTE+6c1cCwnL0GNefiAfZwwNM3j7/xzsEw6nv4Z3D8nt0sr1lWox6Y/2t WFmC7ESzefC1RTa9LTSXx7O80n3GqubvLF6pRrMktyhKX6GSlkO4t9jfVvd8x1ROHu+/ k/iw==
X-Gm-Message-State: AOAM531z5y3sJ/LSg1KoFpBRkJlQ8tE/w6kFK53sMO9uW4x0pRRboD5q 823Qv3C0agNZxF42EEHOjbk5HaMPWL4=
X-Google-Smtp-Source: ABdhPJylW+ErWOdjrPOzjL8l+aErcQqoync+ZOdR4omLJ3ztWYmIg0zGQTpIrt6nWpyVd8UWbIq21Q==
X-Received: by 2002:a63:3548:: with SMTP id c69mr7432435pga.111.1634272508172; Thu, 14 Oct 2021 21:35:08 -0700 (PDT)
Received: from ?IPv6:2406:e003:102d:e801:db7:d041:a2d:ce65? ([2406:e003:102d:e801:db7:d041:a2d:ce65]) by smtp.gmail.com with ESMTPSA id d138sm3863863pfd.74.2021.10.14.21.35.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Oct 2021 21:35:07 -0700 (PDT)
To: Carsten Bormann <cabo@tzi.org>
Cc: cbor@ietf.org, Michael Richardson <mcr+ietf@sandelman.ca>
References: <891995AA-2854-431E-9242-98FFCDA5E161@tzi.org> <dab25fe3-43c4-865e-2c7a-54b24340c295@gmail.com> <19BCDB95-AB61-4F92-A38D-F6FD5CA8BBB1@tzi.org>
From: Brian E Carpenter <brian.e.carpenter@gmail.com>
Message-ID: <a616b11c-0fc3-436b-96b0-12a6156c37f5@gmail.com>
Date: Fri, 15 Oct 2021 17:35:02 +1300
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0
MIME-Version: 1.0
In-Reply-To: <19BCDB95-AB61-4F92-A38D-F6FD5CA8BBB1@tzi.org>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/g72zPdRWJ_eCo6SU4kwJbiTVTq0>
Subject: Re: [Cbor] draft-ietf-cbor-network-addresses: tag validity; deterministic encoding
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 15 Oct 2021 04:35:16 -0000

On 09-Oct-21 11:57, Carsten Bormann wrote:
> Hi Brian,
> 
> The weird thing about the current definition of the prefix is that trailing zero bytes are not sent, even if they are part of the prefix.
> 
>    As an example, ::/128 is encoded as	
>  		
>    54([128, h’’])
> 
> (::/128 is 16 zero bytes).
> 
> So don’t forget to zero-expand the prefix you get (which is another way to do the “recommendation”).
> 
> I’m not fluent in Python after midnight, so here’s Ruby:
> 
>    fail if prefix[-1] == “\0” # may need to check for prefix != ‘’ in your language
>    l = prefix.bytesize
>    fail if l > 16
>    prefix << “\0”.b * (16 - l)
>    [now do the trailing bit check in the document[

I was tidying up my Python code so that it would work with either the cbor or cbor2 library, and was distracted by a mysterious segfault in the Python interpreter, but only on Linux. It was a nightmare to find the offending statement because the GRASP code is threaded and gdb has no way to tell you which thread crashed.

Anyway, there was of course a user error *and* an oversight in the cbor2 library (now fixed: it wasn't reporting my user error as an exception).

So, my ugly code is in the functions build5254() and detag5254() in https://github.com/becarpenter/graspy/blob/master/pfxm4.py

   Brian

> 
> Grüße, Carsten
> 
> 
>> On 9. Oct 2021, at 00:40, Brian E Carpenter <brian.e.carpenter@gmail.com> wrote:
>>
>> On 09-Oct-21 00:52, Carsten Bormann wrote:
>>> There are various admonitions scattered in draft-ietf-cbor-network-addresses about doing the right thing when encoding and decoding the tags.
>>> We do have a concept in CBOR to handle this properly:
>>> Tag validity (Section 5.3.2 of RFC8949).
>>>
>>> In response to various observations about those admonitions during IESG 
>> processing, I went ahead and consolidated the actual content to a proper section about Tag Validity.
>>>
>>> https://github.com/cbor-wg/cbor-network-address/pull/15
>>>
>>> I also wrote:
>>>
>>>> The tag validity rules, combined with the rules in {{Section 4.2.1 of
>>>> -cbor}}, lead to deterministic encoding for tags 54 and 52 and require
>>>> no further Additional Deterministic Encoding Considerations as per
>>>> {{Section 4.2.2 of -cbor}}.
>>>
>>> … which might come in handy when deterministic encoding is actually needed.
>>>
>>> Comments welcome before we merge.
>>
>> I glanced at my Python code while checking the PR and noticed this:
>>
>>>> A recommendation for prefix decoder implementations is to first create
>>>> an array of 16 (or 4) zero bytes.
>>
>> That's exactly what I don't do in my code, although I'm sure it's exactly
>> what I would do in C. I think 'recommendation' is a bit strong.
>>
>>>> check that any unused
>>>> bits in the byte string are zero:
>>
>> I came up with this:
>>
>>    if prefix[length//8] & bytemasks[length%8][0] != prefix[length//8]:
>>        #extra bits in prefix, signal an error
>>
>> I also came up with a corner use case - suppose all I want to convey is
>> a prefix length but no prefix? At the moment, I simply send an all-zeroes
>> prefix, but those are wasted bits. Probably, this isn't worth fixing.
>>
>>   Brian
>>
>>
>>>
>>> Grüße, Carsten
>>>
>>> _______________________________________________
>>> CBOR mailing list
>>> CBOR@ietf.org
>>> https://www.ietf.org/mailman/listinfo/cbor
>