[core] bMAC draft for constraint nodes

Pascal Urien <pascal.urien@gmail.com> Mon, 11 November 2019 19:41 UTC

Return-Path: <pascal.urien@gmail.com>
X-Original-To: core@ietfa.amsl.com
Delivered-To: core@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 74EE71208A9 for <core@ietfa.amsl.com>; Mon, 11 Nov 2019 11:41:43 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.998
X-Spam-Level:
X-Spam-Status: No, score=-1.998 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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 19-_5ClRdi2W for <core@ietfa.amsl.com>; Mon, 11 Nov 2019 11:41:41 -0800 (PST)
Received: from mail-vs1-xe2d.google.com (mail-vs1-xe2d.google.com [IPv6:2607:f8b0:4864:20::e2d]) (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 084A4120024 for <core@ietf.org>; Mon, 11 Nov 2019 11:41:32 -0800 (PST)
Received: by mail-vs1-xe2d.google.com with SMTP id m6so9142694vsn.13 for <core@ietf.org>; Mon, 11 Nov 2019 11:41:31 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=n676DJmbbxtWx8cJLgntdwmWkKYWooHf+kokyrHN3IU=; b=hLs8Msf3gL0d7hRTE/MdHHepBZ+Cyfa1qxW9cTCALde4G6SBQBfwBCJwhC9zZc//8e IlViVQoMU7fHfFdzOXtSR6qEsXd59Rpab3KkGFTDUixqfQNE90i4xM1iq0FSQSV2z0oY 4eykRnTinKtpASbYM63b36Ye5PJWtxoUkC/QKiQhgEPtBNCryX4nqX5+OMmM2USpqQX6 LmSPmOMSC9lBk9ZZ7gfIA2zuJrLSOOxanrJIrSMXFXLEhJ3lEWodMailz6To6e6KY/Ag TN/tep1R5kzMd0ajsun51mkK3G6AXxW24HeDzYj6441x/ikzAl3hvbqAGRBgjFDJDJd1 atRw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=n676DJmbbxtWx8cJLgntdwmWkKYWooHf+kokyrHN3IU=; b=KzZtjKYRIyziBPzV0z+mc7F6NQFxWIxIjeRb1XIl0IElOliIiDJ3O8wsz3hUigVXS1 pJe+Ce01zjGixQ9oonqsx7HTeWLoeyP07cl+T4j4hnMSZnXwP3UA5NdDxjtdF7AvZHgI NtsxbPJJnffThexg3qkqCwqvq2Xx2vgs92TA31iIp3TnpH0d0bKruB7QbJGryTcPPpAj cSrQbELJ3a5d2cYRuF0CkaJb1UmhKmAqmWPdjDyoh3oHZJDo8Kn8E8CYapNAhXLQdnMO +wqiOHbq6IhT+KBt0HbfDJgGISkvwwFYttpk0EDSaFz+aDT1+qR7HlX7veffXslvEApf A8vA==
X-Gm-Message-State: APjAAAVRW36BWKtMGbowyhADctY680yFFQWGh5Rzxxh+D2rmJCQCC6/P qlmZrtpXvVLTI+NxaVHJOSJi+e1FgvQFdQrfMtztypGo4DI=
X-Google-Smtp-Source: APXvYqwQPK1KBGvGPE3PurZ8WnsXOXSC4Lfb98jWQdHUrbQn5nf3wAWcy9WWpESF1KXW0GvzCPGrrrXlLyyMKD7BwCE=
X-Received: by 2002:a05:6102:75c:: with SMTP id v28mr8695302vsg.146.1573501290604; Mon, 11 Nov 2019 11:41:30 -0800 (PST)
MIME-Version: 1.0
From: Pascal Urien <pascal.urien@gmail.com>
Date: Mon, 11 Nov 2019 20:41:19 +0100
Message-ID: <CAEQGKXShH21bg84J1gR2OyqTfGgZ73KV50qn_YqOSwh6zxLjTQ@mail.gmail.com>
To: core <core@ietf.org>
Content-Type: multipart/alternative; boundary="0000000000007aee3f0597175180"
Archived-At: <https://mailarchive.ietf.org/arch/msg/core/TIKxB1jeiXqeoI9RASXmJS8CS9s>
Subject: [core] bMAC draft for constraint nodes
X-BeenThere: core@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Constrained RESTful Environments \(CoRE\) Working Group list" <core.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/core>, <mailto:core-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/core/>
List-Post: <mailto:core@ietf.org>
List-Help: <mailto:core-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/core>, <mailto:core-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 11 Nov 2019 19:41:43 -0000

More details in https://tools.ietf.org/html/draft-urien-core-bmac-00

The goal of the bijective MAC (bMAC) is to compute an integrity value,
which cannot be guessed by off-line malicious software.
For classical keyed MACs, MAC is computed according to a fixed order. In
the bijective MAC, the content of N addresses (A[0]...A[N-1]) (N = #FLASH+
#SRAM…) is hashed according to a hash function H and a permutation P (i.e.
bijective application in [0,N-1]) so that :
bMAC(A, P) = H( A[P(0)] || A[P(1)] ... || A[P(N-1)]
The bMAC key is the permutation P. The number of permutations for N
addresses is N!, as an illustration 35! is greater than 2**128. So the
computation of the bMAC requires the knowledge of the whole memory; this is
trivial for genuine software, but it may be very difficult for corrupted
software.
Why is it difficult for a malicious software to compute bMAC?. Because it
must maintains a copy of the original software, what can be impossible if
the whole memory space is required for bMAC computation, especially in
harward architecture.
We build permutations in [1,q-1], with q prime, q being greater than N+1.
In Z/pZ, numbers prime with p-1 are called generators (gi), i.e. gi**x with
x in [1,q-1] is a permutation in [1,q-1]; so there are phi(p-1) generators
phi being the Euler number. This entropy may be increased by the
composition of multiple permutations, for example P(s2,g2,s1,g1)(x) =
s2.(g2 ** (s1.g1**x)) with s1, s2 in [q-1] and g1,g2 generators.
If the memory size is less than 2**16 calculations work with 32 bits
numbers; if the memory size is less than 2**32, calculations work with 64
bits numbers. For example with 8 bits (AVR) processors and clock in 12/16
MHz range the computing time (for P(s2,g2,s1,g1) is about 1ms/byte.

Here is a simple code for bMAC calculation. H is a SHA3-256 KECCAK hash
function, the address space is N= 9664, the prime number q is 9733. With a
8 bits processor, 12MHz clock, the bMAC is computed in about 10s, i.e. 1ms
per byte. Computations are performed with 32 bits numbers.

uint32-t x,y,bitn,v,gi[13];
uint32-t PRIME, g1=a-generator, s1=a-value, g2=a-generator;
bool tohash;

PRIME =9733;
H.reset();

gi[0]= g2;
for (int n=1;n<=13;n++)
gi[n] = (gi[n-1] * gi[n-1]) % PRIME;

x= s1;

for(int i=1;i<PRIME;i++)
  { tohash = false
    x = (x*g1) % PRIME;
    bitn=x;
    y=1;
    for (int n=1;n<=14;n++)
    { if ( (bitn & 0x1) == 0x1)  y = (y*gi[n-1]) % PRIME;
      bitn = bitn >>1;
    }
    v = (y-1);
    // if address v exists, read the v address content A(v)
    // tohash=true ;
    if (tohash) H.update(A(v));
  }
  H.dofinal();

thoughts ?