[Suit] Code generation from CDDL descriptions

Rønningstad, Øyvind <Oyvind.Ronningstad@nordicsemi.no> Tue, 11 February 2020 19:26 UTC

Return-Path: <Oyvind.Ronningstad@nordicsemi.no>
X-Original-To: suit@ietfa.amsl.com
Delivered-To: suit@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id BCA43120A63 for <suit@ietfa.amsl.com>; Tue, 11 Feb 2020 11:26:30 -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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=nordicsemi.onmicrosoft.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 osd2l4l-iOYZ for <suit@ietfa.amsl.com>; Tue, 11 Feb 2020 11:26:26 -0800 (PST)
Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on062e.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1e::62e]) (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 B4072120A69 for <suit@ietf.org>; Tue, 11 Feb 2020 11:26:25 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Srqz0+j0VNKbNOInaJkFo5/BDCef65C8qfV+Knd4bYE/usi+/zFqhjmd3ZP4W/UNpg9MbkfwGsvIJhBHyKPZ1AvdwwwAJFtnr+NULtQwjWNmTD7rOPo8qIeh2ZBaduE8nhAQlkzwCOHcc4SfzdJMUCRUbX6fW0nfMmCDL8ARNH17960Mxr38G7b+Dd2dllTQqv3QXctRHDlMym4apAEPmn/gTkSKyzEZ68jGzTeGrDtKco8UkDfLz+02xlEhRrx17/dtj7DIsp7yCYBSFb1WL21YYE2dHB3RwrO1SVJ5fbALdO8bpMuAoBb0Un9hIylMSBhZQBQZQUp1380bjt5FLQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6a77oFSCXs2P1fInui+kZWL+iK6RyZsnm6P/FHTTpUU=; b=SIulHZ1HeHVUNV1o5tRLoohQN2svcN2mjilow7MS7iLVkkfyhs0W5QvGNwQMks+z+kl2YgzG+y20WL7gps2/wDegtSv4Qidmkc6a1gmz+5DJMJuNSlLr+pj1YGHcYhdy1Sg9fQnmQv316Gg4PBYDSV+LUtsoBjIQIEj4uC3WUS+EIytTbt64Ao3+0UP91ePTtcrAH8UKAQRuGlpuJ1cqmRwXbOnF2MSLDe+98TKVFPP0qPifzpB2hUsnvWhFxwzukY/ETi51CoEAFh+CX0IWknadE8jlThx1BXNOIP167V1JDN4xYpVEOl0ZmbU8Ya0s0LD87RCWZ8VnJtfOM4G4uA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nordicsemi.no; dmarc=pass action=none header.from=nordicsemi.no; dkim=pass header.d=nordicsemi.no; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nordicsemi.onmicrosoft.com; s=selector2-nordicsemi-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6a77oFSCXs2P1fInui+kZWL+iK6RyZsnm6P/FHTTpUU=; b=B7l/w8XeaslJuqC44DquQyadHOK6pHdeq98lwQ+pjOuw2tk2hGSW4NzMWd3FzHGwud3YCwLryoNypo22RxlOKbPh73Vaxffa6kn4S6EmboBDpMMsD6fS18exWBDpB2FDASKhUq7HffXNX5efaXcVPeaAi823r5QQ/7rQvi+UIo4=
Received: from AM0PR05MB4339.eurprd05.prod.outlook.com (52.134.126.145) by AM0PR05MB6579.eurprd05.prod.outlook.com (20.179.36.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.28; Tue, 11 Feb 2020 19:26:21 +0000
Received: from AM0PR05MB4339.eurprd05.prod.outlook.com ([fe80::d81c:a2c8:889c:816f]) by AM0PR05MB4339.eurprd05.prod.outlook.com ([fe80::d81c:a2c8:889c:816f%7]) with mapi id 15.20.2707.030; Tue, 11 Feb 2020 19:26:21 +0000
From: =?iso-8859-1?Q?R=F8nningstad=2C_=D8yvind?= <Oyvind.Ronningstad@nordicsemi.no>
To: "suit@ietf.org" <suit@ietf.org>
Thread-Topic: Code generation from CDDL descriptions
Thread-Index: AdXhAKGtseWPUAvhTxuGUxLUSCGinw==
Date: Tue, 11 Feb 2020 19:26:21 +0000
Message-ID: <AM0PR05MB4339B8704E1792CC224FC92A88180@AM0PR05MB4339.eurprd05.prod.outlook.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
authentication-results: spf=none (sender IP is ) smtp.mailfrom=Oyvind.Ronningstad@nordicsemi.no;
x-originating-ip: [2001:8c0:5140:12:c17a:9c2:41b0:fa6e]
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: 8e1bbfb3-7a98-4218-46f9-08d7af284697
x-ms-traffictypediagnostic: AM0PR05MB6579:
x-microsoft-antispam-prvs: <AM0PR05MB65794494F5DB62F57FC55A4088180@AM0PR05MB6579.eurprd05.prod.outlook.com>
x-ms-oob-tlc-oobclassifiers: OLM:9508;
x-forefront-prvs: 0310C78181
x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(366004)(199004)(189003)(81156014)(81166006)(86362001)(6916009)(71200400001)(7696005)(8936002)(966005)(498600001)(8676002)(6506007)(55016002)(9686003)(186003)(76116006)(66946007)(66556008)(64756008)(66446008)(52536014)(5660300002)(2906002)(33656002)(66476007); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR05MB6579; H:AM0PR05MB4339.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1;
received-spf: None (protection.outlook.com: nordicsemi.no does not designate permitted sender hosts)
x-ms-exchange-senderadcheck: 1
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: RxqRlA41XGHntainurHoAg2Wd5jngqPERGSiPmgzHve6+5SbLNeCr+tMzHKHqNXZw05/kTxz1GVIIv7tZcrPpVQFKKZv9OBB4T85wDqMJZNv1IK7r2dT6W/fSFXILytxEutD8yk8U+K2aJKG7vyfio4DbYdey/yBwxL0TprsIVAScIZQrCJ5KJvQERItLZfVdEIXGZRJM9QBVoEls5fR2OLTudchMR8oGE92zWrxdmxtNlBWxlSm7CcPPZCCK/JB901/Scs73W/c1YLc1at1BwuicWz8u5YRlTZePrNN3NNfiaLCVaTNUuJ27ZZGrPqE7a9/aRVi5Duteeb8hdIdxtKCgFGZeRg9glPZBAxwruB+tgKjS5Tb3QTbQfljwXUlf6QyAX03VaaPwuuZjCGoUs4Qo2IWzAbJl+GOWFVmEiOp3e09jaIU7BeCwoyLD4g3ArxJGEYUK7devJRTjL31bF4XhiZJ1X61NLWGQpadl4x0LDd36VMJZsjYm0WCJe763PnRdEStDPpwNCJIqUo5KA==
x-ms-exchange-antispam-messagedata: U674yvDPLyfHs0juL4bqEK4jxC64VsMeWgh9foaKnJv5Libn9PnT1/hIYxpaLgtYNeC6NWEucNXL99yKjZ4HQP/kT3VuxhBsX6wzp1zF1S0PL/ycKwKNhaZ7UuJ3xNKa/3xHI4TM24qQhyYqTLCalCrYxcpCGS56VruAqnmkz3Kxg1cOc35ynF/oIQFAsf7xuQg/8gYAg7GuZaIh4FWIcw==
x-ms-exchange-transport-forked: True
Content-Type: multipart/alternative; boundary="_000_AM0PR05MB4339B8704E1792CC224FC92A88180AM0PR05MB4339eurp_"
MIME-Version: 1.0
X-OriginatorOrg: nordicsemi.no
X-MS-Exchange-CrossTenant-Network-Message-Id: 8e1bbfb3-7a98-4218-46f9-08d7af284697
X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Feb 2020 19:26:21.3066 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 28e5afa2-bf6f-419a-8cf6-b31c6e9e5e8d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: CVg06+hmSLFcFNxIzDPVcaGSosuvOXntNjFo2jjvZvWoSMe8H6upr8De3UI6NJn3Y3YtZwQHGE/Fh6M5ZbbQc2ibnmtm89DXGtQd9VQxvxjv4ko6Q6wv4k+6Wxb24kSr
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB6579
Archived-At: <https://mailarchive.ietf.org/arch/msg/suit/XeaulGQ8g7jpoOGVKrPz5Cw3YFA>
Subject: [Suit] Code generation from CDDL descriptions
X-BeenThere: suit@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Software Updates for Internet of Things <suit.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/suit>, <mailto:suit-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/suit/>
List-Post: <mailto:suit@ietf.org>
List-Help: <mailto:suit-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/suit>, <mailto:suit-request@ietf.org?subject=subscribe>
X-List-Received-Date: Tue, 11 Feb 2020 19:26:31 -0000

Hi everyone.
I've created a python script that parses CDDL descriptions and generates C code that decodes and validates CBOR against the description.
The repo is here: https://github.com/oyvindronningstad/cddl_gen
I created it with SUIT in mind, and I've added the current (not updated for -03 yet) and earlier manifest formats as test cases in https://github.com/oyvindronningstad/cddl_gen/tree/master/tests/cbor_decode.
If you want to see it in the wild, I opened a PR to MCUboot for using it in their serial recovery functionality here: https://github.com/JuulLabs-OSS/mcuboot/pull/660

Some numbers:
The MCUboot PR reduces the code size by 1100+ bytes compared to using TinyCBOR.
The current SUIT format can be completely decoded with ~7700 bytes of code, where 652 is from the handwritten library, while the rest comes from the generated code. These numbers are taken from the test case "test2_suit".
The generated code decodes the data into a struct. The OuterWrapper (containing everything, except SUIT_Command_Sequences) struct is 808 bytes, while a SUIT_Command_Sequence struct is 3684 bytes.
Remember that this is for the entire format. My thought is that a SUIT implementation will strip the CDDL to match whatever it supports.
I have not benchmarked runtime.

Any feedback, ideas, thoughts, questions are appreciated.
Thanks,
Øyvind