idnits 2.17.1 draft-irtf-dtnrg-sdnv-09.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (February 23, 2011) is 4801 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Informational ---------------------------------------------------------------------------- -- Looks like a reference, but probably isn't: '0' on line 727 -- Looks like a reference, but probably isn't: '1' on line 727 == Outdated reference: A later version (-10) exists of draft-irtf-dtnrg-ltp-00 -- Obsolete informational reference (is this intentional?): RFC 793 (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 1323 (Obsoleted by RFC 7323) Summary: 0 errors (**), 0 flaws (~~), 2 warnings (==), 7 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group W. Eddy 3 Internet-Draft MTI Systems 4 Intended status: Informational E. Davies 5 Expires: August 27, 2011 Folly Consulting 6 February 23, 2011 8 Using Self-Delimiting Numeric Values in Protocols 9 draft-irtf-dtnrg-sdnv-09 11 Abstract 13 Self-Delimiting Numeric Values (SDNVs) have recently been introduced 14 as a field type in proposed Delay-Tolerant Networking protocols. 15 SDNVs encode an arbitrary-length non-negative integer or arbitrary- 16 length bit-string with minimum overhead. They are intended to 17 provide protocol flexibility without sacrificing economy, and to 18 assist in future-proofing protocols under development. This document 19 describes formats and algorithms for SDNV encoding and decoding, 20 along with notes on implementation and usage. This document is a 21 product of the Delay Tolerant Networking Research Group and has been 22 reviewed by that group. No objections to its publication as an RFC 23 were raised. 25 Status of this Memo 27 This Internet-Draft is submitted in full conformance with the 28 provisions of BCP 78 and BCP 79. 30 Internet-Drafts are working documents of the Internet Engineering 31 Task Force (IETF). Note that other groups may also distribute 32 working documents as Internet-Drafts. The list of current Internet- 33 Drafts is at http://datatracker.ietf.org/drafts/current/. 35 Internet-Drafts are draft documents valid for a maximum of six months 36 and may be updated, replaced, or obsoleted by other documents at any 37 time. It is inappropriate to use Internet-Drafts as reference 38 material or to cite them other than as "work in progress." 40 This Internet-Draft will expire on August 27, 2011. 42 Copyright Notice 44 Copyright (c) 2011 IETF Trust and the persons identified as the 45 document authors. All rights reserved. 47 This document is subject to BCP 78 and the IETF Trust's Legal 48 Provisions Relating to IETF Documents 49 (http://trustee.ietf.org/license-info) in effect on the date of 50 publication of this document. Please review these documents 51 carefully, as they describe your rights and restrictions with respect 52 to this document. Code Components extracted from this document must 53 include Simplified BSD License text as described in Section 4.e of 54 the Trust Legal Provisions and are provided without warranty as 55 described in the Simplified BSD License. 57 Table of Contents 59 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 60 1.1. Problems with Fixed Value Fields . . . . . . . . . . . . . 3 61 1.2. SDNVs for DTN Protocols . . . . . . . . . . . . . . . . . 4 62 1.3. SDNV Usage . . . . . . . . . . . . . . . . . . . . . . . . 5 63 2. Definition of SDNVs . . . . . . . . . . . . . . . . . . . . . 7 64 3. Basic Algorithms . . . . . . . . . . . . . . . . . . . . . . . 9 65 3.1. Encoding Algorithm . . . . . . . . . . . . . . . . . . . . 9 66 3.2. Decoding Algorithm . . . . . . . . . . . . . . . . . . . . 9 67 3.3. Limitations of Implementations . . . . . . . . . . . . . . 10 68 4. Comparison to Alternatives . . . . . . . . . . . . . . . . . . 11 69 5. Security Considerations . . . . . . . . . . . . . . . . . . . 15 70 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 16 71 7. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 17 72 8. Informative References . . . . . . . . . . . . . . . . . . . . 18 73 Appendix A. SNDV Python Source Code . . . . . . . . . . . . . . . 20 74 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 22 76 1. Introduction 78 This document is a product of the Internet Research Task Force (IRTF) 79 Delay-Tolerant Networking (DTN) Research Group (DTNRG). The document 80 has received review and support within the DTNRG, as discussed in the 81 Acknowledgements section of this document. 83 This document begins by describing the drawbacks of using fixed-width 84 protocol fields. It then provides some background on the Self- 85 Delimiting Numeric Values (SDNVs) proposed for use in DTN protocols, 86 and motivates their potential applicability in other networking 87 protocols. The DTNRG has created SDNVs to meet the challenges it 88 attempts to solve, and it has been noted that SDNVs closely resemble 89 certain constructs within ASN.1 and even older ITU protocols, so the 90 problems are not new or unique to DTN. SDNVs focus strictly on 91 numeric values or bitstrings, while other mechanisms have been 92 developed for encoding more complex data structures, such as ASN.1 93 encoding rules, and Haverty's MSDTP [RFC0713]. Because of this 94 focus, SDNVs are can be quickly implemented with only a small amount 95 of code. 97 SDNVs are tersely defined in both the bundle protocol [RFC5050] and 98 LTP [RFC5326] specifications, due to the flow of document production 99 in the DTNRG. This document clarifies and further explains the 100 motivations and engineering decisions behind SDNVs. 102 1.1. Problems with Fixed Value Fields 104 Protocol designers commonly face an optimization problem in 105 determining the proper size for header fields. There is a strong 106 desire to keep fields as small as possible, in order to reduce the 107 protocol's overhead, and also allow for fast processing. Since 108 protocols can be used many years (even decades) after they are 109 designed, and networking technology has tended to change rapidly, it 110 is not uncommon for the use, deployment, or performance of a 111 particular protocol to be limited or infringed upon by the length of 112 some header field being too short. Two well-known examples of this 113 phenomenon are the TCP advertised receive window, and the IPv4 114 address length. 116 TCP segments contain an advertised receive window field that is fixed 117 at 16 bits [RFC0793], encoding a maximum value of around 65 118 kilobytes. The purpose of this value is to provide flow control, by 119 allowing a receiver to specify how many sent bytes its peer can have 120 outstanding (unacknowledged) at any time, thus allowing the receiver 121 to limit its buffer size. As network speeds have grown by several 122 orders of magnitude since TCP's inception, the combination of the 65 123 kilobyte maximum advertised window and long round-trip times 124 prevented TCP senders from being able to achieve the high throughput 125 that the underlying network supported. This limitation was remedied 126 through the use of the Window Scale option [RFC1323], which provides 127 a multiplier for the advertised window field. However, the Window 128 Scale multiplier is fixed for the duration of the connection, 129 requires support from each end of a TCP connection, and limits the 130 precision of the advertised receive window, so this is certainly a 131 less-than-ideal solution. Because of the field width limit in the 132 original design however, the Window Scale is necessary for TCP to 133 reach high sending rates. 135 An IPv4 address is fixed at 32 bits [RFC0791] (as a historical note, 136 an early version of the IP header format specification in [IEN21] 137 used variable-length addresses in multiples of 8-bits up to 120- 138 bits). Due to the way that subnetting and assignment of address 139 blocks was performed, the number of IPv4 addresses has been seen as a 140 limit to the growth of the Internet [Hain05]. Two divergent paths to 141 solve this problem have been the use of Network Address Translators 142 (NATs) and the development of IPv6. NATs have caused a number of 143 other issues and problems [RFC2993], leading to increased complexity 144 and fragility, as well as forcing workarounds to be engineered for 145 many other protocols to function within a NATed environment. The 146 IPv6 solution's transitional work has been underway for several 147 years, but has still only just begun to have visible impact on the 148 global Internet. 150 Of course, in both the case of the TCP receive window and IPv4 151 address length, the field size chosen by the designers seemed like a 152 good idea at the time. The fields were more than big enough for the 153 originally perceived usage of the protocols, and yet were small 154 enough to allow the headers to remain compact and relatively easy and 155 efficient to parse on machines of the time. The fixed sizes that 156 were defined represented a trade off between the scalability of the 157 protocol versus the overhead and efficiency of processing. In both 158 cases, these engineering decisions turned out to be painfully 159 restrictive in the longer term. 161 1.2. SDNVs for DTN Protocols 163 In specifications for the DTN Bundle Protocol (BP) [RFC5050] and 164 Licklider Transmission Protocol (LTP) [RFC5326], SDNVs have been used 165 for several fields including identifiers, payload/header lengths, and 166 serial (sequence) numbers. SDNVs were developed for use in these 167 types of fields, to avoid sending more bytes than needed, as well as 168 avoiding fixed sizes that may not end up being appropriate. For 169 example, since LTP is intended primarily for use in long-delay 170 interplanetary communications [RFC5325], where links may be fairly 171 low in capacity, it is desirable to avoid the header overhead of 172 routinely sending a 64-bit field where a 16-bit field would suffice. 173 Since many of the nodes implementing LTP are expected to be beyond 174 the current range of human spaceflight, upgrading their on-board LTP 175 implementations to use longer values if the defined fields are found 176 to be too short would also be problematic. Furthermore, extensions 177 similar in mechanism to TCP's Window Scale option are unsuitable for 178 use in DTN protocols since, due to high delays, DTN protocols must 179 avoid handshaking and configuration parameter negotiation to the 180 greatest extent possible. All of these reasons make the choice of 181 SDNVs for use in DTN protocols attractive. 183 1.3. SDNV Usage 185 In short, an SDNV is simply a way of representing non-negative 186 integers (both positive integers of arbitrary magnitude and 0), 187 without expending much unnecessary space. This definition allows 188 SDNVs to represent many common protocol header fields, such as: 190 o Random identification fields as used in the IPsec Security 191 Parameters Index or in IP headers for fragment reassembly (Note: 192 the 16-bit IP ID field for fragment reassembly was recently found 193 to be too short in some environments [RFC4963]), 195 o Sequence numbers as in TCP or SCTP, 197 o Values used in cryptographic algorithms such as RSA keys, Diffie- 198 Hellman key-agreement, or coordinates of points on elliptic 199 curves. 201 o Message lengths as used in file transfer protocols. 203 o Nonces and cookies. 205 As any bit-field can be interpreted as an unsigned integer, SDNVs can 206 also encode arbitrary-length bit-fields, including bit-fields 207 representing signed integers or other data types; however, this 208 document assumes SDNV encoding and decoding in terms of unsigned 209 integers. Implementations may differ in the interface that they 210 provide to SDNV encoding and decoding functions, in terms of whether 211 the values are numeric, bit-fields, etc.; this detail does not alter 212 the representation or algorithms described in this document. 214 The use of SDNVs rather than fixed length fields gives protocol 215 designers the ability to ameliorate the consequences of making 216 difficult-to-reverse field-sizing decisions, as the SDNV format grows 217 and shrinks depending on the particular value encoded. SDNVs do not 218 necessarily provide optimal encodings for values of any particular 219 length, however they allow protocol designers to avoid potential 220 blunders in assigning fixed lengths, and remove the complexity 221 involved with either negotiating field lengths or constructing 222 protocol extensions. However, if SDNVs are used to encode bit- 223 fields, it is essential that the sender and receiver have a 224 consistent interpretation of the decoded value. This is discussed 225 further in Section 2. 227 To our knowledge, at this time, no IETF transport or network-layer 228 protocol designed for use outside of the DTN domain has proposed to 229 use SDNVs; however there is no inherent reason not to use SDNVs more 230 broadly in the future. The two examples cited here, of fields that 231 have proven too small in general Internet protocols, are only a small 232 sampling of the much larger set of similar instances that the authors 233 can think of. Outside the Internet protocols, within ASN.1 and 234 previous ITU protocols, constructs very similar to SDNVs have been 235 used for many years due to engineering concerns very similar to those 236 facing the DTNRG. 238 Many protocols use a Type-Length-Value method for encoding variable 239 length fields (e.g. TCP's options format, or many of the fields in 240 IKEv2). An SDNV is equivalent to combining the length and value 241 portions of this type of field, with the overhead of the length 242 portion amortized out over the bytes of the value. The penalty paid 243 for this in an SDNV may be several extra bytes for long values (e.g. 244 1024 bit RSA keys). See Section 4 for further discussion and a 245 comparison. 247 As is shown in later sections, for large values, the current SDNV 248 scheme is fairly inefficient in terms of space (1/8 of the bits are 249 overhead) and not particularly easy to encode/decode in comparison to 250 alternatives. The best use of SDNVs may often be to define the 251 Length field of a TLV structure to be an SDNV whose value is the 252 length of the TLV's Value field. In this way, one can avoid forcing 253 large numbers from being directly encoded as an SDNV, yet retain the 254 extensibility that using SDNVs grants. 256 2. Definition of SDNVs 258 Early in the work of the DTNRG, it was agreed that the properties of 259 an SDNV were useful for DTN protocols. The exact SDNV format used by 260 the DTNRG evolved somewhat over time before the publication of the 261 initial RFCs on LTP and the BP. An earlier version (see [BRF04]) 262 bore a resemblance to the ASN.1 [ASN1] Basic Encoding Rules (BER) 263 [ASN1-BER] for lengths (Section 8.1.3 of X.690). The current SDNV 264 format is the one used by ASN.1 BER for encoding tag identifiers 265 greater than or equal to 31 (Section 8.1.2.4.2 of X.690). A 266 comparison between the current SDNV format and the early SDNV format 267 is made in Section 4. 269 The format currently used is very simple. Before encoding, an 270 integer is represented as a left-to-right bitstring beginning with 271 its most significant bit, and ending with its least significant bit. 272 If the bitstring's length is not a multiple of 7, then the string is 273 left-padded with zeros. When transmitted, the bits are encoded into 274 a series of bytes. The low-order 7 bits of each byte in the encoded 275 format are taken left-to-right from the integer's bitstring 276 representation. The most significant bit of each byte specifies 277 whether it is the final byte of the encoded value (when it holds a 278 0), or not (when it holds a 1). 280 For example: 282 o 1 (decimal) is represented by the bitstring "0000001" and encoded 283 as the single byte 0x01 (in hexadecimal) 285 o 128 is represented by the bitstring "10000001 00000000" and 286 encoded as the bytes 0x81 followed by 0x00. 288 o Other values can be found in the test vectors of the source code 289 in Appendix A 291 To be perfectly clear, and avoid potential interoperability issues 292 (as have occurred with ASN.1 BER time values), we explicitly state 293 two considerations regarding zero-padding. (1) When encoding SDNVs, 294 any leading (most significant) zero bits in the input number might be 295 discarded by the SDNV encoder. Protocols that use SDNVs should not 296 rely on leading-zeros being retained after encoding and decoding 297 operations. (2) When decoding SDNVs, the relevant number of leading 298 zeros required to pad up to a machine word or other natural data unit 299 might be added. These are put in the most-significant positions in 300 order to not change the value of the number. Protocols using SDNVs 301 should consider situations where lost zero-padding may be 302 problematic. 304 The issues of zero-padding are particularly relevant where an SDNV is 305 being used to represent a bit-field to be transmitted by a protocol. 306 The specification of the protocol and any associated IANA registry 307 should specify the allocation and usage of bit positions within the 308 unencoded field. Unassigned and reserved bits in the unencoded field 309 will be treated as zeros by the SDNV encoding prior to transmission. 310 Assuming the bit positions are numbered starting from 0 at the least 311 significant bit position in the integer representation, then if 312 higher numbered positions in the field contain all zeros, the 313 encoding process may not transmit these bits explicitly (e.g., if all 314 the bit positions numbered 7 or higher are zeros then the transmitted 315 SDNV can consist of just one octet). On reception the decoding 316 process will treat any untransmitted higher numbered bits as zeros. 317 To ensure correct operation of the protocol, the sender and receiver 318 must have a consistent interpretation of the width of the bit-field. 319 This can be achieved in various ways: 321 o the bit-field width is implicitly defined by the version of the 322 protocol in use in the sender and receiver, 324 o sending the width of the bit-field explicitly in a separate item, 326 o the higher numbered bits can be safely ignored by the receiver 327 (e.g., because they represent optimizations), or 329 o marking the highest numbered bit by prepending a 1 bit to the bit- 330 field. 332 The protocol specification must record how the consistent 333 interpretation is achieved. 335 The SDNV encoding technique is also known as Variable Byte Encoding 336 (see Section 5.3.1 of [Manning09]) and is equivalent to Base-128 337 Elias Gamma Encoding (see Section 5.3.2 of [Manning09] and Section 338 3.5 of [Sayood02]). However the primary motivation for SDNVs is to 339 provide an extensible protocol framework rather than optimal data 340 compression which is the motivation behind the other uses of the 341 technique. [Manning09] points out that the key feature of this 342 encoding is that it is 'prefix free' meaning that no code is a prefix 343 of any other, which an alternative way of expressing the self- 344 delimiting property 346 3. Basic Algorithms 348 This section describes some simple algorithms for creating and 349 parsing SDNV fields. These may not be the most efficient algorithms 350 possible, however, they are easy to read, understand, and implement. 351 Appendix A contains Python source code implementing the routines 352 described here. The algorithms presented here are convenient for 353 converting between an internal data block and serialized data stream 354 associated with a transmission device. Other approaches are possible 355 with different efficiencies and trade-offs. 357 3.1. Encoding Algorithm 359 There is a very simple algorithm for the encoding operation that 360 converts a non-negative integer (value n, of length 1+floor(log n) 361 bits) into an SDNV. This algorithm takes n as its only argument and 362 returns a string of bytes: 364 o (Initial Step) Set a variable X to a byte sharing the least 365 significant 7 bits of n, and with 0 in the most significant bit, 366 and a variable Y to n, right-shifted by 7 bits. 368 o (Recursion Step) If Y == 0, return X. Otherwise, set Z to the 369 bitwise-or of 0x80 with the 7 least significant bits of Y, and 370 append Z to X. Right-shift Y by 7 bits and repeat the Recursion 371 Step. 373 This encoding algorithm has time complexity of O(log n), since it 374 takes a number of steps equal to ceil(n/7), and no additional space 375 beyond the size of the result (8/7 log n) is required. One aspect of 376 this algorithm is that it assumes strings can be efficiently appended 377 to new bytes. One way to implement this is to allocate a buffer for 378 the expected length of the result and fill that buffer one byte at a 379 time from the right end. 381 If, for some reason, an implementation requires an encoded SDNV to be 382 some specific length (possibly related to a machine word), any 383 leftmost zero-padding included needs to properly set the high-order 384 bit in each byte of padding. 386 3.2. Decoding Algorithm 388 Decoding SDNVs is a more difficult operation than encoding them, due 389 to the fact that no bound on the resulting value is known until the 390 SDNV is parsed, at which point the value itself is already known. 391 This means that if space is allocated for decoding the value of an 392 SDNV into, it is never known whether this space will be overflowed 393 until it is 7 bits away from happening. 395 (Initial Step) Set the result to 0. Set an index to the first byte 396 of the encoded SDNV. 398 (Recursion Step) Shift the result left 7 bits. Add the low-order 7 399 bits of the value at the index to the result. If the high-order bit 400 under the pointer is a 1, advance the index by one byte within the 401 encoded SDNV and repeat the Recursion Step, otherwise return the 402 current value of the result. 404 This decoding algorithm takes no more additional space than what is 405 required for the result (7/8 the length of the SDNV) and the pointer. 406 The complication is that before the result can be left-shifted in the 407 Recursion Step, an implementation needs to first make sure that this 408 won't cause any bits to be lost, and re-allocate a larger piece of 409 memory for the result, if required. The pure time complexity is the 410 same as for the encoding algorithm given, but if re-allocation is 411 needed due to the inability to predict the size of the result, 412 decoding may be slower. 414 These decoding steps include removal of any leftmost zero-padding 415 that might be used by an encoder to create encodings of a certain 416 length. 418 3.3. Limitations of Implementations 420 Because of efficiency considerations or convenience of internal 421 representation of decoded integers, implementations may choose to 422 limit the number of bits in SDNVs that they will handle. To avoid 423 interoperability problems any protocol that uses SDNVs must specify 424 the largest number of bits in an SDNV that an implementation of that 425 protocol is expected to handle. 427 For example Section 4.1 of [RFC5050] specifies that implementations 428 of the DTN Bundle Protocol are not required to handle SDNVs with more 429 than 64 bits in their unencoded value. Accordingly integer values 430 transmitted in SDNVs have an upper limit and SDNV encoded flag fields 431 must be limited to 64 bit positions in any future revisions of the 432 protocol unless the restriction is altered. 434 4. Comparison to Alternatives 436 This section compares three alternative ways of implementing the 437 concept of SDNVs: (1) the TLV scheme commonly used in the Internet 438 family, and many other families of protocols, (2) the old style of 439 SDNVs (both the SDNV-8 and SDNV-16) defined in an early stage of 440 LTP's development [BRF04], and (3) the current SDNV format. 442 The TLV method uses two fixed-length fields to hold the Type and 443 Length elements that then imply the syntax and semantics of the Value 444 element. This is only similar to an SDNV in that the value element 445 can grow or shrink within the bounds capable of being conveyed by the 446 Length field. Two fundamental differences between TLVs and SDNVs are 447 that through the Type element, TLVs also contain some notion of what 448 their contents are semantically, while SDNVs are simply generic non- 449 negative integers, and protocol engineers still have to choose fixed 450 field lengths for the Type and Length fields in the TLV format. 452 Some protocols use TLVs where the value conveyed within the Length 453 field needs to be decoded into the actual length of the Value field. 454 This may be accomplished through simple multiplication, left- 455 shifting, or a look-up table. In any case, this tactic limits the 456 granularity of the possible Value lengths, and can contribute some 457 degree of bloat if Values do not fit neatly within the available 458 decoded Lengths. 460 In the SDNV format originally used by LTP, parsing the first byte of 461 the SDNV told an implementation how much space was required to hold 462 the contained value. There were two different types of SDNVs defined 463 for different ranges of use. The SDNV-8 type could hold values up to 464 127 in a single byte, while the SDNV-16 type could hold values up to 465 32,767 in 2 bytes. Both formats could encode values requiring up to 466 N bytes in N+2 bytes, where N<127. The major difference between this 467 old SDNV format and the current SDNV format is that the new format is 468 not as easily decoded as the old format was, but the new format also 469 has absolutely no limitation on its length. 471 The advantage in ease of parsing the old format manifests itself in 472 two aspects: (1) the size of the value is determinable ahead of time, 473 in a way equivalent to parsing a TLV, and (2) the actual value is 474 directly encoded and decoded, without shifting and masking bits as is 475 required in the new format. For these reasons, the old format 476 requires less computational overhead to deal with, but is also very 477 limited, in that it can only hold a 1024-bit number, at maximum. 478 Since according to IETF Best Current Practices, an asymmetric 479 cryptography key needed to last for a long term requires using moduli 480 of over 1228 bits [RFC3766], this could be seen as a severe 481 limitation of the old-style of SDNVs, which the currently-used style 482 does not suffer from. 484 Table 1 compares the maximum values that can be encoded into SDNVs of 485 various lengths using the old SDNV-8/16 method and the current SDNV 486 method. The only place in this table where SDNV-16 is used rather 487 than SDNV-8 is in the 2-byte row. Starting with a single byte, the 488 two methods are equivalent, but when using 2 bytes, the old method is 489 a more compact encoding by one bit. From 3 to 7 bytes of length 490 though, the current SDNV format is more compact, since it only 491 requires one bit per byte of overhead, whereas the old format used a 492 full byte. Thus, at 8 bytes, both schemes are equivalent in 493 efficiency since they both use 8 bits of overhead. Up to 129 bytes, 494 the old format is more compact than the current one, although after 495 this limit it becomes unusable. 497 +-------+---------------+-------------+---------------+-------------+ 498 | Bytes | SDNV-8/16 | SDNV | SDNV-8/16 | SDNV | 499 | | Maximum Value | Maximum | Overhead Bits | Overhead | 500 | | | Value | | Bits | 501 +-------+---------------+-------------+---------------+-------------+ 502 | 1 | 127 | 127 | 1 | 1 | 503 | | | | | | 504 | 2 | 32,767 | 16,383 | 1 | 2 | 505 | | | | | | 506 | 3 | 65,535 | 2,097,151 | 8 | 3 | 507 | | | | | | 508 | 4 | 2^24 - 1 | 2^28 - 1 | 8 | 4 | 509 | | | | | | 510 | 5 | 2^32 - 1 | 2^35 - 1 | 8 | 5 | 511 | | | | | | 512 | 6 | 2^40 - 1 | 2^42 - 1 | 8 | 6 | 513 | | | | | | 514 | 7 | 2^48 - 1 | 2^49 - 1 | 8 | 7 | 515 | | | | | | 516 | 8 | 2^56 - 1 | 2^56 - 1 | 8 | 8 | 517 | | | | | | 518 | 9 | 2^64 - 1 | 2^63 - 1 | 8 | 9 | 519 | | | | | | 520 | 10 | 2^72 - 1 | 2^70 - 1 | 8 | 10 | 521 | | | | | | 522 | 16 | 2^120 - 1 | 2^112 - 1 | 8 | 16 | 523 | | | | | | 524 | 32 | 2^248 - 1 | 2^224 - 1 | 8 | 32 | 525 | | | | | | 526 | 64 | 2^504 - 1 | 2^448 - 1 | 8 | 64 | 527 | | | | | | 528 | 128 | 2^1016 - 1 | 2^896 - 1 | 8 | 128 | 529 | | | | | | 530 | 129 | 2^1024 - 1 | 2^903 - 1 | 8 | 129 | 531 | | | | | | 532 | 130 | N/A | 2^910 - 1 | N/A | 130 | 533 | | | | | | 534 | 256 | N/A | 2^1792 - 1 | N/A | 256 | 535 +-------+---------------+-------------+---------------+-------------+ 537 Table 1 539 Suggested usages of the SDNV format that leverage its strengths and 540 limit the effects of its weaknesses are discussed in Section 1.3. 542 Another aspect of comparison between SDNVs and alternatives using 543 fixed-length fields is the result of errors in transmission. Bit- 544 errors in an SDNV can result in either errors in the decoded value, 545 or parsing errors in subsequent fields of the protocol. In fixed- 546 length fields, bit errors always result in errors to the decoded 547 value rather than parsing errors in subsequent fields. If the 548 decoded values from either type of field encoding (SDNV or fixed- 549 length) are used as indexes, offsets, or lengths of further fields in 550 the protocol, similar failures result. 552 5. Security Considerations 554 The only security considerations with regards to SDNVs are that code 555 which parses SDNVs should have bounds-checking logic and be capable 556 of handling cases where an SDNV's value is beyond the code's ability 557 to parse. These precautions can prevent potential exploits involving 558 SDNV decoding routines. 560 Stephen Farrell noted that very early definitions of SDNVs also 561 allowed negative integers. This was considered a potential security 562 hole, since it could expose implementations to underflow attacks 563 during SDNV decoding. There is a precedent in that many existing TLV 564 decoders map the Length field to a signed integer and are vulnerable 565 in this way. An SDNV decoder should be based on unsigned types and 566 not have this issue. 568 6. IANA Considerations 570 This document has no IANA considerations. 572 7. Acknowledgements 574 Scott Burleigh, Manikantan Ramadas, Michael Demmer, Stephen Farrell, 575 and other members of the IRTF DTN Research Group contributed to the 576 development and usage of SDNVs in DTN protocols. George Jones and 577 Keith Scott from Mitre, Lloyd Wood, Gerardo Izquierdo, Joel Halpern, 578 Peter TB Brett, Kevin Fall, and Elwyn Davies also contributed useful 579 comments on and criticisms of this document. DTNRG last call 580 comments on the draft were sent to the mailing list by Lloyd Wood, 581 Will Ivancic, Jim Wyllie, William Edwards, Hans Kruse, Janico 582 Greifenberg, Teemu Karkkainen, Stephen Farrell, and Scott Burleigh. 583 Further constructive comments were incorporated from Dave Crocker, 584 Lachlan Andrew and Michael Welzl. 586 Work on this document was performed at NASA's Glenn Research Center, 587 in support of the NASA Space Communications Architecture Working 588 Group (SCAWG), NASA's Earth Science Technology Office (ESTO), and the 589 FAA/Eurocontrol Future Communications Study (FCS) in the 2005-2007 590 time frame, while the editor was an employee of Verizon Federal 591 Network Systems. 593 8. Informative References 595 [ASN1] ITU-T Rec. X.680, "Abstract Syntax Notation One (ASN.1). 596 Specification of Basic Notation", ISO/IEC 8824-1:2002, 597 2002. 599 [ASN1-BER] 600 ITU-T Rec. X.690, "Abstract Syntax Notation One (ASN.1). 601 Encoding Rules: Specification of Basic Encoding Rules 602 (BER), Canonical Encoding Rules (CER) and Distinguished 603 Encoding Rules (DER)", ISO/IEC 8825-1:2002, 2002. 605 [BRF04] Burleigh, S., Ramadas, M., and S. Farrell, "Licklider 606 Transmission Protocol", 607 draft-irtf-dtnrg-ltp-00 (replaced), May 2004. 609 [Hain05] Hain, T., "A Pragmatic Report on IPv4 Address Space 610 Consumption", Internet Protocol Journal Vol. 8, No. 3, 611 September 2005. 613 [IEN21] Cerf, V. and J. Postel, "Specification of Internetwork 614 Transmission Control Program: TCP Version 3", Internet 615 Experimental Note 21, January 1978. 617 [Manning09] 618 Manning, c., Raghavan, P., and H. Schuetze, "Introduction 619 to Information Retrieval", Cambridge University 620 Press ISBN-13: 978-0521865715, 2009, 621 . 623 [RFC0713] Haverty, J., "MSDTP-Message Services Data Transmission 624 Protocol", RFC 713, April 1976. 626 [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, 627 September 1981. 629 [RFC0793] Postel, J., "Transmission Control Protocol", STD 7, 630 RFC 793, September 1981. 632 [RFC1323] Jacobson, V., Braden, B., and D. Borman, "TCP Extensions 633 for High Performance", RFC 1323, May 1992. 635 [RFC2993] Hain, T., "Architectural Implications of NAT", RFC 2993, 636 November 2000. 638 [RFC3766] Orman, H. and P. Hoffman, "Determining Strengths For 639 Public Keys Used For Exchanging Symmetric Keys", BCP 86, 640 RFC 3766, April 2004. 642 [RFC4963] Heffner, J., Mathis, M., and B. Chandler, "IPv4 Reassembly 643 Errors at High Data Rates", RFC 4963, July 2007. 645 [RFC5050] Scott, K. and S. Burleigh, "Bundle Protocol 646 Specification", RFC 5050, November 2007. 648 [RFC5325] Burleigh, S., Ramadas, M., and S. Farrell, "Licklider 649 Transmission Protocol - Motivation", RFC 5325, 650 September 2008. 652 [RFC5326] Ramadas, M., Burleigh, S., and S. Farrell, "Licklider 653 Transmission Protocol - Specification", RFC 5326, 654 September 2008. 656 [Sayood02] 657 Sayood, K., "Lossless Data Compression", Academic 658 Press ISBN-13: 978-0126208610, December 2002, 659 . 661 Appendix A. SNDV Python Source Code 663 # sdnv_decode() takes a string argument (s), which is assumed to be 664 # an SDNV, and optionally a number (slen) for the maximum number of 665 # bytes to parse from the string. The function returns a pair of 666 # the non-negative integer n that is the numeric value encoded in 667 # the SDNV, and integer that is the distance parsed into the input 668 # string. If the slen argument is not given (or is not a non-zero 669 # number) then, s is parsed up to the first byte whose high-order 670 # bit is 0 -- the length of the SDNV portion of s does not have to 671 # be pre-computed by calling code. If the slen argument is given 672 # as a non-zero value, then slen bytes of s are parsed. The value 673 # for n of -1 is returned for any type of parsing error. 674 # 675 # NOTE: In python, integers can be of arbitrary size. In other 676 # languages, such as C, SDNV-parsing routines should take 677 # precautions to avoid overflow (e.g. by using the Gnu MP library, 678 # or similar). 679 # 680 def sdnv_decode(s, slen=0): 681 n = long(0) 682 for i in range(0, len(s)): 683 v = ord(s[i]) 684 n = n<<7 685 n = n + (v & 0x7F) 686 if v>>7 == 0: 687 slen = i+1 688 break 689 elif i == len(s)-1 or (slen != 0 and i > slen): 690 n = -1 # reached end of input without seeing end of SDNV 691 return (n, slen) 693 # sdnv_encode() returns the SDNV-encoded string that represents n. 694 # An empty string is returned if n is not a non-negative integer 695 def sdnv_encode(n): 696 r = "" 697 # validate input 698 if n >= 0 and (type(n) in [type(int(1)), type(long(1))]): 699 flag = 0 700 done = False 701 while not done: 702 # encode lowest 7 bits from n 703 newbits = n & 0x7F 704 n = n>>7 705 r = chr(newbits + flag) + r 706 if flag == 0: 707 flag = 0x80 708 if n == 0: 710 done = True 711 return r 713 # test cases from LTP and BP internet-drafts, only print failures 714 def sdnv_test(): 715 tests = [(0xABC, chr(0x95) + chr(0x3C)), 716 (0x1234, chr(0xA4) + chr (0x34)), 717 (0x4234, chr(0x81) + chr(0x84) + chr(0x34)), 718 (0x7F, chr(0x7F))] 720 for tp in tests: 721 # test encoding function 722 if sdnv_encode(tp[0]) != tp[1]: 723 print "sdnv_encode fails on input %s" % hex(tp[0]) 724 # test decoding function 725 if sdnv_decode(tp[1])[0] != tp[0]: 726 print "sdnv_decode fails on input %s, giving %s" % \ 727 (hex(tp[0]), sdnv_decode(tp[1])) 729 Authors' Addresses 731 Wesley M. Eddy 732 MTI Systems 733 NASA Glenn Research Center 734 MS 500-ASRC; 21000 Brookpark Rd 735 Cleveland, OH 44135 737 Phone: 216-433-6682 738 Email: wes@mti-systems.com 740 Elwyn Davies 741 Folly Consulting 742 Soham 743 UK 745 Phone: 746 Email: elwynd@folly.org.uk 747 URI: