idnits 2.17.00 (12 Aug 2021) /tmp/idnits539/draft-irtf-dtnrg-sdnv-07.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 (October 11, 2010) is 4239 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 695 -- Looks like a reference, but probably isn't: '1' on line 695 == Outdated reference: draft-irtf-dtnrg-ltp has been published as RFC 5326 -- Obsolete informational reference (is this intentional?): RFC 1323 (Obsoleted by RFC 7323) Summary: 0 errors (**), 0 flaws (~~), 2 warnings (==), 6 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: April 14, 2011 Folly Consulting 6 October 11, 2010 8 Using Self-Delimiting Numeric Values in Protocols 9 draft-irtf-dtnrg-sdnv-07 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 April 14, 2011. 42 Copyright Notice 44 Copyright (c) 2010 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. One example of SDNVs being used outside of the DTN 88 protocols is in Hixie's Web Socket protocol 89 [I-D.hixie-thewebsocketprotocol], which includes a binary frame 90 length indicator field identical to an SDNV. The DTNRG has created 91 SDNVs to meet the challenges it attempts to solve, and it has been 92 noted that SDNVs closely resemble certain constructs within ASN.1 and 93 even older ITU protocols, so the problems are not new or unique to 94 DTN. SDNVs focus strictly on numeric values or bitstrings, while 95 other mechanisms have been developed for encoding more complex data 96 structures, such as ASN.1 encoding rules, and Haverty's MSDTP 97 [RFC0713]. Because of this focus, SDNVs are can be quickly 98 implemented with only a small amount of code. 100 SDNVs are tersely defined in both the bundle protocol [RFC5050] and 101 LTP [RFC5326] specifications, due to the flow of document production 102 in the DTNRG. This document clarifies and further explains the 103 motivations and engineering decisions behind SDNVs. 105 1.1. Problems with Fixed Value Fields 107 Protocol designers commonly face an optimization problem in 108 determining the proper size for header fields. There is a strong 109 desire to keep fields as small as possible, in order to reduce the 110 protocol's overhead, and also allow for fast processing. Since 111 protocols can be used many years (even decades) after they are 112 designed, and networking technology has tended to change rapidly, it 113 is not uncommon for the use, deployment, or performance of a 114 particular protocol to be limited or infringed upon by the length of 115 some header field being too short. Two well-known examples of this 116 phenomenon are the TCP advertised receive window, and the IPv4 117 address length. 119 TCP segments contain an advertised receive window field that is fixed 120 at 16 bits [RFC0793], encoding a maximum value of around 65 121 kilobytes. The purpose of this value is to provide flow control, by 122 allowing a receiver to specify how many sent bytes its peer can have 123 outstanding (unacknowledged) at any time, thus allowing the receiver 124 to limit its buffer size. As network speeds have grown by several 125 orders of magnitude since TCP's inception, the combination of the 65 126 kilobyte maximum advertised window and long round-trip times 127 prevented TCP senders from being able to achieve the high throughput 128 that the underlying network supported. This limitation was remedied 129 through the use of the Window Scale option [RFC1323], which provides 130 a multiplier for the advertised window field. However, the Window 131 Scale multiplier is fixed for the duration of the connection, 132 requires support from each end of a TCP connection, and limits the 133 precision of the advertised receive window, so this is certainly a 134 less-than-ideal solution. Because of the field width limit in the 135 original design however, the Window Scale is necessary for TCP to 136 reach high sending rates. 138 An IPv4 address is fixed at 32 bits [RFC0791] (as a historical note, 139 an early version 0 IP header format specification in [IEN21] used 140 variable-length addresses in multiples of 8-bits up to 120-bits). 141 Due to the way that subnetting and assignment of address blocks was 142 performed, the number of IPv4 addresses has been seen as a limit to 143 the growth of the Internet [Hain05]. Two divergent paths to solve 144 this problem have been the use of Network Address Translators (NATs) 145 and the development of IPv6. NATs have caused a number of other 146 issues and problems [RFC2993], leading to increased complexity and 147 fragility, as well as forcing work-arounds to be engineered for many 148 other protocols to function within a NATed environment. The IPv6 149 solution's transitional work has been underway for several years, but 150 has still only just begun to have visible impact on the global 151 Internet. 153 Of course, in both the case of the TCP receive window and IPv4 154 address length, the field size chosen by the designers seemed like a 155 good idea at the time. The fields were more than big enough for the 156 originally perceived usage of the protocols, and yet were small 157 enough to allow the headers to remain compact and relatively easy and 158 efficient to parse on machines of the time. The fixed sizes that 159 were defined represented a tradeoff between the scalability of the 160 protocol versus the overhead and efficiency of processing. In both 161 cases, these engineering decisions turned out to be painfully 162 restrictive in the longer term. 164 1.2. SDNVs for DTN Protocols 166 In specifications for the DTN Bundle Protocol (BP) [RFC5050] and 167 Licklider Transmission Protocol (LTP) [RFC5326], SDNVs have been used 168 for several fields including identifiers, payload/header lengths, and 169 serial (sequence) numbers. SDNVs were developed for use in these 170 types of fields, to avoid sending more bytes than needed, as well as 171 avoiding fixed sizes that may not end up being appropriate. For 172 example, since LTP is intended primarily for use in long-delay 173 interplanetary communications [RFC5325], where links may be fairly 174 low in capacity, it is desirable to avoid the header overhead of 175 routinely sending a 64-bit field where a 16-bit field would suffice. 176 Since many of the nodes implementing LTP are expected to be beyond 177 the current range of human spaceflight, upgrading their on-board LTP 178 implementations to use longer values if the defined fields are found 179 to be too short would also be problematic. Furthermore, extensions 180 similar in mechanism to TCP's Window Scale option are unsuitable for 181 use in DTN protocols since, due to high delays, DTN protocols must 182 avoid handshaking and configuration parameter negotiation to the 183 greatest extent possible. All of these reasons make the choice of 184 SDNVs for use in DTN protocols attractive. 186 1.3. SDNV Usage 188 In short, an SDNV is simply a way of representing non-negative 189 integers (both positive integers of arbitrary magnitude and 0), 190 without expending much unnecessary space. This definition allows 191 SDNVs to represent many common protocol header fields, such as: 193 o Random identification fields as used in the IPsec Security 194 Parameters Index or in IP headers for fragment reassembly (Note: 195 the 16-bit IP ID field for fragment reassembly was recently found 196 to be too short in some environments [RFC4963]), 198 o Sequence numbers as in TCP or SCTP, 200 o Values used in cryptographic algorithms such as RSA keys, Diffie- 201 Hellman key-agreement, or coordinates of points on elliptic 202 curves. 204 o Message lengths as used in file transfer protocols. 206 o Nonces and cookies. 208 o Etc. 210 As any bit-field can be interpreted as an unsigned integer, SDNVs can 211 also encode arbitrary-length bit-fields, including bit-fields 212 representing signed integers or other data types; however, this 213 document assumes SDNV encoding and decoding in terms of unsigned 214 integers. Implementations may differ in the interface that they 215 provide to SDNV encoding and decoding functions, in terms of whether 216 the values are numeric, bit-fields, etc.; this detail does not alter 217 the representation or algorithms described in this document. 219 The use of SDNVs rather than fixed length fields gives protocol 220 designers the ability to ameliorate the consequences of making 221 difficult-to-reverse field-sizing decisions, as the SDNV format grows 222 and shrinks depending on the particular value encoded. SDNVs do not 223 necessarily provide optimal encodings for values of any particular 224 length, however they allow protocol designers to avoid potential 225 blunders in assigning fixed lengths, and remove the complexity 226 involved with either negotiating field lengths or constructing 227 protocol extensions. 229 To our knowledge, at this time, no IETF transport or network-layer 230 protocol designed for use outside of the DTN domain has proposed to 231 use SDNVs; however there is no inherent reason not to use SDNVs more 232 broadly in the future. The two examples cited here, of fields that 233 have proven too small in general Internet protocols, are only a small 234 sampling of the much larger set of similar instances that the authors 235 can think of. Outside the Internet protocols, within ASN.1 and 236 previous ITU protocols, constructs very similar to SDNVs have been 237 used for many years due to engineering concerns very similar to those 238 facing the DTNRG. 240 Many protocols use a Type-Length-Value method for encoding variable 241 length fields (e.g. TCP's options format, or many of the fields in 242 IKEv2). An SDNV is equivalent to combining the length and value 243 portions of this type of field, with the overhead of the length 244 portion amortized out over the bytes of the value. The penalty paid 245 for this in an SDNV may be several extra bytes for long values (e.g. 246 1024 bit RSA keys). See Section 4 for further discussion and a 247 comparison. 249 As is shown in later sections, for large values, the current SDNV 250 scheme is fairly inefficient in terms of space (1/8 of the bits are 251 overhead) and not particularly easy to encode/decode in comparison to 252 alternatives. The best use of SDNVs may often be to define the 253 Length field of a TLV structure to be an SDNV whose value is the 254 length of the TLV's Value field. In this way, one can avoid forcing 255 large numbers from being directly encoded as an SDNV, yet retain the 256 extensibility that using SDNVs grants. 258 2. Definition of SDNVs 260 Early in the work of the DTNRG, it was agreed that the properties of 261 an SDNV were useful for DTN protocols. The exact SDNV format used by 262 the DTNRG evolved somewhat over time before the publication of the 263 initial RFCs on LTP and the BP. An ealier version bore resemblance 264 to the ASN.1 [ASN1] Basic Encoding Rules (BER) [ASN1-BER] for lengths 265 (Section 8.1.3 of X.690). The current SDNV format is the one used by 266 ASN.1 BER for encoding tag identifiers greater than or equal to 31 267 (Section 8.1.2.4.2 of X.690). A comparison between the current SDNV 268 format and the early SDNV format is made in Section 4. 270 The format currently used is very simple. Before encoding, an 271 integer is represented as a left-to-right bitstring beginning with 272 its most significant bit, and ending with its least signifcant bit. 273 If the bitstring's length is not a multiple of 7, then the string is 274 left-padded with zeros. When transmitted, the bits are encoded into 275 a series of bytes. The low-order 7 bits of each byte in the encoded 276 format are taken left-to-right from the integer's bitstring 277 representation. The most significant bit of each byte specifies 278 whether it is the final byte of the encoded value (when it holds a 279 0), or not (when it holds a 1). 281 For example: 283 o 1 (decimal) is represented by the bitstring "0000001" and encoded 284 as the single byte 0x01 (in hexadecimal) 286 o 128 is represented by the bitstring "10000001 00000000" and 287 encoded as the bytes 0x81 followed by 0x00. 289 o Other values can be found in the test vectors of the source code 290 in Appendix A 292 To be perfectly clear, and avoid potential interoperability issues 293 (as have occurred with ASN.1 BER time values), we explicitly state 294 two considerations regarding zero-padding. (1) When encoding SDNVs, 295 any leading (most significant) zero bits in the input number might be 296 discarded by the SDNV encoder. Protocols that use SDNVs should not 297 rely on leading-zeros being retained after encoding and decoding 298 operations. (2) When decoding SDNVs, the relevant number of leading 299 zeros required to pad up to a machine word or other natural data unit 300 might be added. These are put in the most-significant positions in 301 order to not change the value of the number. Protocols using SDNVs 302 should consider situations where lost zero-padding may be 303 problematic. 305 The issues of zero-padding are particularly relevant where an SDNV is 306 being used to represent a bit field to be transmitted by a protocol. 307 The specification of the protocol and any associated IANA registry 308 should specify the allocation and usage of bit positions within the 309 unencoded field. Both sender and receiver will know of this 310 allocation so that they are implicitly aware of the width of the bit 311 field. Unassigned and reserved bits in the unencoded field will be 312 treated as zeroes by the SDNV encoding prior to transmission. 313 Assuming the bit positions are numbered starting from 0 at the least 314 significant bit position in the integer representation, then if 315 higher numbered positions in the field contain all zeroes, the 316 encoding process may not transmit these bits explicitly (e.g., if all 317 the bit positions numbered 7 or higher are zeroes then the 318 transmitted SDNV can consist of just one octet). On reception the 319 decoding process will treat any untransmitted higher numbered bits as 320 zeroes. 322 3. Basic Algorithms 324 This section describes some simple algorithms for creating and 325 parsing SDNV fields. These may not be the most efficient algorithms 326 possible, however, they are easy to read, understand, and implement. 327 Appendix A contains Python source code implementing the routines 328 described here. 330 3.1. Encoding Algorithm 332 There is a very simple algorithm for the encoding operation that 333 converts a non-negative integer (value n, of length 1+floor(log n) 334 bits) into an SDNV. This algorithm takes n as its only argument and 335 returns a string of bytes: 337 o (Initial Step) Set a variable X to a byte sharing the least 338 significant 7 bits of n, and with 0 in the most significant bit, 339 and a variable Y to n, right-shifted by 7 bits. 341 o (Recursion Step) If Y == 0, return X. Otherwise, set Z to the 342 bitwise-or of 0x80 with the 7 least significant bits of Y, and 343 append Z to X. Right-shift Y by 7 bits and repeat the Recursion 344 Step. 346 This encoding algorithm has time complexity of O(log n), since it 347 takes a number of steps equal to ceil(n/7), and no additional space 348 beyond the size of the result (8/7 log n) is required. One aspect of 349 this algorithm is that it assumes strings can be efficiently appended 350 to new bytes. One way to implement this is to allocate a buffer for 351 the expected length of the result and fill that buffer one byte at a 352 time from the right end. 354 If, for some reason, an implementation requires an encoded SDNV to be 355 some specific length (possibly related to a machine word), any 356 leftmost zero-padding included needs to properly set the high-order 357 bit in each byte of padding. 359 3.2. Decoding Algorithm 361 Decoding SNDVs is a more difficult operation than encoding them, due 362 to the fact that no bound on the resulting value is known until the 363 SDNV is parsed, at which point the value itself is already known. 364 This means that if space is allocated for decoding the value of an 365 SDNV into, it is never known whether this space will be overflowed 366 until it is 7 bits away from happening. 368 (Initial Step) Set the result to 0. Set an index to the first byte 369 of the encoded SDNV. 371 (Recursion Step) Shift the result left 7 bits. Add the low-order 7 372 bits of the value at the index to the result. If the high-order bit 373 under the pointer is a 1, advance the index by one byte within the 374 encoded SDNV and repeat the Recursion Step, otherwise return the 375 current value of the result. 377 This decoding algorithm takes no more additional space than what is 378 required for the result (7/8 the length of the SDNV) and the pointer. 379 The complication is that before the result can be left-shifted in the 380 Recursion Step, an implementation needs to first make sure that this 381 won't cause any bits to be lost, and re-allocate a larger piece of 382 memory for the result, if required. The pure time complexity is the 383 same as for the encoding algorithm given, but if re-allocation is 384 needed due to the inability to predict the size of the result, 385 decoding may be slower. 387 These decoding steps include removal of any leftmost zero-padding 388 that might be used by an encoder to create encodings of a certain 389 length. 391 3.3. Limitations of Implementations 393 Because of efficiency considerations or convenience of internal 394 representation of decoded integers, implementations may choose to 395 limit the number of bits in SDNVs that they will handle. To avoid 396 interoperability problems any protocol that uses SDNVs must specify 397 the largest number of bits in an SDNV that an implementation of that 398 protocol is expected to handle. 400 For example Section 4.1 of [RFC5050] specifies that implementations 401 of the DTN Bundle Protocol are not required to handle SDNVs with more 402 than 64 bits in their unencoded value. Accordingly integer values 403 transmitted in SDNVs have an upper limit and SDNV encoded flag fields 404 must be limited to 64 bit positions in any future revisions of the 405 protocol unless the restriction is altered. 407 4. Comparison to Alternatives 409 This section compares three alternative ways of implementing the 410 concept of SDNVs: (1) the TLV scheme commonly used in the Internet 411 family, and many other families of protocols, (2) the old style of 412 SDNVs (both the SDNV-8 and SDNV-16) defined in an early stage of 413 LTP's development [BRF04], and (3) the current SDNV format. 415 The TLV method uses two fixed-length fields to hold the Type and 416 Length elements that then imply the syntax and semantics of the Value 417 element. This is only similar to an SDNV in that the value element 418 can grow or shrink within the bounds capable of being conveyed by the 419 Length field. Two fundamental differences between TLVs and SDNVs are 420 that through the Type element, TLVs also contain some notion of what 421 their contents are semantically, while SDNVs are simply generic non- 422 negative integers, and protocol engineers still have to choose fixed 423 field lengths for the Type and Length fields in the TLV format. 425 Some protocols use TLVs where the value conveyed within the Length 426 field needs to be decoded into the actual length of the Value field. 427 This may be accomplished through simple multiplication, left- 428 shifting, or a look-up table. In any case, this tactic limits the 429 granularity of the possible Value lengths, and can contribute some 430 degree of bloat if Values do not fit neatly within the available 431 decoded Lengths. 433 In the SDNV format originally used by LTP, parsing the first byte of 434 the SDNV told an implementation how much space was required to hold 435 the contained value. There were two different types of SDNVs defined 436 for different ranges of use. The SDNV-8 type could hold values up to 437 127 in a single byte, while the SDNV-16 type could hold values up to 438 32,767 in 2 bytes. Both formats could encode values requiring up to 439 N bytes in N+2 bytes, where N<127. The major difference between this 440 old SDNV format and the current SDNV format is that the new format is 441 not as easily decoded as the old format was, but the new format also 442 has absolutely no limitation on its length. 444 The advantage in ease of parsing the old format manifests itself in 445 two aspects: (1) the size of the value is determinable ahead of time, 446 in a way equivalent to parsing a TLV, and (2) the actual value is 447 directly encoded and decoded, without shifting and masking bits as is 448 required in the new format. For these reasons, the old format 449 requires less computational overhead to deal with, but is also very 450 limited, in that it can only hold a 1024-bit number, at maximum. 451 Since according to IETF Best Current Practices, an asymmetric 452 cryptography key needed to last for a long term requires using moduli 453 of over 1228 bits [RFC3766], this could be seen as a severe 454 limitation of the old-style of SDNVs, which the currently-used style 455 does not suffer from. 457 Table 1 compares the maximum values that can be encoded into SDNVs of 458 various lengths using the old SDNV-8/16 method and the current SDNV 459 method. The only place in this table where SDNV-16 is used rather 460 than SDNV-8 is in the 2-byte row. Starting with a single byte, the 461 two methods are equivalent, but when using 2 bytes, the old method is 462 a more compact encoding by one bit. From 3 to 7 bytes of length 463 though, the current SDNV format is more compact, since it only 464 requires one bit per byte of overhead, whereas the old format used a 465 full byte. Thus, at 8 bytes, both schemes are equivalent in 466 efficiency since they both use 8 bits of overhead. Up to 129 bytes, 467 the old format is more compact than the current one, although after 468 this limit it becomes unusable. 470 +-------+---------------+-------------+---------------+-------------+ 471 | Bytes | SDNV-8/16 | SDNV | SDNV-8/16 | SDNV | 472 | | Maximum Value | Maximum | Overhead Bits | Overhead | 473 | | | Value | | Bits | 474 +-------+---------------+-------------+---------------+-------------+ 475 | 1 | 127 | 127 | 1 | 1 | 476 | | | | | | 477 | 2 | 32,767 | 16,383 | 1 | 2 | 478 | | | | | | 479 | 3 | 65,535 | 2,097,151 | 8 | 3 | 480 | | | | | | 481 | 4 | 2^24 - 1 | 2^28 - 1 | 8 | 4 | 482 | | | | | | 483 | 5 | 2^32 - 1 | 2^35 - 1 | 8 | 5 | 484 | | | | | | 485 | 6 | 2^40 - 1 | 2^42 - 1 | 8 | 6 | 486 | | | | | | 487 | 7 | 2^48 - 1 | 2^49 - 1 | 8 | 7 | 488 | | | | | | 489 | 8 | 2^56 - 1 | 2^56 - 1 | 8 | 8 | 490 | | | | | | 491 | 9 | 2^64 - 1 | 2^63 - 1 | 8 | 9 | 492 | | | | | | 493 | 10 | 2^72 - 1 | 2^70 - 1 | 8 | 10 | 494 | | | | | | 495 | 16 | 2^120 - 1 | 2^112 - 1 | 8 | 16 | 496 | | | | | | 497 | 32 | 2^248 - 1 | 2^224 - 1 | 8 | 32 | 498 | | | | | | 499 | 64 | 2^504 - 1 | 2^448 - 1 | 8 | 64 | 500 | | | | | | 501 | 128 | 2^1016 - 1 | 2^896 - 1 | 8 | 128 | 502 | | | | | | 503 | 129 | 2^1024 - 1 | 2^903 - 1 | 8 | 129 | 504 | | | | | | 505 | 130 | N/A | 2^910 - 1 | N/A | 130 | 506 | | | | | | 507 | 256 | N/A | 2^1792 - 1 | N/A | 256 | 508 +-------+---------------+-------------+---------------+-------------+ 510 Table 1 512 In general, it seems like the most promising use of SDNVs may be to 513 define the Length field of a TLV structure to be an SDNV whose value 514 is the length of the TLV's Value field. This leverages the strengths 515 of the SDNV format and limits the effects of its weaknesses. 517 Another aspect of comparison between SDNVs and alternatives using 518 fixed-length fields is the result of errors in transmission. Bit- 519 errors in an SDNV can result in either errors in the decoded value, 520 or parsing errors in subsequent fields of the protocol. In fixed- 521 length fields, bit errors always result in errors to the decoded 522 value rather than parsing errors in subsequent fields. If the 523 decoded values from either type of field encoding (SDNV or fixed- 524 length) are used as indexes, offsets, or lengths of further fields in 525 the protocol, similar failures result. 527 5. Security Considerations 529 The only security considerations with regards to SDNVs are that code 530 which parses SDNVs should have bounds-checking logic and be capable 531 of handling cases where an SDNV's value is beyond the code's ability 532 to parse. These precautions can prevent potential exploits involving 533 SDNV decoding routines. 535 Stephen Farrell noted that very early definitions of SDNVs also 536 allowed negative integers. This was considered a potential security 537 hole, since it could expose implementations to underflow attacks 538 during SDNV decoding. There is a precedent in that many existing TLV 539 decoders map the Length field to a signed integer and are vulnerable 540 in this way. An SDNV decoder should be based on unsigned types and 541 not have this issue. 543 6. IANA Considerations 545 This document has no IANA considerations. 547 7. Acknowledgements 549 Scott Burleigh, Manikantan Ramadas, Michael Demmer, Stephen Farrell, 550 and other members of the IRTF DTN Research Group contributed to the 551 development and usage of SDNVs in DTN protocols. George Jones and 552 Keith Scott from Mitre, Lloyd Wood, Gerardo Izquierdo, Joel Halpern, 553 Peter TB Brett, Kevin Fall, and Elwyn Davies also contributed useful 554 comments on and criticisms of this document. DTNRG last call 555 comments on the draft were sent to the mailing list by Lloyd Wood, 556 Will Ivancic, Jim Wyllie, William Edwards, Hans Kruse, Janico 557 Greifenberg, Teemu Karkkainen, Stephen Farrell, and Scott Burleigh. 558 Further constructive comments were incorporated from Dave Crocker. 560 Work on this document was performed at NASA's Glenn Research Center, 561 in support of the NASA Space Communications Architecture Working 562 Group (SCAWG), NASA's Earth Science Technology Office (ESTO), and the 563 FAA/Eurocontrol Future Communications Study (FCS) in the 2005-2007 564 timeframe, while the editor was an employee of Verizon Federal 565 Network Systems. 567 8. Informative References 569 [ASN1] ITU-T Rec. X.680, "Abstract Syntax Notation One (ASN.1). 570 Specification of Basic Notation", ISO/IEC 8824-1:2002, 571 2002. 573 [ASN1-BER] 574 ITU-T Rec. X.690, "Abstract Syntax Notation One (ASN.1). 575 Encoding Rules: Specification of Basic Encoding Rules 576 (BER), Canonical Encoding Rules (CER) and Distinguished 577 Encoding Rules (DER)", ISO/IEC 8825-1:2002, 2002. 579 [BRF04] Burleigh, S., Ramadas, M., and S. Farrell, "Licklider 580 Transmission Protocol", 581 draft-irtf-dtnrg-ltp-00 (replaced), May 2004. 583 [Hain05] Hain, T., "A Pragmatic Report on IPv4 Address Space 584 Consumption", Internet Protocol Journal Vol. 8, No. 3, 585 September 2005. 587 [I-D.hixie-thewebsocketprotocol] 588 Hickson, I., "The WebSocket protocol", 589 draft-hixie-thewebsocketprotocol-76 (work in progress), 590 May 2010. 592 [IEN21] Cerf, V. and J. Postel, "Specification of Internetwork 593 Transmission Control Program: TCP Version 3", Internet 594 Experimental Note 21, January 1978. 596 [RFC0713] Haverty, J., "MSDTP-Message Services Data Transmission 597 Protocol", RFC 713, April 1976. 599 [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, 600 September 1981. 602 [RFC0793] Postel, J., "Transmission Control Protocol", STD 7, 603 RFC 793, September 1981. 605 [RFC1323] Jacobson, V., Braden, B., and D. Borman, "TCP Extensions 606 for High Performance", RFC 1323, May 1992. 608 [RFC2993] Hain, T., "Architectural Implications of NAT", RFC 2993, 609 November 2000. 611 [RFC3766] Orman, H. and P. Hoffman, "Determining Strengths For 612 Public Keys Used For Exchanging Symmetric Keys", BCP 86, 613 RFC 3766, April 2004. 615 [RFC4963] Heffner, J., Mathis, M., and B. Chandler, "IPv4 Reassembly 616 Errors at High Data Rates", RFC 4963, July 2007. 618 [RFC5050] Scott, K. and S. Burleigh, "Bundle Protocol 619 Specification", RFC 5050, November 2007. 621 [RFC5325] Burleigh, S., Ramadas, M., and S. Farrell, "Licklider 622 Transmission Protocol - Motivation", RFC 5325, 623 September 2008. 625 [RFC5326] Ramadas, M., Burleigh, S., and S. Farrell, "Licklider 626 Transmission Protocol - Specification", RFC 5326, 627 September 2008. 629 Appendix A. SNDV Python Source Code 631 # sdnv_decode() takes a string argument (s), which is assumed to be 632 # an SDNV, and optionally a number (slen) for the maximum number of 633 # bytes to parse from the string. The function returns a pair of 634 # the non-negative integer n that is the numeric value encoded in 635 # the SDNV, and integer that is the distance parsed into the input 636 # string. If the slen argument is not given (or is not a non-zero 637 # number) then, s is parsed up to the first byte whose high-order 638 # bit is 0 -- the length of the SDNV portion of s does not have to 639 # be pre-computed by calling code. If the slen argument is given 640 # as a non-zero value, then slen bytes of s are parsed. The value 641 # for n of -1 is returned for any type of parsing error. 642 # 643 # NOTE: In python, integers can be of arbitrary size. In other 644 # languages, such as C, SDNV-parsing routines should take 645 # precautions to avoid overflow (e.g. by using the Gnu MP library, 646 # or similar). 647 # 648 def sdnv_decode(s, slen=0): 649 n = long(0) 650 for i in range(0, len(s)): 651 v = ord(s[i]) 652 n = n<<7 653 n = n + (v & 0x7F) 654 if v>>7 == 0: 655 slen = i+1 656 break 657 elif i == len(s)-1 or (slen != 0 and i > slen): 658 n = -1 # reached end of input without seeing end of SDNV 659 return (n, slen) 661 # sdnv_encode() returns the SDNV-encoded string that represents n. 662 # An empty string is returned if n is not a non-negative integer 663 def sdnv_encode(n): 664 r = "" 665 # validate input 666 if n >= 0 and (type(n) in [type(int(1)), type(long(1))]): 667 flag = 0 668 done = False 669 while not done: 670 # encode lowest 7 bits from n 671 newbits = n & 0x7F 672 n = n>>7 673 r = chr(newbits + flag) + r 674 if flag == 0: 675 flag = 0x80 676 if n == 0: 678 done = True 679 return r 681 # test cases from LTP and BP internet-drafts, only print failures 682 def sdnv_test(): 683 tests = [(0xABC, chr(0x95) + chr(0x3C)), 684 (0x1234, chr(0xA4) + chr (0x34)), 685 (0x4234, chr(0x81) + chr(0x84) + chr(0x34)), 686 (0x7F, chr(0x7F))] 688 for tp in tests: 689 # test encoding function 690 if sdnv_encode(tp[0]) != tp[1]: 691 print "sdnv_encode fails on input %s" % hex(tp[0]) 692 # test decoding function 693 if sdnv_decode(tp[1])[0] != tp[0]: 694 print "sdnv_decode fails on input %s, giving %s" % \ 695 (hex(tp[0]), sdnv_decode(tp[1])) 697 Authors' Addresses 699 Wesley M. Eddy 700 MTI Systems 701 NASA Glenn Research Center 702 MS 500-ASRC; 21000 Brookpark Rd 703 Cleveland, OH 44135 705 Phone: 216-433-6682 706 Email: wes@mti-systems.com 708 Elwyn Davies 709 Folly Consulting 710 Soham 711 UK 713 Phone: 714 Email: elwynd@folly.org.uk 715 URI: