Re: [apps-discuss] CBOR: convert CBOR bignum to base64url JSON string

Carsten Bormann <cabo@tzi.org> Fri, 24 May 2013 06:15 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: apps-discuss@ietfa.amsl.com
Delivered-To: apps-discuss@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 2A8B021F8F1E for <apps-discuss@ietfa.amsl.com>; Thu, 23 May 2013 23:15:26 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -106.217
X-Spam-Level:
X-Spam-Status: No, score=-106.217 tagged_above=-999 required=5 tests=[AWL=0.032, BAYES_00=-2.599, HELO_EQ_DE=0.35, RCVD_IN_DNSWL_MED=-4, USER_IN_WHITELIST=-100]
Received: from mail.ietf.org ([12.22.58.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B42HtlQLlXmc for <apps-discuss@ietfa.amsl.com>; Thu, 23 May 2013 23:15:20 -0700 (PDT)
Received: from informatik.uni-bremen.de (mailhost.informatik.uni-bremen.de [IPv6:2001:638:708:30c9::12]) by ietfa.amsl.com (Postfix) with ESMTP id 02B6021F85F4 for <apps-discuss@ietf.org>; Thu, 23 May 2013 23:15:19 -0700 (PDT)
X-Virus-Scanned: amavisd-new at informatik.uni-bremen.de
Received: from smtp-fb3.informatik.uni-bremen.de (smtp-fb3.informatik.uni-bremen.de [134.102.224.120]) by informatik.uni-bremen.de (8.14.4/8.14.4) with ESMTP id r4O6FBGR017668; Fri, 24 May 2013 08:15:11 +0200 (CEST)
Received: from [192.168.217.105] (p54891C3A.dip0.t-ipconnect.de [84.137.28.58]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by smtp-fb3.informatik.uni-bremen.de (Postfix) with ESMTPSA id 289353248; Fri, 24 May 2013 08:15:11 +0200 (CEST)
Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\))
Content-Type: text/plain; charset="iso-8859-1"
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <255B9BB34FB7D647A506DC292726F6E1151A9721A1@WSMSG3153V.srv.dir.telstra.com>
Date: Fri, 24 May 2013 08:15:09 +0200
Content-Transfer-Encoding: quoted-printable
Message-Id: <F04007CB-D23F-4547-BCC4-3ED5A7F141E1@tzi.org>
References: <255B9BB34FB7D647A506DC292726F6E1151A9721A1@WSMSG3153V.srv.dir.telstra.com>
To: "Manger, James H" <James.H.Manger@team.telstra.com>
X-Mailer: Apple Mail (2.1503)
Cc: Paul Hoffman <paul.hoffman@vpnc.org>, "apps-discuss@ietf.org Discuss" <apps-discuss@ietf.org>
Subject: Re: [apps-discuss] CBOR: convert CBOR bignum to base64url JSON string
X-BeenThere: apps-discuss@ietf.org
X-Mailman-Version: 2.1.12
Precedence: list
List-Id: General discussion of application-layer protocols <apps-discuss.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/apps-discuss>, <mailto:apps-discuss-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/apps-discuss>
List-Post: <mailto:apps-discuss@ietf.org>
List-Help: <mailto:apps-discuss-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/apps-discuss>, <mailto:apps-discuss-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 24 May 2013 06:15:26 -0000

On May 24, 2013, at 02:33, "Manger, James H" <James.H.Manger@team.telstra.com> wrote:

> A minor (non-controversial?) suggested change for draft-bormann-cbor:
> 
> Section 4.1. "Converting From CBOR to JSON" 11th dot point says:
> 
>  o  A bignum (major type 7, tag value 8 or 9) becomes a JSON number.
> 
> This might be right in theory, but I don't think it is in practice.
> Presumably a bignum was used because the value (or other expected value for the same field) is too large for normal (32-bit, 64-bit) number types, which are the types many implementations use represent a JSON number. Hence they will fail with a bignum.

That is a very good point.
I haven't done a survey of JSON implementations how they handle large numbers that look like integers.
Of those for platforms that don't have bignums, I would expect many of them to create a double-precision float for large numbers.  
This doesn't fail, but loses precision.

> I suggest converting a bignum to a base64url encoding (without padding) in a JSON string. This is what you get if the positive bignum tag was ignored and you just processed the byte string that followed. For a negative bignum stick "-" before the base64url encoding.

That is certainly good advice if the bignum was, say, a value from an ECDSA signature, where losing precision destroys the utility.
Less so if it was the US national debt (well, for a few more weeks, that will still fit in a 64-bit number :-).

Right now we have limited experience what people would be using bignums for in a JSON-interfacing application.
The conversion rules we set up will shape that usage, so for me the question really is what usage of bignums do we want to encourage.
(E.g., I think it would have been a mistake to put that ECDSA signature value in a bignum in the first place.  
But X9.62 did exactly this, in ASN.1, which doesn't even have unsigned numbers.)
Outside of JSON-interfacing applications, the area of application of bignums is much clearer.

BTW, the "-" convention you propose doesn't work very well with base64url.
(This is the first example I've seen in a long while where base64 would actually work better than base64url.)
But given the semantics of the byte string in CBOR, it should be a "~" anyway, and that is free in base64url.

So how would you plan to use bignums in JSON-interfacing CBOR applications?  For crypto material like ECDSA values?

Grüße, Carsten