Subject: Re: [manet] AODVv2 comments

From: <[email-masked]>
Date: Mon, 21 Sep 2015 21:45:43 +0000

See the wikipedia pagehttps://en.wikipedia.org/wiki/Serial_number_arithmetic  if you want, but this method works for the 8, 16, 32, etc bit integer types in C.  It is different than Chris described.  you do the unsigned subtraction first, then cast the the 2’s compliment.  This method can also work for non-aligned lengths (e.g. 20 bits), but you need to do some shifts as described in the article.

/*
 * If the result is not positive, you should ignore “test" because it
 * is not larger than “current”.
 */
int compare(uint16_t test, uint16_t current) {
   return (int16_t) (test - current);
}

I agree that what Chris quoted is not clear, especially the “signed 32-bit arithmetic” part.  It is not (int) a - (int) b, it is (int)(a - b), where a and b are unsigned integers.  Using this method will always be consistent.

Example using 8-bit.  Assume current = 64:

test = 64 => delta = 0 => ignore it
test = 65 => delta = 1 => accept
test = 127 => delta = 63 => accept
test = 128 => delta = 64 => accept
test = 191 => delta = 127 => accept
test = 192 => delta = -128 => reject ** half way point **
test = 63 => delta = -1 => reject

In the example Chris worked out, current = 128:

test = 128 => delta = 0 => ignore
test = 129 => delta = 1 => accept
test = 255 => delta = 127 => accept
test = 0 => delta = -128 => reject ** half way point **

Marc

On Sep 21, 2015, at 9:00 PM, [email-masked]<mailto:[email-masked]> wrote:

Re: [manet] AODVv2 comments

---

From: "Dearlove, Christopher (UK)" <[email-masked]>
Date: Tue, 22 Sep 2015 08:42:08 +0000

I cast before arithmetic to match the description. I would naturally cast after – or in fact do the comparison unsigned, no cast. But (assuming wrap-around – but see my last comment) the two are the same, but agreed avoiding signed wraparound is better.

But the Wikipedia page, and your examples, don’t actually cover the AODVv2 case, as that excludes zero. You can’t have test = 0.  255 and 1 (using the 8 bit simplification for examples) have a delta of 1, not 2. As I said, it affects only a corner case, but it does mean there is no half-way point. Without the zero case, we wrote the case in RFC 7181 without signed numbers.

(Also, signed isn’t strictly sufficient as a description, it’s assuming two’s complement. Admittedly I’ve never knowingly programmed on anything that isn’t, but precision is good. But avoiding signed is better.)

--
Christopher Dearlove
Senior Principal Engineer
BAE Systems Applied Intelligence
__________________________________________________________________________

T:  +44 (0)1245 242194  |  E: [email-masked]<mailto:[email-masked]>

BAE Systems Applied Intelligence, Chelmsford Technology Park, Great Baddow, Chelmsford, Essex CM2 8HN.
www.baesystems.com/ai<http://www.baesystems.com/ai>
BAE Systems Applied Intelligence Limited
Registered in England & Wales No: 01337451
Registered Office: Surrey Research Park, Guildford, Surrey, GU2 7YP

From: manet [mailto:[email-masked]] On Behalf Of [email-masked]
Sent: 21 September 2015 22:46
To: [email-masked]
Subject: Re: [manet] AODVv2 comments

*** WARNING ***
This message originates from outside our organisation, either from an external partner or the internet.
Consider carefully whether you should click on any links, open any attachments or reply.
For information regarding Red Flags that you can look out for in emails you receive, click here<http://intranet.ent.baesystems.com/howwework/security/spotlights/Documents/Red%20Flags.pdf>.
If you feel the email is suspicious, please follow this process<http://intranet.ent.baesystems.com/howwework/security/spotlights/Documents/Dealing%20With%20Suspicious%20Emails.pdf>.
*** WARNING ***
EXTERNAL EMAIL -- This message originates from outside our organization.

/*

Marc

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

---

From: "Dearlove, Christopher (UK)" <[email-masked]>
Date: Tue, 22 Sep 2015 09:23:05 +0000

I think (i.e. needs checking) that, using A and B where B should be slightly greater than A, in a range of length N (even) but zero ignored, and subtraction is modulo N:

If B >= A then accept if B – A < N/2
If B < A then accept if B – A <= N/2

If there’s a test that doesn’t involve having to use two cases, I can’t see it. (The C-specific hack of (B – A) – (B < A) < N/2 both doesn’t count and is code that should be rejected with prejudice.)

But again, the case B < A and B – A == N/2 is a corner case that isn’t of real criticality. Whether the specification needs to get it perfectly right can be argued.

[Actually I now can see a single case, but it requires arithmetic modulo N-1, which is a cure worse than the disease.]

From: manet [mailto:[email-masked]] On Behalf Of Dearlove, Christopher (UK)
Sent: 22 September 2015 09:42
To: [email-masked]; [email-masked]
Subject: Re: [manet] AODVv2 comments

*** WARNING ***

From: manet [mailto:[email-masked]] On Behalf Of [email-masked]<mailto:[email-masked]>
Sent: 21 September 2015 22:46
To: [email-masked]<mailto:[email-masked]>
Subject: Re: [manet] AODVv2 comments

*** WARNING ***

/*

Marc