draft-josefsson-rfc3548bis-03.txt | draft-josefsson-rfc3548bis.txt | |||
---|---|---|---|---|
Network Working Group S. Josefsson | Network Working Group S. Josefsson | |||
Internet-Draft SJD | Internet-Draft SJD | |||
Obsoletes: 3548 (if approved) May 3, 2006 | Obsoletes: 3548 (if approved) May 2006 | |||
Expires: November 4, 2006 | Intended status: Informational | |||
Expires: November 2, 2006 | ||||
The Base16, Base32, and Base64 Data Encodings | The Base16, Base32, and Base64 Data Encodings | |||
draft-josefsson-rfc3548bis-03 | draft-josefsson-rfc3548bis-04 | |||
Status of this Memo | Status of this Memo | |||
By submitting this Internet-Draft, each author represents that any | By submitting this Internet-Draft, each author represents that any | |||
applicable patent or other IPR claims of which he or she is aware | applicable patent or other IPR claims of which he or she is aware | |||
have been or will be disclosed, and any of which he or she becomes | have been or will be disclosed, and any of which he or she becomes | |||
aware will be disclosed, in accordance with Section 6 of BCP 79. | aware will be disclosed, in accordance with Section 6 of BCP 79. | |||
Internet-Drafts are working documents of the Internet Engineering | Internet-Drafts are working documents of the Internet Engineering | |||
Task Force (IETF), its areas, and its working groups. Note that | Task Force (IETF), its areas, and its working groups. Note that | |||
skipping to change at page 1, line 34 | skipping to change at page 1, line 35 | |||
and may be updated, replaced, or obsoleted by other documents at any | and may be updated, replaced, or obsoleted by other documents at any | |||
time. It is inappropriate to use Internet-Drafts as reference | time. It is inappropriate to use Internet-Drafts as reference | |||
material or to cite them other than as "work in progress." | material or to cite them other than as "work in progress." | |||
The list of current Internet-Drafts can be accessed at | The list of current Internet-Drafts can be accessed at | |||
http://www.ietf.org/ietf/1id-abstracts.txt. | http://www.ietf.org/ietf/1id-abstracts.txt. | |||
The list of Internet-Draft Shadow Directories can be accessed at | The list of Internet-Draft Shadow Directories can be accessed at | |||
http://www.ietf.org/shadow.html. | http://www.ietf.org/shadow.html. | |||
This Internet-Draft will expire on November 4, 2006. | This Internet-Draft will expire on November 2, 2006. | |||
Copyright Notice | ||||
Copyright (C) The Internet Society (2006). | ||||
Keywords | Keywords | |||
Base Encoding, Base64, Base32, Base16, Hex. | Base Encoding, Base64, Base32, Base16, Hex. | |||
Abstract | Abstract | |||
This document describes the commonly used base 64, base 32, and base | This document describes the commonly used base 64, base 32, and base | |||
16 encoding schemes. It also discusses the use of line-feeds in | 16 encoding schemes. It also discusses the use of line-feeds in | |||
encoded data, use of padding in encoded data, use of non-alphabet | encoded data, use of padding in encoded data, use of non-alphabet | |||
characters in encoded data, and use of different encoding alphabets. | characters in encoded data, use of different encoding alphabets, and | |||
canonical encodings. | ||||
Table of Contents | Table of Contents | |||
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 | 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 | |||
2. Conventions Used in this Document . . . . . . . . . . . . . . 3 | 2. Conventions Used in this Document . . . . . . . . . . . . . . 3 | |||
3. Implementation Discrepancies . . . . . . . . . . . . . . . . . 3 | 3. Implementation Discrepancies . . . . . . . . . . . . . . . . . 3 | |||
3.1. Line Feeds In Encoded Data . . . . . . . . . . . . . . . . 3 | 3.1. Line Feeds In Encoded Data . . . . . . . . . . . . . . . . 3 | |||
3.2. Padding Of Encoded Data . . . . . . . . . . . . . . . . . 4 | 3.2. Padding Of Encoded Data . . . . . . . . . . . . . . . . . 4 | |||
3.3. Interpretation Of Non-Alphabet Characters In Encoded | 3.3. Interpretation Of Non-Alphabet Characters In Encoded | |||
data . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 | data . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 | |||
3.4. Choosing The Alphabet . . . . . . . . . . . . . . . . . . 4 | 3.4. Choosing The Alphabet . . . . . . . . . . . . . . . . . . 4 | |||
3.5. Canonical Encoding . . . . . . . . . . . . . . . . . . . . 6 | ||||
4. Base 64 Encoding . . . . . . . . . . . . . . . . . . . . . . . 6 | 4. Base 64 Encoding . . . . . . . . . . . . . . . . . . . . . . . 6 | |||
5. Base 64 Encoding With URL And Filename Safe Alphabet . . . . . 8 | 5. Base 64 Encoding With URL And Filename Safe Alphabet . . . . . 9 | |||
6. Base 32 Encoding . . . . . . . . . . . . . . . . . . . . . . . 8 | 6. Base 32 Encoding . . . . . . . . . . . . . . . . . . . . . . . 10 | |||
7. Base 32 Encoding With Extended Hex Alphabet . . . . . . . . . 10 | 7. Base 32 Encoding With Extended Hex Alphabet . . . . . . . . . 11 | |||
8. Base 16 Encoding . . . . . . . . . . . . . . . . . . . . . . . 11 | 8. Base 16 Encoding . . . . . . . . . . . . . . . . . . . . . . . 13 | |||
9. Illustrations And Examples . . . . . . . . . . . . . . . . . . 12 | 9. Illustrations And Examples . . . . . . . . . . . . . . . . . . 14 | |||
10. Test Vectors . . . . . . . . . . . . . . . . . . . . . . . . . 13 | 10. Test Vectors . . . . . . . . . . . . . . . . . . . . . . . . . 15 | |||
11. ISO C99 Implementation Of Base64 . . . . . . . . . . . . . . . 14 | 11. ISO C99 Implementation Of Base64 . . . . . . . . . . . . . . . 16 | |||
11.1. Prototypes: base64.h . . . . . . . . . . . . . . . . . . . 14 | 11.1. Prototypes: base64.h . . . . . . . . . . . . . . . . . . . 16 | |||
11.2. Implementation: base64.c . . . . . . . . . . . . . . . . . 16 | 11.2. Implementation: base64.c . . . . . . . . . . . . . . . . . 18 | |||
12. Security Considerations . . . . . . . . . . . . . . . . . . . 25 | 12. Security Considerations . . . . . . . . . . . . . . . . . . . 27 | |||
13. Changes Since RFC 3548 . . . . . . . . . . . . . . . . . . . . 25 | 13. Changes Since RFC 3548 . . . . . . . . . . . . . . . . . . . . 27 | |||
14. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 26 | 14. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 28 | |||
15. Copying Conditions . . . . . . . . . . . . . . . . . . . . . . 26 | 15. Copying Conditions . . . . . . . . . . . . . . . . . . . . . . 28 | |||
16. References . . . . . . . . . . . . . . . . . . . . . . . . . . 26 | 16. References . . . . . . . . . . . . . . . . . . . . . . . . . . 28 | |||
16.1. Normative References . . . . . . . . . . . . . . . . . . . 26 | 16.1. Normative References . . . . . . . . . . . . . . . . . . . 28 | |||
16.2. Informative References . . . . . . . . . . . . . . . . . . 26 | 16.2. Informative References . . . . . . . . . . . . . . . . . . 29 | |||
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 28 | Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 29 | |||
Intellectual Property and Copyright Statements . . . . . . . . . . 29 | Intellectual Property and Copyright Statements . . . . . . . . . . 31 | |||
1. Introduction | 1. Introduction | |||
Base encoding of data is used in many situations to store or transfer | Base encoding of data is used in many situations to store or transfer | |||
data in environments that, perhaps for legacy reasons, are restricted | data in environments that, perhaps for legacy reasons, are restricted | |||
to only US-ASCII [1] data. Base encoding can also be used in new | to only US-ASCII [RFC0020] data. Base encoding can also be used in | |||
applications that do not have legacy restrictions, simply because it | new applications that do not have legacy restrictions, simply because | |||
makes it possible to manipulate objects with text editors. | it makes it possible to manipulate objects with text editors. | |||
In the past, different applications have had different requirements | In the past, different applications have had different requirements | |||
and thus sometimes implemented base encodings in slightly different | and thus sometimes implemented base encodings in slightly different | |||
ways. Today, protocol specifications sometimes use base encodings in | ways. Today, protocol specifications sometimes use base encodings in | |||
general, and "base64" in particular, without a precise description or | general, and "base64" in particular, without a precise description or | |||
reference. Multipurpose Internet Mail Extensions (MIME) [4] is often | reference. Multipurpose Internet Mail Extensions (MIME) [RFC2045] is | |||
used as a reference for base64 without considering the consequences | often used as a reference for base64 without considering the | |||
for line-wrapping or non-alphabet characters. The purpose of this | consequences for line-wrapping or non-alphabet characters. The | |||
specification is to establish common alphabet and encoding | purpose of this specification is to establish common alphabet and | |||
considerations. This will hopefully reduce ambiguity in other | encoding considerations. This will hopefully reduce ambiguity in | |||
documents, leading to better interoperability. | other documents, leading to better interoperability. | |||
2. Conventions Used in this Document | 2. Conventions Used in this Document | |||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", | The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", | |||
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this | "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this | |||
document are to be interpreted as described in [2]. | document are to be interpreted as described in [RFC2119]. | |||
3. Implementation Discrepancies | 3. Implementation Discrepancies | |||
Here we discuss the discrepancies between base encoding | Here we discuss the discrepancies between base encoding | |||
implementations in the past, and where appropriate, mandate a | implementations in the past, and where appropriate, mandate a | |||
specific recommended behavior for the future. | specific recommended behavior for the future. | |||
3.1. Line Feeds In Encoded Data | 3.1. Line Feeds In Encoded Data | |||
MIME [4] is often used as a reference for base 64 encoding. However, | MIME [RFC2045] is often used as a reference for base 64 encoding. | |||
MIME does not define "base 64" per se, but rather a "base 64 Content- | However, MIME does not define "base 64" per se, but rather a "base 64 | |||
Transfer-Encoding" for use within MIME. As such, MIME enforces a | Content-Transfer-Encoding" for use within MIME. As such, MIME | |||
limit on line length of base 64 encoded data to 76 characters. MIME | enforces a limit on line length of base 64 encoded data to 76 | |||
inherits the encoding from Privacy Enhanced Mail (PEM) [3] stating it | characters. MIME inherits the encoding from Privacy Enhanced Mail | |||
is "virtually identical", however PEM uses a line length of 64 | (PEM) [RFC1421] stating it is "virtually identical", however PEM uses | |||
characters. The MIME and PEM limits are both due to limits within | a line length of 64 characters. The MIME and PEM limits are both due | |||
SMTP. | to limits within SMTP. | |||
Implementations MUST NOT add line feeds to base encoded data unless | Implementations MUST NOT add line feeds to base encoded data unless | |||
the specification referring to this document explicitly directs base | the specification referring to this document explicitly directs base | |||
encoders to add line feeds after a specific number of characters. | encoders to add line feeds after a specific number of characters. | |||
3.2. Padding Of Encoded Data | 3.2. Padding Of Encoded Data | |||
In some circumstances, the use of padding ("=") in base encoded data | In some circumstances, the use of padding ("=") in base encoded data | |||
is not required nor used. In the general case, when assumptions on | is not required nor used. In the general case, when assumptions on | |||
size of transported data cannot be made, padding is required to yield | size of transported data cannot be made, padding is required to yield | |||
skipping to change at page 6, line 15 | skipping to change at page 6, line 15 | |||
16 and base 32, this determines the use of upper- or lowercase | 16 and base 32, this determines the use of upper- or lowercase | |||
alphabets. For base 64, the non-alphanumeric characters (in | alphabets. For base 64, the non-alphanumeric characters (in | |||
particular "/") may be problematic in file names and URLs. | particular "/") may be problematic in file names and URLs. | |||
o Used as identifiers. Certain characters, notably "+" and "/" in | o Used as identifiers. Certain characters, notably "+" and "/" in | |||
the base 64 alphabet, are treated as word-breaks by legacy text | the base 64 alphabet, are treated as word-breaks by legacy text | |||
search/index tools. | search/index tools. | |||
There is no universally accepted alphabet that fulfills all the | There is no universally accepted alphabet that fulfills all the | |||
requirements. For an example of a highly specialized variant, see | requirements. For an example of a highly specialized variant, see | |||
IMAP [8]. In this document, we document and name some currently used | IMAP [RFC3501]. In this document, we document and name some | |||
alphabets. | currently used alphabets. | |||
3.5. Canonical Encoding | ||||
The padding step in base 64 and base 32 encoding can, if improperly | ||||
implemented, lead to non-significant alterations of the encoded data. | ||||
For example, if the input is only one octet for a base 64 encoding, | ||||
then all six bits of the first symbol are used, but only the first | ||||
two bits of the next symbol are used. These pad bits MUST be set to | ||||
zero by conforming encoders, which is described in the descriptions | ||||
on padding below. If this property do not hold, there is no | ||||
canonical representation of base encoded data, and multiple base | ||||
encoded strings can be decoded to the same binary data. If this | ||||
property (and others discussed in this document) holds, a canonical | ||||
encoding is guaranteed. | ||||
In some environments, the alteration is critical and therefor | ||||
decoders MAY chose to reject an encoding if the pad bits have not | ||||
been set to zero. The specification referring to this may mandate a | ||||
specific behaviour. | ||||
4. Base 64 Encoding | 4. Base 64 Encoding | |||
The following description of base 64 is derived from [3], [4], [5] | The following description of base 64 is derived from [RFC1421], | |||
and [6]. This encoding may be referred to as "base64". | [RFC2045], [RFC2440] and [RFC2535]. This encoding may be referred to | |||
as "base64". | ||||
The Base 64 encoding is designed to represent arbitrary sequences of | The Base 64 encoding is designed to represent arbitrary sequences of | |||
octets in a form that allows the use of both upper- and lowercase | octets in a form that allows the use of both upper- and lowercase | |||
letters but need not be humanly readable. | letters but need not be humanly readable. | |||
A 65-character subset of US-ASCII is used, enabling 6 bits to be | A 65-character subset of US-ASCII is used, enabling 6 bits to be | |||
represented per printable character. (The extra 65th character, "=", | represented per printable character. (The extra 65th character, "=", | |||
is used to signify a special processing function.) | is used to signify a special processing function.) | |||
The encoding process represents 24-bit groups of input bits as output | The encoding process represents 24-bit groups of input bits as output | |||
strings of 4 encoded characters. Proceeding from left to right, a | strings of 4 encoded characters. Proceeding from left to right, a | |||
24-bit input group is formed by concatenating 3 8-bit input groups. | 24-bit input group is formed by concatenating 3 8-bit input groups. | |||
These 24 bits are then treated as 4 concatenated 6-bit groups, each | These 24 bits are then treated as 4 concatenated 6-bit groups, each | |||
of which is translated into a single character in the base 64 | of which is translated into a single character in the base 64 | |||
alphabet. | alphabet. | |||
Each 6-bit group is used as an index into an array of 64 printable | Each 6-bit group is used as an index into an array of 64 printable | |||
characters. The character referenced by the index is placed in the | characters. The character referenced by the index is placed in the | |||
output string. | output string. | |||
skipping to change at page 7, line 42 | skipping to change at page 8, line 4 | |||
all base 64 input is an integral number of octets, only the following | all base 64 input is an integral number of octets, only the following | |||
cases can arise: | cases can arise: | |||
(1) the final quantum of encoding input is an integral multiple of 24 | (1) the final quantum of encoding input is an integral multiple of 24 | |||
bits; here, the final unit of encoded output will be an integral | bits; here, the final unit of encoded output will be an integral | |||
multiple of 4 characters with no "=" padding, | multiple of 4 characters with no "=" padding, | |||
(2) the final quantum of encoding input is exactly 8 bits; here, the | (2) the final quantum of encoding input is exactly 8 bits; here, the | |||
final unit of encoded output will be two characters followed by two | final unit of encoded output will be two characters followed by two | |||
"=" padding characters, or | "=" padding characters, or | |||
(3) the final quantum of encoding input is exactly 16 bits; here, the | (3) the final quantum of encoding input is exactly 16 bits; here, the | |||
final unit of encoded output will be three characters followed by one | final unit of encoded output will be three characters followed by one | |||
"=" padding character. | "=" padding character. | |||
5. Base 64 Encoding With URL And Filename Safe Alphabet | 5. Base 64 Encoding With URL And Filename Safe Alphabet | |||
The Base 64 encoding with an URL and filename safe alphabet has been | The Base 64 encoding with an URL and filename safe alphabet has been | |||
used in [11]. | used in [mojonation]. | |||
An alternative alphabet has been suggested that used "~" as the 63rd | An alternative alphabet has been suggested that used "~" as the 63rd | |||
character. Since the "~" character has special meaning in some file | character. Since the "~" character has special meaning in some file | |||
system environments, the encoding described in this section is | system environments, the encoding described in this section is | |||
recommended instead. | recommended instead. The remaining unreserved URI character is ".", | |||
but some file system environments does not permit multiple "." in a | ||||
filename, thus making the "." character unattractive as well. | ||||
The pad character "=" is typically percent-encoded when used in an | ||||
URI [RFC3986], but if the data length is known implicitly, this can | ||||
be avoided by skipping the padding, see section 3.2. | ||||
This encoding may be referred to as "base64url". This encoding | This encoding may be referred to as "base64url". This encoding | |||
should not be regarded as the same as the "base64" encoding, and | should not be regarded as the same as the "base64" encoding, and | |||
should not be referred to as only "base64". Unless made clear, | should not be referred to as only "base64". Unless made clear, | |||
"base64" refer to the base 64 in the previous section. | "base64" refer to the base 64 in the previous section. | |||
This encoding is technically identical to the previous one, except | This encoding is technically identical to the previous one, except | |||
for the 62:nd and 63:rd alphabet character, as indicated in table 2. | for the 62:nd and 63:rd alphabet character, as indicated in table 2. | |||
Table 2: The "URL and Filename safe" Base 64 Alphabet | Table 2: The "URL and Filename safe" Base 64 Alphabet | |||
skipping to change at page 8, line 46 | skipping to change at page 10, line 7 | |||
10 K 27 b 44 s 61 9 | 10 K 27 b 44 s 61 9 | |||
11 L 28 c 45 t 62 - (minus) | 11 L 28 c 45 t 62 - (minus) | |||
12 M 29 d 46 u 63 _ | 12 M 29 d 46 u 63 _ | |||
13 N 30 e 47 v (underline) | 13 N 30 e 47 v (underline) | |||
14 O 31 f 48 w | 14 O 31 f 48 w | |||
15 P 32 g 49 x | 15 P 32 g 49 x | |||
16 Q 33 h 50 y (pad) = | 16 Q 33 h 50 y (pad) = | |||
6. Base 32 Encoding | 6. Base 32 Encoding | |||
The following description of base 32 is derived from [10] (with | The following description of base 32 is derived from | |||
corrections). This encoding may be referred to as "base32". | [draft-ietf-cat-sasl-gssapi-01] (with corrections). This encoding | |||
may be referred to as "base32". | ||||
The Base 32 encoding is designed to represent arbitrary sequences of | The Base 32 encoding is designed to represent arbitrary sequences of | |||
octets in a form that needs to be case insensitive but need not be | octets in a form that needs to be case insensitive but need not be | |||
humanly readable. | humanly readable. | |||
A 33-character subset of US-ASCII is used, enabling 5 bits to be | A 33-character subset of US-ASCII is used, enabling 5 bits to be | |||
represented per printable character. (The extra 33rd character, "=", | represented per printable character. (The extra 33rd character, "=", | |||
is used to signify a special processing function.) | is used to signify a special processing function.) | |||
The encoding process represents 40-bit groups of input bits as output | The encoding process represents 40-bit groups of input bits as output | |||
skipping to change at page 10, line 20 | skipping to change at page 11, line 30 | |||
(4) the final quantum of encoding input is exactly 24 bits; here, the | (4) the final quantum of encoding input is exactly 24 bits; here, the | |||
final unit of encoded output will be five characters followed by | final unit of encoded output will be five characters followed by | |||
three "=" padding characters, or | three "=" padding characters, or | |||
(5) the final quantum of encoding input is exactly 32 bits; here, the | (5) the final quantum of encoding input is exactly 32 bits; here, the | |||
final unit of encoded output will be seven characters followed by one | final unit of encoded output will be seven characters followed by one | |||
"=" padding character. | "=" padding character. | |||
7. Base 32 Encoding With Extended Hex Alphabet | 7. Base 32 Encoding With Extended Hex Alphabet | |||
The following description of base 32 is derived from [7]. This | The following description of base 32 is derived from [RFC2938]. This | |||
encoding may be referred to as "base32hex". This encoding should not | encoding may be referred to as "base32hex". This encoding should not | |||
be regarded as the same as the "base32" encoding, and should not be | be regarded as the same as the "base32" encoding, and should not be | |||
referred to as only "base32". This encoding is used by, e.g., NSEC3 | referred to as only "base32". This encoding is used by, e.g., NSEC3 | |||
[9] | [I-D.ietf-dnsext-nsec3] | |||
One property with this alphabet, that the base64 and base32 alphabet | One property with this alphabet, that the base64 and base32 alphabet | |||
lack, is that encoded data maintain its sort order when the encoded | lack, is that encoded data maintain its sort order when the encoded | |||
data is compared bit-wise. | data is compared bit-wise. | |||
This encoding is identical to the previous one, except for the | This encoding is identical to the previous one, except for the | |||
alphabet. The new alphabet is found in table 4. | alphabet. The new alphabet is found in table 4. | |||
Table 4: The "Extended Hex" Base 32 Alphabet | Table 4: The "Extended Hex" Base 32 Alphabet | |||
skipping to change at page 12, line 9 | skipping to change at page 14, line 9 | |||
2 2 6 6 10 A 14 E | 2 2 6 6 10 A 14 E | |||
3 3 7 7 11 B 15 F | 3 3 7 7 11 B 15 F | |||
Unlike base 32 and base 64, no special padding is necessary since a | Unlike base 32 and base 64, no special padding is necessary since a | |||
full code word is always available. | full code word is always available. | |||
9. Illustrations And Examples | 9. Illustrations And Examples | |||
To translate between binary and a base encoding, the input is stored | To translate between binary and a base encoding, the input is stored | |||
in a structure and the output is extracted. The case for base 64 is | in a structure and the output is extracted. The case for base 64 is | |||
displayed in the following figure, borrowed from [5]. | displayed in the following figure, borrowed from [RFC2440]. | |||
+--first octet--+-second octet--+--third octet--+ | +--first octet--+-second octet--+--third octet--+ | |||
|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| | |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| | |||
+-----------+---+-------+-------+---+-----------+ | +-----------+---+-------+-------+---+-----------+ | |||
|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| | |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| | |||
+--1.index--+--2.index--+--3.index--+--4.index--+ | +--1.index--+--2.index--+--3.index--+--4.index--+ | |||
The case for base 32 is shown in the following figure, borrowed from | The case for base 32 is shown in the following figure, borrowed from | |||
[7]. Each successive character in a base-32 value represents 5 | [RFC2938]. Each successive character in a base-32 value represents 5 | |||
successive bits of the underlying octet sequence. Thus, each group | successive bits of the underlying octet sequence. Thus, each group | |||
of 8 characters represents a sequence of 5 octets (40 bits). | of 8 characters represents a sequence of 5 octets (40 bits). | |||
1 2 3 | 1 2 3 | |||
01234567 89012345 67890123 45678901 23456789 | 01234567 89012345 67890123 45678901 23456789 | |||
+--------+--------+--------+--------+--------+ | +--------+--------+--------+--------+--------+ | |||
|< 1 >< 2| >< 3 ><|.4 >< 5.|>< 6 ><.|7 >< 8 >| | |< 1 >< 2| >< 3 ><|.4 >< 5.|>< 6 ><.|7 >< 8 >| | |||
+--------+--------+--------+--------+--------+ | +--------+--------+--------+--------+--------+ | |||
<===> 8th character | <===> 8th character | |||
<====> 7th character | <====> 7th character | |||
<===> 6th character | <===> 6th character | |||
<====> 5th character | <====> 5th character | |||
<====> 4th character | <====> 4th character | |||
<===> 3rd character | <===> 3rd character | |||
<====> 2nd character | <====> 2nd character | |||
<===> 1st character | <===> 1st character | |||
The following example of Base64 data is from [5], with corrections. | The following example of Base64 data is from [RFC2440], with | |||
corrections. | ||||
Input data: 0x14fb9c03d97e | Input data: 0x14fb9c03d97e | |||
Hex: 1 4 f b 9 c | 0 3 d 9 7 e | Hex: 1 4 f b 9 c | 0 3 d 9 7 e | |||
8-bit: 00010100 11111011 10011100 | 00000011 11011001 01111110 | 8-bit: 00010100 11111011 10011100 | 00000011 11011001 01111110 | |||
6-bit: 000101 001111 101110 011100 | 000000 111101 100101 111110 | 6-bit: 000101 001111 101110 011100 | 000000 111101 100101 111110 | |||
Decimal: 5 15 46 28 0 61 37 62 | Decimal: 5 15 46 28 0 61 37 62 | |||
Output: F P u c A 9 l + | Output: F P u c A 9 l + | |||
Input data: 0x14fb9c03d9 | Input data: 0x14fb9c03d9 | |||
Hex: 1 4 f b 9 c | 0 3 d 9 | Hex: 1 4 f b 9 c | 0 3 d 9 | |||
skipping to change at page 15, line 20 | skipping to change at page 17, line 20 | |||
General Public License as published by the Free Software | General Public License as published by the Free Software | |||
Foundation; either version 2.1, or (at your option) any | Foundation; either version 2.1, or (at your option) any | |||
later version. | later version. | |||
This program is distributed in the hope that it will be | This program is distributed in the hope that it will be | |||
useful, but WITHOUT ANY WARRANTY; without even the | useful, but WITHOUT ANY WARRANTY; without even the | |||
implied warranty of MERCHANTABILITY or FITNESS FOR A | implied warranty of MERCHANTABILITY or FITNESS FOR A | |||
PARTICULAR PURPOSE. See the GNU Lesser General Public | PARTICULAR PURPOSE. See the GNU Lesser General Public | |||
License for more details. | License for more details. | |||
You should have received a copy of the GNU Lesser General | You can retrieve a copy of the GNU Lesser General Public | |||
Public License along with this program; if not, write to | License from http://www.gnu.org/licenses/lgpl.txt; or by | |||
the Free Software Foundation, Inc., 51 Franklin Street, | writing to the Free Software Foundation, Inc., 51 | |||
Fifth Floor, Boston, MA 02110-1301, USA. */ | Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | |||
#ifndef BASE64_H | #ifndef BASE64_H | |||
# define BASE64_H | # define BASE64_H | |||
/* Get size_t. */ | /* Get size_t. */ | |||
# include <stddef.h> | # include <stddef.h> | |||
/* Get bool. */ | /* Get bool. */ | |||
# include <stdbool.h> | # include <stdbool.h> | |||
skipping to change at page 16, line 29 | skipping to change at page 18, line 29 | |||
General Public License as published by the Free Software | General Public License as published by the Free Software | |||
Foundation; either version 2.1, or (at your option) any | Foundation; either version 2.1, or (at your option) any | |||
later version. | later version. | |||
This program is distributed in the hope that it will be | This program is distributed in the hope that it will be | |||
useful, but WITHOUT ANY WARRANTY; without even the | useful, but WITHOUT ANY WARRANTY; without even the | |||
implied warranty of MERCHANTABILITY or FITNESS FOR A | implied warranty of MERCHANTABILITY or FITNESS FOR A | |||
PARTICULAR PURPOSE. See the GNU Lesser General Public | PARTICULAR PURPOSE. See the GNU Lesser General Public | |||
License for more details. | License for more details. | |||
You should have received a copy of the GNU Lesser General | You can retrieve a copy of the GNU Lesser General Public | |||
Public License along with this program; if not, write to | License from http://www.gnu.org/licenses/lgpl.txt; or by | |||
the Free Software Foundation, Inc., 51 Franklin Street, | writing to the Free Software Foundation, Inc., 51 | |||
Fifth Floor, Boston, MA 02110-1301, USA. */ | Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | |||
/* Written by Simon Josefsson. Partially adapted from GNU | /* Written by Simon Josefsson. Partially adapted from GNU | |||
* MailUtils (mailbox/filter_trans.c, as of 2004-11-28). | * MailUtils (mailbox/filter_trans.c, as of 2004-11-28). | |||
* Improved by review from Paul Eggert, Bruno Haible, and | * Improved by review from Paul Eggert, Bruno Haible, and | |||
* Stepan Kasal. | * Stepan Kasal. | |||
* | * | |||
* Be careful with error checking. Here is how you would | * Be careful with error checking. Here is how you would | |||
* typically use these functions: | * typically use these functions: | |||
* | * | |||
* bool ok = base64_decode_alloc (in, inlen, &out, &outlen); | * bool ok = base64_decode_alloc (in, inlen, &out, &outlen); | |||
skipping to change at page 25, line 16 | skipping to change at page 27, line 16 | |||
12. Security Considerations | 12. Security Considerations | |||
When implementing Base encoding and decoding, care should be taken | When implementing Base encoding and decoding, care should be taken | |||
not to introduce vulnerabilities to buffer overflow attacks, or other | not to introduce vulnerabilities to buffer overflow attacks, or other | |||
attacks on the implementation. A decoder should not break on invalid | attacks on the implementation. A decoder should not break on invalid | |||
input including, e.g., embedded NUL characters (ASCII 0). | input including, e.g., embedded NUL characters (ASCII 0). | |||
If non-alphabet characters are ignored, instead of causing rejection | If non-alphabet characters are ignored, instead of causing rejection | |||
of the entire encoding (as recommended), a covert channel that can be | of the entire encoding (as recommended), a covert channel that can be | |||
used to "leak" information is made possible. The implications of | used to "leak" information is made possible. The ignored characters | |||
this should be understood in applications that do not follow the | could also be used for other nefarious purposes, such as to avoid a | |||
recommended practice. Similarly, when the base 16 and base 32 | string equality comparison or to trigger implementation bugs. The | |||
alphabets are handled case insensitively, alteration of case can be | implications of ignoring non-alphabet characters should be understood | |||
used to leak information. | in applications that do not follow the recommended practice. | |||
Similarly, when the base 16 and base 32 alphabets are handled case | ||||
insensitively, alteration of case can be used to leak information or | ||||
make string equality comparisons fail. | ||||
When padding is used, there are some non-significant bits that | ||||
warrant security concerns, they may be abused to leak information, | ||||
used to bypass string equality comparisons, or to trigger | ||||
implementation problems. | ||||
Base encoding visually hides otherwise easily recognized information, | Base encoding visually hides otherwise easily recognized information, | |||
such as passwords, but does not provide any computational | such as passwords, but does not provide any computational | |||
confidentiality. This has been known to cause security incidents | confidentiality. This has been known to cause security incidents | |||
when, e.g., a user reports details of a network protocol exchange | when, e.g., a user reports details of a network protocol exchange | |||
(perhaps to illustrate some other problem) and accidentally reveals | (perhaps to illustrate some other problem) and accidentally reveals | |||
the password because she is unaware that the base encoding does not | the password because she is unaware that the base encoding does not | |||
protect the password. | protect the password. | |||
Base encoding adds no entropy to the plaintext, but it does increase | Base encoding adds no entropy to the plaintext, but it does increase | |||
skipping to change at page 26, line 15 | skipping to change at page 28, line 24 | |||
14. Acknowledgements | 14. Acknowledgements | |||
Several people offered comments and/or suggestions, including John E. | Several people offered comments and/or suggestions, including John E. | |||
Hadstate, Tony Hansen, Gordon Mohr, John Myers, Chris Newman and | Hadstate, Tony Hansen, Gordon Mohr, John Myers, Chris Newman and | |||
Andrew Sieber. Text used in this document are based on earlier RFCs | Andrew Sieber. Text used in this document are based on earlier RFCs | |||
describing specific uses of various base encodings. The author | describing specific uses of various base encodings. The author | |||
acknowledges the RSA Laboratories for supporting the work that led to | acknowledges the RSA Laboratories for supporting the work that led to | |||
this document. | this document. | |||
This revised version is based in parts on comments and/or suggestions | This revised version is based in parts on comments and/or suggestions | |||
made by Roy Arends, Eric Blake, Elwyn Davies, Ted Hardie, Per Hygum, | made by Roy Arends, Eric Blake, Brian E Carpenter, Elwyn Davies, Bill | |||
Jelte Jansen, Clement Kent, Paul Kwiatkowski, and Ben Laurie. | Fenner, Sam Hartman, Ted Hardie, Per Hygum, Jelte Jansen, Clement | |||
Kent, Tero Kivinen, Paul Kwiatkowski, and Ben Laurie. | ||||
15. Copying Conditions | 15. Copying Conditions | |||
Copyright (c) 2000-2006 Simon Josefsson | Copyright (c) 2000-2006 Simon Josefsson | |||
Regarding the abstract and section 1, 3, 8, 10, 12, 13, and 14 of | Regarding the abstract and section 1, 3, 8, 10, 12, 13, and 14 of | |||
this document, that were written by Simon Josefsson ("the author", | this document, that were written by Simon Josefsson ("the author", | |||
for the remainder of this section), the author makes no guarantees | for the remainder of this section), the author makes no guarantees | |||
and is not responsible for any damage resulting from its use. The | and is not responsible for any damage resulting from its use. The | |||
author grants irrevocable permission to anyone to use, modify, and | author grants irrevocable permission to anyone to use, modify, and | |||
distribute it in any way that does not diminish the rights of anyone | distribute it in any way that does not diminish the rights of anyone | |||
else to use, modify, and distribute it, provided that redistributed | else to use, modify, and distribute it, provided that redistributed | |||
derivative works do not contain misleading author or version | derivative works do not contain misleading author or version | |||
information. Derivative works need not be licensed under similar | information and do not falsely purport to be IETF RFC documents. | |||
terms. | Derivative works need not be licensed under similar terms. | |||
16. References | 16. References | |||
16.1. Normative References | 16.1. Normative References | |||
[1] Cerf, V., "ASCII format for network interchange", RFC 20, | [RFC0020] Cerf, V., "ASCII format for network interchange", RFC 20, | |||
October 1969. | October 1969. | |||
[2] Bradner, S., "Key words for use in RFCs to Indicate Requirement | [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate | |||
Levels", BCP 14, RFC 2119, March 1997. | Requirement Levels", BCP 14, RFC 2119, March 1997. | |||
16.2. Informative References | 16.2. Informative References | |||
[3] Linn, J., "Privacy Enhancement for Internet Electronic Mail: | [RFC1421] Linn, J., "Privacy Enhancement for Internet Electronic | |||
Part I: Message Encryption and Authentication Procedures", | Mail: Part I: Message Encryption and Authentication | |||
RFC 1421, February 1993. | Procedures", RFC 1421, February 1993. | |||
[4] Freed, N. and N. Borenstein, "Multipurpose Internet Mail | [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail | |||
Extensions (MIME) Part One: Format of Internet Message Bodies", | Extensions (MIME) Part One: Format of Internet Message | |||
RFC 2045, November 1996. | Bodies", RFC 2045, November 1996. | |||
[5] Callas, J., Donnerhacke, L., Finney, H., and R. Thayer, | [RFC2440] Callas, J., Donnerhacke, L., Finney, H., and R. Thayer, | |||
"OpenPGP Message Format", RFC 2440, November 1998. | "OpenPGP Message Format", RFC 2440, November 1998. | |||
[6] Eastlake, D., "Domain Name System Security Extensions", | [RFC2535] Eastlake, D., "Domain Name System Security Extensions", | |||
RFC 2535, March 1999. | RFC 2535, March 1999. | |||
[7] Klyne, G. and L. Masinter, "Identifying Composite Media | [RFC2938] Klyne, G. and L. Masinter, "Identifying Composite Media | |||
Features", RFC 2938, September 2000. | Features", RFC 2938, September 2000. | |||
[8] Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - VERSION | [RFC3501] Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - VERSION | |||
4rev1", RFC 3501, March 2003. | 4rev1", RFC 3501, March 2003. | |||
[9] Laurie, B., "DNSSEC Hash Authenticated Denial of Existence", | [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform | |||
draft-ietf-dnsext-nsec3-04 (work in progress), March 2006. | Resource Identifier (URI): Generic Syntax", STD 66, | |||
RFC 3986, January 2005. | ||||
[10] Myers, J., "SASL GSSAPI mechanisms", Work in | [I-D.ietf-dnsext-nsec3] | |||
Laurie, B., "DNSSEC Hash Authenticated Denial of | ||||
Existence", draft-ietf-dnsext-nsec3-04 (work in progress), | ||||
March 2006. | ||||
[draft-ietf-cat-sasl-gssapi-01] | ||||
Myers, J., "SASL GSSAPI mechanisms", Work in | ||||
progress draft-ietf-cat-sasl-gssapi-01, May 2000. | progress draft-ietf-cat-sasl-gssapi-01, May 2000. | |||
[11] Wilcox-O'Hearn, B., "Post to P2P-hackers mailing list", World | [mojonation] | |||
Wide Web http://zgp.org/pipermail/p2p-hackers/2001-September/ | Wilcox-O'Hearn, B., "Post to P2P-hackers mailing list", | |||
000315.html, September 2001. | World Wide Web http://zgp.org/pipermail/p2p-hackers/ | |||
2001-September/000315.html, September 2001. | ||||
Author's Address | Author's Address | |||
Simon Josefsson | Simon Josefsson | |||
SJD | SJD | |||
Email: simon@josefsson.org | Email: simon@josefsson.org | |||
Intellectual Property Statement | Full Copyright Statement | |||
Copyright (C) The IETF Trust (2006). | ||||
This document is subject to the rights, licenses and restrictions | ||||
contained in BCP 78, and except as set forth therein, the authors | ||||
retain all their rights. | ||||
This document and the information contained herein are provided on an | ||||
"AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS | ||||
OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND | ||||
THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS | ||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF | ||||
THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED | ||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. | ||||
Intellectual Property | ||||
The IETF takes no position regarding the validity or scope of any | The IETF takes no position regarding the validity or scope of any | |||
Intellectual Property Rights or other rights that might be claimed to | Intellectual Property Rights or other rights that might be claimed to | |||
pertain to the implementation or use of the technology described in | pertain to the implementation or use of the technology described in | |||
this document or the extent to which any license under such rights | this document or the extent to which any license under such rights | |||
might or might not be available; nor does it represent that it has | might or might not be available; nor does it represent that it has | |||
made any independent effort to identify any such rights. Information | made any independent effort to identify any such rights. Information | |||
on the procedures with respect to rights in RFC documents can be | on the procedures with respect to rights in RFC documents can be | |||
found in BCP 78 and BCP 79. | found in BCP 78 and BCP 79. | |||
skipping to change at page 29, line 28 | skipping to change at line 1237 | |||
attempt made to obtain a general license or permission for the use of | attempt made to obtain a general license or permission for the use of | |||
such proprietary rights by implementers or users of this | such proprietary rights by implementers or users of this | |||
specification can be obtained from the IETF on-line IPR repository at | specification can be obtained from the IETF on-line IPR repository at | |||
http://www.ietf.org/ipr. | http://www.ietf.org/ipr. | |||
The IETF invites any interested party to bring to its attention any | The IETF invites any interested party to bring to its attention any | |||
copyrights, patents or patent applications, or other proprietary | copyrights, patents or patent applications, or other proprietary | |||
rights that may cover technology that may be required to implement | rights that may cover technology that may be required to implement | |||
this standard. Please address the information to the IETF at | this standard. Please address the information to the IETF at | |||
ietf-ipr@ietf.org. | ietf-ipr@ietf.org. | |||
Disclaimer of Validity | ||||
This document and the information contained herein are provided on an | ||||
"AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS | ||||
OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET | ||||
ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, | ||||
INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE | ||||
INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED | ||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. | ||||
Copyright Statement | ||||
Copyright (C) The Internet Society (2006). This document is subject | ||||
to the rights, licenses and restrictions contained in BCP 78, and | ||||
except as set forth therein, the authors retain all their rights. | ||||
Acknowledgment | ||||
Funding for the RFC Editor function is currently provided by the | ||||
Internet Society. | ||||
End of changes. 40 change blocks. | ||||
97 lines changed or deleted | 155 lines changed or added | |||
This html diff was produced by rfcdiff 1.29, available from http://www.levkowetz.com/ietf/tools/rfcdiff/ |