4.3 Canonical Encoding
Any encryption scheme must be compatible with the transparency constraints of its underlying electronic mail facilities. These constraints are generally established based on expected user requirements and on the characteristics of anticipated endpoint transport facilities. SMTP, designed primarily for interpersonal messages and anticipating systems and transport media which may be restricted to a 7-bit character set, can transmit any 7-bit characters (but not arbitrary 8-bit binary data) in message text.
SMTP introduces other transparency constraints related to line lengths and message delimiters. Message text may not contain the string <CR><LF>.<CR><LF> in sequence before the end of a message, and must contain the string <CR><LF> at least every 1000 characters. Another important SMTP transparency issue must be noted. Although SMTP specifies a standard representation for line delimiters (ASCII <CR><LF>), numerous systems use a different native representation to delimit lines. For example, the <CR><LF> sequences delimiting lines in mail inbound to UNIX(tm) systems are transformed to single <LF>s as mail is written into local mailbox files. Lines in mail incoming to record-oriented systems (such as VAX VMS) may be converted to appropriate records by the destination SMTP [6] server. As a result, if the encryption process generated <CR>s or <LF>s, those characters might not be accessible to a recipient UA program at a destination using different line delimiting conventions. It is also possible that conversion between tabs and spaces may be performed in the course of mapping between inter-SMTP and local format; this is a matter of local option. If such transformations changed the form of transmitted ciphertext, decryption would fail to regenerate the transmitted plaintext, and a transmitted MAC would fail to compare with that computed at the destination.
The conversion performed by an SMTP server at a system with EBCDIC as a native character set has even more severe impact, since the conversion from EBCDIC into ASCII is an information-losing transformation. In principle, the transformation function mapping between inter-SMTP canonical ASCII message representation and local format could be moved from the SMTP server up to the UA, given a means to direct that the SMTP server should no longer perform that transformation. This approach has the disadvantage that it would imply internal file (e.g., mailbox) formats which would be incompatible with the systems on which they reside, an untenable prospect. Further, it would require modification to SMTP servers, as mail would be passed to SMTP in a different representation than it is passed at present.
Our approach to this problem selects a canonical character set, uniformly representable across privacy-enhanced UAs regardless of their systems' native character sets, to transport encrypted mail text (but not electronic mail transport headers!) between endpoints.
In this approach, an outbound privacy-enhanced message is transformed between four forms, in sequence:
- (Local_Form) The message text is created (e.g., via an editor) in the system's native character set, with lines delimited in accordance with local convention.
- (Canonicalize) The message text is converted to the universal canonical form, equivalent to the inter-SMTP representation as defined in RFC822 [7] (ASCII character set,
<CR><LF>line delimiters). (The processing required to perform this conversion is relatively small, at least on systems whose native character set is ASCII.) - (Encipher/Authenticate) A padded version of the canonical plaintext representation is created by appending zero-valued octets to the end of the representation until the length is an integral multiple of 8 octets, as is required to perform encryption in the DEA-1 CBC mode. No padding is applied if the canonical plaintext representation's length is already a multiple of 8 octets. This padded representation is used as the input to the encryption function and to the MAC computation function.
- (Encode to Printable Form) The bits resulting from the encryption operation are encoded into characters which are universally representable at all sites, though not necessarily with the same bit patterns (e.g., although the character "E" is represented in an ASCII-based system as hexadecimal 45 and as hexadecimal C5 in an EBCDIC-based system, the local significance of the two representations is equivalent). Use of a 64-character subset of International Alphabet IA5 is proposed, enabling 6 bits to be represented per printable character. (The proposed subset of characters is represented identically in IA5 and ASCII.) Two additional characters, "=" and "*", are used to signify special processing functions. The encoding function's output is delimited into text lines (using local conventions), with each line containing 64 printable characters. The encoding process is performed as follows, transforming strings of 3 arbitrary (8-bit) characters to strings of 4 encoded characters:
- 4a. Proceeding from left to right across the input characters (considered as a contiguous bitstring), each group of 6 bits is used as an index into an array of 64 printable characters; the character referenced by the index is placed in the output string. These characters, identified in Table 1, are selected so as to be universally representable, and the set excludes characters with particular significance to SMTP e.g., ".",
<CR>,<LF>). - 4b. If fewer than 3 input characters are available in a final quantum, zero bits are added (on the right) to form an integral number of 6-bit groups. Output character positions which are not required to represent actual input data are set to a 65th reserved, universally representable character ("="). Use of a reserved character for padding allows compensatory processing to be performed by a recipient, allowing the decoded message text's length to be precisely the same as the input message's length. A final 3-octet input quantum will be represented as a 4 octet encoding with no terminal "=", a 2-octet input quantum will be represented as 3 octets followed by one terminal "=", and a 1-octet input quantum will be represented as 2 octets followed by two occurrences of "=".
- 4a. Proceeding from left to right across the input characters (considered as a contiguous bitstring), each group of 6 bits is used as an index into an array of 64 printable characters; the character referenced by the index is placed in the output string. These characters, identified in Table 1, are selected so as to be universally representable, and the set excludes characters with particular significance to SMTP e.g., ".",
A sender may exclude one or more portions of a message from encryption/authentication processing. Explicit action is required to exclude a portion of a message from such processing; by default, encryption/authentication is applied to the entirety of message text. The user-level delimiter which specifies such exclusion is a local matter, and hence may vary between sender and recipient, but all systems should provide a means for unambiguous identification of areas excluded from encryption/authentication processing. An excluded area is represented in the inter-SMTP transmission form (universal across communicating systems) by bracketing with the reserved delimiter "". Cryptographic state is preserved transparently across an excluded area and continued after the end of the excluded area. A printable encoding quantum (per step 4b) is completed before the delimiter "" is output to initiate or terminate the representation of an excluded block. Note that the canonicalizing transformation (step 2 above) and the encoding to printable form (step 4 above) are applied to all portions of message text, even those excluded from encryption and authentication.
In summary, the outbound message is subjected to the following composition of transformations:
Transmit_Form = Encode(Encipher(Canonicalize(Local_Form)))
The inverse transformations are performed, in reverse order, to process inbound privacy-enhanced mail:
Local_Form = DeCanonicalize(Decipher(Decode(Transmit_Form)))
Note that the local form and the functions to transform messages to and from canonical form may vary between the sender and recipient systems without loss of information.
Value Encoding Value Encoding Value Encoding Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y (1) *
(1) The character "*" is used to delimit portions of an
encoded message to which encryption/authentication
processing has not been applied.
Printable Encoding Characters
Table 1